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

#define NUM 8
#define SIDES 6
#define MAX 128
using namespace std;

char ChangeCase(char c){
	if( isupper( c ) )
		return tolower( c );
	else
		return toupper( c );
}

struct Dice{
	Dice():s(""){
		for(int i = 0; i < MAX; ++i){
			ch[i] = false;
		}
	}
	string s;
	bool ch[MAX];
	void Make(){
		for(unsigned int i = 0; i < s.length(); ++i){
			ch[ s[i] ] = true;
		}
	}
	char GetSide(int side)const{
		return s[side];
	}
	bool Contains(char c)const{
		return ch[ c ];
	}
	void RotHor(){
		char c[SIDES];
		c[0] = s[0]; c[1] = s[3]; c[2] = s[1]; c[3] = s[4]; c[4] = s[2]; c[5] = s[5];
		for(unsigned int i = 0; i < SIDES; ++i)
			s[i] = c[i];
	}
	void RotVer(){
		char c[SIDES];
		c[0] = s[4]; c[1] = s[0]; c[2] = s[2]; c[3] = s[3]; c[4] = s[5]; c[5] = s[1];
		for(unsigned int i = 0; i < SIDES; ++i)
			s[i] = c[i];
	}
	void Rot(){
		char c[SIDES];
		c[0] = s[2]; c[1] = s[1]; c[2] = s[5]; c[3] = s[0]; c[4] = s[4]; c[5] = s[3];
		for(unsigned int i = 0; i < SIDES; ++i)
			s[i] = c[i];
	}
	void Set(char c, int side){
		int pos;
		for(unsigned int i = 0; i < s.length(); ++i){
			if( s[i] == c ){
				pos = i;
				break;
			}
		}
		switch( pos ){
			case 0:
				switch( side ){
					case 0: break;
					case 1: RotVer(); break;
					case 2: RotVer(); RotHor(); break;
					case 3: Rot(); break;
					case 4: RotVer(); RotVer(); RotVer(); break;
					case 5: RotVer(); RotVer(); break;
				}
				break;
			case 1:
				switch( side ){
					case 0: RotHor(); Rot(); break;
					case 1: break;
					case 2: RotHor(); break;
					case 3: RotHor(); RotHor(); RotHor(); break;
					case 4: RotHor(); RotHor(); break;
					case 5: RotVer(); break;
				}
				break;
			case 2:
				switch( side ){
					case 0: Rot(); break;
					case 1: Rot(); RotVer(); break;
					case 2: break;
					case 3: Rot(); Rot(); break;
					case 4: RotHor(); break;
					case 5: Rot(); RotVer(); RotVer(); break;
				}
				break;
			case 3:
				switch( side ){
					case 0: Rot(); Rot(); Rot(); break;
					case 1: RotHor(); break;
					case 2: Rot(); Rot(); break;
					case 3: break;
					case 4: Rot(); RotVer(); break;
					case 5: RotHor(); RotVer(); break;
				}
				break;
			case 4:
				switch( side ){
					case 0: RotVer(); break;
					case 1: RotHor(); RotHor(); break;
					case 2: RotHor(); RotHor(); RotHor(); break;
					case 3: RotHor(); break;
					case 4: break;
					case 5: RotHor(); Rot(); break;
				}
				break;
			case 5:
				switch( side ){
					case 0: Rot(); Rot(); break;
					case 1: RotVer(); RotVer(); RotVer(); break;
					case 2: Rot(); break;
					case 3: RotVer(); RotHor(); break;
					case 4: RotVer(); break;
					case 5: break;
				}
				break;
		}
		assert( GetSide( side ) == c );
	}
};
bool solve(Dice ans[NUM], const Dice pzl[NUM], bool bUse[NUM], int pos ){
	if( pos >= 8 )
		return true;

	if( pos == 0 ){
		//for(unsigned int k = 0; k < NUM; ++k){
		int k = 0;
			ans[pos] = pzl[k];
			bUse[k] = true;
			for(unsigned int i = 0; i < 6; ++i ){
				ans[pos].Set( pzl[k].s[i], 0 );
				for(unsigned int j = 0; j < 4; ++j ){
					if( solve( ans, pzl, bUse, pos + 1 ) )
						return true;
					ans[pos].RotHor();
				}
			}
			bUse[k] = false;
		//}
	}else if( pos == 1 ){
		char c = ans[0].GetSide(2);
		for(unsigned int i = 0; i < NUM; ++i){
			char C = ChangeCase( c );
			if( !bUse[i] && pzl[i].Contains( C ) ){
				ans[pos] = pzl[i];

				bUse[i] = true;
				ans[pos].Set( C, 3 );
				for(unsigned int j = 0; j < 4; ++j){	
					if( solve( ans, pzl, bUse, pos+1 ) )
						return true;
					ans[pos].RotVer();
				}
				bUse[i] = false;
			}
		}
	}else if( pos == 2 ){
		char c = ans[1].GetSide(4);
		for(unsigned int i = 0; i < NUM; ++i){
			char C = ChangeCase( c );
			if( !bUse[i] && pzl[i].Contains( C ) ){
				ans[pos] = pzl[i];

				bUse[i] = true;
				ans[pos].Set( C, 1 );
				for(unsigned int j = 0; j < 4; ++j){	
					if( solve( ans, pzl, bUse, pos+1 ) )
						return true;
					ans[pos].Rot();
				}
				bUse[i] = false;
			}
		}
	}else if( pos == 3 ){
		char c = ans[2].GetSide(3);
		char val_c = ans[0].GetSide(4);
		for(unsigned int i = 0; i < NUM; ++i){
			char C = ChangeCase( c );
			if( !bUse[i] && pzl[i].Contains( C ) ){
				ans[pos] = pzl[i];

				bUse[i] = true;
				ans[pos].Set( C, 2 );
				for(unsigned int j = 0; j < 4; ++j){	
					if( ans[pos].GetSide(1) == ChangeCase( val_c ) ){
						if( solve( ans, pzl, bUse, pos+1 ) )
							return true;
					}
					ans[pos].RotVer();
				}
				bUse[i] = false;
			}
		}
	}else if( pos == 4 ){
		char c = ans[0].GetSide(5);
		for(unsigned int i = 0; i < NUM; ++i){
			char C = ChangeCase( c );
			if( !bUse[i] && pzl[i].Contains( C ) ){
				ans[pos] = pzl[i];

				bUse[i] = true;
				ans[pos].Set( C, 0 );
				for(unsigned int j = 0; j < 4; ++j){	
					if( solve( ans, pzl, bUse, pos+1 ) )
						return true;
					ans[pos].RotHor();
				}
				bUse[i] = false;
			}
		}
	}else if( pos == 5 ){
		char c = ans[4].GetSide(2);
		char val_c = ans[1].GetSide(5);
		for(unsigned int i = 0; i < NUM; ++i){
			char C = ChangeCase( c );
			if( !bUse[i] && pzl[i].Contains( C ) ){
				ans[pos] = pzl[i];

				bUse[i] = true;
				ans[pos].Set( C, 3 );
				for(unsigned int j = 0; j < 4; ++j){	
					if( ans[pos].GetSide( 0 ) == ChangeCase( val_c ) ){
						if( solve( ans, pzl, bUse, pos+1 ) )
							return true;
					}
					ans[pos].RotVer();
				}
				bUse[i] = false;
			}
		}
	}else if( pos == 6 ){
		char c = ans[5].GetSide(4);
		char val_c = ans[2].GetSide(5);
		for(unsigned int i = 0; i < NUM; ++i){
			char C = ChangeCase( c );
			if( !bUse[i] && pzl[i].Contains( C ) ){
				ans[pos] = pzl[i];

				bUse[i] = true;
				ans[pos].Set( C, 1 );
				for(unsigned int j = 0; j < 4; ++j){	
					if( ans[pos].GetSide( 0 ) == ChangeCase( val_c ) ){
						if( solve( ans, pzl, bUse, pos+1 ) )
							return true;
					}
					ans[pos].Rot();
				}
				bUse[i] = false;
			}
		}
	}else if( pos == 7 ){
		char c = ans[6].GetSide(3);
		char val_c = ans[3].GetSide(5);
		char val_comp = ans[4].GetSide(4);
		for(unsigned int i = 0; i < NUM; ++i){
			char C = ChangeCase( c );
			if( !bUse[i] && pzl[i].Contains( C ) ){
				ans[pos] = pzl[i];

				bUse[i] = true;
				ans[pos].Set( C, 2 );
				for(unsigned int j = 0; j < 4; ++j){	
					if( ans[pos].GetSide( 0 ) == ChangeCase( val_c ) &&
						ans[pos].GetSide( 1 ) == ChangeCase( val_comp ) ){
						if( solve( ans, pzl, bUse, pos+1 ) )
							return true;
					}
					ans[pos].RotVer();
				}
				bUse[i] = false;
			}
		}
	}
	return false;
}
int main(){
	while(true){
		Dice ans[NUM];
		Dice pzl[NUM];
		bool bUse[NUM] = {0,};
		
		for(int i = 0; i < 8; ++i){
			string s;
			cin >> s;
			if( s[0] == '0' )
				return 0;
			pzl[i].s = s;
			pzl[i].Make();
		}
		if( solve( ans, pzl, bUse, 0 ) )
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}