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<cctype>
#include<string>
#include<iostream>
#include<algorithm>

using namespace std;

int rotx(string &dice){
	char t=dice[0];
	dice[0]=dice[1];
	dice[1]=dice[5];
	dice[5]=dice[4];
	dice[4]=t;
}

int roty(string &dice){
	char t=dice[0];
	dice[0]=dice[3];
	dice[3]=dice[5];
	dice[5]=dice[2];
	dice[2]=t;
}

int rotz(string &dice){
	char t=dice[1];
	dice[1]=dice[3];
	dice[3]=dice[4];
	dice[4]=dice[2];
	dice[2]=t;
}

void next(string &dice,int i){
	if(i%4==0){
		if(i%8==0)	rotx(dice);
		else		roty(dice);
	}
	rotz(dice);
}

int main(){
	string dice[8];
	while(1){
		for(int i=0;i<8;i++)	cin>>dice[i];
		if(dice[0]=="0")	break;

		char co[128];
		for(int c='A';c<='Z';c++)	co[c]=tolower(c);
		for(int c='a';c<='z';c++)	co[c]=toupper(c);

		bool exist[8][128]={};
		for(int i=0;i<8;i++)for(int j=0;j<6;j++)	exist[i][dice[i][j]]=true;

		bool ok=false;
		int i[]={0,1,2,3,4,5,6,7};
		int a,b,c,d,e,f,g,h;
		string diceA,diceB,diceC,diceD,diceE,diceF,diceG,diceH;
		do{
			a=i[0];	b=i[1];	c=i[2];	d=i[3];
			e=i[4];	f=i[5];	g=i[6];	h=i[7];
			diceA=dice[a];	diceB=dice[b];	diceC=dice[c];	diceD=dice[d];
			diceE=dice[e];	diceF=dice[f];	diceG=dice[g];	diceH=dice[h];

			for(int ia=0;ia<24;ia++,next(diceA,ia)){
if(!exist[b][co[diceA[2]]])	continue;
if(!exist[e][co[diceA[5]]])	continue;
				for(int ib=0;ib<24;ib++,next(diceB,ib)){
					if(co[diceA[2]]!=diceB[3])	continue;
if(!exist[c][co[diceB[4]]])	continue;
if(!exist[f][co[diceB[5]]])	continue;
					for(int ic=0;ic<24;ic++,next(diceC,ic)){
						if(co[diceB[4]]!=diceC[1])	continue;
if(!exist[d][co[diceA[4]]] || !exist[d][co[diceC[3]]])	continue;
if(!exist[g][co[diceC[5]]])	continue;
						for(int id=0;id<24;id++,next(diceD,id)){
							if(co[diceA[4]]!=diceD[1] || co[diceC[3]]!=diceD[2])	continue;
							for(int ie=0;ie<24;ie++,next(diceE,ie)){
								if(co[diceA[5]]!=diceE[0])	continue;
								for(int iF=0;iF<24;iF++,next(diceF,iF)){
									if(co[diceB[5]]!=diceF[0] || co[diceE[2]]!=diceF[3])	continue;
									for(int ig=0;ig<24;ig++,next(diceG,ig)){
										if(co[diceC[5]]!=diceG[0] || co[diceF[4]]!=diceG[1])	continue;
										for(int ih=0;ih<24;ih++,next(diceH,ih)){
											if(co[diceD[5]]!=diceH[0] || co[diceE[4]]!=diceH[1] || co[diceG[3]]!=diceH[2])	continue;
											ok=true;
											goto FOUND;
										}
									}
								}
							}
						}
					}
				}
			}
		}while(next_permutation(i+1,i+8));

		FOUND:
		cout<<(ok?"YES":"NO")<<endl;
	}

	return 0;
}