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>
#include <cstring>
using namespace std;

vector<vector<int> > rot = {
	{0,1,2,3,4,5}, {0,2,4,1,3,5}, {0,4,3,2,1,5}, {0,3,1,4,2,5},
	{1,5,2,3,0,4}, {1,2,0,5,3,4}, {1,0,3,2,5,4}, {1,3,5,0,2,4},
	{2,5,4,1,0,3}, {2,4,0,5,1,3}, {2,0,1,4,5,3}, {2,1,5,0,4,3},
	{3,4,5,0,1,2}, {3,5,1,4,0,2}, {3,1,0,5,4,2}, {3,0,4,1,5,2},
	{4,0,2,3,5,1}, {4,2,5,0,3,1}, {4,5,3,2,0,1}, {4,3,0,5,2,1},
	{5,4,2,3,1,0}, {5,2,1,4,3,0}, {5,1,3,2,4,0}, {5,3,4,1,2,0}
};

vector<vector<vector<int> > > cond = {
	{},
	{{3,0,2}},
	{{1,1,4}},
	{{1,0,4},{2,2,3}},
	{{0,3,5}},
	{{0,2,5},{3,4,2}},
	{{0,1,5},{4,5,1}},
	{{0,0,5},{2,6,3},{4,4,1}}
};

struct State { int id, r; };
State pz[8];

string dice[8];
bool used[8];
bool adj[8][8];

char toggleCase(char c) {
	if (islower(c)) return toupper(c);
	return tolower(c);
}

string solve(int x) {
	if (x == 8) return "YES";
	for (int i=1; i<8; ++i) {
		if (used[i]) continue;
		bool adjacent = true;
		for (int j=0; j<(int)cond[x].size(); ++j) {
			if ( ! adj[i][pz[cond[x][j][1]].id]) {
				adjacent = false; break;
			}
		}
		if ( ! adjacent) continue;
		for (int j=0; j<24; ++j) {
			pz[x].id = i;
			pz[x].r = j;
			bool ok = true;
			for (int k=0; k<(int)cond[x].size(); ++k) {
				int bloc1 = x;
				int face1 = rot[pz[bloc1].r][cond[x][k][0]];
				int bloc2 = cond[x][k][1];
				int face2 = rot[pz[bloc2].r][cond[x][k][2]];
				if (toggleCase(dice[pz[bloc1].id][face1]) != dice[pz[bloc2].id][face2]) {
					ok = false; break;
				}
			}
			if (ok) {
				used[i] = true;
				if (solve(x+1) == "YES") return "YES";
				used[i] = false;
			}
		}
	}
	return "NO";
}

int main() {
	while (cin >> dice[0], dice[0] != "0") {
		for (int i=1; i<8; ++i) {
			cin >> dice[i];
		}
		for (int i=0; i<8; ++i) {
			for (int j=i+1; j<8; ++j) {
				bool ok = false;
				for (int k=0; k<6 && !ok; ++k) {
					for (int l=0; l<6 && !ok; ++l) {
						if (toggleCase(dice[i][k]) == dice[j][l]) ok = true;
					}
				}
				adj[i][j] = adj[j][i] = ok;
			}
		}
		memset(used, false, sizeof used);
		used[0] = true;
		pz[0].id = 0;
		string res = "NO";
		for (int i=0; i<24; ++i) {
			pz[0].r = i;
			if (solve(1) == "YES") {
				res = "YES"; break;
			}
		}
		cout << res << endl;
	}
	return 0;
}