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.*;

import static java.lang.Math.*;


public class Main {
    FastScanner in;
    PrintWriter out;

    static final String FILE = "";

    TreeSet<String> set = new TreeSet<>();
    TreeSet<String> set2 = new TreeSet<>();
    boolean can = false;

    void calc(String s) {
        int x = s.indexOf('X');
        if (set.contains(s))
            return;
        set.add(s);

        char tmp;

        if (x == 0) {
            StringBuffer buffer1 = new StringBuffer(s);
            tmp = s.charAt(1);
            buffer1.setCharAt(x, tmp);
            buffer1.setCharAt(1, 'X');
            calc(buffer1.toString());

            StringBuffer buffer2 = new StringBuffer(s);
            tmp = s.charAt(2);
            buffer2.setCharAt(x, tmp);
            buffer2.setCharAt(2, 'X');
            calc(buffer2.toString());
        } else if (x == 1) {
            StringBuffer buffer1 = new StringBuffer(s);
            tmp = s.charAt(0);
            buffer1.setCharAt(x, tmp);
            buffer1.setCharAt(0, 'X');
            calc(buffer1.toString());

            StringBuffer buffer2 = new StringBuffer(s);
            tmp = s.charAt(3);
            buffer2.setCharAt(x, tmp);
            buffer2.setCharAt(3, 'X');
            calc(buffer2.toString());
        } else if (x == 2) {
            StringBuffer buffer1 = new StringBuffer(s);
            tmp = s.charAt(0);
            buffer1.setCharAt(x, tmp);
            buffer1.setCharAt(0, 'X');
            calc(buffer1.toString());

            StringBuffer buffer2 = new StringBuffer(s);
            tmp = s.charAt(3);
            buffer2.setCharAt(x, tmp);
            buffer2.setCharAt(3, 'X');
            calc(buffer2.toString());
        } else if (x == 3) {
            StringBuffer buffer1 = new StringBuffer(s);
            tmp = s.charAt(1);
            buffer1.setCharAt(x, tmp);
            buffer1.setCharAt(1, 'X');
            calc(buffer1.toString());

            StringBuffer buffer2 = new StringBuffer(s);
            tmp = s.charAt(2);
            buffer2.setCharAt(x, tmp);
            buffer2.setCharAt(2, 'X');
            calc(buffer2.toString());
        }
    }

    void find(String s) {
        if (can)
            return;
        int x = s.indexOf('X');
        if (set.contains(s)) {
            can = true;
            return;
        }
        if (set2.contains(s))
            return;
        set2.add(s);

        char tmp;

        if (x == 0) {
            StringBuffer buffer1 = new StringBuffer(s);
            tmp = s.charAt(1);
            buffer1.setCharAt(x, tmp);
            buffer1.setCharAt(1, 'X');
            find(buffer1.toString());

            StringBuffer buffer2 = new StringBuffer(s);
            tmp = s.charAt(2);
            buffer2.setCharAt(x, tmp);
            buffer2.setCharAt(2, 'X');
            find(buffer2.toString());
        } else if (x == 1) {
            StringBuffer buffer1 = new StringBuffer(s);
            tmp = s.charAt(0);
            buffer1.setCharAt(x, tmp);
            buffer1.setCharAt(0, 'X');
            find(buffer1.toString());

            StringBuffer buffer2 = new StringBuffer(s);
            tmp = s.charAt(3);
            buffer2.setCharAt(x, tmp);
            buffer2.setCharAt(3, 'X');
            find(buffer2.toString());
        } else if (x == 2) {
            StringBuffer buffer1 = new StringBuffer(s);
            tmp = s.charAt(0);
            buffer1.setCharAt(x, tmp);
            buffer1.setCharAt(0, 'X');
            find(buffer1.toString());

            StringBuffer buffer2 = new StringBuffer(s);
            tmp = s.charAt(3);
            buffer2.setCharAt(x, tmp);
            buffer2.setCharAt(3, 'X');
            find(buffer2.toString());
        } else if (x == 3) {
            StringBuffer buffer1 = new StringBuffer(s);
            tmp = s.charAt(1);
            buffer1.setCharAt(x, tmp);
            buffer1.setCharAt(1, 'X');
            find(buffer1.toString());

            StringBuffer buffer2 = new StringBuffer(s);
            tmp = s.charAt(2);
            buffer2.setCharAt(x, tmp);
            buffer2.setCharAt(2, 'X');
            find(buffer2.toString());
        }
    }

    public void solve() {
        String a = in.next() + in.next();
        String b = in.next() + in.next();
        calc(a);
        find(b);

        if (can)
            out.println("YES");
        else
            out.println("NO");
    }

    public void run() {
        if (FILE.equals("")) {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
        } else {
            try {
                in = new FastScanner(new FileInputStream(FILE +
                        ".in"));
                out = new PrintWriter(new FileOutputStream(FILE +
                        ".out"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        solve();
        out.close();
    }

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

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public float nextFloat() {
            return Float.parseFloat(next());
        }
    }

    class Pair<A extends Comparable<A>, B extends Comparable<B>>
            implements Comparable<Pair<A, B>> {
        public A a;
        public B b;

        public Pair(A a, B b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair<A, B> o) {
            if (o == null || o.getClass() != getClass())
                return 1;
            int cmp = a.compareTo(o.a);
            if (cmp == 0)
                return b.compareTo(o.b);
            return cmp;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;

            if (a != null ? !a.equals(pair.a) : pair.a != null) return
                    false;
            return !(b != null ? !b.equals(pair.b) : pair.b != null);
        }
    }

    class PairInt extends Pair<Integer, Integer> {
        public PairInt(Integer u, Integer v) {
            super(u, v);
        }
    }

    class PairLong extends Pair<Long, Long> {
        public PairLong(Long u, Long v) {
            super(u, v);
        }
    }

}