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 <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std; 

class Dice
{
public:
    vector<char> pip; // ì¼kãºÌÚ
    Dice(){
        pip.assign(6, -1);
    }
    void roll(int d){ // ì¼kE¶Éñ]
        int dir[][4] = {{4,2,5,0},{4,3,5,1},{4,0,5,2},{4,1,5,3},{0,3,2,1},{0,1,2,3}};
        char tmp = pip[dir[d][0]];
        for(int i=0; i<3; ++i)
            pip[dir[d][i]] = pip[dir[d][i+1]];
        pip[dir[d][3]] = tmp;
    }
};

vector<Dice> dice(8);
vector<vector<vector<Dice> > > cube(2, vector<vector<Dice> >(2, vector<Dice>(2)));

bool solve(int curr, bitset<8> used)
{
    if(curr == 8)
        return true;
    int x = curr % 2;
    int y = curr / 2 % 2;
    int z = curr / 4 % 2;

    for(int i=0; i<8; ++i){
        if(used[i])
            continue;
        used[i] = true;
        for(int j=0; j<6; ++j){
            if(j < 4)
                dice[i].roll(0);
            else{
                dice[i].roll(1);
                if(j == 5)
                    dice[i].roll(1);
            }
            for(int k=0; k<4; ++k){
                dice[i].roll(4);
                if(x == 1 && abs(cube[0][y][z].pip[0] - dice[i].pip[2]) != abs('A' - 'a'))
                    continue;
                if(y == 1 && abs(cube[x][0][z].pip[4] - dice[i].pip[5]) != abs('A' - 'a'))
                    continue;
                if(z == 1 && abs(cube[x][y][0].pip[3] - dice[i].pip[1]) != abs('A' - 'a'))
                    continue;
                cube[x][y][z] = dice[i];
                if(solve(curr + 1, used))
                    return true;
            }
        }
        used[i] = false;
    }

    return false;
}

int main()
{
    for(;;){
        for(int i=0; i<8; ++i){
            string s;
            cin >> s;
            if(s == "0")
                return 0;

            dice[i].pip[4] = s[0];
            dice[i].pip[0] = s[1];
            dice[i].pip[1] = s[2];
            dice[i].pip[3] = s[3];
            dice[i].pip[2] = s[4];
            dice[i].pip[5] = s[5];
        }

        if(solve(0, 0))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}