#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define vll vector<ll> 
#define vvl vector<vll>
#define pii pair<ll,ll>
#define F first
#define S second
#define endl "\n"
#define M 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll min(ll a,ll b){if(a<b) return a; return b;}
ll mod=998244353;
 
ll po(ll x, ll y){
    if(y==0)
    return 1;
    if(y%2){
        return ((x)*(po(x,y/2)%M)*(po(x,y/2)%M) + M)%M;
    }
   return ((po(x,y/2)%M)*(po(x,y/2)%M) + M)%M;
}
 
void seive(bool prime[]){
    //bool prime[100002]; 
     
  
    for (ll p=2; p*p<=1000001; p++) 
    { 
        if (prime[p]) 
        { 
            for (ll i=p*p; i<=1000001; i+=p) 
                prime[i] = false; 
        } 
    }
}
 
ll powermod(ll x,ll y,ll p)  {
  ll res = 1;     
    x = x % p; 
 if (x == 0) return 0;  
    while (y > 0)  
    {     if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
 
ll gcd(ll x, ll y){
    if (y == 0)
    return x;
    else
    return gcd(y, x % y);
}
 
ll nck(ll n, ll k){
    ll C[k + 1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j]%M + C[j - 1]%M)%M;
    }
    return C[k]%M;
}
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
    cin>>t;
    while(t--){
        ll n; cin>>n;
        ll wins=n/2;
        if(n%2){
            vll v(n,0);
            fo(i,n){
                for(ll j=i+1; j<n; j++){
                    if(v[i]<wins){
                        v[i]++;
                        cout<<1<<" ";
                    }
                    else{
                        v[j]++;
                        cout<<-1<<" ";
                    }
                }
            }
        }
        else{
            wins=(n-2)/2;
            vll v(n,0);
            fo(i,n){
                for(ll j=i+1; j<n; j++){
                    if(j-i==1+wins)
                    cout<<0<<" ";
                    else if(j-i<1+wins){
                        v[i]++;
                        cout<<1<<" ";
                    }
                    else{
                        v[j]++;
                        cout<<-1<<" ";
                    }
                }
            }
        }
        cout<<endl;
    }
    return 0;
}