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.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class A {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

	void solve() throws IOException {
        int t = 1;
        while (t-- > 0) {
            solveTest();
        }
	}

    void solveTest() throws IOException {
        List<Character> x = new ArrayList<>();
        List<Character> y = new ArrayList<>();

        char[][] a = new char[2][2];
        char[][] b = new char[2][2];
        for(int i = 0; i < 2; i++) {
            char[] c = readString().toCharArray();
            for(int j = 0; j < 2; j++) {
                a[i][j] = c[j];
                if(c[j] != 'X') {
                    x.add(c[j]);
                }
            }
        }
        for(int i = 0; i < 2; i++) {
            char[] c = readString().toCharArray();
            for(int j = 0; j < 2; j++) {
                b[i][j] = c[j];
                if(c[j] != 'X') {
                    y.add(c[j]);
                }
            }
        }

        boolean ch = false;
        if(cmp(a, b)) ch = true;
        char[][] z = x(a);
        for(int i = 0; i < 100; i++) {
            if(cmp(z, b)) {
                ch = true;
            }
            z = x(z);
        }

        z = y(a);
        for(int i = 0; i < 100; i++) {
            if(cmp(z, b)) {
                ch = true;
            }
            z = y(z);
        }
        if(ch) out.println("YES");
        else out.println("NO");
    }

    char[][] pov(char[][] a) {
        char[][] res = new char[2][2];
        res[0][1] = a[0][0];
        res[1][1] = a[0][1];
        res[1][0] = a[1][1];
        res[0][0] = a[1][0];
        return res;
    }

    char[][] x(char[][] a) {
        char[][] res = new char[2][2];
        res[0][0] = a[0][0];
        res[0][1] = a[0][1];
        res[1][0] = a[1][0];
        res[1][1] = a[1][1];

        if(a[0][0] == 'X') {
            res[0][0] = a[0][1];
            res[0][1] = a[0][0];
        }
        if(a[0][1] == 'X') {
            res[0][1] = a[1][1];
            res[1][1] = a[0][1];
        }
        if(a[1][0] == 'X') {
            res[1][0] = a[0][0];
            res[0][0] = a[1][0];
        }
        if(a[1][1] == 'X') {
            res[1][1] = a[1][0];
            res[1][0] = a[1][1];
        }
        return res;
    }
    char[][] y(char[][] a) {
        char[][] res = new char[2][2];
        res[0][0] = a[0][0];
        res[0][1] = a[0][1];
        res[1][0] = a[1][0];
        res[1][1] = a[1][1];

        if(a[0][0] == 'X') {
            res[0][0] = a[1][0];
            res[1][0] = a[0][0];
        }
        if(a[0][1] == 'X') {
            res[0][1] = a[0][0];
            res[0][0] = a[0][1];
        }
        if(a[1][0] == 'X') {
            res[1][0] = a[1][1];
            res[1][1] = a[1][0];
        }
        if(a[1][1] == 'X') {
            res[1][1] = a[0][1];
            res[0][1] = a[1][1];
        }
        return res;
    }

    boolean cmp(char[][] a, char[][] b) {
        for(int i = 0; i < 2; i++) {
            for(int j = 0; j < 2; j++) {
                if(a[i][j] != b[i][j]) return false;
            }
        }
        return true;
    }

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

    public static void main(String[] args) {
        new A().run();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}