// Problem: C. Minimum Ties
// Contest: Codeforces - Educational Codeforces Round 104 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1487/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//Weakness disgust me
#include"bits/stdc++.h"                  
#define fill(a)  memset(a, 0, sizeof (a))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
#define int ll
const ll MOD = 1e9 + 7;
using namespace std;
void solve()
{  
	ll n;
	cin>>n;
	ll res[n][n];
	memset(res,0,sizeof(res));
	
	for(int i=1;i<=((n-1)/2);i++)
	{
		for(int j=0;j<n;j++)
		{
			res[(j+i)%n][j]=-1;
			res[j][(j+i)%n]=1;
		}
	}
	
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			cout<<res[i][j]<<" ";
		}
		
	}
	
	
}
signed main()
{    
	fast;
    int t=1;
    cin>>t;
    while( t-- )
    {  
        solve();
        cout<<"\n";
    }
   
}