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<cstring>
#define rv(p,q) (a[c[p]][q]+('A'-'a')*('a'<=a[c[p]][q]&&a[c[p]][q]<='z'?1:-1))
using namespace std;
int fi();
int fj();
int fk();
int fl();
int fm();
int fn();
int fo();
char a[8][7];
int b[8],c[8];
enum ea{
  E,S,R,W,N,L,EE,SS,RR,NL
};
void rd(char a[],int p){
  static int b[6][4]={
    {0,3,5,2},
    {0,4,5,1},
    {1,2,4,3},
    {0,2,5,3},
    {0,1,5,4},
    {1,3,4,2}
  };
  int i;
  if(p==EE||p==SS||p==RR){
    rd(a,p-6);
    rd(a,p-6);
  }else{
    char s=a[b[p][0]];
    for(i=0;i<3;++i)
      a[b[p][i]]=a[b[p][i+1]];
    a[b[p][i]]=s;
  }
  return;
}
void rd(char a[],int p,int q,int r){
  static int b[6][6]={
    {NL,S,E,W,N,NL},
    {N,NL,L,R,NL,S},
    {W,R,NL,NL,L,E},
    {E,L,NL,NL,R,W},
    {S,NL,R,L,NL,N},
    {NL,N,W,E,S,NL}
  };
  b[0][5]=b[5][0]=(r==SS||r==EE?r:SS);
  b[1][4]=b[4][1]=(r==SS||r==RR?r:SS);
  b[2][3]=b[3][2]=(r==EE||r==RR?r:EE);
  if(b[p][q]!=NL)
    rd(a,b[p][q]);
  return;
}
int fi(){
  int i,j,k;
  for(i=0;i<8;++i){
    if(b[i]){
      b[i]=0;
      c[1]=i;
      for(j=0;j<6;++j){	
	if(a[i][j]==rv(0,2)){
	  rd(a[i],j,3,SS);
	  for(k=0;k<4;++k){
	    if(fj())
	      return 1;
	    rd(a[i],N);
	  }
	  rd(a[i],3,j,SS);
	}
      }
      b[i]=-1;
    }
  }
  return 0;
}
int fj(){
  int i,j,k;
  for(i=0;i<8;++i){
    if(b[i]){
      b[i]=0;
      c[2]=i;
      for(j=0;j<6;++j){	
	if(a[i][j]==rv(0,4)){
	  rd(a[i],j,1,SS);
	  for(k=0;k<4;++k){
	    if(fk())
	      return 1;
	    rd(a[i],E);
	  }
	  rd(a[i],1,j,SS);
	}
      }
      b[i]=-1;
    }
  }
  return 0;
}
int fk(){
  int i,j,k;
  for(i=0;i<8;++i){
    if(b[i]){
      b[i]=0;
      c[3]=i;
      for(j=0;j<6;++j){
	if(a[i][j]==rv(1,4)){
	  rd(a[i],j,1,SS);
	  for(k=0;k<6;++k){
	    if(k!=1&&k!=4&&a[i][k]==rv(2,2)){
	      rd(a[i],k,3,EE);
	      if(fl())
		return 1;
	      rd(a[i],3,k,EE);
	    }
	  }
	  rd(a[i],1,j,SS);
	}
      }
      b[i]=-1;
    }
  }
  return 0;
}
int fl(){
  int i,j,k;
  for(i=0;i<8;++i){
    if(b[i]){
      b[i]=0;
      c[4]=i;
      for(j=0;j<6;++j){	
	if(a[i][j]==rv(0,0)){
	  rd(a[i],j,5,SS);
	  for(k=0;k<4;++k){
	    if(fm())
	      return 1;
	    rd(a[i],R);
	  }
	  rd(a[i],5,j,SS);
	}
      }
      b[i]=-1;
    }
  }
  return 0;
}
int fm(){
  int i,j,k;
  for(i=0;i<8;++i){
    if(b[i]){
      b[i]=0;
      c[5]=i;
      for(j=0;j<6;++j){
	if(a[i][j]==rv(1,0)){
	  rd(a[i],j,5,SS);
	  for(k=0;k<6;++k){
	    if(k!=0&&k!=5&&a[i][k]==rv(4,2)){
	      rd(a[i],k,3,RR);
	      if(fn())
		return 1;
	      rd(a[i],3,k,RR);
	    }
	  }
	  rd(a[i],5,j,SS);
	}
      }
      b[i]=-1;
    }
  }
  return 0;
}
int fn(){
  int i,j,k;
  for(i=0;i<8;++i){
    if(b[i]){
      b[i]=0;
      c[6]=i;
      for(j=0;j<6;++j){
	if(a[i][j]==rv(2,0)){
	  rd(a[i],j,5,SS);
	  for(k=0;k<6;++k){
	    if(k!=0&&k!=5&&a[i][k]==rv(4,4)){
	      rd(a[i],k,1,RR);
	      if(fo())
		return 1;
	      rd(a[i],1,k,RR);
	    }
	  }
	  rd(a[i],5,j,SS);
	}
      }
      b[i]=-1;
    }
  }
  return 0;
}
int fo(){
  int i,j,k;
  for(i=0;i<8;++i){
    if(b[i]){
      b[i]=0;
      c[7]=i;
      for(j=0;j<6;++j){
	if(a[i][j]==rv(3,0)){
	  rd(a[i],j,5,SS);
	  for(k=0;k<6;++k){
	    if(k!=0&&k!=5&&a[i][k]==rv(5,4)){
	      rd(a[i],k,1,RR);
	      if(a[i][3]==rv(6,2))
		return 1;
	      rd(a[i],1,k,RR);
	    }
	  }
	  rd(a[i],5,j,SS);
	}
      }
      b[i]=-1;
    }
  }
  return 0;
}
int main(){
  int i;
  while(cin>>a[0],a[0][0]!='0'){
    for(i=1;i<8;++i)
      cin>>a[i];
    memset(b,-1,sizeof(b));
    b[0]=0;
    c[0]=0;
    int d[24]={L,L,L,E,L,L,L,E,L,L,L,W,L,L,L,W,L,L,L,E,L,L,L,L};
    for(i=0;i<24;++i){
      if(fi())
	break;
      rd(a[0],d[i]);
    }
    if(i<24)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}