#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int v;
	cin>>v;
	while (v--){
		int n;
	cin>>n;	
	int dem1[1000],dem2[1000],hoa[1000];
	for (int i=1; i<=n; i++) {
		dem1[i]=(n-1)/2;
		dem2[i]=dem1[i];
		hoa[i]=n-1-dem1[i]-dem2[i];
	}
	for (int i=1; i<n; i++) {
		int t=1;
		for (int j=1; j<=dem1[i]; j++) {
			cout<<"1 ";
			dem2[i+t]--;
			t++;
		}
		for (int j=1; j<=hoa[i]; j++) {
			cout<<"0 ";
			hoa[i+t]--;
			t++;
		}
		for (int j=1; j<=dem2[i]; j++) {
			cout<<"-1 ";
			dem1[i+t]--;
			t++;
		}
	}
	cout<<endl;
	}
}