use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
  fn get_as_vec<T: FromStr>(&mut self) -> Vec<T> {
    self.iter.clone().map(|v| v.parse().ok().unwrap()).collect()
  }
  fn get_line(&mut self) -> String {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    line.trim().to_string()
  }
}

struct Dice {
  label: Vec<i32>,
}

#[allow(dead_code)]
impl Dice {
  fn new(dice: Vec<i32>) -> Dice {
    Dice { label: dice }
  }
  fn top(&self) -> i32 {
    self.label[0]
  }
  fn front(&self) -> i32 {
    self.label[1]
  }
  fn right(&self) -> i32 {
    self.label[2]
  }
  fn rotate(&mut self, a: usize, b: usize, c: usize, d: usize) {
    let tmp = self.label[a];
    self.label[a] = self.label[b];
    self.label[b] = self.label[c];
    self.label[c] = self.label[d];
    self.label[d] = tmp;
  }
  fn rotate_order(&mut self, order: char) {
    match order {
      'E' => self.east(),
      'W' => self.west(),
      'N' => self.north(),
      'S' => self.south(),
      'L' => self.rot_left(),
      'R' => self.rot_right(),
      _   => {}
    };
  }
  fn east(&mut self) {
    self.rotate(0, 3, 5, 2);
  }
  fn west(&mut self) {
    self.rotate(0, 2, 5, 3);
  }
  fn north(&mut self) {
    self.rotate(0, 1, 5, 4);
  }
  fn south(&mut self) {
    self.rotate(0, 4, 5, 1);
  }
  fn rot_right(&mut self) {
    self.rotate(1, 3, 4, 2);
  }
  fn rot_left(&mut self) {
    self.rotate(1, 2, 4, 3);
  }
  fn include_of(&self, elem: i32) -> usize {
    self.label.iter().position(|&e| e == elem).unwrap()
  }
  fn include_horizontal(&self, elem: i32) -> bool {
    match self.include_of(elem) {
      1 | 2 | 3 | 4 => true,
      _ => false
    }
  }
  fn include_vertical(&self, elem: i32) -> bool {
    match self.include_of(elem) {
      0 | 1 | 4 | 5 => true,
      _ => false
    }
  }
  fn included(&self, elem: i32) -> bool {
    self.label.iter().any(|&e| e == elem)
  }
  fn is_equal(&self, other: &Dice) -> bool {
    let mut other = Dice { label: other.label.clone() };
    let mut ans = true;
    for i in self.label.iter() {
      if !other.label.contains(i) {
        ans = false;
      }
    }
    if ans {
      let order = "RRRRNRRRNLLLLNLLLLNLLLNLLL";
      for o in order.chars() {
        other.rotate_order(o);
        ans = true;
        for i in 0..6 {
          if self.label[i] != other.label[i] {
            ans = false;
            break;
          }
        }
        if ans { break; }
      }
    }
    ans
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  sc.new_line();
  let n = scan!(sc; usize);
  let mut ans: Vec<bool> = Vec::with_capacity(n);
  sc.new_line();
  let d: Vec<i32> = sc.get_as_vec();
  let d = Dice::new(d);
  for _ in 0..n - 1 {
    sc.new_line();
    let d_: Vec<i32> = sc.get_as_vec();
    let d_ = Dice::new(d_);
    ans.push(d.is_equal(&d_));
  }
  let ans = ans.into_iter().filter(|&b| b).collect::<Vec<bool>>().len() == 0;
  println!("{}", if ans { "Yes" } else { "No" });
}



Measured memory_bytes: 5036