#include <bits/stdc++.h>

#define fi first
#define se second
#define SIZ 200011

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair <ii, ii> iiii;
typedef pair <ll, ll> pll;

int n, a[200011];
int score[111][111], win_row[111], win_col[111];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
//    freopen("INP.INP", "r", stdin);
//    freopen("OUT.OUT", "w", stdout);
    int tc;
    cin >> tc;
    for (int i = 1; i <= 101; i++) {
        for (int j = 1; j <= 101; j++)
            score[i][j] = 2;
    }
    while (tc--) {
        cin >> n;
        int win = (n - 1)/2;
        if ((n - 1) % 2 !=  0) {
            for (int i = 1; i <= n; i += 2)
                score[i][i + 1] = 0;
        }
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (score[i][j] != 2)
                    continue;
                if (win_row[i] < win && win_col[j] < win) {
                    score[i][j] = 1;
                    win_row[i]++;
                    win_col[j]++;
                }
                else
                    score[i][j] = -1;
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++)
                cout << score[i][j] << " ";
//            cout << '\n';
        }
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                score[i][j] = 2;
        for (int i = 1; i <= n; i++)
            win_row[i] = win_col[i] = 0;
        cout << '\n';
    }
    return 0;
}

/*
    long long range?
    reset array?
    special case?
    check array size
*/
