import Data.Functor( (<$>))
import Control.Monad( replicateM)

main = do
    let
	readLine = (read <$>) . words <$> getLine   ::IO [Int]

    n <- read <$> getLine
    dices <- replicateM n readLine
    let
	isId d1 d2
	  = case matchedState d2 [d1!!0, d1!!1] of
		[]  -> False
		list -> or $ ((drop 2 d1 ==) . (drop 2)) <$> list
	  where
	    matchedState dice [top, front]
	      = filter checkFront checkList
	        where
		    roll d 'S' = [d!!4, d!!0, d!!2, d!!3, d!!5, d!!1]
		    roll d 'N' = [d!!1, d!!5, d!!2, d!!3, d!!0, d!!4]
		    roll d 'W' = [d!!2, d!!1, d!!5, d!!0, d!!4, d!!3]
		    roll d 'E' = [d!!3, d!!1, d!!0, d!!5, d!!4, d!!2]

		    rolls d dirs = foldl roll d dirs

		    checkTop d = top == head d
		    checkFront d = front== d!!1
		    rot d = rolls d "ESW"
		    candidate = filter checkTop
				[ dice
				, rolls dice "S"
				, rolls dice "SS"
				, rolls dice "SSS"
				, rolls dice "E"
				, rolls dice "EE"
				, rolls dice "EEE"]
		    checkList = do
			c <- candidate
			[c, rot c, rot.rot $ c, rot.rot.rot $ c]

    if or $ uncurry isId <$>
	[(dices!!ix1, dices!!ix2) | ix1<-[0..n-2], ix2<-[ix1+1..n-1]]
    then putStrLn "No"
    else putStrLn "Yes"

