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 <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef pair<P,P> Edge;
typedef long long ll;

// 24ñÅ³ÉàÇé
/*
zñÆ_CXÌÊÌÖW
c0ÍRXgN^ÌøÅ^¦çêéxN^Ìvf
0 c4 0 0
c3 c0 c2 c5
0 c1 0 0
*/
class Dice{
private:
	int yoko;
	int tate;
	int round;
private:
	int face[3][4];
public:
	int getFace(const int idx)const{
		if(idx==0)return face[1][1];
		else if(idx==1)return face[2][1];
		else if(idx==2)return face[1][2];
		else if(idx==3)return face[1][0];
		else if(idx==4)return face[0][1];
        else if(idx==5)return face[1][3];
		return -1;
	}
    Dice(){}
	Dice(vector<int> v){
		init();
		face[1][1]=v[0];
		face[2][1]=v[1];
		face[1][2]=v[2];
		face[1][0]=v[3];
		face[0][1]=v[4];
		face[1][3]=v[5];
	}
private:
	// _CXÌú»
	void init(){
		for(int i=0;i<3;i++)for(int j=0;j<4;j++)face[i][j]=-1;
		yoko=0;
		tate=0;
		round=0;
	}
public:
	// _CXÌñ]
	void rotate(){
		if(round<4){
			int tmp = face[2][1];
			face[2][1]=face[1][2];
			face[1][2]=face[0][1];
			face[0][1]=face[1][0];
			face[1][0]=tmp;
			round++;
		}
		if(round>=4){
			round=0;
			// àÇÁÄ«½çA¡ÌXbgðñ]³¹é
			if(yoko<4){
				int tmp = face[1][3];
				for(int i = 2; i >= 0; i--)
					face[1][i+1]=face[1][i];
				face[1][0]=tmp;
				yoko++;
			}
			// àÇÁÄ«½çAcÌXbgðñ]³¹é
			if(yoko>=4){
				if(tate<4){
					int loop=1;
					if(tate==1)loop=2;
					while(loop--){
						tate++;
						int tmp = face[1][3];
						face[1][3]=face[0][1];
						for(int i = 0; i < 2; i++)
							face[i][1]=face[i+1][1];
						face[2][1]=tmp;
					}
				}
				if(tate>=4){
					round=0;
					tate=0;
					yoko=0;
				}
			}
		}
	};
};

vector<int> idxs;
int cnt;
Dice dices[8];
void dfs(int pos){
    if(pos==0){
        for(int i=0;i<24;i++){
            dfs(pos+1);
            if(cnt>0)return;
            dices[idxs[pos]].rotate();
        }
    }
    else if(pos==1){
        for(int i=0;i<24;i++){
            // Êª¤©`FbN
            int ch1=dices[idxs[0]].getFace(2);
            int ch2=dices[idxs[pos]].getFace(3);
            if(abs(ch1-ch2)==32)dfs(pos+1);
            if(cnt>0)return;
            dices[idxs[pos]].rotate();
        }
    }
    else if(pos==2){
        for(int i=0;i<24;i++){
            // Êª¤©`FbN
            int ch1=dices[idxs[1]].getFace(1);
            int ch2=dices[idxs[pos]].getFace(4);
            if(abs(ch1-ch2)==32)dfs(pos+1);
            if(cnt>0)return;
            dices[idxs[pos]].rotate();
        }
    }
    else if(pos==3){
        for(int i=0;i<24;i++){
            // Êª¤©`FbN
            int ch1=dices[idxs[2]].getFace(3);
            int ch2=dices[idxs[pos]].getFace(2);
            int ch3=dices[idxs[0]].getFace(1);
            int ch4=dices[idxs[pos]].getFace(4);
            if(abs(ch1-ch2)==32&&abs(ch3-ch4)==32)dfs(pos+1);
            if(cnt>0)return;
            dices[idxs[pos]].rotate();
        }
    }
    else if(pos==4){
        for(int i=0;i<24;i++){
            // Êª¤©`FbN
            int ch1=dices[idxs[0]].getFace(5);
            int ch2=dices[idxs[pos]].getFace(0);
            if(abs(ch1-ch2)==32)dfs(pos+1);
            if(cnt>0)return;
            dices[idxs[pos]].rotate();
        }
    }
    else if(pos==5){
        for(int i=0;i<24;i++){
            // Êª¤©`FbN
            int ch1=dices[idxs[4]].getFace(2);
            int ch2=dices[idxs[pos]].getFace(3);
            int ch3=dices[idxs[1]].getFace(5);
            int ch4=dices[idxs[pos]].getFace(0);
            if(abs(ch1-ch2)==32&&abs(ch3-ch4)==32)dfs(pos+1);
            if(cnt>0)return;
            dices[idxs[pos]].rotate();
        }
    }
    else if(pos==6){
        for(int i=0;i<24;i++){
            // Êª¤©`FbN
            int ch1=dices[idxs[5]].getFace(1);
            int ch2=dices[idxs[pos]].getFace(4);
            int ch3=dices[idxs[2]].getFace(5);
            int ch4=dices[idxs[pos]].getFace(0);
            if(abs(ch1-ch2)==32&&abs(ch3-ch4)==32)dfs(pos+1);
            if(cnt>0)return;
            dices[idxs[pos]].rotate();
        }
    }
    else if(pos==7){
        for(int i=0;i<24;i++){
            // Êª¤©`FbN
            int ch1=dices[idxs[4]].getFace(1);
            int ch2=dices[idxs[pos]].getFace(4);
            int ch3=dices[idxs[6]].getFace(3);
            int ch4=dices[idxs[pos]].getFace(2);
            int ch5=dices[idxs[3]].getFace(5);
            int ch6=dices[idxs[pos]].getFace(0);
            if(abs(ch1-ch2)==32&&abs(ch3-ch4)==32&&abs(ch5-ch6)==32)dfs(pos+1);
            if(cnt>0)return;
            dices[idxs[pos]].rotate();
        }
    }
    else cnt++;
}

