#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#pragma GCC optimize("O2")

#define _9trash no WA
#define ll long long
#define pb push_back

void io() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

// -------------------------------------------------------------

signed main() {
    io();

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            int win = (n - 1) / 2;
            for (int j = i + 1; j <= n; j++) {
                if (j - i <= win)
                    cout << 1 << " ";
                else if (j - i == win + 1 && n % 2 == 0)
                    cout << 0 << " ";
                else
                    cout << -1 << " ";
            }
        }
        cout << "\n";
    }

    return 0;
}