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 <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int N = 8;

int H[6][6] = { {1,5,2,3,0,4}, {3,1,0,5,4,2}, {2,1,5,0,4,3}, {4,0,2,3,5,1}, {0,2,4,1,3,5}, {0,3,1,4,2,5} };

enum{TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM};
struct Cube{
  vector<char> d, bef;
  Cube(vector<char> v) { d = v; }
  Cube(string &s){ d = vector<char>(6); REP(i, s.length()) d[i] = s[i]; }
  Cube(){ d = vector<char>(6, '-'); }
  void roll(int dir) {
    bef = d;
    for(int i = 0 ; i < 6 ; i++ ) d[i] = bef[H[dir][i]];
  }
  string to_string(){
    stringstream ss;
    REP(i, 6) ss << d[i];
    return ss.str();
  }
};

bool ans = false;
int D[12][4] = {
  {0, 1, RIGHT, LEFT},
  {0, 2, FRONT, BACK},
  {0, 4, BOTTOM, TOP},
  {1, 3, FRONT, BACK},
  {1, 5, BOTTOM, TOP},
  {2, 3, RIGHT, LEFT},
  {2, 6, BOTTOM, TOP},
  {3, 7, BOTTOM, TOP},
  {4, 5, RIGHT, LEFT},
  {4, 6, FRONT, BACK},
  {5, 7, FRONT, BACK},
  {6, 7, RIGHT, LEFT}
};

bool check(int n, vector<Cube> &v){
  REP(i, 12){
    int a = D[i][0], b = D[i][1], da = D[i][2], db = D[i][3];
    if(b != n) continue;
    if(toupper(v[a].d[da]) != toupper(v[b].d[db])) return false;
    if(v[a].d[da] == v[b].d[db]) return false;
  }
  return true;
}

void dfs(int n, vector<Cube> &v, Cube cs[N], vector<bool> &used){
  if(ans) return ;
  if(n >= N) { ans = true; return ; }

  REP(i, N){
    if(used[i]) continue;
    used[i] = true;

    Cube c = cs[i];
    v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used);
    REP(i, 3) { c.roll(4); v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used); }
    c.roll(4);

    c.roll(0);
    v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used);
    REP(i, 3) { c.roll(4); v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used); }
    c.roll(4);

    c.roll(0);
    v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used);
    REP(i, 3) { c.roll(4); v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used); }
    c.roll(4);

    c.roll(0);
    v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used);
    REP(i, 3) { c.roll(4); v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used); }
    c.roll(4);

    c.roll(0); c.roll(1);
    v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used);
    REP(i, 3) { c.roll(4); v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used); }
    c.roll(4);

    c.roll(2); c.roll(2);
    v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used);
    REP(i, 3) { c.roll(4); v[n] = c; if(!ans && check(n, v)) dfs(n + 1, v, cs, used); }
    c.roll(4);

    v[n] = Cube();
    used[i] = false;
  }
}

int main() {
  string s;
  while(cin >>s && s != "0"){
    Cube cs[N]; cs[0] = Cube(s);
    FOR(i, 1, N) { cin >>s; cs[i] = Cube(s); }

    ans = false;
    vector<Cube> v(N, Cube());
    vector<bool> used(N, 0);
    dfs(0, v, cs, used);
    cout <<(ans ? "YES" : "NO") <<endl;
  }
  return 0;
}