#include<bits/stdc++.h> 
using namespace std; 
 
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define pll pair<lli,lli>
#define ve vector<lli>
#define vep vector<pair<lli,lli> >
#define fr(i,a,n) for(lli i=a;i<(n);i++)
#define frx(i,a,n) for(lli i=a;i>(n);i--)
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define endl '\n'
#define op(x) cout<<x<<endl
#define db(x) cout << "[ " << x << " ]" << endl
#define db2(x,y) cout<<"[ " <<x<<" "<<y<< " ]" <<endl
#define parr(arr,a,n) fr(u,a,n) cout<<arr[u]<<" "; cout<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define mem(a,x) memset(a,x,sizeof(a))

void solve(){
    lli n;
    cin>>n;
    lli a[n][n];
    fr(i,0,n){
        fr(j,0,n){
            a[i][j]=-10;
        }
    }
    fr(i,0,n){
        fr(j,1,(n-1)/2+1){
            a[i][(i+j)%n]=1;
        }
        if(n%2==0)a[i][(i+n/2)%n]=0;
    }
    fr(i,0,n){
        fr(j,i+1,n){
            lli temp=a[i][j];
            if(temp==-10)temp=-a[j][i];
            cout<<temp<<" ";
        }
    }
    cout<<endl;
}

int main(){
    fast;
    lli t=1;
    cin>>t;
    while(t--){
        solve();
    }
}