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<vector>
#include<string>

std::vector<std::string> buf(8);

//Eñ]ÉiÞûüÅ³ÊÌCfbNXÆAEÌCfbNXðwèµÄãÌCfbNXðÔ·
inline int uppderindex(int front, int right){
	int table[][6] = {
		{0, 3, 5, 2, 4, 0},
		{4, 0, 1, 6, 0, 3},
		{2, 6, 0, 0, 1, 5},
		{5, 1, 0, 0, 6, 2},
		{3, 0, 6, 1, 0, 4},
		{0, 4, 2, 5, 3, 0}
	};
	return table[front][right]-1;
}
//½Î¤ÌCfbNXðÔ·
inline int otherindex(int h){
	return 5-h;
}
inline int otherc(int c){
	return c+(c>96?-32:32);
}
//³ÊðwèµÄOüÌCfbNXðÔ·
int aroundindex(int front, int idx){
	for(int i=0,cnt=0; i<6; i++){
		if(front!=i&&otherindex(front)!=i){
			if(cnt==idx) return i;
			cnt++;
		}
	}
	return 0;
}

int dindexlist[4];
int uindexlist[4];
int firstindex;
int firstindex2;

bool same(int *arr){
	for(int i=0; i<4; i++){
		if( otherc(buf[arr[i]][otherindex(dindexlist[i])]) != 
			buf[(arr+4)[i]][uindexlist[i]] )
			return false;
	}
	return true;
}

bool check_around2(int *d, int idx, int nest, int *arr){
	int c = otherc(buf[*d][idx]);
	if( nest == 3 ){
		//±êÍÅÌ³¢±ëÆêv·é©ð©éàÌÈÌÅÁÊ
		for(int around=0; around<4; around++){
			int ar = aroundindex(firstindex2,around);
			if( c == buf[*(d-3)][ar] ){ //¡Ì¶ª éÆl¦éÌÍÊ|I
				//ÅÌ³¢±ëÌãCfbNX
				arr[0] = uppderindex( ar, firstindex2 );
				return true;
			}
		}
		return false;
	}

	//Ì³¢±ë
	d++;
	for(int i=0; i<6; i++){
		if( c == buf[*d][i] ){
			for(int around=0; around<4; around++){
				int ar = aroundindex(i,around);

				//CfbNXÌXg¶áÈ­Ä¶ñÉµ½Ù¤ª¢¢©È
				arr[nest+1] = uppderindex( i, ar );
				if( check_around2(d, ar, nest+1, arr) ){
					if( nest == 2 ){
						//OóÉÂÈªÁÄéÌªmèµÄÜ·
						if( same(d-7) ) return true;
					}else{
						return true;
					}
				}
			}
		}
	}
	return false;
}

bool check2(int* d, int* idxlist){
	for(int i=0; i<6; i++){ //³¢±ëÌ»ê¼êÌ¶ÉÂ¢Ä²×é
		if( check_around2(d, firstindex2=i, 0, idxlist) ) return true;
	}
	return false;
}



bool check_around(int *d, int idx, int nest, int *arr){
	int c = otherc(buf[*d][idx]);
	if( nest == 3 ){
		//±êÍÅÌ³¢±ëÆêv·é©ð©éàÌÈÌÅÁÊ
		for(int around=0; around<4; around++){
			int ar = aroundindex(firstindex,around);
			if( c == buf[*(d-3)][ar] ){ //¡Ì¶ª éÆl¦éÌÍÊ|I
				//ÅÌ³¢±ëÌãCfbNX
				arr[0] = uppderindex( ar, firstindex );
				return true;
			}
		}
		return false;
	}

	//Ì³¢±ë
	d++;
	for(int i=0; i<6; i++){
		if( c == buf[*d][i] ){
			for(int around=0; around<4; around++){
				int ar = aroundindex(i,around);

				//CfbNXÌXg¶áÈ­Ä¶ñÉµ½Ù¤ª¢¢©È
				arr[nest+1] = uppderindex( i, ar );
				if( check_around(d, ar, nest+1, arr) ){
					if( nest == 2 ){
						//OóÉÂÈªÁÄéÌªmèµÄÜ·
						if( check2( d+1, uindexlist ) ) return true;
					}else{
						return true;
					}
				}
			}
		}
	}
	return false;
}

bool check(int* d, int* idxlist){
	for(int i=0; i<6; i++){ //³¢±ëÌ»ê¼êÌ¶ÉÂ¢Ä²×é
		if( check_around(d, firstindex=i, 0, idxlist) ) return true;
	}
	return false;
}

bool check_around_pre(int *d, int idx, int nest){
	int c = otherc(buf[*d][idx]);
	if( nest == 3 ){
		//±êÍÅÌ³¢±ëÆêv·é©ð©éàÌÈÌÅÁÊ
		for(int around=0; around<4; around++){
			int ar = aroundindex(firstindex,around);
			if( c == buf[*(d-3)][ar] ) return true;
		}
		return false;
	}

	//Ì³¢±ë
	d++;
	for(int i=0; i<6; i++){
		if( c == buf[*d][i] ){
			for(int around=0; around<4; around++){
				int ar = aroundindex(i,around);
				if( check_around_pre(d, ar, nest+1) ) return true;
			}
		}
	}
	return false;
}

bool check_pre(int* d){
	for(int i=0; i<6; i++){ //³¢±ëÌ»ê¼êÌ¶ÉÂ¢Ä²×é
		if( check_around_pre(d, firstindex=i, 0) ) return true;
	}
	return false;
}

bool get(){
	for(int i=0; i<8; ++i){
		std::getline(std::cin,buf[i]);
		if(buf[i]=="0")return false;
	}
	return true;
}
int main(){
	while(get()){
		int d[8] = {0,1,2,3,4,5,6,7};
		for(int i=1; i<8; ++i){
			d[5] = i;
			int d2[6];
			int addi = 1;
			for(int j=0; j<6; ++j){
				d2[j] = addi==i?++addi:addi;
				++addi;
			}
			do{
				d[3] = d2[2];
				d[4] = d2[3];
				d[6] = d2[4];
				d[7] = d2[5];
				for(int k=0; k<2; ++k){
					d[1+k] = d2[0];
					d[2-k] = d2[1];
					//Æè ¦¸2ÂÚÌXgÍìÁÄÌÄçêéñª½·¬éÌÅAæÉ1ÂÅà¶Ý·é©Ç¤©Å}Øè·é
					if( /*check_pre(d) && check_pre(d+4) &&*/ check(d,dindexlist) ){
						puts("YES");
						goto next;
					}
				}
			}while(std::next_permutation(d2+1, d2+6));
		}
		puts("NO");
next:
		;
	}
}