#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;
	while (t--)
	{
		int n, i, j;
		cin >> n;
		map<pair<int, int>, int> match;
		if (n % 2) {
			for (i = 1; i <= n; i++) {
				for (j = i + 1; j <= n; j++) {
					if (abs(i - j) % 2 && i > j)
						match[ {i, j}] = 1;
					else if (abs(i - j) % 2 && i < j)
						match[ {i, j}] = -1;
					else if (abs(i - j) % 2 == 0 && i < j)
						match[ {i, j}] = 1;
					else if (abs(i - j) % 2 == 0 && i > j)
						match[ {i, j}] = -1;
				}
			}
		}
		else {
			int x1 = 0, x2 = 0;
			for (i = 1; i <= n; i++) {
				for (j = i + 1; j <= n; j++) {
					if (j - i == n / 2)
						match[ {i, j}] = 0;
					else if (j - i < n / 2)
						match[ {i, j}] = 1;
					else
						match[ {i, j}] = -1;
				}
			}
		}

		for (i = 1; i <= n; i++) {
			for (j = i + 1; j <= n; j++) {
				cout << match[ {i, j}] << " ";
			}
		}
		cout << "\n";
	}

	return 0;
}