Problem: 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:

<image>

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.

Input

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.

Output

Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).

Examples

Input

AB
XC
XB
AC


Output

YES


Input

AB
XC
AC
BX


Output

NO

Note

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...

Solution (in JAVA):

Solution:
import java.util.*;
import java.math.*;
import java.io.*;
public final class ccnov1
{
	public static void main(String args [])	throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out, true);
		String p1[][]=new String [2][2];
		String p2[][]=new String [2][2];
		String p3[][]=new String [2][2];
		String str[]=in.readLine().split("");
		String str2[]=in.readLine().split("");
		String str1[]=in.readLine().split("");
		String str3[]=in.readLine().split("");
		int a=0,b=0,c=0,d=0;
		//String a="",b="";
		for(int i=0; i<2; i++)
		{
			
			for(int j=0; j<2; j++)
			{
				if(i==0)
				{p1[i][j]=(str[j]);p2[i][j]=(str1[j]);}
				else
				{p1[i][j]=(str2[j]);p2[i][j]=(str3[j]);}
				if(p1[i][j].equals("A"))
				{a=i;b=j;}
				if(p2[i][j].equals("A"))
				{c=i;d=j;}
			}
		}
		String use=comb("",a,b,0,p1);
		String use2=comb("",c,d,0,p2);
		if(use.equalsIgnoreCase(use2))
		{pw.println("YES");}
		else
		{pw.println("NO");}
	}
	public static String comb(String ret,int i, int j, int n, String p1[][])
	{
		if(n==4)return ret;
		if(i==0 && j==0)
		{
			if(p1[i][j].equals("X"))ret=comb(ret,0,1,n+1,p1);
			else ret=comb(ret+p1[i][j],0,1,n+1,p1);
			//ret=ret+p1[i][j];
			return ret;
		}
		if(i==0 && j==1)
		{
			if(p1[i][j].equals("X"))ret=comb(ret,1,1,n+1,p1);
			else ret=comb(ret+p1[i][j],1,1,n+1,p1);
			//ret=ret+p1[i][j];
			return ret;
		}
		if(i==1 && j==1)
		{
			if(p1[i][j].equals("X"))ret=comb(ret,1,0,n+1,p1);
			else ret=comb(ret+p1[i][j],1,0,n+1,p1);
			//ret=ret+p1[i][j];
			return ret;
		}
		if(i==1 && j==0)
		{
			if(p1[i][j].equals("X"))ret=comb(ret,0,0,n+1,p1);
			else ret=comb(ret+p1[i][j],0,0,n+1,p1);
			//ret=ret+p1[i][j];
			return ret;
		}
	return null;
	}
}