#include <bits/stdc++.h>
using namespace std;
vector<string> f, s;
int main() {
  f.resize(2);
  cin >> f[0] >> f[1];
  s.resize(2);
  cin >> s[0] >> s[1];
  reverse(f[1].begin(), f[1].end());
  reverse(s[1].begin(), s[1].end());
  string fs = f[0] + f[1];
  string ss = s[0] + s[1];
  int cnt = 0;
  string fres;
  for (int i = 0; cnt != 2; i = (i + 1) % fs.size()) {
    if (fs[i] == 'A') {
      ++cnt;
      if (cnt == 2) {
        break;
      }
    }
    if (cnt && fs[i] != 'X') {
      fres += fs[i];
    }
  }
  cnt = 0;
  string sres;
  for (int i = 0; cnt != 2; i = (i + 1) % ss.size()) {
    if (ss[i] == 'A') {
      ++cnt;
      if (cnt == 2) {
        break;
      }
    }
    if (cnt && ss[i] != 'X') {
      sres += ss[i];
    }
  }
  if (fres == sres) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
