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.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Artem Gilmudinov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        HashSet<String> set1 = new HashSet<>();
        HashSet<String> set2 = new HashSet<>();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[][] map1 = new char[2][2];
            for (int i = 0; i < 2; i++) {
                map1[i] = in.readLine().toCharArray();
            }
            char[][] map2 = new char[2][2];
            for (int i = 0; i < 2; i++) {
                map2[i] = in.readLine().toCharArray();
            }
            dfs(map1, set1);
            dfs(map2, set2);
            for (String res : set1) {
                if (set2.contains(res)) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");

        }

        public void dfs(char[][] a, HashSet<String> set) {
            String s = make(a);
            if (set.contains(s)) {
                return;
            }
            set.add(s);
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    if (a[i][j] == 'X') {
                        char[][] b = new char[2][2];
                        if (i - 1 >= 0) {
                            copy(a, b);
                            swap(b, i - 1, j, i, j);
                            dfs(b, set);
                        }
                        if (i + 1 < 2) {
                            copy(a, b);
                            swap(b, i + 1, j, i, j);
                            dfs(b, set);
                        }
                        if (j - 1 >= 0) {
                            copy(a, b);
                            swap(b, i, j - 1, i, j);
                            dfs(b, set);
                        }
                        if (j + 1 < 2) {
                            copy(a, b);
                            swap(b, i, j + 1, i, j);
                            dfs(b, set);
                        }
                    }
                }
            }
        }

        public String make(char[][] a) {
            String s = new String(a[0]) + new String(a[1]);
            return s;
        }

        public void swap(char[][] a, int x1, int y1, int x2, int y2) {
            char temp = a[x1][y1];
            a[x1][y1] = a[x2][y2];
            a[x2][y2] = temp;
        }

        public void copy(char[][] a, char[][] b) {
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[i].length; j++) {
                    b[i][j] = a[i][j];
                }
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

    }
}