#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ITP1_11-D

Structure and Class - Dice IV
Time Limit : 1 sec, Memory Limit : 65536 KB
???????????? IV

Dice I ??¨????§????????????§?????\??????????????°????????? n

???????????????????????????????????????????????????????????????????????¨?????°???????????????????????????????????????????????°?????????????????????????????????????????????????????????????????? Dice III ??????????????¨????????????
Input

????????????????????????????????° n
?????????????????????????¶???? n

??????????????????????????¢?????°???????????????????????????

????????????????????????????????¢?????°???????????????????????????????????????????????§??????????????????????????????
Output

??\??????????????????????????????????????°????????´??? "Yes"??????????????????????????\?????????????????´??? "No" ??¨????????????????????????????????????
Constraints

    2???n???100

0???
??\?????????????????????????????¢?????°??? ???100

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No


Sample Input 2

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes

=end

class Dice
  def initialize(f)
    @face = Array.new(7,"")
    (0.upto(f.length-1)).each {|i| @face[i+1] = f[i]} 
  end

  def dump
    puts @face[1] + " " +  @face[2] + " " + @face[6] + " " +  @face[5] + " " + @face[4] + " " +  @face[3]
  end

  def e
    tmp = @face[1] 
    @face[1] = @face[4]
    @face[4] = @face[6]
    @face[6] = @face[3] 
    @face[3] = tmp
    @face[1]
  end

  def w
    tmp = @face[1] 
    @face[1] = @face[3]
    @face[3] = @face[6]
    @face[6] = @face[4]
    @face[4] = tmp
    @face[1]
  end

  def n
    tmp = @face[1] 
    @face[1] = @face[2]
    @face[2] = @face[6]
    @face[6] = @face[5]
    @face[5] = tmp
    @face[1]
  end

  def s
    tmp = @face[1] 
    @face[1] = @face[5]
    @face[5] = @face[6]
    @face[6] = @face[2]
    @face[2] = tmp
    @face[1]
  end

  def upface
    @face[1]
  end

  def frontface
    @face[2]
  end

  def rightface
    @face[3]
  end

  def face(i)
    @face[i]
  end

  def srchRight(s,t)
    (1..4).each {|i|
      break if self.frontface() == t;
      self.s
    }
    if self.frontface() != t then
      self.e
      (1..4).each {|i|
        break if self.frontface() == t;
        self.s
      }
    end
    return(false) if self.frontface() != t;
#    abort "strange #{t} not found" if self.frontface() != t;
    (1..4).each {|i|
      break if self.upface() == s;
      self.e
    }
    return(false) if self.upface() != s;
    #abort "strange #{s} not found" if self.upface() != s;

    self.rightface()
  end

  def same?(d)
    if not self.srchRight(d.upface(),d.frontface()) then
      return(false)
    end
    (0..(@face.length-1)).each {|i|
      if self.face(i) != d.face(i) then
        return(false)
      end}
    true
  end
end

class Main
  def initialize
    #fh = open("IPT1_11_B.txt")
    fh = STDIN
    d=[]
    n = fh.gets.chomp.to_i
    (1..n).each {|i|
      fl = fh.gets.chomp.split
      abort "small face data" + fl.join(" ") if fl.length != 6
      d[i] = Dice.new(fl) }

    ans=""
    (2..n).each{|i|
      (1..(i-1)).each{|j|
        if d[i].same?(d[j]) then
          ans="No"
          break
        end}}
    if ans=="" then
      ans="Yes"
    end

    puts ans

  end
end

if $0==__FILE__ then
  Main.new()
end

Measured memory_bytes: 8812