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 <bits/stdc++.h>

using namespace std;

class Dice{
private:
  void roll(int a,int b,int c,int d){
    swap(x[a],x[b]);
    swap(x[b],x[d]);
    swap(x[c],x[d]);
  }
public:
  char x[6];
  void roll_N(){ roll(0,1,4,5); }
  void roll_E(){ roll(0,3,2,5); }
  void roll_S(){ roll(0,4,1,5); }
  void roll_W(){ roll(0,2,3,5); }
  void rotation(){ roll(1,2,3,4); }
};

Dice d[8],e[2][2][2];

int diff(char a,char b){
  return abs(a-b) == 32;
}

bool check(int idx){
  bool res = true;
  if(idx == 0){ return res; }
  if(idx == 1){
    return diff(e[0][0][0].x[1],e[1][0][0].x[4]);
  }
  if(idx == 2){
    return diff(e[0][0][0].x[2],e[0][1][0].x[3]);
  }
  if(idx == 3){
    res &= diff(e[1][0][0].x[2],e[1][1][0].x[3]);
    res &= diff(e[0][1][0].x[1],e[1][1][0].x[4]);
  }
  if(idx == 4){
    return diff(e[0][0][0].x[5],e[0][0][1].x[0]);
  }
  if(idx == 5){
    res &= diff(e[1][0][0].x[5],e[1][0][1].x[0]);
    res &= diff(e[0][0][1].x[1],e[1][0][1].x[4]);
  }
  if(idx == 6){
    res &= diff(e[0][0][1].x[2],e[0][1][1].x[3]);
    res &= diff(e[0][1][0].x[5],e[0][1][1].x[0]);
  }
  if(idx == 7){
    res &= diff(e[1][0][1].x[2],e[1][1][1].x[3]);
    res &= diff(e[0][1][1].x[1],e[1][1][1].x[4]);
    res &= diff(e[1][1][0].x[5],e[1][1][1].x[0]);
  }
  return res;
}

bool rec(int idx,int S){
  if(S == (1<<8)-1){ return true; }
  for(int i = 0 ; i < 8 ; i++){
    if((S >> i) & 1){ continue; }
    for(int j = 0 ; j < 4 ; j++){
      for(int k = 0 ; k < 4 ; k++){
        d[i].roll_N();
        e[idx%2][(idx%4)>1][idx>3] = d[i];
        if(check(idx) && rec(idx+1,S|(1<<i))){
          return true;
        }
      }
      for(int k = 0 ; k < 4 ; k++){
        d[i].roll_E();
        e[idx%2][(idx%4)>1][idx>3] = d[i];
        if(check(idx) && rec(idx+1,S|(1<<i))){
          return true;
        }
      }
      d[i].rotation();
    }
  }
  return false;
}

int main(){
  while(cin >> d[0].x[0],d[0].x[0] != '0'){
    for(int i = 0 ; i < 8 ; i++){
      for(int j = (i == 0) ; j < 6 ; j++){
        cin >> d[i].x[j];
      }
    }
    cout << (rec(0,0) ? "YES" : "NO") << endl;
  }
  return 0;
}