/**
 *   Author:   ShacozzZ
 *   Created:  2021-02-15 22:21:53
**/

#include <bits/stdc++.h>
using namespace std;
#define check(x) cout << "x = " << x << " "
#define endl "\n";
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const int md = 1e9 + 7;
const int maxn = 1e2 + 5;
const int maxm = 1e9;
const ull B = 233;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

ll n, m;
ll a[maxn][maxn];

inline void solve() {
    cin >> n;
    if(n % 2) {
        for(int i = 1; i <= n; i++) {
            for(int j = i + 1; j <= n; j++) {
                if(j - i <= (n - 1) / 2) {
                    cout << 1 << " ";
                } else {
                    cout << -1 << " ";
                }
            }
        }
    } else {
        for(int i = 1; i <= n; i++) {
            for(int j = i + 1; j <= n; j++) {
                if(j - i <= (n - 1) / 2) {
                    cout << 1 << " ";
                } else if(j - i == (n - 1) / 2 + 1) {
                    cout << 0 << " ";
                } else {
                    cout << -1 << " ";
                }
            }
        }
    }
    cout << endl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("/Users/zhoukaijie/Documents/ACM/a.in", "r", stdin);
    freopen("/Users/zhoukaijie/Documents/ACM/a.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int __ = 1;
    cin >> __;
    // init();
    while(__--) {
        solve();
    }
    return 0;
}
