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 <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <limits>
using namespace std;
typedef long long ll;

enum Face {
	TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM, FACE_SIZE
};

template<class T>
struct Dice {
	T face[FACE_SIZE];

	Dice(){}
	Dice(T top, T front, T right, T left, T back, T bottom){
		face[TOP] = top;
		face[FRONT] = front;
		face[RIGHT] = right;
		face[LEFT] = left;
		face[BACK] = back;
		face[BOTTOM] = bottom;
	}

	void roll_y(){
		roll(FRONT, RIGHT, BACK, LEFT);
	}

	void roll_x(){
		roll(FRONT, BOTTOM, BACK, TOP);
	}

	void roll_z(){
		roll(TOP, RIGHT, BOTTOM, LEFT);
	}

	void roll(Face a, Face b, Face c, Face d){
		char tmp = face[d];
		face[d] = face[c];
		face[c] = face[b];
		face[b] = face[a];
		face[a] = tmp;
	}

	T at(Face a) const {
		return face[a];
	}

	static std::vector< Dice<T> > all_rolls(Dice<T> dice){
		std::vector< Dice<T> > res;
		for(int k=0;k<6;(k&1?dice.roll_y():dice.roll_x()),k++){
			for(int j=0;j<4;dice.roll_z(),j++){
				res.push_back(dice);
			}
		}
		return res;
	}
};


int dz[] =  {0, 0,  0,  0, 1, -1};
int dy[] =  {1, -1, 0,  0, 0, 0};
int dx[] =  {0, 0,  1, -1, 0, 0};
Face from[] = {BOTTOM, TOP, RIGHT, LEFT, BACK, FRONT};
Face to[] =   {TOP, BOTTOM, LEFT, RIGHT, FRONT, BACK};


bool valid[300][300];


Dice<char> rolls[8][24];

bool used[2][2][2];
Dice<char> cube[2][2][2];

bool dfs(int n, int mask){
	if(n >= 8)return true;

	int m = n;
	int x = m % 2; m /= 2;
	int y = m % 2; m /= 2;
	int z = m;

	for(int i=0;i<8;i++){
		if((mask >> i) & 1)continue;

		for(int r=0;r<24;r++){
			Dice<char> dice = rolls[i][r];
			bool ok = true;

			for(int k=0;k<6;k++){
				int nz = z + dz[k];
				int ny = y + dy[k];
				int nx = x + dx[k];

				if(nz < 0 || nz >= 2 || ny < 0 || ny >= 2 || nx < 0 || nx >= 2)continue;
				if(!used[nz][ny][nx])continue;

				if(!valid[ dice.at(from[k]) ][ cube[nz][ny][nx].at(to[k]) ]){
					ok = false;
					break;
				}
			}

			if(!ok)continue;

			used[z][y][x] = true;
			cube[z][y][x] = dice;


			if(dfs(n + 1, mask | (1 << i)))return true;

			used[z][y][x] = false;

		}
	}

	return false;
}

inline string solve(const vector< Dice<char> > &dice_vec){
	for(int i=0;i<dice_vec.size();i++){
		vector< Dice<char> > all_rolls = Dice<char>::all_rolls(dice_vec[i]);
		for(int j=0;j<all_rolls.size();j++){
			rolls[i][j] = all_rolls[j];
		}
	}

	memset(used, false, sizeof(used));
	return dfs(0, 0) ? "YES" : "NO";
}


Dice<char> toDice(const string& init){
	return Dice<char>(init[0], init[1], init[2], init[3], init[4], init[5]);
}

int main(){
	memset(valid, false, sizeof(valid));
	for(int i=0;i<26;i++){
		char a = 'a' + i;
		char b = 'A' + i;
		valid[a][b] = true;
		valid[b][a] = true;
	}

	string init;
	while(cin >> init){
		if(init == "0")break;

		vector< Dice<char> > dices;
		dices.push_back(toDice(init));

		for(int t=0;t<7;t++){
			cin >> init;
			dices.push_back(toDice(init));
		}

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

	return 0;
}