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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Arthur Gazizov  [2oo7] - Kazan FU
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void swap(char[][] a, int i1, int j1, int i2, int j2) {
            char temp = a[i1][j1];
            a[i1][j1] = a[i2][j2];
            a[i2][j2] = temp;
        }

        public boolean check(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;
        }

        public void solve(int testNumber, FastScanner in, FastPrinter out) {
            char[][] a = new char[2][];
            for (int i = 0; i < 2; i++) {
                a[i] = in.next().toCharArray();
            }
            char[][] t = new char[2][];
            for (int i = 0; i < 2; i++) {
                t[i] = in.next().toCharArray();
            }
            int last = 0;
            if (t[0][0] == 'X') last = 0;
            if (t[0][1] == 'X') last = 1;
            if (t[1][1] == 'X') last = 2;
            if (t[1][0] == 'X') last = 3;
            boolean ok = false;
            for (int i = 0; i < 100; i++) {
                if (last == 0) {
                    swap(t, 0, 0, 0, 1);
                    last = 1;
                    if (check(a, t)) {
                        ok = true;
                    }
                } else if (last == 1) {
                    swap(t, 0, 1, 1, 1);
                    last = 2;
                    if (check(a, t)) {
                        ok = true;
                    }
                } else if (last == 2) {
                    swap(t, 1, 1, 1, 0);
                    last = 3;
                    if (check(a, t)) {
                        ok = true;
                    }
                } else if (last == 3) {
                    swap(t, 1, 0, 0, 0);
                    last = 0;
                    if (check(a, t)) {
                        ok = true;
                    }
                }
            }
            out.printYES_NO(ok);
        }

    }

    static class FastScanner extends BufferedReader {
        boolean isEOF;

        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public FastScanner(InputStreamReader inputStreamReader) {
            super(inputStreamReader);
        }

        public int read() {
            try {
                int ret = super.read();
                if (isEOF && ret < 0) {
                    throw new InputMismatchException();
                }
                isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            while (!isWhiteSpace(c)) {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        public static boolean isWhiteSpace(int c) {
            return c >= -1 && c <= 32;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(Writer writer) {
            super(writer);
        }

        public FastPrinter(OutputStream out) {
            super(out);
        }

        public void printYES_NO(boolean condition) {
            print(condition ? "YES" : "NO");
        }

        public void close() {
            super.close();
        }

    }
}