#include<stdio.h>
#include<string.h>
int main()
{
int M;
char str[60];
scanf("%d",&M);
while(M--)
{
int i,a=0,b=0,c=0,d=0,t,len;
scanf("%s",str);
len=strlen(str);
// if(len<8||len>16)
// {
// printf("NO\n");
// break;
// }
for(i=0;i<len;i++)
{
if(str[i]>='A'&&str[i]<='Z') a=1;
if(str[i]>='a'&&str[i]<='z') b=1;
if(str[i]>='0'&&str[i]<='9') c=1;
if(str[i]=='~'||str[i]=='!'||str[i]=='@'||str[i]=='#'||str[i]=='$'||str[i]=='%'||str[i]=='^') d=1;
}
t=a+b+c+d;
if(t>=3&&len>=8&&len<=16) printf("YES\n");
else printf("NO\n");
}
return 0;
}
#include<string.h>
int main()
{
int M;
char str[60];
scanf("%d",&M);
while(M--)
{
int i,a=0,b=0,c=0,d=0,t,len;
scanf("%s",str);
len=strlen(str);
// if(len<8||len>16)
// {
// printf("NO\n");
// break;
// }
for(i=0;i<len;i++)
{
if(str[i]>='A'&&str[i]<='Z') a=1;
if(str[i]>='a'&&str[i]<='z') b=1;
if(str[i]>='0'&&str[i]<='9') c=1;
if(str[i]=='~'||str[i]=='!'||str[i]=='@'||str[i]=='#'||str[i]=='$'||str[i]=='%'||str[i]=='^') d=1;
}
t=a+b+c+d;
if(t>=3&&len>=8&&len<=16) printf("YES\n");
else printf("NO\n");
}
return 0;
}