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;
long long sigma(long long n) { return (n * (n + 1) / 2); }
long long MOD(long long x) {
  if (x >= 0) return x;
  return (-x);
}
bool great(long long a, long long b) { return a > b; }
long long max3(long long a, long long b, long long c) {
  return (max(a, max(b, c)));
}
long long max4(long long a, long long b, long long c, long long d) {
  return (max(max(a, b), max(c, d)));
}
long long min3(long long a, long long b, long long c) {
  return (min(a, min(b, c)));
}
long long min4(long long a, long long b, long long c, long long d) {
  return (min(min(a, b), min(c, d)));
}
vector<long long> factors(long long x) {
  vector<long long> v;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      v.push_back(i);
      if (i != x / i) {
        v.push_back(x / i);
      }
    }
  }
  return v;
}
vector<long long> ispr;
vector<long long> min_prime;
unordered_map<long long, long long> prime_fact(long long x) {
  unordered_map<long long, long long> mp;
  while (x != 1) {
    mp[min_prime[x]]++;
    x /= min_prime[x];
  }
  return mp;
}
map<long long, long long> factorizee(long long n) {
  map<long long, long long> mp;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    mp[n]++;
  }
  return mp;
}
long long power(long long a, long long b, long long m) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2) {
      ans = (ans * a) % m;
    }
    a = (a * a) % m;
    b = b / 2;
  }
  return ans;
}
pair<long long, long long> doer(long long x, long long y) {
  pair<long long, long long> ff;
  if (x == 0 && y == 0) {
    ff.first = 1;
    ff.second = 0;
  }
  if (x == 0 && y == 1) {
    ff.first = 0;
    ff.second = 0;
  }
  if (x == 1 && y == 0) {
    ff.first = 1;
    ff.second = 1;
  }
  if (x == 1 && y == 1) {
    ff.first = 0;
    ff.second = 1;
  }
  return ff;
}
int main() {
  char mat[2][2][2][12];
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) {
      for (long long k = 0; k < 2; k++) {
        cin >> mat[j][k][i][0];
      }
    }
  }
  for (long long j = 0; j < 2; j++) {
    for (long long i = 1; i < 12; i++) {
      pair<long long, long long> xx;
      pair<long long, long long> tt;
      for (long long k = 0; k < 2; k++) {
        for (long long l = 0; l < 2; l++) {
          mat[k][l][j][i] = mat[k][l][j][i - 1];
          if (mat[k][l][j][i - 1] == 'X') {
            xx.first = k;
            xx.second = l;
            tt = doer(k, l);
          }
        }
      }
      swap(mat[xx.first][xx.second][j][i], mat[tt.first][tt.second][j][i]);
    }
  }
  for (long long i = 0; i < 12; i++) {
    for (long long j = 0; j < 12; j++) {
      bool ff = true;
      for (long long k = 0; k < 2; k++) {
        for (long long l = 0; l < 2; l++) {
          if (mat[k][l][0][i] != mat[k][l][1][j]) {
            ff = false;
          }
        }
      }
      if (ff) {
        cout << "YES" << endl;
        exit(0);
        ;
      }
    }
  }
  cout << "NO" << endl;
  exit(0);
  ;
}