#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 */
char getchar();
char pro(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int t;
  char a, b, x, y, k;
  scanf("%i", &t);
  while (t--) {
    getchar();
    k = getchar();
    getchar();
    a = getchar();
    a = pro(a);
    x = getchar();
    getchar();
    b = getchar();
    b = pro(b);
    y = getchar();
    if (x == k) {
      puts("YES");
    } else if (y == k) {
      puts("NO");
    } else if (a > b) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1257 <main+0x117>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x19(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1060 <pro@plt>
mov    %al,-0x15(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x17(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x16(%rbp)
movsbl -0x16(%rbp),%edi
call   1060 <pro@plt>
mov    %al,-0x16(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x18(%rbp)
movsbl -0x17(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    11fa <main+0xba>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
jmp    1252 <main+0x112>
movsbl -0x18(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    121b <main+0xdb>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
jmp    124d <main+0x10d>
movsbl -0x15(%rbp),%eax
movsbl -0x16(%rbp),%ecx
cmp    %ecx,%eax
jle    123c <main+0xfc>
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
jmp    1248 <main+0x108>
lea    0xdc4(%rip),%rdi
call   1030 <puts@plt>
jmp    124d <main+0x10d>
jmp    1252 <main+0x112>
jmp    1166 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1174 <main+0x34>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe88(%rip),%r12
lea    0xe85(%rip),%r13
jmp    119c <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1030 <puts@plt>
subl   $0x1,0x4(%rsp)
jb     1163 <main+0x23>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
movsbl %al,%edi
call   1060 <pro@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
movsbl %al,%edi
call   1060 <pro@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %r12,%rdi
cmp    %r15b,%bl
je     1190 <main+0x50>
mov    %r13,%rdi
cmp    %r15b,%al
je     1190 <main+0x50>
cmp    %r14b,%bpl
mov    %r13,%rdi
cmovg  %r12,%rdi
jmp    1190 <main+0x50>

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [4 x i8] c"YES\00"
@.str.2 = [3 x i8] c"NO\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %13
13: ; preds = %57, %2
%14 = load i32, i32* %6
%15 = add nsw i32 %14, -1
store i32 %15, i32* %6
%16 = icmp ne i32 %14, 0
br i1 %16, label %17, label %58
17: ; preds = %13
%18 = call signext i8 (...) @getchar()
%19 = call signext i8 (...) @getchar()
store i8 %19, i8* %11
%20 = call signext i8 (...) @getchar()
%21 = call signext i8 (...) @getchar()
store i8 %21, i8* %7
%22 = load i8, i8* %7
%23 = call signext i8 @pro(i8 signext %22)
store i8 %23, i8* %7
%24 = call signext i8 (...) @getchar()
store i8 %24, i8* %9
%25 = call signext i8 (...) @getchar()
%26 = call signext i8 (...) @getchar()
store i8 %26, i8* %8
%27 = load i8, i8* %8
%28 = call signext i8 @pro(i8 signext %27)
store i8 %28, i8* %8
%29 = call signext i8 (...) @getchar()
store i8 %29, i8* %10
%30 = load i8, i8* %9
%31 = sext i8 %30 to i32
%32 = load i8, i8* %11
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %31, %33
br i1 %34, label %35, label %37
35: ; preds = %17
%36 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %57
37: ; preds = %17
%38 = load i8, i8* %10
%39 = sext i8 %38 to i32
%40 = load i8, i8* %11
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %39, %41
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %56
45: ; preds = %37
%46 = load i8, i8* %7
%47 = sext i8 %46 to i32
%48 = load i8, i8* %8
%49 = sext i8 %48 to i32
%50 = icmp sgt i32 %47, %49
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %55
53: ; preds = %45
%54 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53, %51
br label %56
56: ; preds = %55, %43
br label %57
57: ; preds = %56, %35
br label %13
58: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@.str.1 = [4 x i8] c"YES\00"
@.str.2 = [3 x i8] c"NO\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = load i32, i32* %3
%7 = add nsw i32 %6, -1
store i32 %7, i32* %3
%8 = icmp eq i32 %6, 0
br i1 %8, label %32, label %9
9: ; preds = %2, %26
%10 = call signext i8 (...) @getchar()
%11 = call signext i8 (...) @getchar()
%12 = call signext i8 (...) @getchar()
%13 = call signext i8 (...) @getchar()
%14 = call signext i8 @pro(i8 signext %13)
%15 = call signext i8 (...) @getchar()
%16 = call signext i8 (...) @getchar()
%17 = call signext i8 (...) @getchar()
%18 = call signext i8 @pro(i8 signext %17)
%19 = call signext i8 (...) @getchar()
%20 = icmp eq i8 %15, %11
br i1 %20, label %26, label %21
21: ; preds = %9
%22 = icmp eq i8 %19, %11
br i1 %22, label %26, label %23
23: ; preds = %21
%24 = icmp sgt i8 %14, %18
%25 = select i1 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br label %26
26: ; preds = %23, %21, %9
%27 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %21 ], [ %25, %23 ]
%28 = call i32 @puts(i8* dereferenceable(1) %27)
%29 = load i32, i32* %3
%30 = add nsw i32 %29, -1
store i32 %30, i32* %3
%31 = icmp eq i32 %29, 0
br i1 %31, label %32, label %9
32: ; preds = %26, %2
ret i32 0
}