#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <regex>
#include <unordered_set>
#include <unordered_map>
#include <climits>
#include <iomanip>
#include <math.h>

#define ll long long
#define ld long double
#define INFL LLONG_MAX
#define INFI INT_MAX
#define PI 3.14159265358979323846
#define MOD 998244353

using namespace std;

int main() {

    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    for (int ti = 0; ti < t; ti++) {
        int n;
        cin >> n;

        if (n == 2) {
            cout << 0 << endl;
            continue;
        }
        if (n == 3) {
            cout << "1 -1 1" << endl;
            continue;
        }

        int a[n][n];
        if (n % 2 == 1) {
            int currentRowStart = 1;
            for (int i = 0; i < n; i++) {
                int current = currentRowStart;
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    a[i][j] = current;
                    current *= -1;
                }
                currentRowStart *= -1;
            }
        } else {
            int currentRowStart = 1;
            for (int i = 0; i < n; i++) {
                int current = currentRowStart;
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    if (i + j == n-1) {
                        a[i][j] = 0;
                        continue;
                    }
                    a[i][j] = current;
                    current *= -1;
                }
                currentRowStart *= -1;
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                cout << a[i][j] << " ";
            }
        }
        cout << endl;
    }
}

/**
 NOOB CHECK

 - Integers overflow
 - Initialize arrays
 - Don't continue to next test case before finishing reading the input
 - Add 2 lines to speed up the input
*/