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<bits/stdc++.h>

using namespace std;

string CubeInfo[8];
pair<int, int*> Selected[8];
bool Used[8];
//top front right left back bottom
int RotateBase[24][6] = {
	{ 0,1,2,3,4,5 },{},{},{},
	{ 1,5,2,3,0,4 },{},{},{},
	{ 2,1,5,0,4,3 },{},{},{},
	{ 3,1,0,5,4,2 },{},{},{},
	{ 4,0,2,3,5,1 },{},{},{},
	{ 5,4,2,3,1,0 },{},{},{},
};


void fullRotateBase() {
	int tmp[6], num;

	for (int i = 0; i < 21; i += 4) {
		for (int j = 0; j < 6; ++j) {
			tmp[j] = RotateBase[i][j];
		}
		for (int k = 1; k < 4; ++k) {
			num = tmp[1];
			tmp[1] = tmp[3];
			tmp[3] = tmp[4];
			tmp[4] = tmp[2];
			tmp[2] = num;
			for (int j = 0; j < 6; ++j) {
				RotateBase[i + k][j] = tmp[j];
			}
		}
	}
}

bool checkSame(int dice1, int pos1, int dice2, int id, int pos2) {
	char c1, c2;

	c1 = CubeInfo[Selected[dice1].first][Selected[dice1].second[pos1]];
	c2 = CubeInfo[dice2][RotateBase[id][pos2]];

	if (abs(c1 - c2) == 32) {
		return true;
	}
	return false;
}

int solve(int currentId) {
	bool flag;

	if (currentId == 8) {
		return true;
	}

	for (int i = 0; i < 8; ++i) {
		if (Used[i]) {
			continue;
		}
		Used[i] = true;
		for (int id = 0; id < 24; ++id) {
			flag = false;
			//cout << "pos:" << currentId << " =(now_" << i + 1 << ")_pattern:" << setw(2) << id+1 << " = " << StrTmp[currentId] << endl;
			switch (currentId)
			{
			case 0:flag = true; break;
			case 1:
				if (checkSame(0, 2, i, id, 3)) {
					flag = true;
				}
				break;
			case 2:
				if (checkSame(0, 1, i, id, 4)) {
					flag = true;
				}
				break;
			case 3:
				if (checkSame(1, 1, i, id, 4) && checkSame(2, 2, i, id, 3)) {
					flag = true;
				}
				break;
			case 4:
				if (checkSame(0, 5, i, id, 0)) {
					flag = true;
				}
				break;
			case 5:
				if (checkSame(1, 5, i, id, 0) && checkSame(4, 2, i, id, 3)) {
					flag = true;
				}
				break;
			case 6:
				if (checkSame(2, 5, i, id, 0) && checkSame(4, 1, i, id, 4)) {
					flag = true;
				}
				break;
			case 7:
				if (checkSame(3, 5, i, id, 0) && checkSame(5, 1, i, id, 4) && checkSame(6, 2, i, id, 3)) {
					flag = true;
				}
				break;
			default:
				break;
			}
			Selected[currentId] = make_pair(i, RotateBase[id]);
			if (flag && solve(currentId + 1)) {
				return true;
			}
		}
		Used[i] = false;
	}
	return false;
}

int main() {
	int cnt;
	string str;

	fullRotateBase();
	cnt = 0;
	while (cin >> str, str[0] != '0') {
		CubeInfo[cnt] = str;
		++cnt;
		while (cnt != 8) {
			cin >> str;
			CubeInfo[cnt] = str;
			++cnt;
		}
		//show:
		/*for (int i = 0; i < cnt; ++i) {
		cout << CubeInfo[i] << endl;
		}*/
		memset(Used, false, sizeof(Used));
		memset(Selected, 0, sizeof(Selected));
		if (solve(0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		cnt = 0;
	}

	return 0;
}