Problem: There is a dice with one letter of the alphabet (a ~ z, A ~ Z) drawn on each side.


<image>


Consider combining eight such dice to make a 2 x 2 x 2 cube.


<image>


There are conditions on how to combine the dice, and the facing faces of each dice must have the same alphabet, one in lowercase and the other in uppercase. For example, a surface marked a can be touched by a face marked A. However, the orientation of the characters when touching them does not matter.


<image>


According to this rule, input the information of 8 dice and create a program to judge whether or not you can make a cube. If you can make a cube, output YES (half-width uppercase letters), and if you cannot make it, output NO (half-width uppercase letters).

The letters on each side of the dice will be represented as c1 to c6 as shown in the following figure. Also, assume that the same letter is never drawn multiple times on a single dice (uppercase and lowercase letters of the same alphabet are not the case).


<image>



Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:


s1
s2
::
s8


The i-line gives the information si of the i-th dice. si is a string of length 6 and the jth character corresponds to each side cj of the dice.

The number of datasets does not exceed 50.

Output

The judgment result (half-width uppercase letters) is output to one line for each data set.

Example

Input

zabZNq
BCxmAi
ZcbBCj
aizXCm
QgmABC
JHzMop
ImoXGz
MZTOhp
zabZnQ
BCxmAi
ZcbBCj
aizXCm
QgmABC
JHzMop
ImoXGz
MZTOhp
abcdef
ABDCFE
FBDCAE
abcdef
BEACDF
bfcaed
fabcde
DEABCF
UnivOf
AizuaH
zTXZYW
piglIt
GRULNP
higGtH
uAzIXZ
FizmKZ
UnivOf
AizuaH
piglIt
higGtH
GRULNP
uAzIXZ
FizmKZ
ZTXzYW
0


Output

YES
NO
YES
YES
NO

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

// dice<hoge> di(arr); ÈÇÆé¾·é
// ±ÌÆ«AarrÍ hoge di[6];Åé¾³êÄ¨èAid ÌlÌÉÊÌlªi[³êÄ¢éKvª éB
// á¦ÎAid[TOP] = 3 ÈçÎAdi[3] ÌlªTOPÉÝè³êéB
// TCRÆµÄµ¢©Ç¤©Ì»èÉ equivalent_to ðg¤B
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class dice {
public:
  dice(){}
  dice(T *v) {
    id[TOP] = 0; id[FRONT] = 1; id[RIGHT] = 2;
    id[LEFT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
    REP(i,6)
      var[i] = v[i];
  }
  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const { return var[id[f]]; }
  bool operator==(const dice<T>& b) const {
    const dice<T> &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
           a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
           a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
  vector<dice> all_rolls() {
    vector<dice> ret;
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        ret.push_back(*this);
    return ret;
  }
  bool equivalent_to(const dice& di) {
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        if (*this == di) return true;
    return false;
  }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    int tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};

typedef vector<dice<char> > vdc;
vdc di(8);

char hoge(char a) {
  return isupper(a) ? tolower(a) : toupper(a);
}


bool step7(vdc vd, int S) {
  for (int i = 1; i<8; ++i) {
    if (S & (1<<i)) continue;
    vdc v = di[i].all_rolls();
    FOR(it, v) {
      if (hoge(vd[3][BACK]) == (*it)[FRONT]
          && hoge(vd[5][BOTTOM]) == (*it)[TOP]
          && hoge(vd[6][RIGHT]) == (*it)[LEFT]) {
        return true;
      }
    }
  }
  return false;
}
bool step6(vdc vd, int S) {
  // cout << bitset<8>(S) << " " << vd[4][FRONT] << endl;
  // REP(i, vd.size()) {
  //   cout << i << ": ";
  //   cout << vd[i][TOP] << vd[i][FRONT] << vd[i][RIGHT];
  //   cout << vd[i][LEFT] << vd[i][BACK] << vd[i][BOTTOM];
  //   cout << endl;
  // }
  // cout << hoge(vd[2][BACK]) << " "  << hoge(vd[4][BOTTOM]) << endl;
  for (int i = 1; i<8; ++i) {
    if (S & (1<<i)) continue;
    vdc v = di[i].all_rolls();
    FOR(it, v) {
      if (hoge(vd[2][BACK]) == (*it)[FRONT] && hoge(vd[4][BOTTOM]) == (*it)[TOP]) {
        vdc tmp = vd;
        tmp.push_back(*it);
        if (step7(tmp, S|(1<<i))) return true;
      }
    }
  }
  return false;
}
bool step5(vdc vd, int S) {
  for (int i = 1; i<8; ++i) {
    if (S & (1<<i)) continue;
    vdc v = di[i].all_rolls();
    FOR(it, v) {
      if (hoge(vd[1][BACK]) == (*it)[FRONT] && hoge(vd[4][RIGHT]) == (*it)[LEFT]) {
        vdc tmp = vd;
        tmp.push_back(*it);
        if (step6(tmp, S|(1<<i))) return true;
      }
    }
  }
  return false;
}

bool step4(vdc vd, int S) {
  for (int i = 1; i<8; ++i) {
    if (S & (1<<i)) continue;
    vdc v = di[i].all_rolls();
    FOR(it, v) {
      if (hoge(vd[0][BACK]) == (*it)[FRONT]) {
        vdc tmp = vd;
        tmp.push_back(*it);
        if (step5(tmp, S|(1<<i))) return true;
      }
    }
  }
  return false;
}

bool step3(vdc vd, int S) {
  for (int i = 1; i<8; ++i) {
    if (S & (1<<i)) continue;
    vdc v = di[i].all_rolls();
    FOR(it, v) {
      if (hoge(vd[1][BOTTOM]) == (*it)[TOP] && hoge(vd[2][RIGHT]) == (*it)[LEFT]) {
        vdc tmp = vd;
        tmp.push_back(*it);
        if (step4(tmp, S|(1<<i))) return true;
      }
    }
  }
  return false;
}

bool step2(vdc vd, int S) {
  for (int i = 1; i<8; ++i) {
    if (S & (1<<i)) continue;
    vdc v = di[i].all_rolls();
    FOR(it, v) {
      if (hoge(vd[0][BOTTOM]) == (*it)[TOP]) {
        vdc tmp = vd;
        tmp.push_back(*it);
        if (step3(tmp, S|(1<<i))) return true;
      }
    }
  }
  return false;
}

bool step1(vdc vd, int S) {
  for (int i = 1; i<8; ++i) {
    vdc v = di[i].all_rolls();
    FOR(it, v) {
      if (hoge(vd[0][RIGHT]) == (*it)[LEFT]) {
        vdc tmp = vd;
        tmp.push_back(*it);
        if (step2(tmp, S|(1<<i))) return true;
      }
    }
  }
  return false;
}

int main() {
  string s;
  while(cin >> s, s!="0") {
    REP(k,8) {
      if (k) cin >> s;
      char a[6];
      REP(i,6) a[i] = s[i];
      di[k] = dice<char>(a);
    }
    vdc ve = di[0].all_rolls();
    bool f = 0;
    FOR(it, ve) {
      vdc tmp;
      tmp.push_back(*it);
      if (step1(tmp, 1)) {
        f = 1;
        break;
      }
    }
    if (f)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}