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.Set;
import java.io.IOException;
import java.io.Reader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.io.StringReader;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

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

    static class TaskA {
        private final FastScanner in;
        private final PrintWriter out;

        public TaskA(FastScanner in, PrintWriter out) {
            this.in = in;
            this.out = out;
        }

        public void solve(int testNumber) throws IOException {
            String a = in.next() + in.next();
            String b = in.next() + in.next();

            List<String> verts = new ArrayList<>();
            char[] chars = {'A', 'B', 'C', 'X'};
            for (int i1 = 0; i1 < 4; i1++) {
                for (int i2 = 0; i2 < 4; i2++) {
                    for (int i3 = 0; i3 < 4; i3++) {
                        for (int i4 = 0; i4 < 4; i4++) {
                            char c1 = chars[i1];
                            char c2 = chars[i2];
                            char c3 = chars[i3];
                            char c4 = chars[i4];
                            Set<Character> set = new HashSet<>();
                            set.add(c1);
                            set.add(c2);
                            set.add(c3);
                            set.add(c4);
                            if (set.size() == 4) {
                                verts.add("" + c1 + c2 + c3 + c4);
                            }
                        }
                    }
                }
            }

            int n = verts.size();

            boolean[][] canMove = new boolean[n][n];
            for (int i = 0; i < n; i++) {
                nextV:
                for (int j = 0; j < n; j++) {
                    String u = verts.get(i);
                    String v = verts.get(j);
                    for (int s = 0; s < 4; s++) {
                        for (int t = 0; t < 4; t++) {
                            if (canMove(u, v, s, t)) {
                                canMove[i][j] = true;
                                continue nextV;
                            }
                        }
                    }
                }
            }

            for (int k = 0; k < n; k++) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        canMove[i][j] = canMove[i][j] || canMove[i][k] && canMove[k][j];
                    }
                }
            }

            int i = Collections.binarySearch(verts, a);
            int j = Collections.binarySearch(verts, b);

            out.println(canMove[i][j] ? "YES" : "NO");
        }

        boolean canMove(String u, String v, int s, int t) {
            int sx = s % 2;
            int sy = s / 2;
            int tx = t % 2;
            int ty = t / 2;

            if (sx != tx && sy != ty) {
                return false;
            }

            if (u.charAt(s) != 'X' && v.charAt(t) != 'X') {
                return false;
            }

            if (u.charAt(s) != v.charAt(t) || u.charAt(t) != v.charAt(s)) {
                return false;
            }

            for (int i = 0; i < 4; i++) {
                if (i != s && i != t) {
                    if (u.charAt(i) != v.charAt(i)) {
                        return false;
                    }
                }
            }

            return true;
        }

    }

    static class FastScanner {
        private final BufferedReader br;
        private String line;
        private int pos;

        public FastScanner(String s) throws IOException {
            this(new StringReader(s));
        }

        public FastScanner(InputStream is) throws IOException {
            this(new InputStreamReader(is, "UTF-8"));
        }

        public FastScanner(Reader reader) throws IOException {
            this(new BufferedReader(reader));
        }

        public FastScanner(BufferedReader reader) throws IOException {
            br = reader;
            line = br.readLine();
            pos = 0;
        }

        public String next() throws IOException {
            if (!skipWhitespace()) {
                return null;
            }

            int start = pos;

            while (pos < line.length()) {
                char c = line.charAt(pos);

                if (c == ' ' || c == '\t') {
                    break;
                }

                pos++;
            }

            return line.substring(start, pos);
        }

        private boolean skipWhitespace() throws IOException {
            while (line != null) {
                while (pos < line.length()) {
                    char c = line.charAt(pos);

                    if (c != ' ' && c != '\t') {
                        return true;
                    }

                    pos++;
                }

                line = br.readLine();
                pos = 0;
            }

            return false;
        }

    }
}