import Data.List
 
toDice :: [Int] -> [[Int]]
toDice [a,b,c,d,e,f] = [[a,f],[b,e],[c,d]]
 
pattern1 :: [Int] -> [String]
pattern1 x = map show [(x !! 0),(x !! 1),(x !! 5),(x !! 4),(x !! 0)]
 
pattern2 :: [Int] -> [String]
pattern2 x = map show [(x !! 1),(x !! 2),(x !! 4),(x !! 3),(x !! 1)]
 
pattern3 :: [Int] -> [String]
pattern3 x = map show [(x !! 2),(x !! 0),(x !! 3),(x !! 5),(x !! 2)]
 
solve :: [Int] -> String -> Int
solve list x
  | isInfixOf x (unwords $ pattern1 list) = list !! 2
  | isInfixOf x (unwords $ pattern2 list) = list !! 0
  | isInfixOf x (unwords $ pattern3 list) = list !! 1
  | isInfixOf x (unwords $ reverse $ pattern1 list) = list !! 3
  | isInfixOf x (unwords $ reverse $ pattern2 list) = list !! 5
  | isInfixOf x (unwords $ reverse $ pattern3 list) = list !! 4
  | otherwise = -1
 
check1 :: [[Int]] -> [[[Int]]]
check1 [] = []
check1 (i : is) = (sort . map sort . toDice) i : check1 is
 
check2 :: [[Int]] -> String -> [Int]
check2 [] _ = []
check2 (i : is) s = (solve i s) : check2 is s

diff :: [[Int]] -> String -> Bool
diff is s = ((m $ check1 is) == l) && (((m . check2 is) s) == l)
  where l = length is
        m = length . nub
        
main = getContents >>= putStrLn . (\xs -> if diff xs (mkstr $ head xs) then "Yes" else "No") . map(map read . words) . tail . lines
  where mkstr = unwords . map show . take 2