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>
#pragma comment(linker, "/STACK:66777216")
#pragma warning(disable : 4996)
#pragma hdrstop
namespace std {}
namespace Random {}
class IO {
 public:
  constexpr static const std::size_t kBufferSize = 1 << 18;
  IO()
      : read_bytes_count_(0),
        read_buffer_offset_(0),
        current_char_(0),
        eof_(false) {
    static_assert(kBufferSize > 32,
                  "Size of a buffer must be greater than 32 due to comparison "
                  "in IO::flush() method.");
  }
  ~IO() { flush(); }
  IO(const IO&) = delete;
  IO& operator=(const IO&) = delete;
  IO(const IO&&) = delete;
  IO& operator=(const IO&&) = delete;
  inline void shift_char();
  inline void skipws();
  inline void next_string(char* s);
  IO& operator>>(char* s);
  inline void flush();
  inline void new_line();
  inline void print_string(const char* s);
  IO& operator<<(const char* s);
  IO& operator<<(std::ostream& (*)(std::ostream&));

 private:
  using Buffer = std::array<char, kBufferSize>;
  Buffer read_buffer_;
  Buffer write_buffer_;
  std::size_t read_bytes_count_;
  std::size_t read_buffer_offset_;
  std::size_t write_buffer_offset_;
  bool eof_;
  char current_char_;
  inline void update_buffer();
};
extern bool useFastIO;
extern std::istream* pin;
extern std::ostream* pout;
extern IO io;
inline void next_string(char* s);
inline void new_line();
inline void print_string(const char* s);
using namespace std;
IO io;
char s[4];
string get() {
  io >> s;
  string ret(s);
  io >> s;
  reverse(s, s + 2);
  ret += string(s);
  string result = "";
  for (auto& ch : ret) {
    if (ch != 'X') {
      result += ch;
    }
  }
  return result;
}
void solve(istream& ins, ostream& out) {
  string a = get(), b = get();
  a += a;
  for (int i = 0; i < 3; ++i) {
    if (a.substr(i, 3) == b) {
      io << "YES" << endl;
      return;
    }
  }
  io << "NO" << endl;
}
extern class IO io;
bool useFastIO = false;
istream* pin;
ostream* pout;
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream& in = cin;
  useFastIO = true;
  ostream& out = cout;
  out << fixed << setprecision(16);
  pin = &in;
  pout = &out;
  solve(in, out);
  return 0;
}
inline void IO::skipws() {
  while (!eof_ && (current_char_ == ' ' || current_char_ == '\n')) {
    shift_char();
  }
}
inline void IO::update_buffer() {
  if (read_buffer_offset_ == read_bytes_count_) {
    read_bytes_count_ = fread(&read_buffer_[0], sizeof(read_buffer_[0]),
                              read_buffer_.size(), stdin);
    if (read_bytes_count_ == 0) {
      eof_ = true;
      return;
    }
    read_buffer_offset_ = 0;
  }
}
inline void IO::shift_char() {
  update_buffer();
  current_char_ = read_buffer_[read_buffer_offset_++];
}
inline void IO::next_string(char* s) {
  if (current_char_ == '\0') {
    shift_char();
  }
  skipws();
  std::size_t index = 0;
  while (!eof_ && current_char_ != ' ' && current_char_ != '\n') {
    s[index++] = current_char_;
    shift_char();
  }
  s[index] = 0;
}
IO& IO::operator>>(char* s) {
  ::next_string(s);
  return *this;
}
inline void IO::flush() {
  fwrite(&write_buffer_[0], sizeof(write_buffer_[0]), write_buffer_offset_,
         stdout);
  write_buffer_offset_ = 0;
}
inline void IO::new_line() {
  if (write_buffer_offset_ == kBufferSize) {
    flush();
  }
  write_buffer_[write_buffer_offset_++] = '\n';
}
inline void IO::print_string(const char* s) {
  for (std::size_t i = 0; s[i] != '\0'; ++i) {
    if (write_buffer_offset_ == kBufferSize) {
      flush();
    }
    write_buffer_[write_buffer_offset_++] = s[i];
  }
}
IO& IO::operator<<(const char* s) {
  ::print_string(s);
  return *this;
}
IO& IO::operator<<(std::ostream& (*)(std::ostream&)) {
  ::new_line();
  return *this;
}
inline void next_string(char* s) {
  if (useFastIO) {
    io.next_string(s);
    return;
  }
  *pin >> s;
}
inline void new_line() {
  if (useFastIO) {
    io.new_line();
    return;
  }
  *pout << std::endl;
}
inline void print_string(const char* s) {
  if (useFastIO) {
    io.print_string(s);
    return;
  }
  *pout << s;
}