#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;

const int N = INT_MAX;
const int64_t mod = 1LL + N;

vector<vector<int>> Solve(int n){
    vector<vector<int>> result(n, vector<int>(n));
    if (n == 2){
        result[0][1] = 0;
    }
    else if (n == 3){
        result[0][1] = 1;
        result[1][2] = 1;
        result[0][2] = -1;
    }
    else{
        vector<vector<int>> au = Solve(n-2);
        for (int i = 0; i < n - 2; i++){
            for (int j = i+1; j < n-2; j++){
                result[i][j] = au[i][j];
            }
        }
        if (n&1){
            result[n-2][n-1]=-1;
            for (int i = 0; i < (n-1)/2; i++){
                result[i][n-1] = 1;
                result[i][n-2] = -1;
            }
            for (int i = (n-1)/2; i < n-2; i++){
                result[i][n-1] = -1;
                result[i][n-2] = 1;
            }
        }
        else{
            result[n-2][n-1] = 0;
            for (int i = 0; i<(n-2)/2; i++){
                result[i][n-2] = 1;
                result[i][n-1] = -1;
            }
            for (int i = (n-2)/2; i < n-2; i++){
                result[i][n-2] = -1;
                result[i][n-1] = 1;
            }
        }
    }
    return result;
}

void solve(){
   int n; cin >> n;
   vector<vector<int>> result = Solve(n);
   for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            cout << result[i][j] << " ";
        }
   }
   cout << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
	ll t = 1;
    cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
//120 50 100 100 70000
