#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

#define D_N 0
#define D_E 1
#define D_S 2
#define D_W 3

using namespace std;

class Dice {
private:
  int side_values[6];

public:
  void set_values(vector<int> v) {
    for(int i=0; i<6; i++) {
      this->side_values[i] = v[i];
    }
  }

  void roll(int dir) {
    int side_temp[6];
    switch(dir) {
    case D_N:
      side_temp[0] = this->side_values[1];
      side_temp[1] = this->side_values[5];
      side_temp[2] = this->side_values[2];
      side_temp[3] = this->side_values[3];
      side_temp[4] = this->side_values[0];
      side_temp[5] = this->side_values[4];
      break;
    case D_E:
      side_temp[0] = this->side_values[3];
      side_temp[1] = this->side_values[1];
      side_temp[2] = this->side_values[0];
      side_temp[3] = this->side_values[5];
      side_temp[4] = this->side_values[4];
      side_temp[5] = this->side_values[2];
      break;
    case D_S:
      side_temp[0] = this->side_values[4];
      side_temp[1] = this->side_values[0];
      side_temp[2] = this->side_values[2];
      side_temp[3] = this->side_values[3];
      side_temp[4] = this->side_values[5];
      side_temp[5] = this->side_values[1];
      break;
    case D_W:
      side_temp[0] = this->side_values[2];
      side_temp[1] = this->side_values[1];
      side_temp[2] = this->side_values[5];
      side_temp[3] = this->side_values[0];
      side_temp[4] = this->side_values[4];
      side_temp[5] = this->side_values[3];
      break;
    default:
      break;
    }

    for(int i=0; i<6; i++) {
      this->side_values[i] = side_temp[i];
    }
  }

  int get_side_idx_of_value(int val) {
    for(int i=0; i<6; i++) {
      if(this->side_values[i] == val) {
        return i;
      }
    }

    return -1;
  }

  void roll_for_idx(int idx) {
    switch(idx) {
    case 1:
      this->roll(D_N);
      break;
    case 2:
      this->roll(D_W);
      break;
    case 3:
      this->roll(D_E);
      break;
    case 4:
      this->roll(D_S);
      break;
    case 5:
      this->roll(D_N);
      this->roll(D_N);
      break;
    default:
      break;
    }
  }
  
  void roll_for_value(int val) {
    int side_idx = this->get_side_idx_of_value(val);
    this->roll_for_idx(side_idx);
  }

  int get_value() {
    return this->side_values[0];
  }
  int get_invisible_value() {
    return this->side_values[5];
  }

  void get_standing_sides(int * sides) {
    sides[0] = this->side_values[1];
    sides[1] = this->side_values[2];
    sides[2] = this->side_values[4];
    sides[3] = this->side_values[3];
  }
};
      
int main() {
  // Put your favorite codes here
  vector<vector<int>> vs;
  vector<Dice> dices;
  int n;
  int da_idx = 0, db_idx = 1;
  int da_sides[4], db_sides[4];
  bool is_identical = false;

  cin >> n;
  for(int i=0; i<n; i++) {
    Dice dt;
    vector<int> vt;
    for(int j=0; j<6; j++) {
      int temp;
      cin >> temp;
      vt.push_back(temp);
    }
    vs.push_back(vt);
    dt.set_values(vt);
    dices.push_back(dt);
  }

  for(da_idx=0; da_idx<n-1; da_idx++) {
    dices[da_idx].set_values(vs[da_idx]);
    for(db_idx=da_idx+1; db_idx<n; db_idx++) {
      for(int k=0; k<6; k++) {
        int db_search_idx = 0;
        dices[db_idx].set_values(vs[db_idx]);
        dices[db_idx].roll_for_idx(k);
        if(dices[da_idx].get_value() != dices[db_idx].get_value()) {
          continue;
        }
        if(dices[da_idx].get_invisible_value() != dices[db_idx].get_invisible_value()) {
          continue;
        }

        dices[da_idx].get_standing_sides(da_sides);
        dices[db_idx].get_standing_sides(db_sides);
        while(db_search_idx < 4 && da_sides[0] != db_sides[db_search_idx]) {
          db_search_idx++;
        }
        if(db_search_idx >= 4) {
          continue;
        }
        db_search_idx++;
        if(db_search_idx >= 4) {
          db_search_idx = 0;
        }

        is_identical = true;
        for(int i=1; i<4; i++) {
          if(da_sides[i] != db_sides[db_search_idx]) {
            is_identical = false;
            break;
          }
          db_search_idx++;
          if(db_search_idx >= 4) {
            db_search_idx = 0;
          }
        }
        if(is_identical) {
          break;
        } else {
          continue;
        }
      }
      
      if(is_identical) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 3172