#include <bits/stdc++.h>
using namespace std;
const int kN = 505;
const int kInf = 1e9 + 7;

int n;
int a[kN][kN];

void No() {
  puts("No"); exit(0);
}
int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) scanf("%d", &a[i][j]);
  }

  for(int i = 0; i < n - 1; i++) {
    int diff = a[i + 1][0] - a[i][0];
    for(int j = 0; j < n; j++) {
      if(a[i + 1][j] - a[i][j] != diff) No();
    }
  }

  for(int j = 0; j < n - 1; j++) {
    int diff = a[0][j + 1] - a[0][j];
    for(int i = 0; i < n; i++) {
      if(a[i][j + 1] - a[i][j] != diff) No();
    }
  }

  vector<int> x(n), y(n);

  int mn = kInf, nx = -1, ny = -1;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(mn > a[i][j]) {
        mn = a[i][j], nx = i, ny = j;
      }
    }
  }

  for(int i = 0; i < n; i++) x[i] = mn + a[i][0] - a[nx][0];
  for(int i = 0; i < n; i++) y[i] = a[0][i] - a[0][ny];

  puts("Yes");
  for(int i = 0; i < n; i++) printf("%d ", x[i]); puts("");
  for(int i = 0; i < n; i++) printf("%d ", y[i]); puts("");

  return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>
#define ll long long int
#define inf 1000000000000
#define mod 1000000007

// templates
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ps(x,y)   fixed<<setprecision(y)<<x
#define fo(i,a,b) for(int i=a;i<b;i++)
#define ro(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define sc(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pr(n) printf("%d\n",n)
#define pl(n) printf("%lld\n",n)
#define prs(n) printf("%d ",n)
#define pls(n) printf("%lld ",n)
using namespace std;

ll GCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1LL;
		y = 0LL;
		return a;
	}
	ll x1, y1;
	ll d = GCD(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * 1LL * (a / b);
	return d;
}
void solve()
{
	ll n, s, k;
	sl(n), sl(s), sl(k);
	ll x, y;
	ll gc = __gcd(n, k);
	if (s % gc) {
		pl(-1LL);
	}
	else {
		// y->loops x->moves x*k+s=y*n => (x*k-y*n=-s)
		n /= gc, s /= gc, k /= gc;
		gc = GCD(k, n, x, y);
		ll mod_inv = (x % n + n) % n;
		ll ans = ((-s * mod_inv) % n + n) % n;
		pl(ans);
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	scanf("%d", &t);
	while (t--) {
		solve();
	}

}