process.stdin.resume();
process.stdin.setEncoding('utf8');

class Dice {
    constructor(top, front, right, left, back, bottom) {
        this.top = top;
        this.front = front;
        this.right = right;
        this.left = left;
        this.back = back;
        this.bottom = bottom;
    }
    rollVertical() {
        return new Dice(this.front, this.bottom, this.right, this.left, this.top, this.back);
    }
    rollHorizontal() {
        return new Dice(this.top, this.right, this.back, this.front, this.left, this.bottom);
    }
    existVertial(number) {
        return [this.top, this.front, this.bottom, this.back].includes(number);
    }
    existHorizontal(number) {
        return [this.front, this.left, this.back, this.right].includes(number);
    }
    /**
     * 別のDice１つを引数に取り、同じであればtrue, 違えばfalseを返す
     * @param {Dice}} otherDice 
     */
    isSameDice(otherDice) {
        // console.log(`${JSON.stringify(this)} === ${JSON.stringify(otherDice)}`)
        return JSON.stringify(this) === JSON.stringify(otherDice);
    }

    /**
     * 他のダイス１つ引数に取り、回転しているだけで同じダイスであればtrue,別のダイスであればfalseを返す
     * @param {Dice} otherDice 
     */
    detectSameDice(otherDice) {


        const verticalDiceList = otherDice.vertialRollDiceList();
        const verticalHorizontaldiceList = verticalDiceList.map(x => x.horizontalRollDiceList());

        const rolledDice = otherDice.rollHorizontal();

        const verticalDiceList2 = rolledDice.vertialRollDiceList();
        const verticalHorizontaldiceList2 = verticalDiceList2.map(x => x.horizontalRollDiceList());

        const diceListFlat = Array.prototype.concat.apply([], verticalHorizontaldiceList.concat(verticalHorizontaldiceList2));

        return diceListFlat.find(x => x.isSameDice(this)) ? true : false;
    }

    /**
     * 自分を横に四回回して得られる全てのサイコロを配列で返す
     */
    horizontalRollDiceList() {
        const diceList = [];
        let diceState = this;
        [...Array(4).keys()].forEach(x => {
            diceList.push(diceState);
            diceState = diceState.rollHorizontal();
        });
        return diceList;
    }
    /**
     * 自分を縦に四回回して得られる全てのサイコロを返す
     */
    vertialRollDiceList() {
        const diceList = [];
        let diceState = this;
        [...Array(4).keys()].forEach(x => {
            diceList.push(diceState);
            diceState = diceState.rollVertical();
        });
        return diceList;
    }

}


process.stdin.on('data', function (chunk) {
    const n = chunk.toString() // 文字列化する
        .split("\n") // \nで分割
        .filter(x => x !== "");
    let dice = [];
    const [, ...alldice] = n;
    const all = alldice.map(x => x.split(" "));
    for (let i = 0; i < alldice.length; i++) {
        var [top, front, right, left, back, bottom] = all[i];
        dice.push(new Dice(top, front, right, left, back, bottom));
    }
    let ans = [];
    dice.forEach(x => {
        for (i = 0; i < dice.length; i++) {
            ans.push(x.detectSameDice(dice[i]) ? "Yes" : "No");
        }
    })

    let countY = 0;

    for (i = 0; i < ans.length; i++) {
        if (ans[i] === "Yes") {
            countY += 1;
        }
    }
    if (countY === dice.length) {
        console.log("Yes");
    } else {
        console.log("No");
    }

});
