#include using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define rep(i,n) for(ll i=0;i T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); } template T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); } template inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template ostream &operator<<(ostream &os, const vector &a){ if (a.empty()) return os; os << a.front(); for (auto e : a | views::drop(1)){ os << ' ' << e; } return os; } void dump(auto ...vs){ ((cout << vs << ' '), ...) << endl; } void solve() { ll N; cin>>N; ll S=(N-1)*(N-1); vector C(S); rep(i,S)cin>>C[i]; sort(all(C)); vector> A(N,vector(N,0)); rep(i,N-1){ if (i%2==0){ rep(j,N-1){ A[i+1][j+1]=C[i*(N-1)+j]-A[i+1][j]-A[i][j+1]-A[i][j]; } } else{ rep(j,N-1){ A[i+1][N-j-2]=C[i*(N-1)+j]-A[i+1][N-j-1]-A[i][N-j-2]-A[i][N-j-1]; } } } rep(i,N){ rep(j,N){ cout<sync_with_stdio(0); ll T=1; cin>>T; while (T--){ solve(); } return 0; }