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>
const double EPS = 1e-24;
const long long mod = 1000000007ll;
const long long mod1 = 1000000009ll;
const long long mod2 = 1100000009ll;
const double PI = 3.14159265359;
int INF = 2147483645;
long long INFINF = 9223372036854775807;
template <class T>
T Max2(T a, T b) {
  return a < b ? b : a;
}
template <class T>
T Min2(T a, T b) {
  return a < b ? a : b;
}
template <class T>
T Max3(T a, T b, T c) {
  return Max2(Max2(a, b), c);
}
template <class T>
T Min3(T a, T b, T c) {
  return Min2(Min2(a, b), c);
}
template <class T>
T Max4(T a, T b, T c, T d) {
  return Max2(Max2(a, b), Max2(c, d));
}
template <class T>
T Min4(T a, T b, T c, T d) {
  return Min2(Min2(a, b), Max2(c, d));
}
using namespace std;
long long bit_count(long long _x) {
  long long _ret = 0;
  while (_x) {
    if (_x % 2 == 1) _ret++;
    _x /= 2;
  }
  return _ret;
}
long long bit(long long _mask, long long _i) {
  return (_mask & (1 << _i)) == 0 ? 0 : 1;
}
long long powermod(long long _a, long long _b, long long _m) {
  long long _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
long long add(long long a, long long b, long long m) {
  long long x = a + b;
  while (x >= m) x -= m;
  return x;
}
long long sub(long long a, long long b, long long m) {
  long long x = a - b;
  while (x < 0) x += m;
  return x;
}
long long mul(long long a, long long b, long long m) {
  long long x = a * b;
  x %= m;
  return x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int c = 0;
  string s[2], s1[2], a = "", b = "";
  cin >> s[0] >> s[1] >> s1[0] >> s1[1];
  for (int i = 0; i < 2; i++) {
    for (int j = i; j < i + 2; j++) {
      if (s[i][j % 2] != 'X') a += s[i][j % 2];
      if (s1[i][j % 2] != 'X') b += s1[i][j % 2];
    }
  }
  for (int i = 0; i < 3; i++) {
    if (a[i] == b[i]) {
      for (int j = i; j < i + 3; j++) {
        int k = j % 3;
        if (a[k] != b[k]) c++;
      }
      break;
    }
  }
  if (c == 0)
    cout << "YES";
  else
    cout << "NO";
}