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>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sign(T a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int dxK[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dyK[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dxKn[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int dyKn[] = {1, 2, 2, 1, -1, -2, -2, -1};
const int N = int(1e6) + 9;
const int M = int(1e3) + 9;
const int LOGN = 21;
const int SQN = 350;
const int MOD = int(1e9) + 7;
const int INF = 1e9 + 100;
const long long INF64 = 2e18;
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-9;
string a[2], b[2];
void f(string &s) {
  for (int i = 0; i < (int)(3); ++i) {
    string s2 = "";
    for (int j = 0; j < (int)(3); ++j) {
      s2 += s[(i + j) % 3];
    }
    if (s2[0] == 'A') {
      s = s2;
      return;
    }
  }
}
void solve() {
  for (int i = 0; i < (int)(2); ++i) cin >> a[i];
  for (int i = 0; i < (int)(2); ++i) cin >> b[i];
  string s1 = "", s2 = "";
  for (int i = 0; i < (int)(2); ++i)
    if (a[0][i] != 'X') s1 += a[0][i];
  for (int i = int(2) - 1; i >= 0; --i)
    if (a[1][i] != 'X') s1 += a[1][i];
  for (int i = 0; i < (int)(2); ++i)
    if (b[0][i] != 'X') s2 += b[0][i];
  for (int i = int(2) - 1; i >= 0; --i)
    if (b[1][i] != 'X') s2 += b[1][i];
  f(s1), f(s2);
  if (s1 == s2)
    cout << "YES";
  else
    cout << "NO";
}
int main() {
  srand(time(NULL));
  srand(time(NULL));
  cout << setprecision(10) << fixed;
  cerr << setprecision(10) << fixed;
  solve();
  return 0;
}