#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

vector<int> up(const vector<int> &x) {
    vector<int> res = {x[2], x[1], x[5], x[0], x[4], x[3]};
    return res;
}

vector<int> left(const vector<int> &x) {
    vector<int> res = {x[1], x[5], x[2], x[3], x[0], x[4]};
    return res;
}

struct test {
    void solve() {
        int n;
        cin >> n;
        vector<vector<int>> a(n, vector<int>(n));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> a[i][j];
            }
        }
        vector<set<vector<int>>> d(n);
        d[n - 1].insert({a[n - 1][n - 1], -1, -1, -1, -1, -1});
        for (int i = n - 1; i >= 0; i--) {
            vector<set<vector<int>>> dd(n);
            for (int j = n - 1; j >= 0; j--) {
                for (auto &x : d[j]) {
                    if (i > 0) {
                        auto y = up(x);
                        if (y[0] == -1) y[0] = a[i - 1][j];
                        if (y[0] == a[i - 1][j]) {
                            dd[j].insert(y);
                        }
                    }
                    if (j > 0) {
                        auto y = left(x);
                        if (y[0] == -1) y[0] = a[i][j - 1];
                        if (y[0] == a[i][j - 1]) {
                            d[j - 1].insert(y);
                        }
                    }
                }
            }
            if (i > 0) d = dd;
        }
        if (d[0].empty()) {
            cout << "No\n";
        } else {
            auto x = *d[0].begin();
            cout << "Yes\n";
            for (int t : x) {
                cout << (t == -1 ? 0 : t) << " ";
            }
            cout << "\n";
        }
    }
};

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        test().solve();
    }

    return 0;
}