#include<bits/stdc++.h>
#define M_PIl 3.141592653589793238462643383279502884L /* pi */
#define lld long long int
#define ld long double
#define mod 1000000007
#define modd 998244353
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[300000][3];
int main()
{
     ios;
     lld TESTS,q,a,b,l,r,c,k,p,h,w,x,y,z,xs,ys,t,f;
     ld d;
     TESTS=1;
     cin>>TESTS;
     while(TESTS--)
     {
         cin>>n;
         if(n%2){
            rep(i,1,n){
                arr[i][0]=0;
                arr[i][1]=arr[i][2]=n/2;
            }
         }
         else {
            rep(i,1,n){
                arr[i][0]=1;
                arr[i][1]=arr[i][2]=n/2-1;
            }
         }
         rep(i,1,n)rep(j,i+1,n){
            if(arr[i][1]&&arr[j][2]){
                cout<<1<<" ";
                arr[i][1]--;
                arr[j][2]--;
            }
            else if(arr[i][0]&&arr[j][0]){
                cout<<0<<" ";
                arr[i][0]--;
                arr[j][0]--;
            }
            else {
                cout<<-1<<" ";
                arr[i][2]--;
                arr[j][1]--;
            }
         }
         cout<<"\n";
     }
    return 0;
}
