import Control.Monad
import Control.Applicative
import Data.List

data Dice = Dice{tp::Int, fr::Int, rt::Int, lt::Int, bk::Int, bm::Int} deriving (Show, Eq)

roll :: Dice -> Char -> Dice
roll (Dice tp fr rt lt bk bm) dir
  | dir == 'N' = Dice fr bm rt lt tp bk
  | dir == 'S' = Dice bk tp rt lt bm fr
  | dir == 'E' = Dice lt fr tp bm bk rt
  | dir == 'W' = Dice rt fr bm tp bk lt
  | otherwise = Dice tp fr rt lt bk bm

rolls :: Dice -> String -> Dice
rolls d s = foldl roll d s

initDice :: [Int] -> Dice
initDice (tp:fr:rt:lt:bk:bm:_) = Dice tp fr rt lt bk bm

setDice :: Dice -> Int -> Int -> [Dice]
setDice d t f = d2s
  where
    d1s = filter (\x -> tp x == t) $ scanl roll d "NENEN"
    d2s = (nub . concat) $ do
      d1 <- d1s
      return (filter (\x -> fr x == f) $ scanl rolls d1 ["NES","NES","NES"])

eql :: ([Int], [Int]) -> Bool
eql (xs, ys)
  | d1 `elem` d2s = True
  | otherwise = False
  where d1 = initDice xs
        d2s = setDice (initDice ys) (tp d1) (fr d1)

comb2 :: [a] -> [(a,a)]
comb2 [x,y] = [(x,y)]
comb2 (x:xs) = [(x,y) | y <- xs] ++ comb2 xs

solve :: [[Int]] -> String
solve xs
  | or zs = "No"
  | otherwise = "Yes"
  where
    ys = comb2 xs
    zs = map eql ys
    
main = do
  n <- readLn :: IO Int
  xs <- map (map read . words) <$> replicateM n getLine :: IO [[Int]]
  putStrLn $ solve xs

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6