#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::set;
using std::swap;
using std::vector;
void TaskA() {
  vector<char> first;
  vector<char> second;
  char a;
  int f, s;
  for (int i = 0; i < 4; i++) {
    cin >> a;
    first.push_back(a);
    if (a == 'A') f = i;
  }
  swap(first[2], first[3]);
  if (f == 2)
    f = 3;
  else if (f == 3)
    f = 2;
  for (int i = 0; i < 4; i++) {
    cin >> a;
    second.push_back(a);
    if (a == 'A') s = i;
  }
  swap(second[2], second[3]);
  if (s == 2)
    s = 3;
  else if (s == 3)
    s = 2;
  if (first[(f + 1) % 4] == 'X') f = (f + 1) % 4;
  if (second[(s + 1) % 4] == 'X') s = (s + 1) % 4;
  if (first[(f + 1) % 4] == second[(s + 1) % 4])
    cout << "YES";
  else
    cout << "NO";
}
int main() {
  TaskA();
  return 0;
}
