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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

struct Dice
{
	char f[8];
	int count;
	
	Dice() : count(0) {}
	
	void swap(int a, int b, int c, int d)
	{
		char tmp = f[a];
		f[a] = f[b];
		f[b] = f[c];
		f[c] = f[d];
		f[d] = tmp;
	}
	
	void xroll()
	{
		swap(0, 1, 5, 4);
	}
	
	void yroll()
	{
		swap(1, 2, 4, 3);
	}
	
	void zroll()
	{
		swap(0, 2, 5, 3);
	}
	
	void next()
	{
		zroll();
		if(count % 8 == 3)
			xroll();
		else if(count % 8 == 7)
			yroll();
		++count;
	}

	bool operator< (const Dice& d)const
	{
		return strcmp(f, d.f) < 0;
	}
};

bool okok(char a, char b)
{
	return a != b && (tolower(a) == b || a == tolower(b));
}

bool search(Dice d[8], int depth)
{
	if(depth == 8)
		return true;
	
	rep(i, 24){
		bool ok;
		if(depth == 1)
			ok = okok(d[0].f[2], d[1].f[3]);
		else if(depth == 2)
			ok = okok(d[0].f[4], d[2].f[1]);
		else if(depth == 3)
			ok = okok(d[1].f[4], d[3].f[1]) && okok(d[2].f[2], d[3].f[3]);
		else if(depth == 4)
			ok = okok(d[0].f[0], d[4].f[5]);
		else if(depth == 5)
			ok = okok(d[1].f[0], d[5].f[5]) && okok(d[4].f[2], d[5].f[3]);
		else if(depth == 6)
			ok = okok(d[2].f[0], d[6].f[5]) && okok(d[4].f[4], d[6].f[1]);
		else
			ok = okok(d[3].f[0], d[7].f[5]) && okok(d[5].f[4], d[7].f[1]) && okok(d[6].f[2], d[7].f[3]);
		
		if(ok && search(d, depth+1))
			return true;
		
		d[depth].next();
	}
	return false;
}

int main()
{
	Dice dice[8];
	while(1){
		bool quit = false;
		rep(i, 8){
			scanf("%s", dice[i].f);
			if(dice[i].f[0] == '0'){
				quit = true;
				break;
			}
		}
		if(quit)
			break;

		int ans = false;
		sort(dice, dice+8);
		do{
			bool ok = false;
			set<int> memo;
			rep(i, 24){
				char c[3] = {dice[0].f[0], dice[0].f[2], dice[0].f[4]};
				sort(c, c+3);
				int key = (c[0]<<16) + (c[1]<<8) + c[2];
				if(!memo.count(key)){
					memo.insert(key);
					if(search(dice, 1)){
						ok = true;
						break;
					}
				}
				dice[0].next();
			}
			if(ok){
				ans = true;
				break;
			}
		}while(next_permutation(dice+1, dice+8));
		puts(ans ? "YES" : "NO");
	}

	return 0;
}