//bool search(){
//    cnt=0;
//    for(int i=0;i<8;i++)idxs[i]=i;
//    do{
//        for(int i=0;i<24;i++){
//            for(int j=0;j<24;j++){
//                // Êª¤©`FbN
//                int ch1=dices[idxs[0]].getFace(2);
//                int ch2=dices[idxs[1]].getFace(3);
//                if(abs(ch1-ch2)==32){
//                    for(int k=0;k<24;k++){
//                        // Êª¤©`FbN
//                        int ch1=dices[idxs[1]].getFace(1);
//                        int ch2=dices[idxs[2]].getFace(4);
//                        if(abs(ch1-ch2)==32){
//                            for(int l=0;l<24;l++){
//                                // Êª¤©`FbN
//                                int ch1=dices[idxs[2]].getFace(3);
//                                int ch2=dices[idxs[3]].getFace(2);
//                                int ch3=dices[idxs[0]].getFace(1);
//                                int ch4=dices[idxs[3]].getFace(4);
//                                if(abs(ch1-ch2)==32&&abs(ch3-ch4)==32){
//                                    for(int m=0;m<24;m++){
//                                        // Êª¤©`FbN
//                                        int ch1=dices[idxs[0]].getFace(5);
//                                        int ch2=dices[idxs[4]].getFace(0);
//                                        if(abs(ch1-ch2)==32){
//                                            for(int n=0;n<24;n++){
//                                                // Êª¤©`FbN
//                                                int ch1=dices[idxs[4]].getFace(2);
//                                                int ch2=dices[idxs[5]].getFace(3);
//                                                int ch3=dices[idxs[1]].getFace(5);
//                                                int ch4=dices[idxs[5]].getFace(0);
//                                                if(abs(ch1-ch2)==32&&abs(ch3-ch4)==32){
//                                                    for(int o=0;o<24;o++){
//                                                        // Êª¤©`FbN
//                                                        int ch1=dices[idxs[5]].getFace(1);
//                                                        int ch2=dices[idxs[6]].getFace(4);
//                                                        int ch3=dices[idxs[2]].getFace(5);
//                                                        int ch4=dices[idxs[6]].getFace(0);
//                                                        if(abs(ch1-ch2)==32&&abs(ch3-ch4)==32){
//                                                            for(int p=0;p<24;p++){
//                                                                // Êª¤©`FbN
//                                                                int ch1=dices[idxs[4]].getFace(1);
//                                                                int ch2=dices[idxs[7]].getFace(4);
//                                                                int ch3=dices[idxs[6]].getFace(3);
//                                                                int ch4=dices[idxs[7]].getFace(2);
//                                                                int ch5=dices[idxs[3]].getFace(5);
//                                                                int ch6=dices[idxs[7]].getFace(0);
//                                                                if(abs(ch1-ch2)==32&&abs(ch3-ch4)==32&&abs(ch5-ch6)==32){
//                                                                    return true;
//                                                                }
//                                                                dices[idxs[7]].rotate();
//                                                            }
//                                                        }
//                                                        dices[idxs[6]].rotate();
//                                                    }
//                                                }
//                                                dices[idxs[5]].rotate();
//                                            }
//                                        }
//                                        dices[idxs[4]].rotate();
//                                    }
//                                }
//                                dices[idxs[3]].rotate();
//                            }
//                        }
//                        dices[idxs[2]].rotate();
//                    }
//                }
//                dices[idxs[1]].rotate();
//            }
//            dices[idxs[0]].rotate();
//        }
//        //dfs(0);
//        //if(cnt>0)break;
//    }while(next_permutation(idxs,idxs+8));
//    return false;
//}

int main(){
    string s;
    while(getline(cin,s)&&s!="0"){
        vector<int> d;
        for(int i=0;i<s.size();i++)d.push_back(s[i]);
        dices[0]=Dice(d);
        for(int i=0;i<7;i++){
            d.clear();
            getline(cin,s);
            for(int j=0;j<s.size();j++)d.push_back(s[j]);
            dices[i+1]=Dice(d);
        }
        cnt=0;
        idxs.clear();
        for(int i=0;i<8;i++)idxs.push_back(i);
        // ·ÅÉTõ³ê½àÌðÂÁ±ñÅ¨­
        set<vector<int> > searched;
        do{
            if(searched.find(idxs)!=searched.end()){
                continue;
            }
            dfs(0);
            for(int i=0;i<4;i++){
                searched.insert(idxs);
                for(int base=0;base<2;base++){
                    int a=base*4;
                    int tmp=idxs[3+a];
                    idxs[3+a]=idxs[2+a];
                    idxs[2+a]=idxs[1+a];
                    idxs[1+a]=idxs[0+a];
                    idxs[a]=tmp;
                }
            }
            if(cnt>0)break;
        }while(next_permutation(idxs.begin(),idxs.end()));
        //if(search())cnt++;
        if(cnt>0)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

    return 0;
}