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;
template <typename T>
inline T MAX(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
inline T MIN(T a, T b) {
  return a > b ? b : a;
}
template <typename T>
inline void SWAP(T &a, T &b) {
  T tp = a;
  a = b;
  b = tp;
}
template <typename T>
inline T GCD(T a, T b) {
  return b > 0 ? GCD(b, a % b) : a;
}
template <typename T>
inline void ADD_TO_VEC_int(T &n, vector<T> &vec) {
  vec.clear();
  cin >> n;
  for (int i = 0; i < n; i++) {
    T x;
    cin >> x, vec.push_back(x);
  }
}
template <typename T>
inline pair<T, T> MaxInVector_ll(vector<T> vec) {
  T MaxVal = -1e18, MaxId = 0;
  for (int i = 0; i < (int)vec.size(); i++)
    if (MaxVal < vec[i]) MaxVal = vec[i], MaxId = i;
  return {MaxVal, MaxId};
}
template <typename T>
inline pair<T, T> MinInVector_ll(vector<T> vec) {
  T MinVal = 1e18, MinId = 0;
  for (int i = 0; i < (int)vec.size(); i++)
    if (MinVal > vec[i]) MinVal = vec[i], MinId = i;
  return {MinVal, MinId};
}
template <typename T>
inline pair<T, T> MaxInVector_int(vector<T> vec) {
  T MaxVal = -0x7FFFFFFF, MaxId = 0;
  for (int i = 0; i < (int)vec.size(); i++)
    if (MaxVal < vec[i]) MaxVal = vec[i], MaxId = i;
  return {MaxVal, MaxId};
}
template <typename T>
inline pair<T, T> MinInVector_int(vector<T> vec) {
  T MinVal = 0x7FFFFFFF, MinId = 0;
  for (int i = 0; i < (int)vec.size(); i++)
    if (MinVal > vec[i]) MinVal = vec[i], MinId = i;
  return {MinVal, MinId};
}
template <typename T>
inline pair<map<T, T>, vector<T> > DIV(T n) {
  T nn = n;
  map<T, T> cnt;
  vector<T> div;
  for (long long i = 2; i * i <= nn; i++) {
    while (n % i == 0) {
      if (!cnt[i]) div.push_back(i);
      cnt[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    if (!cnt[n]) div.push_back(n);
    cnt[n]++;
    n /= n;
  }
  return {cnt, div};
}
vector<vector<char> > tgt;
vector<vector<char> > stt;
int flag = 0;
inline void DFS(vector<vector<char> > cur, int steps) {
  if (flag || steps >= 10) return;
  if (cur == tgt) {
    cout << "YES" << endl;
    flag = true;
    return;
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (cur[i][j] == 'X') {
        if (i == 0)
          SWAP(cur[i][j], cur[i + 1][j]), DFS(cur, steps + 1),
              SWAP(cur[i][j], cur[i + 1][j]);
        else if (i == 1)
          SWAP(cur[i][j], cur[i - 1][j]), DFS(cur, steps + 1),
              SWAP(cur[i][j], cur[i - 1][j]);
        if (j == 0)
          SWAP(cur[i][j], cur[i][j + 1]), DFS(cur, steps + 1),
              SWAP(cur[i][j], cur[i][j + 1]);
        else if (j == 1)
          SWAP(cur[i][j], cur[i][j - 1]), DFS(cur, steps + 1),
              SWAP(cur[i][j], cur[i][j - 1]);
      }
    }
  }
}
int main() {
  for (int i = 0; i < 2; i++) {
    vector<char> vec;
    for (int j = 0; j < 2; j++) {
      char x;
      cin >> x;
      vec.push_back(x);
    }
    tgt.push_back(vec);
  }
  for (int i = 0; i < 2; i++) {
    vector<char> vec;
    for (int j = 0; j < 2; j++) {
      char x;
      cin >> x;
      vec.push_back(x);
    }
    stt.push_back(vec);
  }
  DFS(stt, 0);
  if (!flag) cout << "NO" << endl;
  exit(0);
}