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;

template <typename T>
struct Dice {
	vector<T> val;
	Dice(){ val.resize(6); }
	Dice(vector<T> &v) { val = v; }
	bool operator == (const Dice &t) const {
		return val == t.val;
	}
	bool operator != (const Dice &t) const {
		return val != t.val;
	}
	bool operator < (const Dice &t) const {
		return val < t.val;
	}
	inline T at(int i){
		return val[i];
	}
	inline void rotate_right(){
		T tmp = val[1];
		val[1] = val[2];
		val[2] = val[4];
		val[4] = val[3];
		val[3] = tmp;
	}
	inline void roll_front(){
		T tmp = val[0];
		val[0] = val[1];
		val[1] = val[5];
		val[5] = val[4];
		val[4] = tmp;
	}
	inline void roll_right(){
		T tmp = val[0];
		val[0] = val[3];
		val[3] = val[5];
		val[5] = val[2];
		val[2] = tmp;
	}
	vector<Dice> all_pattern(){
		vector<Dice> res;
		Dice d = *this;
		for (int i = 0; i < 6; i++){
			for (int j = 0; j < 4; j++){
				res.push_back(d);
				d.rotate_right();
			}
			if (i == 0) d.roll_front();
			else if (i < 5) d.roll_right();
			else d.roll_front();
		}
		return res;
	}
};

const int dx[] = {1, 0, 0, 0, 0, -1};
const int dy[] = {0, -1, 0, 0, 1, 0};
const int dz[] = {0, 0, 1, -1, 0, 0};
inline bool ok(int x, int y, int z)
{
	return x >= 0 && y >= 0 && z >= 0 &&
	       x <= 1 && y <= 1 && z <= 1;
}


char must[2][2][2][6];
vector<Dice<char> > ds;
vector<vector<Dice<char> > > D;
bool used[8];

bool check(int n)
{
	if (n == 8) return true;
	
	for (int now = 0; now < 8; now++){
		int x = !!(n & 4);
		int y = !!(n & 2);
		int z = n & 1;
		
		if (used[now]) continue;
		used[now] = true;
		for (int i = D[now].size() - 1; i >= 0; i--){	
			Dice<char> &dice = D[now][i];
			bool f = true;
			for (int j = 0; j < 6; j++){
				if (must[x][y][z][j] && must[x][y][z][j] != dice.at(j)){
					f = false;
					break;
				}
			}
			if (!f) continue;
			for (int dir = 0; dir < 6; dir++){
				int nx = x + dx[dir];
				int ny = y + dy[dir];
				int nz = z + dz[dir];
				if (!ok(nx, ny, nz)) continue;
				int to = (nx << 2) + (ny << 1) + nz;
				if (to < n) continue;
				//printf("%d\n", to);
				must[nx][ny][nz][5 - dir] = dice.at(dir) ^ 32;
			}
			if (check(n + 1)) return true;
		}
		used[now] = false;
	}
	
	return false;
}

void solve()
{
	memset(used, false, sizeof(used));
	if (check(0)){
		puts("YES");
		return;
	}
	puts("NO");
}

int main()
{	
	while (true){
		ds.clear();
		D.clear();
		for (int i = 0; i < 8; i++){
			vector<char> v(6);
			for (int j = 0; j < 6; j++){
				scanf(" %c", &v[j]);
				if (v[j] == '0') return 0;
			}
			ds.push_back(Dice<char>(v));
			D.push_back(ds[i].all_pattern());
		}
		solve();
	}
}