//config = {stdin: 'tmp', newline: '\r\n'}; // win
config = {stdin: '/dev/stdin', newline: '\n'}; // linux

line = require('fs').readFileSync(config.stdin, 'ascii')
       .split(config.newline)
       .map(function (line) { return line.split(' '); });
line = line.slice(1, parseInt(line[0], 10) + 1);

function compare(dice1, dice2) {
  var d1 = dice1.sorted, d2 = dice2.sorted;
  for (var i in d1)
    if (d1[i] !== d2[i]) return d1[i] - d2[i];
  return 0;
}

line = line.map(function(dice) {
  var sorted = [].concat(dice);
  sorted.sort();
  return {
    raw: dice,
    sorted: sorted
  };
});
line.sort(compare);

group = [];
g = [];
for (i in line) {
  if (g.length === 0) {
    g.push(line[i]);
  } else if (compare(line[i], g[0]) === 0) {
    g.push(line[i]);
  } else {
    group.push(g);
    g = [line[i]];
  }
}
group.push(g);

dice_pos = {
  1: [0, 0, 0.5], 2: [0, -0.5, 0], 3: [0.5, 0, 0],
  4: [-0.5, 0, 0], 5: [0, 0.5, 0], 6: [0, 0, -0.5] };

function find(dice1, dice2, i) {
  return dice2.indexOf(dice1[i - 1]);
}

function sub(x, y) {
  return [x[0] - y[0], x[1] - y[1], x[2] - y[2]];
}

function get_vector_by_index(dice1, dice2, i, j) {
  var pi = find(dice1, dice2, i), pj = find(dice1, dice2, j);
  if (pi === -1 || pj === -1) return null;
  return sub(dice_pos[pi + 1], dice_pos[pj + 1]);
}

function equal(dice1, dice2) {
  var d1 = dice1.raw;
  var d2 = dice2.raw;
  var v16 = get_vector_by_index(d1, d2, 6, 1);
  var v25 = get_vector_by_index(d1, d2, 5, 2);
  var v34 = get_vector_by_index(d1, d2, 4, 3);
  var outer;

  if (v16 === null || v25 === null || v34 === null) return false;
  
  outer = [ v16[1] * v25[2] - v16[2] * v25[1],
            v16[2] * v25[0] - v16[0] * v25[2],
            v16[0] * v25[1] - v16[1] * v25[0] ];

  return (outer[0] === -v34[0] && outer[1] === -v34[1] && outer[2] == -v34[2]);
}

res = group.map(function (group) {
  for (var i = 0; i < group.length; i++)
    for (var j = i + 1; j < group.length; j++)
      if (equal(group[i], group[j])) return false;
  return true;
});

res = res.reduce(function (p, c) { return p && c; }, true);

console.log(res ? "Yes" : "No");