
object Main extends App {

  override def main(args: Array[String]): Unit = {
    val n = io.StdIn.readLine.toInt
    
    val list = (1 to n).map(_ => io.StdIn.readLine.split(' ')).map(i => new Dice(i(0),i(1),i(2),i(3),i(4),i(5))).toIndexedSeq

    val pairs = for(i <- (0 until n ); j <- (i+1 until n)) yield { (list(i),list(j)) }

    val cond = pairs.exists(p => p._1.isSame(p._2))
    
    if(cond) println("No")
    else println("Yes")
  }

  case class Dice(top: String, south: String, east: String, west: String, north: String, buttom: String) {

    def toNorth: Dice = {
      new Dice(south, buttom, east, west, top, north)
    }
    def toSouth: Dice = {
      new Dice(north, top, east, west, buttom, south)
    }
    def toEast: Dice = {
      new Dice(west, south, top, buttom, north, east)
    }
    def toWest: Dice = {
      new Dice(east, south, buttom, top, north, west)
    }
    def rotRight: Dice = {
      new Dice(top, east, north, south, west, buttom)
    }
    def rotLeft: Dice = {
      new Dice(top, west, south, north, east, buttom)
    }

    def getAsTop(toTop: String): List[Dice] =  List(
        if (top == toTop) List(this) else List.empty,
        if (south == toTop) List(toNorth) else List.empty,
        if (north == toTop) List(toSouth) else List.empty,
        if (west == toTop) List(toEast) else List.empty,
        if (east == toTop) List(toWest) else List.empty,
        if (buttom == toTop) List(toEast.toEast) else List.empty
        ).flatten

    def getAsSouthByRot(toSouth: String): List[Dice] = List(
        if (south == toSouth) List(this) else List.empty,
        if (north == toSouth) List(rotLeft.rotLeft) else List.empty,
        if (west == toSouth) List(rotLeft) else List.empty,
        if (east == toSouth) List(rotRight) else List.empty
        ).flatten

    def getAsTopAndSouthIs(top: String, south: String): List[Dice] = {
        getAsTop(top).flatMap(_.getAsSouthByRot(south))
    }
    
    def isSame(target :Dice) : Boolean = {
        getAsTopAndSouthIs(target.top, target.south).exists(rot => rot == target)
    }

  }

}