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<cstdio>
#include<cassert>
#include<climits>
#include<algorithm>
#include<vector>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)

using namespace std;

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class dice {
public:
  dice() {
    id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
    id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
  }
  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const { return var[id[f]]; }
  bool operator==(const dice<T>& b) const {
    const dice<T> &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
      a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
      a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
  vector<dice> all_rolls() {
    vector<dice> ret;
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        ret.push_back(*this);
    return ret;
  }
  bool equivalent_to(const dice& di) {
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        if (*this == di) return true;
    return false;
  }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    T tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};

FACE face[] = {TOP,FRONT,RIGHT,LEFT,BACK,BOTTOM};

int dx[] = {-1,0,0};
int dy[] = {0,-1,0};
int dz[] = {0,0,-1};
FACE dc[] = {RIGHT,FRONT,BOTTOM};
FACE rdc[] = {LEFT,BACK,TOP};
dice<char> field[2][2][2];
bool found;

void dfs(int x,int y,int z,int state,vector<dice<char> >& dices)
{
  if(found)return;
  if(state >= (1<<8)-1)
    {
      found = true;
      return;
    }

  rep(i,8)
    {
      if((state>>i) & 1)continue;
      vector<dice<char> > next = dices[i].all_rolls();
      rep(j,next.size())
	{
	  bool ok = true;
	  rep(k,3)
	    {
	      int nx = x + dx[k];
	      int ny = y + dy[k];
	      int nz = z + dz[k];
	      if(!( 0 <= nx && nx < 2 && 0 <= ny && ny < 2 && 0 <= nz && nz < 2 ))continue;
	      char a = field[nz][ny][nx][dc[k]];
	      char b = next[j][rdc[k]];
	      if(!(a != b && tolower(a) == tolower(b) ))
		{
		  ok = false;
		  break;
		}
	    }

	  int nx = x + 1;
	  int ny = y;
	  int nz = z;
	  if(nx >= 2)nx %= 2, ny++;
	  if(ny >= 2)ny %= 2, nz++;

	  if(ok)
	    {
	      field[z][y][x] = next[j];
	      dfs(nx,ny,nz,state|(1<<i),dices);
	      if(found)return;
	    }
	}
    }

}

int main()
{
  while(true)
    {
      vector<dice<char> > dices((8),dice<char>());
      rep(i,8)
	{
	  rep(j,6)
	    {
	      cin >> dices[i][face[j]];
	      if(dices[i][face[j]] == '0')goto Fin;
	    }
	}

      found = false;
      dfs(0,0,0,0,dices);
      cout << (found?"YES":"NO") << endl;
    }
 Fin:;
  return 0;
}