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>
T& input(T& v) {
  for (int i = 0; i < v.size(); i++) cin >> v[i];
  return v;
}
template <typename T>
T& input_2d(T& v) {
  int N = v.size();
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < v[i].size(); j++) cin >> v[i][j];
  }
}
template <typename T>
T& input_pair(T& v) {
  for (int i = 0; i < v.size(); i++) cin >> v[i].first >> v[i].second;
  return v;
}
template <typename T>
void print(const T& v) {
  int N = v.size();
  for (int i = 0; i < N; i++) cout << v[i] << " ";
  cout << '\n';
}
template <typename T>
void print_2d(T& v) {
  int N = v.size();
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < v[i].size(); j++) cout << v[i][j] << " ";
    cout << '\n';
  }
}
template <typename T>
void print_pair(const T& v) {
  int N = v.size();
  for (int i = 0; i < N; i++) cout << v[i].first << " " << v[i].second << '\n';
}
template <typename T>
inline int digits(const T& N) {
  return (N > 0 ? (int)((log10(N)) + 1) : 1);
}
inline bool ispoweroftwo(int x) { return (x && (!(x & (x - 1)))); }
bool if_integer(double x) {
  if (x - floor(x) == 0 && x > 0)
    return true;
  else
    return false;
}
int binomial(int n, int k) {
  vector<int> C(k + 1, 0);
  C[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1];
  }
  return C[k];
}
inline double distance(int a, int b, int c, int d) {
  return sqrt(((long long)(a - c)) * (a - c) + ((long long)(b - d)) * (b - d));
}
class compare {
  bool operator()(pair<int, int>& p1, pair<int, int>& p2) {
    if (p1.first == p2.first) return p1.second > p2.second;
    return p1.first > p2.first;
  }
};
bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first == b.first) return (a.second < b.second);
  return (a.first > b.first);
}
bool mysort(const vector<int>& a, const vector<int>& b) {
  return (a.size() < b.size());
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<string> s(4);
  input(s);
  vector<int> v(4), v2(4);
  int m = 0, k1, k2;
  for (int i = 0; i < 2; i++) {
    int j = 0, k;
    if (i == 0) {
      j = 0;
      k = 1;
    } else {
      j = 1;
      k = -1;
    }
    for (; j >= 0 && j < 2; j = j + k) {
      if (s[i][j] == 'X') v[m] = 0;
      if (s[i][j] == 'A') {
        v[m] = 1;
        k1 = m;
      }
      if (s[i][j] == 'B') v[m] = 2;
      if (s[i][j] == 'C') v[m] = 3;
      m++;
    }
  }
  m = 0;
  for (int i = 2; i < 4; i++) {
    int j = 0, k;
    if (i == 2) {
      j = 0;
      k = 1;
    } else {
      j = 1;
      k = -1;
    }
    for (; j >= 0 && j < 2; j = j + k) {
      if (s[i][j] == 'X') v2[m] = 0;
      if (s[i][j] == 'A') {
        v2[m] = 1;
        k2 = m;
      }
      if (s[i][j] == 'B') v2[m] = 2;
      if (s[i][j] == 'C') v2[m] = 3;
      m++;
    }
  }
  int k = 0;
  for (int i = 0; i < 3; i++) {
    if (v[k1] == 0) k1++;
    if (v2[k2] == 0) k2++;
    if (k1 > 3) k1 = 0;
    if (k2 > 3) k2 = 0;
    if (v[k1] == v2[k2]) k++;
    k1++;
    k2++;
    if (k1 > 3) k1 = 0;
    if (k2 > 3) k2 = 0;
  }
  if (k == 3) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}