#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 *, ...);
scalar_t__ strcmp(char *, char *);
int main() {
  int i, j, c, len, num, temp, t, res, flag;
  char front[10], back[10], left[10], right[10], top[10], bottom[10];
  scanf("%d", &t);
  while (t--) {
    flag = 0;
    scanf("%s %s %s %s %s %s", front, back, left, right, top, bottom);
    if (strcmp(top, left) == 0 || strcmp(bottom, left) == 0) {
      if (strcmp(left, front) == 0 || strcmp(left, back) == 0)
        flag = 1;
    }
    if (strcmp(top, right) == 0 || strcmp(bottom, right) == 0) {
      if (strcmp(right, front) == 0 || strcmp(right, back) == 0)
        flag = 1;
    }
    if (flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
je     1292 <main+0x162>
movl   $0x0,-0x28(%rbp)
lea    -0x32(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x46(%rbp),%rcx
lea    -0x50(%rbp),%r8
lea    -0x5a(%rbp),%r9
lea    -0x64(%rbp),%rax
lea    0xe78(%rip),%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x5a(%rbp),%rdi
lea    -0x46(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11c4 <main+0x94>
lea    -0x64(%rbp),%rdi
lea    -0x46(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11fe <main+0xce>
lea    -0x46(%rbp),%rdi
lea    -0x32(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11f2 <main+0xc2>
lea    -0x46(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f9 <main+0xc9>
movl   $0x1,-0x28(%rbp)
jmp    11fe <main+0xce>
lea    -0x5a(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     122c <main+0xfc>
lea    -0x64(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1266 <main+0x136>
lea    -0x50(%rbp),%rdi
lea    -0x32(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     125a <main+0x12a>
lea    -0x50(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1261 <main+0x131>
movl   $0x1,-0x28(%rbp)
jmp    1266 <main+0x136>
cmpl   $0x0,-0x28(%rbp)
je     1281 <main+0x151>
lea    0xd9e(%rip),%rdi
call   1030 <printf@plt>
jmp    128d <main+0x15d>
lea    0xd92(%rip),%rdi
call   1030 <printf@plt>
jmp    1151 <main+0x21>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xebb(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0x8(%rsp)
jae    1169 <main+0x39>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x16(%rsp),%r15
lea    0x3e(%rsp),%r13
lea    0x34(%rsp),%rbx
lea    0x2a(%rsp),%rbp
lea    0x20(%rsp),%r14
jmp    11a3 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
subl   $0x1,0x8(%rsp)
jb     1158 <main+0x28>
mov    %r15,(%rsp)
lea    0xe55(%rip),%rdi
mov    %r13,%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e9 <main+0xb9>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
mov    $0x1,%r12b
test   %rax,%rax
jne    1211 <main+0xe1>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     120e <main+0xde>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1040 <strcmp@plt>
mov    $0x1,%r12b
test   %rax,%rax
jne    1211 <main+0xe1>
xor    %r12d,%r12d
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1250 <main+0x120>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1250 <main+0x120>
lea    0xde0(%rip),%rdi
test   %r12b,%r12b
jne    1190 <main+0x60>
jmp    1197 <main+0x67>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r13,%rsi
call   1040 <strcmp@plt>
lea    0xdb6(%rip),%rdi
test   %rax,%rax
je     1197 <main+0x67>
mov    %rbp,%rdi
lea    0xc(%rsp),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
setne  %al
lea    0xd93(%rip),%rdi
test   %al,%r12b
jne    1190 <main+0x60>
jmp    1197 <main+0x67>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [18 x i8] c"%s %s %s %s %s %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 = alloca [10 x i8]
%4 = alloca [10 x i8]
%5 = alloca [10 x i8]
%6 = alloca [10 x i8]
%7 = alloca [10 x i8]
%8 = bitcast i32* %1 to i8*
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%16 = load i32, i32* %1
%17 = add nsw i32 %16, -1
store i32 %17, i32* %1
%18 = icmp eq i32 %16, 0
br i1 %18, label %55, label %19
19: ; preds = %0, %49
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10, i8* %11, i8* %12, i8* %13, i8* %14)
%21 = call i64 @strcmp(i8* %13, i8* %11)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = call i64 @strcmp(i8* %14, i8* %11)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23, %19
%27 = call i64 @strcmp(i8* %11, i8* %9)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i64 @strcmp(i8* %11, i8* %10)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29, %26
br label %33
33: ; preds = %29, %32, %23
%34 = phi i1 [ true, %29 ], [ false, %32 ], [ true, %23 ]
%35 = call i64 @strcmp(i8* %13, i8* %12)
%36 = icmp eq i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = call i64 @strcmp(i8* %14, i8* %12)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %37, %33
%41 = call i64 @strcmp(i8* %12, i8* %9)
%42 = icmp eq i64 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %40
%44 = call i64 @strcmp(i8* %12, i8* %10)
%45 = icmp ne i64 %44, 0
%46 = and i1 %34, %45
br i1 %46, label %48, label %49
47: ; preds = %37
br i1 %34, label %48, label %49
48: ; preds = %43, %47
br label %49
49: ; preds = %47, %40, %43, %48
%50 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0), %48 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0), %43 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0), %40 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0), %47 ]
%51 = call i32 @puts(i8* dereferenceable(1) %50)
%52 = load i32, i32* %1
%53 = add nsw i32 %52, -1
store i32 %53, i32* %1
%54 = icmp eq i32 %52, 0
br i1 %54, label %55, label %19
55: ; preds = %49, %0
ret i32 0
}