#include <bits/stdc++.h>
bool visited[5][5][5][5];
char T[5][5], Ans[5][5];
int gen(char a) {
  if (a >= 'A' && a <= 'C')
    return a - 'A';
  else
    return 3;
}
bool rec(int a, int b, int c, int d) {
  visited[a][b][c][d] = true;
  if (a == gen(Ans[0][0]) && b == gen(Ans[0][1]) && c == gen(Ans[1][0]) &&
      d == gen(Ans[1][1]))
    return 1;
  if (a == 3) {
    if (!visited[b][a][c][d] && rec(b, a, c, d)) return 1;
    if (!visited[c][b][a][d] && rec(c, b, a, d)) return 1;
  } else if (b == 3) {
    if (!visited[b][a][c][d] && rec(b, a, c, d)) return 1;
    if (!visited[a][d][c][b] && rec(a, d, c, b)) return 1;
  } else if (c == 3) {
    if (!visited[c][b][a][d] && rec(c, b, a, d)) return 1;
    if (!visited[a][b][d][c] && rec(a, b, d, c)) return 1;
  } else if (d == 3) {
    if (!visited[a][d][c][b] && rec(a, d, c, b)) return 1;
    if (!visited[a][b][d][c] && rec(a, b, d, c)) return 1;
  }
  return 0;
}
int main() {
  for (int i = 0; i < 2; ++i) scanf("%s", T[i]);
  for (int i = 0; i < 2; ++i) scanf("%s", Ans[i]);
  if (rec(gen(T[0][0]), gen(T[0][1]), gen(T[1][0]), gen(T[1][1])))
    printf("YES");
  else
    printf("NO");
  return 0;
}
