#include<iostream>
//#include<cmath>
#include <string>
#include<vector>
#include <iomanip>
using namespace std;

class Dice{
private:
//  vector<vector<int>> nextsurface(6,vector<int>(4));
vector<int> surface;
public:
  Dice(){}
  Dice(vector<int> dice){
    surface=dice;
  }
  void set_Dice(vector<int> dice){
    surface=dice;
  }

  void roll_dice(char direction){
    if(direction=='N'){
      int temp=surface.at(0);
      surface.at(0)=surface.at(1);
      surface.at(1)=surface.at(5);
      surface.at(5)=surface.at(4);
      surface.at(4)=temp;
    }
    else if(direction=='E'){
      int temp=surface.at(0);
      surface.at(0)=surface.at(3);
      surface.at(3)=surface.at(5);
      surface.at(5)=surface.at(2);
      surface.at(2)=temp;
    }
    else if(direction=='S'){
      int temp=surface.at(0);
      surface.at(0)=surface.at(4);
      surface.at(4)=surface.at(5);
      surface.at(5)=surface.at(1);
      surface.at(1)=temp;
    }
    else{
      int temp=surface.at(0);
      surface.at(0)=surface.at(2);
      surface.at(2)=surface.at(5);
      surface.at(5)=surface.at(3);
      surface.at(3)=temp;
    }
  }

  void disp_topdice(){
    cout<<surface.at(0)<<endl;
  }

  int get_surfacenum(int snum){
    return surface.at(snum-1);
  }
  int get_insurfacenum(int snum){
    return surface.at(snum);
  }

  int right_side(int upper,int front){
    int upperface,frontface;
    for(int i=0;i<6;i++){
      if(upper==surface.at(i)) upperface=i;
      if(front==surface.at(i)) frontface=i;
    }
    switch(upperface){
      //return は内部のindex+1
      case 0:
      if(frontface==1) return 2+1;
      else if(frontface==2) return 4+1;
      else if(frontface==4) return 3+1;
      else if(frontface==3) return 1+1;
      break;
      case 1:
      if(frontface==5) return 2+1;
      else if(frontface==2) return 1;
      else if(frontface==0) return 3+1;
      else if(frontface==3) return 5+1;
      break;
      case 2:
      if(frontface==5) return 4+1;
      else if(frontface==4) return 1;
      else if(frontface==0) return 1+1;
      else if(frontface==1) return 5+1;
      break;
      case 3:
      if(frontface==5) return 1+1;
      else if(frontface==1) return 1;
      else if(frontface==0) return 4+1;
      else if(frontface==4) return 5+1;
      break;
      case 4:
      if(frontface==5) return 3+1;
      else if(frontface==3) return 1;
      else if(frontface==0) return 2+1;
      else if(frontface==2) return 5+1;
      break;
      case 5:
      if(frontface==1) return 3+1;
      else if(frontface==3) return 4+1;
      else if(frontface==4) return 2+1;
      else if(frontface==2) return 1+1;
      break;
    }
  }
  void cicle_dice(string roll){
    if(roll=="CCW"){
      int temp=surface.at(1);
      surface.at(1)=surface.at(3);
      surface.at(3)=surface.at(4);
      surface.at(4)=surface.at(2);
      surface.at(2)=temp;
    }
    if(roll=="CW"){
      int temp=surface.at(1);
      surface.at(1)=surface.at(2);
      surface.at(2)=surface.at(4);
      surface.at(4)=surface.at(3);
      surface.at(3)=temp;
    }
  }

};
bool correct_rolling(Dice dice1,Dice dice2){//at(0)はもう一個の0番目の面
  for(int i=0;i<6;i++){
    if(dice1.get_insurfacenum(0)==dice2.get_insurfacenum(i)){
      switch(i){
        case 0: break;
        case 1:
        dice2.roll_dice('N'); break;
        case 2:
        dice2.roll_dice('W'); break;
        case 3:
        dice2.roll_dice('E'); break;
        case 4:
        dice2.roll_dice('S'); break;
        case 5:
        dice2.roll_dice('N');dice2.roll_dice('N');
        break;
      }
      if(dice1.get_insurfacenum(5)==dice2.get_insurfacenum(5)){
        for(int n=0;n<4;n++){
          for(int j=1;j<5;j++){
            if(dice1.get_insurfacenum(j)!=dice2.get_insurfacenum(j)) break;
            if(j==4&&(dice1.get_insurfacenum(j)==dice2.get_insurfacenum(j))){
              return true;
            }
          }
          dice2.cicle_dice("CW");
        }
      }
    }
  }
  return false;
}


int main(void){
  vector<int> vdice(6);
//  string str;
  int loop;
  bool flag=true;
  cin>>loop;
  Dice dice[loop];
  for(int i=0;i<loop;i++){
    for(int i=0;i<6;i++) cin>>vdice.at(i);
    dice[i].set_Dice(vdice);
  }

  for(int i=0;i<loop;i++){
    for(int j=i+1;j<loop;j++){
      if(correct_rolling(dice[i],dice[j])){
        cout<<"No"<<endl;
        flag=false;
        break;
      }
    }
    if(flag==false) break;
  }
  if(flag) cout<<"Yes"<<endl;

//  cin>>str;
  //for(int i=0;i<str.size();i++) dice1.roll_dice(str[i]);
//  dice1.disp_topdice();
//cin>>loop;
//for(int i=0;i<loop;i++){
//  cin>>up>>frnt;
//  snum=dice1.get_surfacenum(dice1.right_side(up,frnt));
//  cout<<snum<<endl;
//}

  return 0;


}



Measured memory_bytes: 3148