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.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.interfaces.DSAKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class a {

	public static class in {
		static BufferedReader reader;
		static StringTokenizer tokenizer;

		static void init(InputStream input) {
			reader = new BufferedReader(new InputStreamReader(input));
			tokenizer = new StringTokenizer("");
		}

		static String next() throws IOException {
			while (!tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(reader.readLine());
			return tokenizer.nextToken();
		}

		static int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		static double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		static long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}

	public static long comp(int n, int r) {
		r = Math.min(r, n - r);
		long ans = 1;
		for (int i = 1; i <= r; i++) {
			ans = ans * (long) (n - r + i) / (long) i;
		}
		return ans;

	}

	public static class node {

		long t;
		long d;
		int idx;

		node(long t, long d, int idx) {
			this.t = t;
			this.d = d;
			this.idx = idx;

		}

	}

	public static long gcd(int x, int y) {
		if (y == 0)
			return x;
		return gcd(y, x % y);
	}

	public static int z[];

	public static void Z_algorithm(char[] a, ArrayList<Long> arr) {
		z = new int[a.length];
		z[0] = a.length;
		int l = 0, r = 0;
		for (int i = 1; i < a.length; i++) {

			if (i > r) {
				l = r = i;

				while (r < a.length && a[r - l] == a[r]
						&& (long) arr.get(r - l) == (long) arr.get(r)) {

					r++;
				}

				z[i] = r - l;
				r--;
			} else {
				int k = i - l;
				if (z[k] < r - i + 1)
					z[i] = z[k];
				else {
					l = i;
					while (r < a.length && a[r - l] == a[r]
							&& (long) arr.get(r - l) == (long) arr.get(r))
						r++;
					z[i] = r - l;
					r--;
				}
			}

		}
	}

	public static long tree[];
	public static int n;

	public static void add(int idx, long val) {

		while (idx <= n) {
			tree[idx] += val;
			idx += (idx & -idx);
		}
	}

	public static long get(int idx) {
		long g = 0;
		while (idx > 0) {
			g += tree[idx];
			idx -= (idx & -idx);
		}
		return g;
	}

	public static String fin = "";
	public static HashSet<String> set = new HashSet();
	public static int dx[] = { 1, 0, 0, -1 };
	public static int dy[] = { 0, 1, -1, 0 };
	public static boolean ok = false;

	public static void solve(int i, int j, char a[][], String b) {
		if (b.equals(fin)) {
			ok = true;
			return;
		}
		if (ok)
			return;
		if (set.contains(b))
			return;
		set.add(b);

		for (int k = 0; k < 4; k++) {
			int x = i + dx[k];
			int y = j + dy[k];
			if (x < 0 || y < 0 || y == 2 || x == 2)
				continue;
			char temp = a[x][y];
			a[x][y] = a[i][j];
			a[i][j] = temp;
			String u = "";
			for (int l = 0; l < 2; l++) {
				for (int l2 = 0; l2 < 2; l2++) {
					u += a[l][l2];
				}
			}
			solve(x, y, a, u);
			temp = a[x][y];
			a[x][y] = a[i][j];
			a[i][j] = temp;
		}
	}

	public static void main(String[] args) throws IOException {
		StringBuilder qq = new StringBuilder();
		in.init(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// source code
		// String hostNamee = "http://";
		// System.out.println(hostNamee.length());
		char a[][] = new char[2][2];
		int i1 = 0;
		int j1 = 0;
		for (int i = 0; i < 2; i++) {
			String b = in.next();
			a[i] = b.toCharArray();
			for (int j = 0; j < 2; j++) {
				if (a[i][j] == 'X') {
					i1 = i;
					j1 = j;
				}
			}
		}

		for (int i = 0; i < 2; i++) {
			fin += in.next();
		}
		String u = "";
		for (int l = 0; l < 2; l++) {
			for (int l2 = 0; l2 < 2; l2++) {
				u += a[l][l2];
			}
		}

		solve(i1, j1, a, u);
		if (ok)
			System.out.println("YES");
		else
			System.out.println("NO");
		out.close();

	}
}