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 <vector>
using namespace std;

enum{
	T, F, R, Ba, L, Bo
};

const char* pattern[ 24 ] =
{
	/*
	"012345", "023415", "034125", "041235",
	"104523", "145203", "152043", "120453",
	"201534", "215304", "253014", "230154",
	"302541", "325401", "354021", "340251",
	"403512", "435102", "451032", "410352",
	"514320", "543210", "532140", "521430",
	*/
	"012435", "024315", "043125", "031245",
	"103524", "135204", "152034", "120354",
	"201543", "215403", "254013", "240153",
	"304512", "345102", "351042", "310452",
	"402531", "425301", "453021", "430251",
	"513420", "534210", "542130", "521340",
};

const int contact[ 8 ][ 6 ] =
{
	{ -1, -1, -1, -1, -1, -1 },
	{ -1, -1, 0, -1, -1, -1 },
	{ -1, -1, -1, 0, -1, -1 },
	{ -1, -1, 2, 1, -1, -1 },
	{ 0, -1, -1, -1, -1, -1 },
	{ 1, -1, -1, 4, -1, -1 },
	{ 2, -1, -1, -1, 4, -1 },
	{ 3, -1, -1, 6, 5, -1 },
};

const int touch[] =
{
	Bo, Ba, L, F, R, T,
};

bool rec( vector< string >& dice, vector< pair< int, int > >& put, int n, int selected )
{
	if( n == 8 ){
		return true;
	}

	int offset = 'a' - 'A';
	for( int i = 0; i < 8; ++i ){
		if( selected & ( 1 << i ) ){
			continue;
		}
		for( int j = 0; j < 24; ++j ){
			put.push_back( make_pair( i, j ) );
			bool miss = false;
			for( int k = 0; k < 6; ++k ){
				int pos = contact[ n ][ k ];
				if( pos >= 0 ){
					char c1 = dice[ i ][ pattern[ j ][ k ] - '0' ];
					char c2 = dice[ put[ pos ].first ][ pattern[ put[ pos ].second ][ touch[ k ] ] - '0' ];
					if( c1 > c2 ){
						c1 -= offset;
					}else{
						c2 -= offset;
					}
					if( c1 != c2 ){
						miss = true;
						break;
					}
				}
			}
			if( !miss && rec( dice, put, n + 1, selected | ( 1 << i ) ) ){
				return true;
			}
			put.pop_back();
		}
	}

	return false;
}

string solve( vector< string >& dice )
{
	vector< pair< int, int > > put;
	if( rec( dice, put, 0, 0 ) ){
		return "YES";
	}
	return "NO";
}

int main()
{
	string s;
	while( cin >> s && s != "0" ){
		vector< string > dice;
		dice.push_back( s );
		for( int i = 0; i < 8 - 1; ++i ){
			cin >> s;
			dice.push_back( s );
		}

		cout << solve( dice ) << endl;
	}

	return 0;
}