#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int i, j, k, t, flag1, flag2, flag3;
  char str[10];
  scanf("%d", &t);
  while (t--) {
    flag1 = 0;
    flag2 = 0;
    scanf("%s", str);
    for (i = 0; i < 5; i++) {
      if (str[i] <= 90 && str[i] >= 65) {
      } else {
        flag1 = 1;
      }
    }
    for (i = 5; i < 9; i++) {
      if (str[i] >= 48 && str[i] <= 57) {
      } else {
        flag2 = 1;
      }
    }
    flag3 = 0;
    if (str[9] >= 65 && str[9] <= 90) {
    } else
      flag3 = 1;
    if (flag1 == 0 && flag2 == 0 && flag3 == 0)
      printf("YES\n");
    else
      printf("NO\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     128a <main+0x16a>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x2a(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11c9 <main+0xa9>
movslq -0x8(%rbp),%rax
movsbl -0x2a(%rbp,%rax,1),%eax
cmp    $0x5a,%eax
jg     11af <main+0x8f>
movslq -0x8(%rbp),%rax
movsbl -0x2a(%rbp,%rax,1),%eax
cmp    $0x41,%eax
jl     11af <main+0x8f>
jmp    11b6 <main+0x96>
movl   $0x1,-0x18(%rbp)
jmp    11bb <main+0x9b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117c <main+0x5c>
movl   $0x5,-0x8(%rbp)
cmpl   $0x9,-0x8(%rbp)
jge    121d <main+0xfd>
movslq -0x8(%rbp),%rax
movsbl -0x2a(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jl     1203 <main+0xe3>
movslq -0x8(%rbp),%rax
movsbl -0x2a(%rbp,%rax,1),%eax
cmp    $0x39,%eax
jg     1203 <main+0xe3>
jmp    120a <main+0xea>
movl   $0x1,-0x1c(%rbp)
jmp    120f <main+0xef>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d0 <main+0xb0>
movl   $0x0,-0x20(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x41,%eax
jl     1243 <main+0x123>
movsbl -0x21(%rbp),%eax
cmp    $0x5a,%eax
jg     1243 <main+0x123>
jmp    124a <main+0x12a>
movl   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1279 <main+0x159>
cmpl   $0x0,-0x1c(%rbp)
jne    1279 <main+0x159>
cmpl   $0x0,-0x20(%rbp)
jne    1279 <main+0x159>
lea    0xd97(%rip),%rdi
call   1030 <printf@plt>
jmp    1285 <main+0x165>
lea    0xd8b(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xf1e(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x8(%rsp)
jae    1153 <main+0x33>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xef9(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xef3(%rip),%r12
lea    0xee9(%rip),%rbx
jmp    117c <main+0x5c>
nop
call   1030 <puts@plt>
subl   $0x1,0x8(%rsp)
jb     1145 <main+0x25>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movzbl 0x11(%rsp),%eax
movzbl 0x15(%rsp),%ecx
add    $0xd0,%al
add    $0xbf,%cl
mov    %r12,%rdi
cmp    $0x1a,%cl
jb     11a3 <main+0x83>
mov    %rbx,%rdi
movd   0xc(%rsp),%xmm0
cmp    $0xa,%al
movzwl 0x12(%rsp),%eax
movd   %eax,%xmm1
movd   0x10(%rsp),%xmm2
movdqa 0xe3e(%rip),%xmm4
movdqa %xmm4,%xmm3
pandn  %xmm2,%xmm3
pxor   %xmm5,%xmm5
punpcklbw %xmm5,%xmm0
pshuflw $0x6c,%xmm0,%xmm0
pshufd $0xc4,%xmm0,%xmm0
packuswb %xmm0,%xmm0
pand   %xmm4,%xmm0
por    %xmm3,%xmm0
movdqa 0xe20(%rip),%xmm3
pand   %xmm3,%xmm0
movd   0x14(%rsp),%xmm2
psllq  $0x28,%xmm2
pandn  %xmm2,%xmm3
por    %xmm0,%xmm3
movdqa 0xe11(%rip),%xmm2
pand   %xmm2,%xmm3
punpcklbw %xmm5,%xmm1
pshuflw $0xe1,%xmm1,%xmm0
pshufd $0x0,%xmm0,%xmm0
packuswb %xmm0,%xmm0
movdqa %xmm2,%xmm1
pandn  %xmm0,%xmm1
por    %xmm3,%xmm1
paddb  0xdf7(%rip),%xmm1
movdqa %xmm1,%xmm0
pminub 0xdfb(%rip),%xmm0
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%eax
cmovae %rbx,%rdi
xor    $0xff,%al
je     1170 <main+0x50>
mov    %rbx,%rdi
jmp    1170 <main+0x50>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"YES\0A\00"
@.str.3 = [4 x i8] c"NO\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [10 x i8]
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
br label %11
11: ; preds = %90, %0
%12 = load i32, i32* %5
%13 = add nsw i32 %12, -1
store i32 %13, i32* %5
%14 = icmp ne i32 %12, 0
br i1 %14, label %15, label %91
15: ; preds = %11
store i32 0, i32* %6
store i32 0, i32* %7
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 0, i32* %2
br label %18
18: ; preds = %38, %15
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 5
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp sle i32 %26, 90
br i1 %27, label %28, label %36
28: ; preds = %21
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp sge i32 %33, 65
br i1 %34, label %35, label %36
35: ; preds = %28
br label %37
36: ; preds = %28, %21
store i32 1, i32* %6
br label %37
37: ; preds = %36, %35
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %18
41: ; preds = %18
store i32 5, i32* %2
br label %42
42: ; preds = %62, %41
%43 = load i32, i32* %2
%44 = icmp slt i32 %43, 9
br i1 %44, label %45, label %65
45: ; preds = %42
%46 = load i32, i32* %2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp sge i32 %50, 48
br i1 %51, label %52, label %60
52: ; preds = %45
%53 = load i32, i32* %2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp sle i32 %57, 57
br i1 %58, label %59, label %60
59: ; preds = %52
br label %61
60: ; preds = %52, %45
store i32 1, i32* %7
br label %61
61: ; preds = %60, %59
br label %62
62: ; preds = %61
%63 = load i32, i32* %2
%64 = add nsw i32 %63, 1
store i32 %64, i32* %2
br label %42
65: ; preds = %42
store i32 0, i32* %8
%66 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 9
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp sge i32 %68, 65
br i1 %69, label %70, label %76
70: ; preds = %65
%71 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 9
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp sle i32 %73, 90
br i1 %74, label %75, label %76
75: ; preds = %70
br label %77
76: ; preds = %70, %65
store i32 1, i32* %8
br label %77
77: ; preds = %76, %75
%78 = load i32, i32* %6
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %88
80: ; preds = %77
%81 = load i32, i32* %7
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = load i32, i32* %8
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %83
%87 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %90
88: ; preds = %83, %80, %77
%89 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %90
90: ; preds = %88, %86
br label %11
91: ; preds = %11
%92 = load i32, i32* %1
ret i32 %92
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@str = [3 x i8] c"NO\00"
@str.4 = [4 x i8] c"YES\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %47, label %9
9: ; preds = %0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 9
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 4
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 6
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 8
%15 = bitcast [10 x i8]* %2 to <4 x i8>*
%16 = bitcast i8* %13 to <2 x i8>*
br label %17
17: ; preds = %9, %17
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%19 = load <4 x i8>, <4 x i8>* %15
%20 = load i8, i8* %11
%21 = load i8, i8* %12
%22 = add i8 %21, -48
%23 = icmp ult i8 %22, 10
%24 = load <2 x i8>, <2 x i8>* %16
%25 = load i8, i8* %14
%26 = insertelement <8 x i8> poison, i8 %20, i64 0
%27 = shufflevector <4 x i8> %19, <4 x i8> poison, <8 x i32> <i32 3, i32 2, i32 1, i32 0, i32 undef, i32 undef, i32 undef, i32 undef>
%28 = shufflevector <8 x i8> %26, <8 x i8> %27, <8 x i32> <i32 0, i32 8, i32 9, i32 10, i32 11, i32 undef, i32 undef, i32 undef>
%29 = insertelement <8 x i8> %28, i8 %25, i64 5
%30 = shufflevector <2 x i8> %24, <2 x i8> poison, <8 x i32> <i32 1, i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%31 = shufflevector <8 x i8> %29, <8 x i8> %30, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 8, i32 9>
%32 = freeze <8 x i8> %31
%33 = add <8 x i8> %32, <i8 -65, i8 -65, i8 -65, i8 -65, i8 -65, i8 -48, i8 -48, i8 -48>
%34 = icmp ugt <8 x i8> %33, <i8 25, i8 25, i8 25, i8 25, i8 25, i8 9, i8 9, i8 9>
%35 = load i8, i8* %10
%36 = add i8 %35, -65
%37 = icmp ult i8 %36, 26
%38 = bitcast <8 x i1> %34 to i8
%39 = icmp eq i8 %38, 0
%40 = select i1 %39, i1 %23, i1 false
%41 = select i1 %40, i1 %37, i1 false
%42 = select i1 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0)
%43 = call i32 @puts(i8* dereferenceable(1) %42)
%44 = load i32, i32* %1
%45 = add nsw i32 %44, -1
store i32 %45, i32* %1
%46 = icmp eq i32 %44, 0
br i1 %46, label %47, label %17
47: ; preds = %17, %0
ret i32 0
}