import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Dice dice[] = new Dice[n];
		for(int j = 0; j < n; j++){
			int ravel[] = new int[6];
			for(int i = 0; i < 6; i++){
				ravel[i] = scan.nextInt();
			}
			dice[j] = new Dice(ravel);
		}
		scan.close();
		boolean bln = true;
		for(int i = 0; i < n; i ++){
			for(int j = i + 1; j < n; j++){
				if(dice[i].IsSame(dice[j])){
					bln = false;	//???????????????????????´???false
					break;
				}
			}
			if(!bln){
				break;
			}
		}
		if(bln){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

	static class Dice implements Cloneable{
		public int ravel[] = new int[6];

		public Dice(int[] _ravel) {
			ravel = _ravel;
		}

		@Override
	    public Dice clone() { //?????¬?????????public????£????????????????????????????????????????????????¨??????
			Dice b = null;

	        /*Object????????????clone???????????????CloneNotSupportedException????????????????????§??????????????§???try-catch?????§?¨???°(????????????????????????????????????)*/
	        try {
	            b=(Dice)super.clone(); //???????????????clone???????????????????????????(????????????????????§?????£??????????????§???????????????????????§????????£????????????????????????????????????)
	            b.ravel = this.ravel.clone(); //???????????????clone??????????????§??±????????????(????£????????????????????????°??¨????£????????????????????????°??§????????????????????????????????????????????????????????????)?????????????????????????????????????????°??????????????°???clone??????????????§????£???????????£????????????????????????°?????£??\
	        }catch (Exception e){
	            e.printStackTrace();
	        }
	        return b;
	    }

		static class TestCase{
			int topRavel;
			int frontRavel;
			boolean res = false;

			public TestCase(int _topRavel, int _frontRavel){
				topRavel = _topRavel;
				frontRavel = _frontRavel;
			}
		}

		public boolean IsSame(Dice cmp){
			TestCase testCase[][] = new TestCase[6][4];
			for(int k = 0; k < 6; k++){
				Dice copy = this.clone();
				switch(k){
				case 0:
					break;
				case 1:
					copy.MoveExec('N');
					break;
				case 2:
					copy.MoveExec('W');
					break;
				case 3:
					copy.MoveExec('E');
					break;
				case 4:
					copy.MoveExec('S');
					break;
				case 5:
					copy.Move("NN");
					break;
				}
				for(int j = 0; j < 4; j++){ //???????????±??????4??????
					copy.Rotate(j);
					testCase[k][j] = new TestCase(copy.ravel[0], copy.ravel[1]);
					for(int m = 0; m < 6; m++){ //?????§6???????§????
						Dice copyCmp = cmp.clone();
						switch(m){
						case 0:
							break;
						case 1:
							copyCmp.MoveExec('N');
							break;
						case 2:
							copyCmp.MoveExec('W');
							break;
						case 3:
							copyCmp.MoveExec('E');
							break;
						case 4:
							copyCmp.MoveExec('S');
							break;
						case 5:
							copyCmp.Move("NN");
							break;
						}
						boolean bln = true;
						for(int l = 0; l < 4; l++){ //?????§4?????¢???
							copyCmp.Rotate(l);
							bln = true;
							for(int i = 0; i < 6; i++){
								if(copy.ravel[i] != copyCmp.ravel[i]){
									bln = false;
									break;
								}
							}
							if(bln){
								break;
							}
						}
						if(bln){
							testCase[k][j].res = true;
							break;
						}
					}
				}
			}
			for(int i = 0; i < 6; i++){
				for(int j = 0; j < 4; j++){
					if(!testCase[i][j].res){
						return false;
					}
				}
			}
			return true;
		}

		public void Right(int topRavel, int frontRavel) {
			this.ShowSpecifiedTop(topRavel);
			this.ShowSpecifiedFront(frontRavel);
//			return ravel[2];
		}

		public void ShowSpecifiedTop(int topRavel){
			int pos = 0;
			for(int i = 0; i < 6; i++){
				if(ravel[i] == topRavel){
					pos = i;
					break;
				}
			}
			switch(pos){
			case 0:
				break;
			case 1:
				this.MoveExec('N');
				break;
			case 2:
				this.MoveExec('W');
				break;
			case 3:
				this.MoveExec('E');
				break;
			case 4:
				this.MoveExec('S');
				break;
			case 5:
				this.Move("NN");
				break;
			}
		}

		public void ShowSpecifiedFront(int frontRavel){
			int pos = 1;
			for(int i = 1; i <= 4; i++){
				if(ravel[i] == frontRavel){
					pos = i;
					break;
				}
			}
			int[] oldRavel = ravel.clone();
			switch(pos){
			case 1:
				break;
			case 2:
				ravel[1] = oldRavel[2];
				ravel[2] = oldRavel[4];
				ravel[4] = oldRavel[3];
				ravel[3] = oldRavel[1];
				break;
			case 3:
				ravel[1] = oldRavel[3];
				ravel[3] = oldRavel[4];
				ravel[4] = oldRavel[2];
				ravel[2] = oldRavel[1];
				break;
			case 4:
				ravel[1] = oldRavel[4];
				ravel[3] = oldRavel[2];
				ravel[4] = oldRavel[1];
				ravel[2] = oldRavel[3];
				break;
			}
		}

		public void Rotate(int count){
			//????¨???????????????¢??????
			count = Math.floorMod(count, 4);
			int[] oldRavel = ravel.clone();
			switch(count){
			case 1:
				ravel[1] = oldRavel[2];
				ravel[2] = oldRavel[4];
				ravel[4] = oldRavel[3];
				ravel[3] = oldRavel[1];
				break;
			case 2:
				ravel[1] = oldRavel[4];
				ravel[3] = oldRavel[2];
				ravel[4] = oldRavel[1];
				ravel[2] = oldRavel[3];
				break;
			case 3:
				ravel[1] = oldRavel[3];
				ravel[3] = oldRavel[4];
				ravel[4] = oldRavel[2];
				ravel[2] = oldRavel[1];
				break;
			case 4:
				break;
			}
		}

		public void Move(String order){
			char ch[] = order.toCharArray();
			for(int i = 0; i < ch.length; i++){
				MoveExec(ch[i]);
			}
		}

		private void MoveExec(char chOrder){
			int[] oldRavel = ravel.clone();
			switch(chOrder){
			case 'E':
				ravel[0] = oldRavel[3];
				ravel[3] = oldRavel[5];
				ravel[5] = oldRavel[2];
				ravel[2] = oldRavel[0];
				break;
			case 'N':
				ravel[0] = oldRavel[1];
				ravel[1] = oldRavel[5];
				ravel[5] = oldRavel[4];
				ravel[4] = oldRavel[0];
				break;
			case 'S':
				ravel[0] = oldRavel[4];
				ravel[4] = oldRavel[5];
				ravel[5] = oldRavel[1];
				ravel[1] = oldRavel[0];
				break;
			case 'W':
				ravel[0] = oldRavel[2];
				ravel[2] = oldRavel[5];
				ravel[5] = oldRavel[3];
				ravel[3] = oldRavel[0];
				break;
			}
		}
	}
}

Measured memory_bytes: 97052