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 <stdlib.h>
using namespace std;

int f[8],n[8],v[8];
int d[24][6],da[6][6]={{1,2,3,5,4,6},{2,3,1,4,6,5},{3,2,6,5,1,4},{4,2,1,5,6,3},{5,4,1,3,6,2},{6,5,3,2,4,1}};
char pd[8][7];

int check(int k) {
	int i,j,s;
	for (i=1;i<8;i++) {
		if (f[i]==1) continue;
		f[i]=1; n[k]=i; 
		for (j=0;j<24;j++) {
			v[k]=j; s=0;
			switch(k) {
				case 1: if (abs(pd[0][d[v[0]][3]]-pd[i][d[j][1]]) == 32) s=check(2); break;
				case 2: if (abs(pd[0][d[v[0]][2]]-pd[i][d[j][4]]) == 32) s=check(3); break;
				case 3: if (abs(pd[0][d[v[0]][0]]-pd[i][d[j][5]]) == 32) s=check(4); break;
				case 4: if (abs(pd[n[1]][d[v[1]][2]]-pd[i][d[j][4]]) == 32 && abs(pd[n[2]][d[v[2]][3]]-pd[i][d[j][1]]) == 32) s=check(5); break;
				case 5: if (abs(pd[n[3]][d[v[3]][3]]-pd[i][d[j][1]]) == 32 && abs(pd[n[1]][d[v[1]][0]]-pd[i][d[j][5]]) == 32) s=check(6); break;
				case 6: if (abs(pd[n[3]][d[v[3]][2]]-pd[i][d[j][4]]) == 32 && abs(pd[n[2]][d[v[2]][0]]-pd[i][d[j][5]]) == 32) s=check(7); break;
				case 7: if (abs(pd[n[6]][d[v[6]][3]]-pd[i][d[j][1]]) == 32 &&
				             abs(pd[n[5]][d[v[5]][2]]-pd[i][d[j][4]]) == 32 &&
				             abs(pd[n[4]][d[v[4]][0]]-pd[i][d[j][5]]) == 32 ) s=1;
				            break;
						}
						if (s==1) return 1;
			}
			f[i]=0;
		}
	return 0;
}

int main() {
	int i,j,k,m;
	for (i=0;i<6;i++) {
		for (j=0;j<4;j++) {
		 for (k=0;k<6;k++) d[i*4+j][k]=da[i][k]-1;
		 m=da[i][1]; 
		 for (k=1;k<4;k++) da[i][k]=da[i][k+1];
		 da[i][4]=m;
	 }
 }	
 
	while(cin >> pd[0]) {
		if (pd[0][0]=='0') break;
		for (i=1;i<8;i++) { cin >> pd[i]; f[i]=0;}
		for (i=0;i<24;i++) { v[0]=i; if (check(1)==1) break; }
		if (i==24) cout << "NO" << endl; else cout << "YES" << endl;
	}	
	return 0;
}