#include<bits/stdc++.h>
using namespace std;
#define forn(i,l,u) for(i=l;i<u;i++)
#define fors(i,l,u,s) for(i=l;i<u;i+=s)
#define fors_dw(i,u,l,s) for(i=u;i>=l;i-=s)
typedef long long ll;
#define pii pair<int,int>
map<int,vector<int>>wow;
//vector<int>ans;
map<int,int>cnt;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        if(n&1){
            int win = (n-1)/2;
            int i = 0;
            for(int i = n-1;i>=0;i--){
                int lol = win;
                for(int j = 0;j<i;j++){
                    if(lol > 0)
                    cout<<1<<" ";
                    else
                    {
                        cout<<-1<<" ";
                    }
                    lol--;
                }
            }
            cout<<"\n";

        }
        else{
            int win = n/2-1;
            int tie = 1;
            for(int i = n-1;i>=0;i--){
                int lol = win;
                for(int j = 0;j<i;j++){
                    if(lol > 0)
                    cout<<1<<" ";
                    else if(lol == 0){
                    cout<<0<<" ";
                    }
                    else
                    {
                        cout<<-1<<" ";
                    }
                    lol--;
                }
            }
        }

    }
}
