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<algorithm>
#include<string>
#define b(n)c##n=v(B[*(d+n)][i]),
#define g(a,b,k)if(c##a==B[*(d+b)][j])h|=1<<k;
std::string B[8];int u(int f,int r){int t[]={0,2,4,1,3,0,3,0,0,5,0,2,1,5,0,0,0,4,4,0,0,0,5,1,2,0,5,0,0,3,0,3,1,4,2,0};return t[f*6+r];}int q(int h){return 5-h;}int v(int c){return c+(c>96?-32:32);}int o(int f,int x){for(int i=0,c=0;i<6;i++)if(f!=i&&q(f)!=i){if(c==x)return i;c++;}}int w[4],z[4];bool C(int*d,int x,int nest,int*l,int e,bool(*f)(int*)){int c=v(B[*d][x]),i,a;if(nest==3){for(a=0;a<4;a++){int ar=o(e,a);if(c==B[*(d-3)][ar]){l[0]=u(ar,e);return true;}}}else{d++;for(i=0;i<6;i++)if(c==B[*d][i])for(a=0;a<4;a++){int ar=o(i,a);l[nest+1]=u(i,ar);if(C(d,ar,nest+1,l,e,f)){if(nest==2){if(f(d))return true;}else{return true;}}}}return false;}bool S(int*l){l-=7;for(int i=0;i<4;i++)if(v(B[l[i]][q(w[i])])!=B[(l+4)[i]][z[i]])return false;return true;}bool K(int*d){++d;for(int i=0;i<6;i++)if(C(d,i,0,z,i,S))return true;return false;}bool p(int*d){int h=0,i=0,k;for(;i<6;i++){int b(0)b(1)b(2)b(3)b(4)b(5)b(6)b(7)j;for(j=0;j<6;j++){g(0,1,0)g(1,2,1)g(2,3,2)g(3,0,3)g(4,5,4)g(5,6,5)g(6,7,6)g(7,4,7)g(0,4,8)g(1,5,9)g(2,6,10)g(3,7,11)if(h==4095){for(k=0;k<6;k++)if(C(d,k,0,w,k,K)){puts("YES");return true;}return false;}}}return false;}int main(){for(;;){int i,j,k,a,d[8],e[6];for(i=0;i<8;++i){std::getline(std::cin,B[i]);if(B[i]=="0")return 0;}d[0]=0;for(i=1;i<8;++i){d[5]=i;for(j=0,a=1;j<6;++j,++a)e[j]=a==i?++a:a;do{d[3]=e[2];d[4]=e[3];d[6]=e[4];d[7]=e[5];for(k=0;k<2;++k){d[1+k]=e[0];d[2-k]=e[1];if(p(d))goto n;}}while(std::next_permutation(e+1,e+6));}puts("NO");n:;}}