Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:

In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
The first two lines of the input consist of a 2 × 2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2 × 2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.

In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...
AB
XC
XB
AC
YES
AB
XC
AC
BX
NO
XC
BA
CB
AX
NO
AB
XC
AX
CB
YES
CB
AX
XA
BC
YES
BC
XA
BA
XC
NO
CA
XB
BA
CX
NO
CA
XB
AC
BX
NO
CB
AX
CX
AB
YES
AX
CB
BC
XA
YES
CA
XB
BA
XC
NO
CX
AB
AX
CB
NO
AB
XC
AB
CX
YES
XC
BA
XC
AB
NO
BA
XC
AC
XB
YES
AX
BC
AC
BX
YES
XC
BA
CB
XA
NO
CB
AX
XC
BA
NO
AX
CB
BC
AX
YES
AB
XC
BX
AC
YES
XA
CB
BA
CX
NO
CX
BA
BX
AC
YES
AB
XC
XC
AB
NO
BA
CX
AC
BX
YES
XA
CB
AB
XC
YES
XC
BA
AC
BX
NO
CA
BX
BA
XC
NO
AX
BC
CA
XB
NO
BC
AX
XC
BA
YES
XB
AC
BX
AC
YES
CX
BA
AX
BC
NO
XB
CA
XC
BA
NO
BX
CA
XB
CA
YES
XB
AC
XC
A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
s=str(input())
s1=str(input())
s2=str(input())
s3=str(input())
e=''
f=''
flag=0
for i in range(0,len(s)):
    if(s[i]!='X'):
        e=e+s[i]
for i in range(0,len(s1)):
    if(s1[i]!='X'):
        f=f+s1[i]
print(e,f)
if((e=='AB' and f=='C') or (e=='BC' and f=='A') or (e=='CA' and f=='B') or (e=='A' and f=='CB') or (e=='B' and f=='AC')or(e=='C' and f=='BA')):
    pass
else:
    flag=1
if(flag==0):
    e=''
    f=''
    for i in range(0,len(s2)):
        if(s2[i]!='X'):
            e=e+s2[i]
    for i in range(0,len(s3)):
        if(s3[i]!='X'):
            f=f+s3[i]
    if(e=='AB' and f=='C' or (e=='BC' and f=='A') or (e=='CA' and f=='B') or (e=='A' and f=='CB') or (e=='B' and f=='AC')or(e=='C' and f=='BA')):
        pass
    else:
        flag=1
if(flag==0):
    print('NO')
else:
    print('YES')