<?php
fscanf(STDIN, "%d", $n);

$dices = array();
for ($i = 0; $i < $n; $i++) {
    $labels = fscanf(STDIN, '%d %d %d %d %d %d');
    $dices[] = new Dice($labels);
}

for ($i = 0; $i < $n-1; $i++) {
    for ($j = $i+1; $j < $n; $j++) {
        if (same_dice($dices[$i], $dices[$j])) {
            echo "No\n";
            exit;
        }
    }
}

echo "Yes\n";

function same_dice($d1, $d2)
{
    if ($d1->equalsTo($d2)) {
        return true;
    }

    $d1->moveToDown();
    $d1->moveToDown();

    if ($d1->equalsTo($d2)) {
        return true;
    }

    $d1->setDefault();
    $d1->moveToLeft();
    if ($d1->equalsTo($d2)) {
        return true;
    }

    $d1->moveToLeft();
    $d1->moveToLeft();
    if ($d1->equalsTo($d2)) {
        return true;
    }

    $d1->setDefault();
    $d1->moveToUp();
    if ($d1->equalsTo($d2)) {
        return true;
    }

    $d1->moveToUp();
    $d1->moveToUp();
    if ($d1->equalsTo($d2)) {
        return true;
    }

    return false;
}

class Dice
{
    private $labels;

    private $top;
    private $bottom;
    private $front;
    private $back;
    private $left;
    private $right;

    public function __construct(array $labels=array(1,2,3,4,5,6))
    {
        $this->labels = $labels;
        $this->setDefault();
    }

    public function setDefault()
    {
        $this->top    = 1;
        $this->bottom = 6;
        $this->front  = 2;
        $this->back   = 5;
        $this->left   = 4;
        $this->right  = 3;

        return $this;
    }

    public function moveTo($direct)
    {
        $directions = is_array($direct) ? $direct : array($direct);

        foreach ($directions as $dir) {
            switch ($dir) {
            case 'N':
                $this->moveToUp();
                break;
            case 'S':
                $this->moveToDown();
                break;
            case 'E':
                $this->moveToRight();
                break;
            case 'W':
                $this->moveToLeft();
                break;
            }
        }

        return $this;
    }

    public function moveToDown()
    {
        $this->front  = $this->top;
        $this->top    = $this->back;
        $this->back   = 7 - $this->front;
        $this->bottom = 7 - $this->top;

        return $this;
    }

    public function moveToUp()
    {
        $this->back   = $this->top;
        $this->top    = $this->front;
        $this->front  = 7 - $this->back;
        $this->bottom = 7 - $this->top;

        return $this;
    }

    public function moveToRight()
    {
        $this->right  = $this->top;
        $this->top    = $this->left;
        $this->left   = 7 - $this->right;
        $this->bottom = 7 - $this->top;

        return $this;
    }

    public function moveToLeft()
    {
        $this->left   = $this->top;
        $this->top    = $this->right;
        $this->right  = 7 - $this->left;
        $this->bottom = 7 - $this->top;

        return $this;
    }

    public function rotateToRight()
    {
        $this->right = $this->back;
        $this->back  = $this->left;
        $this->left  = 7 - $this->right;
        $this->front = 7 - $this->back;

        return $this;
    }

    public function rotateToLeft()
    {
        $this->left  = $this->back;
        $this->back  = $this->right;
        $this->right = 7 - $this->left;
        $this->front = 7 - $this->back;

        return $this;
    }

    public function top()
    {
        return $this->label($this->top);
    }

    public function bottom()
    {
        return $this->label($this->bottom);
    }

    public function front()
    {
        return $this->label($this->front);
    }

    public function back()
    {
        return $this->label($this->back);
    }

    public function left()
    {
        return $this->label($this->left);
    }

    public function right()
    {
        return $this->label($this->right);
    }

    public function equalsTo(Dice $dice)
    {
        if ($this->top() != $dice->top()) {
            return false;
        }

        if ($this->bottom() != $dice->bottom()) {
            return false;
        }

        $around1  = $this->left().$this->front().$this->right().$this->back();
        $around1 .= $around1;

        $around2 = $dice->left().$dice->front().$dice->right().$dice->back();

        return false !== strpos($around1, $around2);
    }

    private function label($index)
    {
        return $this->labels[$index-1];
    }

    private function index($label)
    {
        foreach ($this->labels as $index => $val) {
            if ($val == $label) {
                return $key + 1;
            }
        }
    }
}

Measured memory_bytes: 6976