// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
struct dice_{
  int x[6];
  dice_(){}
  void input(){
    rep(i, 6)cin >> x[i];
  }
  void north(){
    int y[6];
    y[0] = x[1];
    y[1] = x[5];
    y[2] = x[2];
    y[3] = x[3];
    y[4] = x[0];
    y[5] = x[4];
    swap(x, y);
  }
  void south(){
    int y[6];
    y[0] = x[4];
    y[1] = x[0];
    y[2] = x[2];
    y[3] = x[3];
    y[4] = x[5];
    y[5] = x[1];
    swap(x, y);
  }
  void east(){
    int y[6];
    y[0] = x[3];
    y[1] = x[1];
    y[2] = x[0];
    y[3] = x[5];
    y[4] = x[4];
    y[5] = x[2];
    swap(x, y);
  }
  void west(){
    int y[6];
    y[0] = x[2];
    y[1] = x[1];
    y[2] = x[5];
    y[3] = x[0];
    y[4] = x[4];
    y[5] = x[3];
    swap(x, y);
  }
  void right(){
    int y[6];
    y[0] = x[0];
    y[1] = x[2];
    y[2] = x[4];
    y[3] = x[1];
    y[4] = x[3];
    y[5] = x[5];
    swap(x, y);
  }
  void left(){
    int y[6];
    y[0] = x[0];
    y[1] = x[3];
    y[2] = x[1];
    y[3] = x[4];
    y[4] = x[2];
    y[5] = x[5];
    swap(x, y);
  }
  void set(int a, int b){
    if(x[0] == a){
      rep(i, 4){
        left();
        if(x[1] == b)return;
      }
    }
    if(x[5] == a){
      north(); north();
      rep(i, 4){
        left();
        if(x[1] == b)return;
      }
    }
    north();
    if(x[0] == a){
      rep(i, 4){
        left();
        if(x[1] == b)return;
      }
    }
    south(); south();
    if(x[0] == a){
      rep(i, 4){
        left();
        if(x[1] == b)return;
      }
    }
    north(); east();
    if(x[0] == a){
      rep(i, 4){
        left();
        if(x[1] == b)return;
      }
    }
    west(); west();
    if(x[0] == a){
      rep(i, 4){
        left();
        if(x[1] == b)return;
      }
    }
    east();
  }
};

using dice = struct dice_;

bool eq(dice &a, dice &b){
  bool res = true;
  rep(i, 6)res &= (a.x[i] == b.x[i]);
  return res;
}

bool comp(dice &a, dice &b){
  bool res = false;
  rep(i, 4){
    b.left();
    res |= eq(a, b);
  }
  b.north();
  rep(i, 4){
    b.left();
    res |= eq(a, b);
  }
  b.south(); b.south();
  rep(i, 4){
    b.left();
    res |= eq(a, b);
  }
  b.north(); b.west();
  rep(i, 4){
    b.left();
    res |= eq(a, b);
  }
  b.east(); b.east();
  rep(i, 4){
    b.left();
    res |= eq(a, b);
  }
  b.west(); b.north(); b.north();
  rep(i, 4){
    b.left();
    res |= eq(a, b);
  }
  b.south(); b.south();

  return res;
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<dice> d(n);
  rep(i, n){
    d[i].input();
  }
  bool res = false;
  rep(i, n){
    FOR(j, i+1, n){
      res |= comp(d[i], d[j]);
    }
  }
  if(res)cout << "No" << endl;
  else cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 3108