#include "iostream"
using namespace std;

class Dice{
  public:
    int NowDiceNumber[6];
    Dice(){
      for(int i=0;i<6;i++){
        cin>>this->NowDiceNumber[i];
      }
    }
    void toNorth(){
      int alternativeDice[6];
      for(int i=0;i<6;i++){
        alternativeDice[i]=this->NowDiceNumber[i];
      }
      alternativeDice[0]=this->NowDiceNumber[4];
      alternativeDice[1]=this->NowDiceNumber[0];
      alternativeDice[2]=this->NowDiceNumber[2];
      alternativeDice[3]=this->NowDiceNumber[3];
      alternativeDice[4]=this->NowDiceNumber[5];
      alternativeDice[5]=this->NowDiceNumber[1];
      for(int i=0;i<6;i++){
        this->NowDiceNumber[i]=alternativeDice[i];
      }
    }
    void toSouth(){
      int alternativeDice[6];
      for(int i=0;i<6;i++){
        alternativeDice[i]=this->NowDiceNumber[i];
      }
      alternativeDice[0]=this->NowDiceNumber[1];
      alternativeDice[1]=this->NowDiceNumber[5];
      alternativeDice[2]=this->NowDiceNumber[2];
      alternativeDice[3]=this->NowDiceNumber[3];
      alternativeDice[4]=this->NowDiceNumber[0];
      alternativeDice[5]=this->NowDiceNumber[4];
      for(int i=0;i<6;i++){
        this->NowDiceNumber[i]=alternativeDice[i];
      }
    }
    void toEast(){
      int alternativeDice[6];
      for(int i=0;i<6;i++){
        alternativeDice[i]=this->NowDiceNumber[i];
      }
      alternativeDice[0]=this->NowDiceNumber[2];
      alternativeDice[1]=this->NowDiceNumber[1];
      alternativeDice[2]=this->NowDiceNumber[5];
      alternativeDice[3]=this->NowDiceNumber[0];
      alternativeDice[4]=this->NowDiceNumber[4];
      alternativeDice[5]=this->NowDiceNumber[3];
      for(int i=0;i<6;i++){
        this->NowDiceNumber[i]=alternativeDice[i];
      }
    }
    void toWest(){
      int alternativeDice[6];
      for(int i=0;i<6;i++){
        alternativeDice[i]=this->NowDiceNumber[i];
      }
      alternativeDice[0]=this->NowDiceNumber[3];
      alternativeDice[1]=this->NowDiceNumber[1];
      alternativeDice[2]=this->NowDiceNumber[0];
      alternativeDice[3]=this->NowDiceNumber[5];
      alternativeDice[4]=this->NowDiceNumber[4];
      alternativeDice[5]=this->NowDiceNumber[2];
      for(int i=0;i<6;i++){
        this->NowDiceNumber[i]=alternativeDice[i];
      }
    }
};

class checkDice: public Dice{
  public:
    /*int checkNumber;
    checkDice(int HowManyDices){
      for(int i;i<HowManyDices;i++){
        Dice dice[i];
      }
    }*/
    int checkEqul(Dice *dice1,Dice *dice2){
      for(int i=0;i<4;i++){
        dice1->toNorth();
        if(dice1->NowDiceNumber[0]==dice2->NowDiceNumber[0])break;
      }
      if(dice1->NowDiceNumber[0]!=dice2->NowDiceNumber[0]){
        dice1->toWest();
        if(dice1->NowDiceNumber[0]!=dice2->NowDiceNumber[0]){
          dice1->toNorth();
          dice1->toNorth();
          if(dice1->NowDiceNumber[0]!=dice2->NowDiceNumber[0])return 0;
        }
      }
      dice1->toWest();
      dice2->toWest();
      if(dice1->NowDiceNumber[0]!=dice2->NowDiceNumber[0]){
        for(int i=0;i<4;i++){
          dice1->toNorth();
          if(dice1->NowDiceNumber[0]==dice2->NowDiceNumber[0])break;
        }
        if(dice1->NowDiceNumber[0]!=dice2->NowDiceNumber[0])return 0;
      }
      if(dice1->NowDiceNumber[1]==dice2->NowDiceNumber[1]&&
      dice1->NowDiceNumber[2]==dice2->NowDiceNumber[2]&&
      dice1->NowDiceNumber[3]==dice2->NowDiceNumber[3]&&
      dice1->NowDiceNumber[4]==dice2->NowDiceNumber[4]){
        return 1;
      }else{
        return 0;
      }
    }
};

int main(){
  int HowManyDices;
  int x=0;
  cin>>HowManyDices;
  Dice dice[HowManyDices];
  checkDice cdice;
  int count=1;
  for(int i=0;i<HowManyDices-1;i++){
    for(int v=count;v<HowManyDices;v++){
      x+=cdice.checkEqul(&(dice[i]),&(dice[v]));
      count++;
    }
  }
  //cout<<x<<endl;
  if(x==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}



Measured memory_bytes: 3088