#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[5001];
int t,n,k;
signed main( )
{
	cin>>t;
	while(t)
	{
		t--;
		cin>>n;
		if(n%2==0)
		{
			int ban=(n+1)/2;
			for(int i=n-1;i>=0;i--)
			for(int j=1;j<=i;j++)
			{
				if(j<ban)cout<<"1 ";
				else if(j==ban)cout<<"0 ";
				else cout<<"-1 "; 
			}
			cout<<endl;
		}
		else 
		{
			int ban=(n-1)/2;
			for(int i=n-1;i>=0;i--)
			for(int j=1;j<=i;j++)
			{
				if(j<=ban)cout<<"1 ";
				else cout<<"-1 "; 
			}
			cout<<endl;
		}
	}
} 
