#include<bits/stdc++.h>
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0);
#define test  int tt; cin>>tt; for(int ii=0;ii<tt;ii++)
#define endl  "\n"
#define pb    push_back
#define D(x)  cout<<"#"<<x<<endl;
#define LL    long long
#define HI    cout<<endl<<"hi"<<endl;
using namespace std;
int main()
{
   fast

   test
   {
        LL n,i,j,cnt;
        cin>>n;
        if(n%2==0)
        {
            LL odd[n-1];
            for(i=0;i<(n-1)/2;i++) odd[i]=1;
            odd[i++]=0;
            for(;i<(n-1);i++) odd[i]=-1;

            LL pnt=n-1;
            j=0;
            i=0;
            cnt=0;
            while(j<(n*(n-1))/2)
            {
                if(i==pnt) { i=0; pnt--; }
                cout<<odd[i++]<<" ";
                j++;
            }
        }
        else
        {
            LL even[n-1];
            for(i=0;i<(n-1)/2;i++) even[i]=1;
            for(;i<(n-1);i++) even[i]=-1;

                        LL pnt=n-1;
            j=0;
            i=0;
            cnt=0;
            while(j<(n*(n-1))/2)
            {
                if(i==pnt) { i=0; pnt--; }
                cout<<even[i++]<<" ";
                j++;

            }
        }

        cout<<endl;


   }
    return 0;
}