object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val dices = (0 until n).map(_ => Dice(io.StdIn.readLine().split(" ").map(_.toInt)))

    val answer =
      if (dices
        .zipWithIndex
        .forall { case (dice, i) => (i + 1 until n).forall(j => Dice.notEquals(dice, dices(j))) }) {
        "Yes"
      } else {
        "No"
      }

    println(answer)
  }

  case class Dice(upSide: Int, southSide: Int, eastSide: Int, westSide: Int, northSide: Int, downSide: Int) {
    import Direction._
    def roll(direction: Direction): Dice = direction match {
      case North =>
        Dice(southSide, downSide, eastSide, westSide, upSide, northSide)
      case South =>
        Dice(northSide, upSide, eastSide, westSide, downSide, southSide)
      case West =>
        Dice(eastSide, southSide, downSide, upSide, northSide, westSide)
      case East =>
        Dice(westSide, southSide, upSide, downSide, northSide, eastSide)
    }
  }
  object Dice {
    def apply(sides: Array[Int]): Dice = Dice(sides(0), sides(1), sides(2), sides(3), sides(4), sides(5))

    def equals(d1: Dice, d2: Dice): Boolean = {
      import Direction._

      val sides = d1.northSide :: d1.westSide :: d1.southSide :: d1.eastSide ::
                  d1.northSide :: d1.westSide :: d1.southSide :: Nil
      @annotation.tailrec
      def sameDice(next: Option[Direction], d: Dice): Boolean = {
        val same =
          if (d1.upSide == d.upSide && d1.downSide == d.downSide) {
            sides.containsSlice(d.northSide :: d.westSide :: d.southSide :: d.eastSide :: Nil)
          } else if (d1.upSide == d.downSide && d1.downSide == d.upSide) {
            sides.containsSlice(d.northSide :: d.eastSide :: d.southSide :: d.westSide :: Nil)
          } else {
            false
          }
        if (same) {
          true
        } else {
          next match {
            case Some(North) => sameDice(Some(West), d.roll(North))
            case Some(West) => sameDice(None, d.roll(West))
            case _ => false
          }
        }
      }

      sameDice(Some(North), d2)
    }

    def notEquals(d1: Dice, d2: Dice): Boolean = !equals(d1, d2)
  }

  sealed trait Direction
  object Direction {
    case object North extends Direction
    case object South extends Direction
    case object West extends Direction
    case object East extends Direction

    def apply(c: Char): Direction = c match {
      case 'N' => North
      case 'S' => South
      case 'E' => East
      case 'W' => West
      case _ => throw new Exception
    }
  }
}