import Control.Monad
import Control.Applicative

move [a,b,c,d,e,f] o
	| o == 'E' = [d,b,a,f,e,c]
	| o == 'N' = [b,f,c,d,a,e]
	| o == 'S' = [e,a,c,d,f,b]
	| o == 'W' = [c,b,f,a,e,d]

allDicePattern dice = f dice (take 24 $ cycle "EEENNWWS")
	where
		f _ [] = []
		f dice (x:xs) = dice : f (move dice x) xs

solve (x:xs) = if any (`elem` allDicePattern x) xs then "No" else "Yes"

main = getContents >>= putStrLn . solve . map words . tail . lines