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<cmath>
#include<algorithm>
#include<string>
using namespace std;

string dice[8];
bool use[8];
string cube[8];

char trans(char a){
  if('a'<=a && a<='z')return a-32;
  else return a+32;
}

bool rec(int times){
  if(times == 8)return true;
  for(int i=0;i<8;i++){
    if(!use[i]){
      bool f = true;
      char ex;
      if(times%2){
	bool f2 = false;
	ex = trans(cube[times-1][5]);
	for(int j=0;j<6;j++)
	  if(dice[i][j]==ex)f2 = true;
	f &= f2;
      }

      if(times%4>=2){
	bool f2 = false;
	ex = trans(cube[times-2][3]);
	for(int j=0;j<6;j++)
	  if(dice[i][j]==ex)f2 = true;
	f &= f2;
      }
      if(times>=4){
	bool f2 = false;
	ex = trans(cube[times-4][4]);
	for(int j=0;j<6;j++)
	  if(dice[i][j]==ex)f2 = true;
	f &= f2;
      }
      if(f){
	use[i] = true;
	string tmp = dice[i];
	for(int l=0;l<3;l++){
	  if(l==1){
	    swap(tmp[0],tmp[5]);
	    swap(tmp[1],tmp[4]);
	  }
	  if(l==2){
	    swap(tmp[0],tmp[5]);
	    swap(tmp[2],tmp[3]);
	  }
	  for(int j=0;j<3;j++){
	    swap(tmp[0],tmp[1]);
	    swap(tmp[1],tmp[2]);
	    swap(tmp[5],tmp[4]);
	    swap(tmp[4],tmp[3]);
	    for(int k=0;k<4;k++){
	      swap(tmp[1],tmp[2]);
	      swap(tmp[2],tmp[4]);
	      swap(tmp[4],tmp[3]);

	      //if(!i && !times)cout << tmp << endl;
	      f = true;
	      if(times%2){
		if(trans(tmp[0])!=cube[times-1][5])f = false;
	      }
	      if(times%4>=2){
		if(trans(tmp[2])!=cube[times-2][3])f = false;
	      }
	      if(times>=4){
		if(trans(tmp[1])!=cube[times-4][4])f = false;
	      }
	      if(f){
		cube[times] = tmp;
		if(rec(times+1))return true;
	      }
	    }
	  }
	}
	use[i] = false;
      }
    }
  }

  return false;
}

int main(){
  for(;;){
    cin >> dice[0];
    if(dice[0] == "0")break;
    for(int i=1;i<8;i++)cin >> dice[i];
    for(int i=0;i<8;i++)use[i] = false;

    if(rec(0))cout << "YES\n";
    else cout << "NO\n";
    //for(int i=0;i<8;i++)cout << cube[i] << endl;
  }
}