#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define ls rt<<1
#define rs rt<<1|1
#define MS 200009
#define INF 20000009
#define mod 1000000007
#define Pi acos(-1.0)
#define Pair pair<LL,LL>

LL n,m,k;
LL p[109][109];

int main() {
	ios::sync_with_stdio(false);
	cin >> k;
	while(k--){
		cin >> n;
		if(n&1){
			for(int i=1;i<=n-1;i++){
				int t = 1;
				for(int j=i+1;j<=n;j++){
					p[i][j] = t;
					t *= -1;
					cout << p[i][j] << " ";
				}
			}
		}
		else{
			for(int i=2;i<=n;i+=2) p[i-1][i] = 2;
			for(int i=1;i<=n-1;i++){
				int t = i&1;
				if(t == 0) t = -1;
				for(int j=i+1;j<=n;j++){
					if(p[i][j] == 2) continue;
					p[i][j] = t;
					t *= -1;
				}
			}
			for(int i=1;i<=n-1;i++){
				for(int j=i+1;j<=n;j++){
					if(p[i][j] == 2) cout << 0 << " ";
					else cout << p[i][j] << " ";
				}
			}
			/*cout << endl;
			cout << "--------------" << endl;
			for(int i=1;i<=n;i++){
				int cc = 0;
				for(int j=1;j<=n;j++){
					if(i == j) continue;
					if(i>j){
						swap(i,j);
						if(p[i][j] == 2) cc++;
						else if(p[i][j] == 1) cc+=3;
						swap(i,j);
					} 
					else{
						if(p[i][j] == 2) cc++;
						else if(p[i][j] == 1) cc+=3;
					}
				}
				cout << cc << endl;
			}
			cout << "--------------" << endl;*/
		}
		cout << endl;
	}
	
	

	return 0;
}