#include <bits/stdc++.h>
#define LL long long
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 505;

inline void gg(){
	cout << "No\n",exit(0);
}

int n;
LL c[N][N];
LL a[N],b[N];

int main(){
	int i,j;
	cin >> n;
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) cin >> c[i][j];
	
	LL mn = c[1][1];
	for (i = 1; i <= n; ++i) a[i] = c[i][1],mn = min(mn,a[i]);
	for (i = 1; i <= n; ++i) a[i] -= mn;
	for (i = 1; i <= n; ++i) b[i] = c[1][i] - a[1];
	
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) if (a[i] + b[j] != c[i][j]) gg();
	for (i = 1; i <= n; ++i) if (a[i] < 0 || b[i] < 0) gg();
	
	cout << "Yes\n";
	for (i = 1; i <= n; ++i) cout << a[i] << (i<n?' ':'\n');
	for (i = 1; i <= n; ++i) cout << b[i] << (i<n?' ':'\n');
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using P = pair<int, int>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

// @param m `1 <= m`
// @return x mod m
constexpr ll safe_mod(ll x, ll m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}

constexpr pair<ll, ll> inv_gcd(ll a, ll b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};

    // Contracts:
    // [1] s - m0 * a = 0 (mod b)
    // [2] t - m1 * a = 0 (mod b)
    // [3] s * |m1| + t * |m0| <= b
    ll s = b, t = a;
    ll m0 = 0, m1 = 1;

    while (t) {
        ll u = s / t;
        s -= t * u;
        m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b

        // [3]:
        // (s - t * u) * |m1| + t * |m0 - m1 * u|
        // <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
        // = s * |m1| + t * |m0| <= b

        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    // by [3]: |m0| <= b/g
    // by g != b: |m0| < b/g
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}

// (rem, mod)
pair<ll, ll> crt(const vector<ll>& r,
                                    const vector<ll>& m) {
    assert(r.size() == m.size());
    int n = int(r.size());
    // Contracts: 0 <= r0 < m0
    ll r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++) {
        assert(1 <= m[i]);
        ll r1 = safe_mod(r[i], m[i]), m1 = m[i];
        if (m0 < m1) {
            swap(r0, r1);
            swap(m0, m1);
        }
        if (m0 % m1 == 0) {
            if (r0 % m1 != r1) return {0, 0};
            continue;
        }
        // assume: m0 > m1, lcm(m0, m1) >= 2 * max(m0, m1)

        // (r0, m0), (r1, m1) -> (r2, m2 = lcm(m0, m1));
        // r2 % m0 = r0
        // r2 % m1 = r1
        // -> (r0 + x*m0) % m1 = r1
        // -> x*u0*g % (u1*g) = (r1 - r0) (u0*g = m0, u1*g = m1)
        // -> x = (r1 - r0) / g * inv(u0) (mod u1)

        // im = inv(u0) (mod u1) (0 <= im < u1)
        ll g, im;
        tie(g, im) = inv_gcd(m0, m1);

        ll u1 = (m1 / g);
        // |r1 - r0| < (m0 + m1) <= lcm(m0, m1)
        if ((r1 - r0) % g) return {0, 0};

        // u1 * u1 <= m1 * m1 / g / g <= m0 * m1 / g = lcm(m0, m1)
        ll x = (r1 - r0) / g % u1 * im % u1;

        // |r0| + |m0 * x|
        // < m0 + m0 * (u1 - 1)
        // = m0 + m0 * m1 / g - m0
        // = lcm(m0, m1)
        r0 += x * m0;
        m0 *= u1;  // -> lcm(m0, m1)
        if (r0 < 0) r0 += m0;
    }
    return {r0, m0};
}

void solve(){
	ll x, y, p, q;
	cin >> x >> y >> p >> q;
	ll ans = INF;
	FOR(i,x,x+y){
		FOR(j,p,p+q){
			auto re =  crt({i, j}, {2 * (x + y), (p + q)});
			if(re.first == 0 && re.second == 0){
				continue;
			}
			ans = min(ans, re.first);
		}
	}
	if(ans==INF){
		cout << "infinity" << endl;
	}else{
		cout << ans << endl;
	}
}

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin >> T;
	while(T--){
		solve();
	}

	return 0;
}

