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

#define rep(i,n) for(int i = 0 ; i < (int)(n) ; i++)
#define f first
#define s second
#define mp make_pair
typedef pair<int, string>P;

//top, front, right, left, back, bottom;
string table[24] = {"012345","024135","043215","031426",
		    "103254","135024","152304","120534",
		    "201453","215043","254103","240513",
		    "304152","345012","351402","310542",
		    "402351","425031","453201","430521",
		    "513240","534120","542310","521430"};

P selectDice[8];
string face[8];
bool ok;
bool used[8];

bool check(int d1, int s1, int d2, int idx, int s2){
   char c1 = face[selectDice[d1].f][((int)selectDice[d1].s[s1]-'0')];
   char c2 = face[d2][((int)table[idx][s2]-'0')];
   if((isupper(c1) && isupper(c2)) || (islower(c1) && islower(c2)))return false;
   return (c1 - 32 == c2) || (c1 == c2 - 32);
} 

void dfs(int index){
   if(ok)return;
   
   if(index==8) ok = true;
   
   else{
      for(int i = 0 ; i < 8 ; i++){
	 if(used[i])continue;
	 used[i] = true;
	 for(int j = 0 ; j < 24 ; j++){
	    if(index==1 && !check(0, 2, i, j, 3))continue;
	    if(index==2 && !check(0, 1, i, j, 4))continue;
	    if(index==3 && (!check(1, 1, i, j, 4) || !check(2, 2, i, j, 3)))continue;
	    if(index==4 && !check(0, 5, i, j, 0))continue;
	    if(index==5 && (!check(1, 5, i, j, 0) || !check(4, 2, i, j, 3)))continue;
	    if(index==6 && (!check(2, 5, i, j, 0) || !check(4, 1, i, j, 4)))continue;
	    if(index==7 && (!check(3, 5, i, j, 0) || !check(5, 1, i, j, 4) || !check(6, 2, i, j, 3)))continue;
	    
	    selectDice[index] = mp(i, table[j]);
	    dfs(index+1);
	 }
	 used[i] = false;
      } 
   }
}

string solve(){
   ok = false;
   memset(used,false,sizeof(used));
   dfs(0);
   return ok ? "YES" : "NO";
}

int main(){
   while(cin >> face[0]){
      if(face[0]=="0")break;
      
      for(int i = 1 ; i < 8 ; i++) cin >> face[i];
	
      cout << solve() << endl;
   }
   return 0;
}