import Data.List

pattern1 :: [Int] -> [String]
pattern1 [a,b,_,_,e,f] = map show [a,b,f,e,a]

pattern2 :: [Int] -> [String]
pattern2 [a,_,c,d,_,f] = map show [c,a,d,f,c]

pattern3 :: [Int] -> [String]
pattern3 [_,b,c,d,e,_] = map show [b,c,e,d,b]

solve :: [Int] -> String -> Int
solve list x
  | isInfixOf x (unwords $ pattern1 list) = list !! 2
  | isInfixOf x (unwords $ pattern2 list) = list !! 1
  | isInfixOf x (unwords $ pattern3 list) = list !! 0
  | isInfixOf x (unwords $ reverse $ pattern1 list) = list !! 3
  | isInfixOf x (unwords $ reverse $ pattern2 list) = list !! 4
  | isInfixOf x (unwords $ reverse $ pattern3 list) = list !! 5
  | otherwise = -1

check :: [[Int]] -> [String] -> [[Int]]
check [] _ = []
check (i : is) all@[s1,s2,s3] = [solve i s1, solve i s2, solve i s3] : check is all

diff :: [[Int]] -> [String] -> Bool
diff is s = (length $ nub $ check is s) == length is

main = getContents >>= putStrLn . (\xs -> if diff xs (mkstr $ head xs) then "Yes" else "No") . map(map read . words) . tail . lines
  where mkstr [a,b,c,d,e,f] = map (unwords . map show) [[a,b],[f,d],[a,d]]