#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back 
#define mod 1000000007
#define FIO  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve()
{
    int n,m,x,y,i,j,ans=0,c=0,sum=0;

    cin >> n;

    if(n == 2)
    {
        cout << 0 << "\n";
        return;
    }

    for(i=1;i<n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            int dif = j-i;
            if(2*dif < n)
                cout << 1 << " ";
            else if(2*dif == n)
                cout << 0 << " ";
            else
                cout << -1 << " ";
        }
    }

    cout << "\n";
    
}

int main()
{
    FIO
    
    int t;
    t = 1;
    cin >> t;

    while(t--)
    {
        solve();
    }
    
    return 0;
}


