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.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P645A {
  final static int [] CODES = { 6939,  6957,  6966,  6987,  7026,  7032,  7053,  7059,  7068,  7110,  7137,  7140,  7710,
                                7719,  7737,  7758,  7779,  7788,  7815,  7857,  7860,  7881,  7890,  7896, 10023, 10041,
                               10062, 10083, 10092, 10119, 10161, 10164, 10185, 10194, 10200, 11565, 11574, 11595, 11634,
                               11640, 11661, 11667, 11676, 11718, 11745, 11748, 13878, 13899, 13938, 13944, 13965, 13971,
                               13980, 14022, 14049, 14052, 14649, 14670, 14691, 14700, 14727, 14769, 14772, 14793, 14802,
                               14808, 19275, 19314, 19320, 19341, 19347, 19356, 19398, 19425, 19428, 20046, 20067, 20076,
                               20103, 20145, 20148, 20169, 20178, 20184, 25443, 25452, 25479, 25521, 25524, 25545, 25554,
                               25560, 27756, 27783, 27825, 27828, 27849, 27858, 27864, 29298, 29304, 29325, 29331, 29340,
                               29382, 29409, 29412, 30840, 30861, 30867, 30876, 30918, 30945, 30948, 34695, 34737, 34740,
                               34761, 34770, 34776, 36237, 36243, 36252, 36294, 36321, 36324, 37779, 37788, 37830, 37857,
                               37860, 40092, 40134, 40161, 40164, 45489, 45492, 45513, 45522, 45528, 46260, 46281, 46290,
                               46296, 50886, 50913, 50916, 51657, 51666, 51672, 53970, 53976, 55512, 57825, 57828, 58596 };

  public void run() throws Exception {
    int code = 0;
    for (char c : (next() + next() + next() + next()).toCharArray()) {
      code = (code << 2) | ((c == 'X') ? 0b00 : ((c == 'A') ? 0b01 : ((c == 'B') ? 0b10 : 0b11)));
    }
    println((Arrays.binarySearch(CODES, (Math.min(code >> 8, code & 0xff) << 8) |
                                         Math.max(code >> 8, code & 0xff)) >= 0) ? "YES" : "NO");
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P645A().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}