//.at(i)を[i]と書いても警告が出るように #ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include using namespace std; struct RedCerr : public streambuf { streambuf* orig; bool line_start = true; RedCerr() : orig(cerr.rdbuf()) { cerr.rdbuf(this); } ~RedCerr() { cerr.rdbuf(orig); } int overflow(int c) override { if (c == EOF) return c; if (line_start) { string red = "\033[31m"; orig->sputn(red.c_str(), red.size()); line_start = false; } orig->sputc(c); if (c == '\n') { string reset = "\033[0m"; orig->sputn(reset.c_str(), reset.size()); line_start = true; } return c; } } red_cerr; //int64_t using lint = int64_t; //long double using ld = long double; //ベクター template using vc = vector; //1次元リスト template using vv = vector>; //2次元リスト template using vvv = vector>>; //3次元リスト template using vvvv = vector>>>; //4次元リスト //ペア using pll = pair; //プライオリティーキュー template using pq = priority_queue>; // 大きい順 template using pqg = priority_queue, greater>; // 小さい順 #define pb push_back #define mp make_pair #define fi first #define se second //all マクロ #define all(v) (v).begin(), (v).end() //ループマクロ #define re(n) for (int64_t r_= 0; r_< int64_t(n);r_++) #define rep(i, n) for (int64_t i = 0; i < int64_t(n); i++) #define repp(i, n) for (int64_t i = 0; i <= int64_t(n); i++) #define rrep(i, a, b) for (int64_t i = int64_t(a); i < int64_t(b); i++) #define rrepp(i, a, b) for (int64_t i = int64_t(a); i <= int64_t(b); i++) #define reep(i, n) for (int64_t i = int64_t(n)-1; i >= 0; i--) #define reepp(i, n) for (int64_t i = int64_t(n); i >= 0; i--) #define rreep(i, a, b) for (int64_t i = int64_t(b)-1; i >= int64_t(a); i--) #define rreepp(i, a, b) for (int64_t i = int64_t(b); i >= int64_t(a); i--) //sizeをint64_t型に #define sz(x) ((int64_t)x.size()) //next_permutation #define next_p(v) next_permutation((v).begin(), (v).end()) //無限 const int64_t inf = 1001001001; const int64_t INF = 4004004004004004004LL; //モッド const int64_t MOD = 998244353; //const int64_t MOD = 1000000007; //パイ const long double pi = 3.141592653589793238L; //ネイピア数 const long double napier = 2.7182818284590452353L; //移動 static constexpr int64_t dh[] = {0, -1, 0, 1, -1, -1, 1, 1}; static constexpr int64_t dw[] = {1, 0, -1, 0, 1, -1, -1, 1}; //cin cout オーバーロード //vector template istream &operator>>(istream &is, vector &v) { for (T & in : v) is >> in; return is; } template ostream &operator<<(ostream & os, const vector &v) { for (int64_t i = 0; i < (int64_t)v.size(); i++) { os << v[i] << (i + 1 != (int64_t)v.size() ? " " : ""); } return os; } template ostream &operator<<(ostream &os, const vector> &v) { for (int64_t i = 0; i < (int64_t)v.size(); i++) { os << v[i] << endl; } return os; } template ostream &operator<<(ostream &os, const vector>> &v) { for (int64_t i = 0; i < (int64_t)v.size(); i++) { os << "i = " << i << endl; os << v[i]; } return os; } //pair template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream & os, const pair & p) { os << "(" << p.first << "," << p.second << ")"; return os; } //vector複数行受け取り template void vcin(vector &u, vector &v) { if (u.size() != v.size()) { cerr << "vcinエラー サイズが異なります" << endl; assert(false); return; } for (int64_t i = 0; i < (int64_t)u.size(); i++) { cin >> u[i] >> v[i]; } return; } template void vcin(vector &u, vector &v, vector &w) { if (u.size() != v.size() || v.size() != w.size()) { cerr << "vcinエラー サイズが異なります" << endl; assert(false); return; } for (int64_t i = 0; i < (int64_t)u.size(); i++) { cin >> u[i] >> v[i] >> w[i]; } return; } //Yes No出力 #define YES cout << "YES" << endl; #define Yes cout << "Yes" << endl; #define NO cout << "NO" << endl; #define No cout << "No" << endl; void YN (bool b) { if (b) cout << "YES" << endl; else cout << "NO" << endl; return; } void yn (bool b) { if (b) cout << "Yes" << endl; else cout << "No" << endl; return; } // 値の更新 template bool chmax(T1 &x, const T2 &y) { bool compare = x < y; if (compare) x = y; return compare; } template bool chmin(T1 &x, const T2 &y) { bool compare = x > y; if (compare) x = y; return compare; } //経過時間 long double Time () { return 1.0 * (clock()) / CLOCKS_PER_SEC; } //小さい順 template void Vsort (vector &v) { sort(v.begin(), v.end()); return; } //大きい順 template void Vsortg (vector &v) { sort(v.rbegin(), v.rend()); return; } //リバース template void Vreverse (vector &v) { reverse(v.begin(), v.end()); return; } //重複の削除 template void Vunique (vector &v) { #ifndef ONLINE_JUDGE static bool w = false; if (!w) { cerr << "Vuniqueでは必ずソートされてますか?" << endl; w = true; } #endif v.erase(unique(v.begin(), v.end()), v.end()); return; } //上下反転 template void UDflip (vector> &v) { reverse(v.begin(), v.end()); return; } //左右反転 template void LRflip (vector> &v) { for (auto &x : v) { reverse(x.begin(), x.end()); } return; } //リストの移動 template void Vrotate (vector &v, int64_t n) { if (v.empty()) return; n %= (int64_t)v.size(); rotate(v.begin(), v.begin() + n, v.end()); return; } //右回転 template void VVrotate (vector> &v) { int64_t H = v[0].size(); int64_t W = v.size(); vector> L(H, vector(W)); for (int64_t i = 0; i < H; i++) { for (int64_t j = 0; j < W; j++) { L[j][W - i - 1] = v[i][j]; } } v = L; return; } //左回転 template void VVrotateg (vector> &v) { int64_t H = v[0].size(); int64_t W = v.size(); vector> L(H, vector(W)); for (int64_t i = 0; i < H; i++) { for (int64_t j = 0; j < W; j++) { L[H - j - 1][i] = v[i][j]; } } v = L; return; } //2次元距離 template long double distan (T x1, T y1, T x2, T y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } //2次元距離の2乗 template T distan2 (T x1, T y1, T x2, T y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } //範囲内チェック #define in_grid(h, w, H, W) if (!(0 <= h && 0 <= w && h < H && w < W)) continue; //nPr int64_t nPr (int64_t n, int64_t r) { int64_t Ans = 1; for (int64_t i = 0; i < r; i++) { Ans *= n - i; } return Ans; } //nCr vector> nCr_memo; int64_t nCr (int64_t n, int64_t r) { if (n < r) { cerr << "Error nCrのrがnより大きいです" << endl; assert(false); return 0; } for (int64_t i = (int64_t)nCr_memo.size(); i <= n; i++) { nCr_memo.push_back(vector(i + 1, 1)); for (int64_t j = 1; j < i; j++) { nCr_memo[i][j] = nCr_memo[i - 1][j - 1] + nCr_memo[i - 1][j]; } } return nCr_memo[n][r]; } //累乗 int64_t power (int64_t a, int64_t b) { int64_t Ans = 1; while (b > 0) { if (b & 1) Ans *= a; a *= a; b >>= 1; } return Ans; } //階乗 int64_t factorial(int64_t n) { int64_t Ans = 1; for (int64_t i = 1; i <= n; i++) Ans *= i; return Ans; } //数値のN桁目 int64_t digit(int64_t x, int64_t k) { while (k--) x /= 10; return x % 10; } //!#################################################################################################### void solve () { lint N; cin >> N; vc C((N-1) * (N-1)); cin >> C; Vsort(C); vv L(N, vc(N, 0)); rep (h, N-1) { rep (w, N-1) { lint c = 0; c += L[h][w]; c += L[h][w+1]; c += L[h+1][w]; L[h+1][w+1] = C[h*(N-1)+w] - c; } } cout << L; return; } int main () { ios::sync_with_stdio(false); cin.tie(nullptr); RedCerr red_cerr; //VSCodeで色つけるやつ cout << fixed << setprecision(15); cerr << fixed << setprecision(15); lint T = 1; cin >> T; re (T) solve(); cerr << endl << Time() << endl; }