import scala.io.StdIn.{readInt,readLine}
/**
  * AOJ
  */

object Main {

  def main(args: Array[String]): Unit = {

    val n = readInt()
    var dices = List.empty[Array[Int]]
    for(_ <- 1 to n){
      dices :+= readLine().split(" ").map(_.toInt)
    }
    println(if(differentFromEachOther(dices)) "Yes" else "No")
  }

  def differentFromEachOther(dices:List[Array[Int]]): Boolean ={
    for(i <- 0 until dices.size; j <- (i + 1) until dices.size){
      if(diceEqual(dices(i),dices(j))) return false
    }
    return true
  }

  def diceEqual(dice1:Array[Int], dice2:Array[Int]) : Boolean = {
    for(i <- createDiceArray(dice1,"WNNNW"); j <- createDiceArray(i,"HHH")){
      if((j zip dice2).forall(x => x._1 == x._2)) return true
    }
    return false
  }

  def createDiceArray(dice:Array[Int],commands:String) : List[Array[Int]] = {
    var dices = List(dice)
    for(cmd <- commands.toCharArray){
      dices :+= getNextStatus(cmd,dices.last)
    }
    dices
  }

  def getNextStatus(cmd:Char,dice:Array[Int]): Array[Int] = cmd match {
    case 'N' => Array(dice(1), dice(5), dice(2), dice(3), dice(0), dice(4))
    case 'H' => Array(dice(0), dice(2), dice(4), dice(1), dice(3), dice(5))
    case 'W' => Array(dice(2), dice(1), dice(5), dice(0), dice(4), dice(3))
  }
}