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 JAVA):

Solution:
import java.util.*;
public class Main {
    Dice [] data;
    boolean flg;
    boolean [] used;
    ArrayList<ArrayList<Dice>> map;
    String [] order = {"", "n", "s", "e", "w", "nn"};
    String [] orderrev = {"", "s", "n", "w", "e", "nn"};
    int [][] pos = {
            {},
            {0},
            {0},
            {1,2},
            {0},
            {4,1},
            {4,2},
            {3,5,6}
    };
    int [][] face = {
            {},
            {2},
            {1},
            {1,2},
            {4},
            {2,4},
            {1,4},
            {4,1,2}
    };


    //dice is, 2 = south, 3 = east, 1 = top, 6 = bottom, 4 = west, 5 = north;
    class Dice{
        int [] dice;
        public Dice(int[] dice) {
            
            this.dice = new int[dice.length];
            for(int i = 0 ; i < dice.length; i++){
                this.dice[i] = dice[i];
            }
        }
        private void slide() {
            swap(2,4,5,3);
        }
        private void turn(char c) {
            switch(c){
            case 'n':
                swap(1,5,6,2); break;
            case 's':
                swap(1,2,6,5); break;
            case 'w':
                swap(1,4,6,3); break;
            case 'e':
                swap(1,3,6,4); break;
            }
        }
        private void swap(int i, int j, int k, int l) {
            int temp = dice[l];
            dice[l] = dice[k];
            dice[k] = dice[j];
            dice[j] = dice[i];
            dice[i] = temp;
        }
        public String toString(){
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i <= 6; i++){
                sb.append((char)(dice[i]) + " ");
            }
            return sb.toString();
        }
    }

    private void doit(){
        Scanner sc = new Scanner(System.in);
        while(true){
            Dice [] d = new Dice[8];
            String s = sc.next();
            if(s.equals("0")) break;
            d[0] = create(s);
            for(int i = 1; i < 8; i++){
                s = sc.next();
                Dice tempd = create(s);
                d[i] = tempd;
            }
            init(Arrays.copyOf(d, d.length));
            data = new Dice[8];
            flg = false;
            used = new boolean[8];
            dfs(0);
            if(flg){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }

        }
    }

    private void init(Dice[] d) {
        map =  new ArrayList<ArrayList<Dice>>();
        for(int i = 0; i < 8; i++){
            map.add(new ArrayList<Dice>());
        }

        for(int ii = 0; ii < 8; ii++){
            for(int i = 0; i < order.length; i++){
                for(int j = 0; j < order[i].length(); j++){
                    d[ii].turn(order[i].charAt(j));
                }

                for(int j = 0; j < 4; j++){
                    d[ii].slide();
                    map.get(ii).add(new Dice(d[ii].dice));
                }
                for(int j = 0; j < orderrev[i].length(); j++){
                    d[ii].turn(orderrev[i].charAt(j));
                }
            }
        }
//        for(int ind = 0; ind < map.size(); ind++){
//            for(int i = 0 ; i < map.get(ind).size(); i++){
//                System.out.println(map.get(ind).get(i));
//            }
//            System.out.println("////");
//        }

    }

    private void dfs(int deep) {
        //System.out.println("deep " + deep);
        if(deep == 8){
            flg = true;
            return ;
        }
        
        for(int i = 0; i < 8; i++){
            if(! used[i]){
                used[i] = true;
                for(int j = 0; j < map.get(i).size(); j++){
                    Dice now = map.get(i).get(j);
                    boolean isOK = true;
                    for(int k = 0; k < pos[deep].length; k++){
                        int myface = face[deep][k];
                        if(! match(data[pos[deep][k]].dice[7 - myface], now.dice[myface])){
                            isOK = false;
                            break;
                        }
                    }
                    if(isOK){
                        data[deep] = now;
                        dfs(deep+1);
                        if(flg) return ;
                    }
                }
                used[i] = false;
            }
        }
    }

    private boolean match(int i, int j) {
        if(Math.abs(i - j) == ('a' - 'A')){
            return true;
        }
        return false;
    }
    private Dice create(String s) {
        int [] res = new int[7];
        for(int i = 0; i < 6; i++){
            char c = s.charAt(i);
            res[i+1] = c;
        }
        return new Dice(res);
    }

    public static void main(String[] args) {
        Main obj = new Main();
        obj.doit();
    }
}