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.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static String[] list = new String[]{
		    "012345","024135","031425","043215","103254","120534",
		    "135024","152304","201453","215043","240513","254103",
		    "304152","310542","345012","351402","402351","425031",
		    "430521","453201","513240","521430","534120","542310"
	};
	
	static Dice[][] data;
	static int h;
	static int w;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		IN:while(true) {
			data = new Dice[8][24];
			for(int i = 0; i < 8; i++) {
				String in = sc.next();
				if(in.equals("0")) break IN;
				
				for(int j = 0; j < 24; j++) {
					String tmp = "";
					for(int k = 0; k < 6; k++) {
						tmp += in.charAt(list[j].charAt(k) - '0');
					}
					data[i][j] = new Dice(tmp);
				}
			}
			if(dfs(new Data(data))) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
	}
	
	static class Dice {
		char[] c;
		Dice(String a) {
			c = a.toCharArray();
		}
	}
	static class Block {
		Dice[] list;
		int count = 0;
		Block() {
			list = new Dice[8];
		}
		Block(Block a) {
			list = Arrays.copyOf(a.list, a.list.length);
			count = a.count;
		}
		boolean set(Dice a) {
			list[count++] = a;
			if(count == 1) {
				return true;
			}
			if(count == 2) {
				if(Character.toUpperCase(list[0].c[2]) == Character.toUpperCase(list[1].c[3]) && list[0].c[2] != list[1].c[3]) {
					return true;
				}
			}
			if(count == 3) {
				if(Character.toUpperCase(list[2].c[4]) == Character.toUpperCase(list[0].c[1]) && list[2].c[4] != list[0].c[1]) {
					return true;
				}
			}
			if(count == 4) {
				if(Character.toUpperCase(list[3].c[4]) == Character.toUpperCase(list[1].c[1]) && list[3].c[4] != list[1].c[1]) {
					if(Character.toUpperCase(list[3].c[3]) == Character.toUpperCase(list[2].c[2]) && list[3].c[3] != list[2].c[2]) {
						return true;
					}
				}
				
			}
			if(count == 5) {
				if(Character.toUpperCase(list[4].c[5]) == Character.toUpperCase(list[0].c[0]) && list[4].c[5] != list[0].c[0]) {
					return true;
				}
			}
			if(count == 6) {
				if(Character.toUpperCase(list[5].c[5]) == Character.toUpperCase(list[1].c[0]) && list[5].c[5] != list[1].c[0]) {
					if(Character.toUpperCase(list[5].c[3]) == Character.toUpperCase(list[4].c[2]) && list[5].c[3] != list[4].c[2]) {
						return true;
					}
				}
				
			}
			if(count == 7) {
				if(Character.toUpperCase(list[6].c[5]) == Character.toUpperCase(list[2].c[0]) && list[6].c[5] != list[2].c[0]) {
					if(Character.toUpperCase(list[6].c[4]) == Character.toUpperCase(list[4].c[1]) && list[6].c[4] != list[4].c[1]) {
						return true;
					}
				}
				
			}
			if(count == 8) {
				if(Character.toUpperCase(list[7].c[5]) == Character.toUpperCase(list[3].c[0]) && list[7].c[5] != list[3].c[0]) {
					if(Character.toUpperCase(list[7].c[3]) == Character.toUpperCase(list[6].c[2]) && list[7].c[3] != list[6].c[2]) {
						if(Character.toUpperCase(list[7].c[4]) == Character.toUpperCase(list[5].c[1]) && list[7].c[4] != list[5].c[1]) {
							return true;
						}
					}
				}
			}
			list[--count] = null;
			return false;
		}
	}
	static class Data {
		boolean[] useDice;
		Dice[][] DiceList;
		Block block;
		Data(Dice[][] a) {
			useDice = new boolean[8];
			DiceList = a;
			block = new Block();
		}

	}

	static boolean dfs(Data a) {
		for(int i = 0; i < 8; i++) {
			if(a.useDice[i]) {
				continue;
			}
			for(int j = 0; j < 24; j++) {
				if(a.block.set(data[i][j])) {
					if(a.block.count == 8) return true;
					a.useDice[i] = true;
					if(dfs(a)) return true;
					a.useDice[i] = false;
					a.block.list[--a.block.count] = null;
				}
			}
		}
		return false;
	}

	

}