#include<bits/stdc++.h>
#define inf 2000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false);cin.tie(NULL)
#define rng_23 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef set<int> si;
typedef multiset<int> msi;
typedef map<int,int> mii;
int ara[100][100],lcnt[100],wcnt[100];
int main()
{
    int t;
    int i,j,k;
    int n,res;
    cin>>t;
    while(t--){
        cin>>n;
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
                ara[i][j]=2;
        for(i=0;i<n;i++){
            wcnt[i]=(n-1)/2;
            lcnt[i]=n-1-(n-1)/2;
            ara[i][i]=0;
        }

        if(n%2==0){
            for(i=0;i<n;i++)
                lcnt[i]--;
            for(i=0;i<n;i+=2){
                ara[i][i+1]=0;
                ara[i+1][i]=0;

            }

        }
        //for(i=0;i<n;i++){
         //       cout<<wcnt[i]<<" "<<lcnt[i]<<endl;

            //}
            for(i=0;i<n;i++){
                //cout<<wcnt[i]<<" "<<lcnt[i]<<endl;
                for(j=0;j<n;j++){
                    if(ara[i][j]==2 && wcnt[i] && lcnt[j]){
                        wcnt[i]--;
                        lcnt[j]--;
                        ara[i][j]=1;
                        ara[j][i]=-1;
                    }
                }
            }
            for(i=0;i<n-1;i++){
                for(j=i+1;j<n;j++){
                    cout<<ara[i][j]<<" ";
                }
            }
            cout<<"\n";



    }
}

