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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int mf[4] = {0, 1, 0, -1}, mc[4] = {1, 0, -1, 0};
int mk[100005], mt[5][5];
char a[5][5], b[5][5], ta[5][5], tb[5][5];
int v(char c) {
  if (c == 'A') return 1;
  if (c == 'B') return 2;
  if (c == 'C') return 3;
  return 4;
}
int main() {
  scanf("%s", a[1] + 1);
  scanf("%s", a[2] + 1);
  scanf("%s", b[1] + 1);
  scanf("%s", b[2] + 1);
  int f, c;
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= 2; j++) {
      if (a[i][j] == 'X') f = i, c = j;
      ta[i][j] = a[i][j];
    }
  }
  int tf = f, tc = c;
  int dir = 0, mv = 3;
  while (mv--) {
    int nf, nc;
    mt[f][c] = 1;
    do {
      nf = f + mf[dir];
      nc = c + mc[dir];
      dir = (dir + 1) % 4;
    } while (nf < 1 || nf > 2 || nc < 1 || nc > 2 || mt[nf][nc]);
    swap(a[f][c], a[nf][nc]);
    int h = v(a[1][1]) + v(a[1][2]) * 10 + v(a[2][1]) * 100 + v(a[2][2]) * 1000;
    mk[h] = 1;
    f = nf, c = nc;
  }
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= 2; j++) a[i][j] = ta[i][j];
  memset(mt, 0, sizeof(mt));
  f = tf, c = tc;
  dir = 3, mv = 3;
  while (mv--) {
    int nf, nc;
    mt[f][c] = 1;
    do {
      nf = f + mf[dir];
      nc = c + mc[dir];
      dir = (dir - 1 + 4) % 4;
    } while (nf < 1 || nf > 2 || nc < 1 || nc > 2 || mt[nf][nc]);
    swap(a[f][c], a[nf][nc]);
    int h = v(a[1][1]) + v(a[1][2]) * 10 + v(a[2][1]) * 100 + v(a[2][2]) * 1000;
    mk[h] = 1;
    f = nf, c = nc;
  }
  memset(mt, 0, sizeof(mt));
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= 2; j++) {
      if (b[i][j] == 'X') f = i, c = j;
      tb[i][j] = b[i][j];
    }
  dir = 0, mv = 3;
  tf = f, tc = c;
  while (mv--) {
    int nf, nc;
    mt[f][c] = 1;
    do {
      nf = f + mf[dir];
      nc = c + mc[dir];
      dir = (dir + 1) % 4;
    } while (nf < 1 || nf > 2 || nc < 1 || nc > 2 || mt[nf][nc]);
    swap(b[f][c], b[nf][nc]);
    int h = v(b[1][1]) + v(b[1][2]) * 10 + v(b[2][1]) * 100 + v(b[2][2]) * 1000;
    if (mk[h]) {
      printf("YES\n");
      return 0;
    }
    f = nf, c = nc;
  }
  f = tf, c = tc;
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= 2; j++) b[i][j] = tb[i][j];
  memset(mt, 0, sizeof(mt));
  dir = 3, mv = 3;
  while (mv--) {
    int nf, nc;
    mt[f][c] = 1;
    do {
      nf = f + mf[dir];
      nc = c + mc[dir];
      dir = (dir - 1 + 4) % 4;
    } while (nf < 1 || nf > 2 || nc < 1 || nc > 2 || mt[nf][nc]);
    swap(b[f][c], b[nf][nc]);
    int h = v(b[1][1]) + v(b[1][2]) * 10 + v(b[2][1]) * 100 + v(b[2][2]) * 1000;
    if (mk[h]) {
      printf("YES\n");
      return 0;
    }
    f = nf, c = nc;
  }
  printf("NO\n");
  return 0;
}