A big football championship will occur soon! $n$ teams will compete in it, and each pair of teams will play exactly one game against each other.

There are two possible outcomes of a game:

the game may result in a tie, then both teams get $1$ point;

one team might win in a game, then the winning team gets $3$ points and the losing team gets $0$ points.

The score of a team is the number of points it gained during all games that it played.

You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well.

Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 100$) — the number of test cases.

Then the test cases follow. Each test case is described by one line containing one integer $n$ ($2 \le n \le 100$) — the number of teams.


-----Output-----

For each test case, print $\frac{n(n - 1)}{2}$ integers describing the results of the games in the following order: the first integer should correspond to the match between team $1$ and team $2$, the second — between team $1$ and team $3$, then $1$ and $4$, ..., $1$ and $n$, $2$ and $3$, $2$ and $4$, ..., $2$ and $n$, and so on, until the game between the team $n - 1$ and the team $n$.

The integer corresponding to the game between the team $x$ and the team $y$ should be $1$ if $x$ wins, $-1$ if $y$ wins, or $0$ if the game results in a tie.

All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score.


-----Examples-----

Input
2
2
3
Output
0 
1 -1 1


-----Note-----

In the first test case of the example, both teams get $1$ point since the game between them is a tie.

In the second test case of the example, team $1$ defeats team $2$ (team $1$ gets $3$ points), team $1$ loses to team $3$ (team $3$ gets $3$ points), and team $2$ wins against team $3$ (team $2$ gets $3$ points).

Difficulty: MEDIUM
Tags: Graph algorithms

Graph traversal

Constructive algorithms

Implementation

Complete search

Greedy algorithms

Mathematics
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	(m, r) = ((n - 1) // 2, 1 - n % 2)
	for i in range(1, n):
		lst = [1] * m + [0] * r + [-1] * m
		lst = lst[:n - i]
		print(*lst, end=' ')
	print()


n = int(input())
for i in range(n):
	xi = int(input())
	if xi % 2 == 1:
		tot = xi * (xi - 1) // 2
		ans = [0] * tot
		st = 1
		for i in range(tot):
			ans[i] = st
			if st == 1:
				st = -1
			else:
				st = 1
	else:
		ans = []
		for i in range(xi):
			for j in range(i + 1, xi):
				if j - i < xi // 2:
					ans.append(1)
				elif j - i == xi // 2:
					ans.append(0)
				else:
					ans.append(-1)
	print(*ans)


import sys
pin = sys.stdin.readline
for T in range(int(pin())):
	N = int(pin())
	M = N - 1
	(a, b) = (M // 2, M % 2)
	L = [1] * a + [0] * b + [-1] * (M - a - b)
	for m in range(M):
		for i in range(M - m):
			print(L[i], end=' ')
	print()


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

def In():
	return map(int, input().split())

def ln():
	return list(map(int, input().split()))

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	n = I()
	if n & 1 == 1:
		for i in range(n):
			for j in range(i + 1, n):
				if j - i <= n // 2:
					print(1, end=' ')
				else:
					print(-1, end=' ')
		print()
	else:
		for i in range(n):
			for j in range(i + 1, n):
				if j - i < n // 2:
					print(1, end=' ')
				elif j - i == n // 2:
					print(0, end=' ')
				else:
					print(-1, end=' ')
		print()
	pass

def main():
	T = I()
	for i in range(T):
		solve()
M = 998244353
P = 1000000007

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


T = int(input())
arr = []
for i in range(T):
	n = int(input())
	arrLog = []
	if n % 2 == 0:
		for j in range((n - 1) // 2):
			arrLog.append(1)
		arrLog.append(0)
		for j in range((n - 1) // 2):
			arrLog.append(-1)
	else:
		for j in range((n - 1) // 2):
			arrLog.append(1)
		for j in range((n - 1) // 2):
			arrLog.append(-1)
	arr.append(arrLog)
for i in arr:
	for k in range(len(i)):
		for j in i[0:len(i) - k]:
			print(j, end=' ')
	print()


def resi(n):
	if n % 2 == 1:
		for i in reversed(range(n)):
			for j in range(i):
				print((-1) ** j, end=' ')
	else:
		for i in reversed(range(n)):
			for j in range(i):
				if j == 0 and i % 2 == 1:
					print(0, end=' ')
				else:
					print((-1) ** j, end=' ')
	print('')
	return
for _ in range(int(input())):
	n = int(input())
	resi(n)


t = int(input())
while t > 0:
	n = int(input())
	number_of_mathes = n * (n - 1) // 2
	rem = 3 * number_of_mathes % n
	total_for_each_team = (3 * number_of_mathes - rem) // n
	quotas = [0 for i in range(n)]
	if n == 2:
		print(0)
	elif n % 2 == 0:
		m = (n - 1) // 2
		p1 = [1 for i in range(m)]
		p1.append(0)
		p3 = [-1 for i in range(m)]
		p1.extend(p3)
		i = n - 1 - 1
		while i >= 0:
			j = 0
			while j <= i:
				print(p1[j], end=' ')
				j += 1
			i -= 1
		print()
	else:
		m = n // 2
		p1 = [1 for i in range(m)]
		p3 = [-1 for i in range(m)]
		p1.extend(p3)
		i = n - 1 - 1
		while i >= 0:
			j = 0
			while j <= i:
				print(p1[j], end=' ')
				j += 1
			i -= 1
		print()
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	points = [0 for _ in range(n + 1)]
	games = n * (n - 1) // 2
	if n % 2 == 1:
		current = 1
		counter = 0
		goal = 3 * (n - 1) // 2
		for j in range(games):
			if points[current] < goal:
				print(1, end=' ')
				points[current] += 3
			else:
				print(-1, end=' ')
				points[current + counter + 1] += 3
			counter += 1
			if counter == n - current:
				counter = 0
				current += 1
	elif n % 2 == 0:
		current = 1
		counter = 0
		goal = 3 * (n - 2) // 2 + 1
		for j in range(games):
			if goal - points[current] >= 3:
				print(1, end=' ')
				points[current] += 3
			elif goal - points[current] == 1:
				print(0, end=' ')
				points[current] += 1
				points[current + counter + 1] += 1
			else:
				print(-1, end=' ')
				points[current + counter + 1] += 3
			counter += 1
			if counter == n - current:
				counter = 0
				current += 1
	print()


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def isInt(s):
	return '0' <= s[0] <= '9'
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	tmp = [1] * ((N - 1) // 2) + [0] * ((N - 1) % 2) + [-1] * ((N - 1) // 2)
	ans = []
	for i in range(N):
		for j in range(N - i - 1):
			ans.append(tmp[j])
	print(*ans)
	return
for _ in range(getInt()):
	solve()


from sys import stdin, stdout
import sys
import math
import itertools
sys.setrecursionlimit(10 ** 6)

def swap(a, b):
	t = a
	a = b
	b = t
	return (a, b)

def match(n):
	m = int(n * (n - 1) / 2)
	a = [0] * m
	if n % 2 == 1:
		for i in range(0, m):
			if i % 2 == 0:
				a[i] = 1
			else:
				a[i] = -1
	else:
		lost = 1
		win = 0
		i = 1
		k = 1
		while i in range(1, m + 1):
			if k % 2 == 1:
				tie = 1
			else:
				tie = 0
			k += 1
			cnt = 0
			for j in range(i, min(m + 1, i + n - k + 1)):
				cnt += 1
				if tie == 1:
					a[j - 1] = 0
					tie = 0
					continue
				if lost == 1:
					a[j - 1] = -1
				else:
					a[j - 1] = 1
				(lost, win) = swap(lost, win)
			(lost, win) = swap(lost, win)
			i += cnt
	return a

def main():
	t = int(stdin.readline().strip())
	for i in range(1, t + 1):
		n = int(stdin.readline().strip())
		ans = match(n)
		for i in ans:
			stdout.write(str(i) + ' ')
		stdout.write('\n')
main()


for _ in range(int(input())):
	n = int(input())
	if n % 2 != 0:
		for i in range(n):
			for j in range(i + 1, n):
				if j - i <= n // 2:
					print(1, end=' ')
				else:
					print(-1, end=' ')
		print()
	else:
		for i in range(n):
			for j in range(i + 1, n):
				if j - i < n // 2:
					print(1, end=' ')
				elif j - i == n // 2:
					print(0, end=' ')
				else:
					print(-1, end=' ')
		print()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	n = int(input())
	if n % 2:
		l = []
		for i in range(n * (n - 1) // 2):
			if i % 2:
				l.append(-1)
			else:
				l.append(1)
	else:
		l1 = []
		l = []
		for i in range(1, n):
			for j in range(i + 1, n + 1):
				l1.append([i, j])
		c = 1
		d = 1
		y = 1
		for i in l1:
			if i[0] == c and i[1] == c + 1:
				l.append(0)
				c = i[1] + 1
			else:
				if i[0] != y:
					y = i[0]
					d ^= 1
				if d:
					l.append(1)
					d ^= 1
				else:
					l.append(-1)
					d ^= 1
	print(*l)


for _ in range(int(input())):
	n = int(input())
	matches = n * (n - 1) // 2
	max_score = matches * 3
	ties = 0
	while max_score % n:
		max_score -= 1
		ties += 1
	score_per = max_score // n
	memo = {}
	for i in range(n):
		memo[i] = 0
	ans = ''
	for i in range(n):
		for j in range(i + 1, n):
			if memo[i] < score_per:
				if score_per - memo[i] >= 3:
					ans += '1 '
					memo[i] += 3
				else:
					ans += '0 '
					memo[i] += 1
					memo[j] += 1
			else:
				memo[j] += 3
				ans += '-1 '
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	a += [1 for i in range((n - 1) // 2)]
	if n % 2 == 0:
		a.append(0)
	a += [-1 for i in range((n - 1) // 2)]
	for j in range(n - 1):
		print(*a[:n - j - 1], end=' ')
	print()


def main():
	for _ in range(int(input())):
		n = int(input())
		odd = n % 2
		(le, res) = ((n - 2 + odd) // 2, [])
		ptrn = ['1'] * le
		if not odd:
			ptrn.append('0')
		ptrn += ['-1'] * le
		for _ in range(n - 1):
			res += ptrn
			del ptrn[-1]
		print(' '.join(res))
main()


t = int(input())
for k in range(t):
	n = int(input())
	w = (n - 1) // 2
	lst = []
	for i in range(w):
		lst.append(1)
	if n % 2 == 0:
		lst.append(0)
	for i in range(w):
		lst.append(-1)
	for i in range(n):
		for j in range(n - i - 1):
			print(lst[j], end=' ')
	print('\n', end='')


import sys

def solve():
	teams = int(sys.stdin.readline().rstrip())
	games = teams * (teams - 1) // 2
	limit = games // teams
	g = [[1] * teams for _ in range(teams)]
	if teams % 2 == 0:
		half = teams // 2
		for i in range(0, half):
			g[i][i + half] = 0
			g[i + half][i] = 0
	res = []
	for i in range(teams):
		(wins, loses) = (0, 0)
		for j in range(i):
			wins += g[i][j] == 1
			loses += g[i][j] == -1
		for j in range(i + 1, teams):
			if g[i][j] == 0:
				res += ['0']
			elif wins < limit:
				g[i][j] = 1
				g[j][i] = -1
				wins += 1
				res += ['1']
			elif loses < limit:
				g[i][j] = -1
				g[j][i] = 1
				loses += 1
				res += ['-1']
	print(' '.join(res))
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
	solve()


result = []
cases = int(input())
for i in range(cases):
	n = int(input())
	ch = int(n * (n - 1) / 2)
	arr = [[0] * n for i in range(n)]
	win = ch // n
	for j in range(n):
		z = 0
		for k in range(win):
			if j + k + 1 < n:
				arr[j][j + k + 1] = 1
			else:
				arr[z][j] = -1
				z += 1
	temp = []
	for l in range(n - 1):
		for m in range(l + 1, n):
			temp.append(str(arr[l][m]))
	result.append(' '.join(temp))
for _ in result:
	print(_)


for _ in range(int(input())):
	n = int(input())
	rounds = n * (n - 1) // 2
	if n % 2:
		s = '1 -1 ' * (rounds // 2)
		s = s[:-1]
		if rounds % 2:
			print(f'{s} 1')
		else:
			print(f'{s}')
	else:
		points = rounds * 3 // 4
		d = ['0'] * rounds
		counter = 0
		for i in range(1, n + 1):
			if i % 2:
				fl = True
				for j in range(i + 1, n + 1):
					if j == i + 1:
						d[counter] = '0'
					elif fl:
						d[counter] = '1'
						fl = not fl
					else:
						d[counter] = '-1'
						fl = not fl
					counter += 1
			else:
				fl = False
				for j in range(i + 1, n + 1):
					if fl:
						d[counter] = '1'
						fl = not fl
					else:
						d[counter] = '-1'
						fl = not fl
					counter += 1
		print(' '.join((str(i) for i in d)))


n1 = int(input())

def even(n):
	ans = []
	a = []
	for _ in range(int(n / 2) - 1):
		a.append(1)
	a.append(0)
	for _ in range(int(n / 2) - 1):
		a.append(-1)
	for i in range(n - 1):
		ans += a[:n - i - 1]
	return ans

def odd(n):
	(ans, a) = ([], [])
	for _ in range(int(n / 2)):
		a.append(1)
	for _ in range(int(n / 2)):
		a.append(-1)
	for i in range(n - 1):
		ans += a[:n - i - 1]
	return ans
for _ in range(n1):
	n = int(input())
	if n % 2 == 0:
		ans = even(n)
		for item in ans:
			print(item, end=' ')
		print()
	else:
		ans = odd(n)
		for item in ans:
			print(item, end=' ')
		print()


t = int(input())
for l in range(t):
	n = int(input())
	if n == 3 - 1:
		print(0)
	else:
		for i in range(n - 1):
			if i == n - 2:
				print(1)
			else:
				for j in range(n - 1 - i):
					if (j + 1) % n < n / 2:
						print(1, end=' ')
					elif (j + 1) % n == n / 2:
						print(0, end=' ')
					else:
						print(-1, end=' ')


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	ans = []
	if n % 2:
		for i in range(n - 1, 0, -1):
			for j in range(i):
				ans.append(1) if j % 2 == 0 else ans.append(-1)
	else:
		for i in range(n - 1, 0, -1):
			if i % 2:
				ans.append(0)
				for j in range(i - 1):
					ans.append(1) if j % 2 == 0 else ans.append(-1)
			else:
				for j in range(i):
					ans.append(-1) if j % 2 == 0 else ans.append(1)
	return ans
for _ in range(int(input())):
	print(*solve())


for _ in range(int(input())):
	n = int(input())
	z = []
	for i in range(n - 1):
		for j in range(i + 1, n):
			if j - i < n / 2:
				z.append(1)
			elif j - i > n / 2:
				z.append(-1)
			else:
				z.append(0)
	print(*z)


import math
for _ in range(int(input())):
	n = int(input())
	req = (n - 1) // 2 * 3 + int((n - 1) % 2)
	dic = {i + 1: 0 for i in range(n)}
	for i in range(n - 1):
		for j in range(i + 1, n):
			if req - dic[i + 1] <= 0:
				print(-1, end=' ')
				dic[j + 1] += 3
			elif req - dic[i + 1] >= 3:
				print(1, end=' ')
				dic[i + 1] += 3
			else:
				print(0, end=' ')
				dic[i + 1] += 1
				dic[j + 1] += 1
	print()


T = int(input())
for case in range(T):
	i = int(input())
	dp = [[0] * i for x in range(i)]
	for x in range(i):
		for y in range(i):
			if x == y:
				continue
			elif (x - y) % i < (y - x) % i:
				dp[x][y] = 1
			elif (x - y) % i > (y - x) % i:
				dp[x][y] = -1
	ret = []
	for x in range(i):
		for y in range(i):
			if x >= y:
				continue
			else:
				ret.append(str(dp[x][y]))
	print(' '.join(ret))


import math
import heapq

def S():
	return input()

def M():
	return map(int, input().split())

def I():
	return int(S())

def L():
	return list(M())
for _ in range(I()):
	n = I()
	s = ''
	if (n - 1) % 2 == 0:
		t = (n - 1) // 2
		k = 0
	else:
		t = (n - 1) // 2 + 1
		k = 1
	for i in range(n - 1, 0, -1):
		x = min(i, t - k)
		y = min(k, max(i - x, 0))
		z = i - x - y
		s += '1 ' * x + '0 ' * y + '-1 ' * z
	print(s)


t = int(input())

def get_next_r(node, n, r):
	node -= 1
	return set([(node + inc) % n + 1 for inc in range(1, r + 1)])
for _ in range(t):
	n = int(input())
	no_edges = n - 1
	output = []
	if no_edges % 2:
		r = no_edges // 2
		drawn = set()
		for node in range(1, n + 1):
			cur_set = get_next_r(node, n, r)
			for opponent in range(node + 1, n + 1):
				if opponent in cur_set:
					output.append(1)
				elif node not in drawn:
					drawn.add(opponent)
					drawn.add(node)
					output.append(0)
				else:
					output.append(-1)
	else:
		r = n // 2
		for node in range(1, n + 1):
			cur_set = get_next_r(node, n, r)
			for opponent in range(node + 1, n + 1):
				if opponent in cur_set:
					output.append(1)
				else:
					output.append(-1)
	print(*output)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(inp())
	g = [[-1] * n for i in range(n)]
	temp = n // 2
	for i in range(n):
		for k in range(1, temp + 1):
			g[i][(i + k) % n] = 1
	for i in range(n):
		for j in range(n):
			if g[i][j] == g[j][i]:
				g[i][j] = 0
	ans = []
	for i in range(n):
		for j in range(i + 1, n):
			ans.append(g[i][j])
	print(' '.join((str(i) for i in ans)))
testcase(int(inp()))


import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
read = lambda : map(int, input().split())
out = []
for _ in range(int(input())):
	n = int(input())
	o = []
	if n % 2:
		for i in range(n):
			for j in range(i + 1, n):
				if (j - i) % n <= n // 2:
					o.append('1')
				else:
					o.append('-1')
	else:
		for i in range(n):
			for j in range(i + 1, n):
				if (j - i) % n == n // 2:
					o.append('0')
				elif (j - i) % n < n // 2:
					o.append('1')
				else:
					o.append('-1')
	out.append(' '.join(o))
print('\n'.join(out))


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj

def sieve():
	li = [True] * (10 ** 3 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	(prime, cur) = ([0] * 200, 0)
	for i in range(10 ** 3 + 5):
		if li[i] == True:
			prime[cur] = i
			cur += 1
	return prime

def SPF():
	mx = 10 ** 6 + 1
	spf[1] = 1
	for i in range(2, mx):
		if spf[i] == 1000000000.0:
			spf[i] = i
			for j in range(i * i, mx, i):
				if i < spf[j]:
					spf[j] = i
	return

def prime(n, d):
	prm = set()
	while n != 1:
		prm.add(spf[n])
		n = n // spf[n]
	for ele in prm:
		d[ele] = d.get(ele, 0) + 1
	return
mod = 998244353
inf = 10000000000000000

def solve():
	n = II()
	tot = n * (n - 1)
	tot //= 2
	ans = [0 for i in range(tot)]
	win = tot // n
	cnt = 0
	d = defaultdict(list)
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			d[cnt].append([i, j])
			cnt += 1
	for winner in range(1, n + 1):
		found = win
		for j in range(tot):
			if found == 0:
				break
			if ans[j] == 0:
				li = d[j][0]
				if li[0] == winner:
					ans[j] = 1
					found -= 1
		if found:
			for j in range(tot):
				if found == 0:
					break
				if ans[j] == 0:
					li = d[j][0]
					if li[1] == winner:
						ans[j] = -1
						found -= 1
	print(*ans)
	return
t = II()
for i in range(t):
	solve()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(200001)]
pp = [0] * 200001

def SieveOfEratosthenes(n=200000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
for _ in range(int(input())):
	n = int(input())
	s = set()
	if n % 2 == 0:
		for i in range(0, n - 1, 2):
			s.add((i, i + 1))
	a = []
	b = -1
	for i in range(n - 1):
		curr = -1
		b += 1
		for j in range(i + 1, n):
			if (i, j) in s:
				a.append(0)
			else:
				a.append(curr)
			curr = curr * -1
	print(*a)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	ans = []
	if n % 2 != 0:
		for i in range(n):
			for j in range(i + 1, n):
				if j - i <= n / 2:
					ans.append(1)
				else:
					ans.append(-1)
	else:
		d = n // 2
		w = n * (n - 1) / 2 - d
		for i in range(n):
			for j in range(i + 1, n):
				if j - i < n / 2:
					ans.append(1)
				elif j - i == n / 2:
					ans.append(0)
				else:
					ans.append(-1)
	print(*ans)


import math

def solve(n):
	strpnt = ''
	if n % 2 == 0:
		maxx = n // 2
		for i in range(n):
			for j in range(n - i - 1):
				if strpnt != '':
					strpnt += ' '
				if j == n // 2 - 1:
					strpnt += '0'
				elif j < n // 2:
					if j % 2 == 0:
						strpnt += '1'
					else:
						strpnt += '-1'
				elif j % 2 == 0:
					strpnt += '-1'
				else:
					strpnt += '1'
	else:
		count = 0
		for i in range((n ** 2 - n) // 2):
			if strpnt == '':
				strpnt += '1'
			else:
				strpnt += ' '
				if i % 2 == 1:
					strpnt += '-1'
				else:
					strpnt += '1'
	print(strpnt)
t = int(input())
for i in range(t):
	n = int(input())
	solve(n)


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import heapify, heappop, heappush
from statistics import median, mean
from math import gcd, sqrt, floor, factorial, ceil, log2, log10, log
import fractions
import copy
from copy import deepcopy
import sys
import io
sys.setrecursionlimit(10 ** 8)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7
import random
from random import random, randint, randrange
from time import time

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def normalncr(n, r):
	r = min(r, n - r)
	count = 1
	for i in range(n - r, n + 1):
		count *= i
	for i in range(1, r + 1):
		count //= i
	return count
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def reverse_bisect_right(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x > a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x >= a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def get_list():
	return list(map(int, input().split()))

def get_str_list_in_int():
	return [int(i) for i in list(input())]

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def input_int():
	return int(input())

def matrix(a, b):
	return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
	return (b, a)

def find_gcd(l):
	a = l[0]
	for i in range(len(l)):
		a = gcd(a, l[i])
	return a

def is_prime(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return 0
	return 1

def prime_factors(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return [i] + prime_factors(n // i)
	return [n]
nc = 'NO'
yc = 'YES'
ns = 'No'
ys = 'Yes'

def get_next(a):
	if a == n:
		return 1
	return a + 1

def get_prev(a):
	if a == 1:
		return n
	return a - 1

def div(a, n):
	return a // (n // 2)

def mod(k, n):
	k = k % n
	if k == 0:
		return n
	return k
t = int(input())
for theta in range(t):
	n = int(input())
	dict = defaultdict(int)
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			if n % 2 == 0:
				if i + j == n + 1:
					print(0, end=' ')
					continue
			if dict[i] == 0:
				print(1, end=' ')
				dict[i] = 1
				dict[j] = 0
			else:
				print(-1, end=' ')
				dict[i] = 0
				dict[j] = 1
	print('')


for _ in range(int(input())):
	n = int(input())
	lis = [1] * (n // 2 + n % 2 - 1) + [0] * (1 - n % 2) + [-1] * (n // 2 + n % 2 - 1)
	for i in range(n - 1, -1, -1):
		for j in lis[:i]:
			print(j, end=' ')
	print()


import sys
input = sys.stdin.buffer.readline
a = int(input())
for x in range(a):
	b = int(input())
	if b % 2 == 1:
		s = '1'
		for y in range(int(b * (b - 1) // 2)):
			print(s, end=' ')
			if s == '1':
				s = '-1'
			else:
				s = '1'
		print()
	elif b == 2:
		print(0)
	else:
		t = []
		for y in range(b - 1):
			if y == (b - 1) // 2:
				t.append(0)
			elif y < (b - 1) // 2:
				t.append(1)
			else:
				t.append(-1)
		count = 0
		for y in range(b - 1):
			for z in range(b - y - 1):
				print(t[z], end=' ')
				count += 1
		print()


def eqscore(n):
	answer = ''
	if n % 2:
		wins = (n - 1) // 2
		table = ['1'] * wins + ['-1'] * wins
		for _ in range(n - 1):
			answer += ' '.join(table) + ' '
			table.pop()
	else:
		wins = (n - 2) // 2
		table = ['1'] * wins + ['0'] + ['-1'] * wins
		for _ in range(n - 1):
			answer += ' '.join(table) + ' '
			table.pop()
	return answer if answer else 0
t = int(input())
while t:
	print(eqscore(int(input())))
	t -= 1


import sys, math, itertools, random, bisect
from collections import defaultdict
INF = sys.maxsize

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	if n & 1:
		for i in range(n * (n - 1) // 2):
			if i & 1:
				print(-1, end=' ')
			else:
				print(1, end=' ')
		print()
	else:
		a = [0] * 105
		ans = []
		x = set()
		for i in range(1, n):
			for j in range(i + 1, n + 1):
				if i + 1 == j and i not in x and (j not in x):
					ans.append(0)
					x.add(i)
					x.add(j)
				elif a[i] == 0 and a[j] == 0:
					ans.append(1)
					a[i] = 1
					a[j] = -1
				elif a[i] == 1:
					ans.append(-1)
					a[i] = -1
					a[j] = 1
				elif a[j] == 1:
					ans.append(1)
					a[i] = 1
					a[j] = -1
				elif a[i] == -1:
					ans.append(1)
					a[i] = 1
					a[j] = -1
				else:
					ans.append(-1)
					a[i] = -1
					a[j] = 1
		print(*ans)


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	n = int(input())
	table = [[0] * n for _ in range(n)]
	bat = n * (n - 1) // 2
	while True:
		if bat % n == 0:
			win = bat // n
			for i in range(n):
				for j in range(i + 1, i + win + 1):
					table[i][j % n] = 1
					table[j % n][i] = -1
			break
		else:
			bat -= 1
	ans = []
	for i in range(n):
		for j in range(i + 1, n):
			ans.append(table[i][j])
	print(*ans)


test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	t = n * (n - 1) // 2
	k = t // n
	d = t - k * n
	game = dict()
	for kk in range(1, k + 1):
		for i in range(1, n + 1):
			t1 = i
			t2 = i + kk
			if t2 > n:
				t2 %= n
			game[min(t1, t2), max(t1, t2)] = t1
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			m = (i, j)
			if m not in game:
				print('0', end='')
			elif game[m] == i:
				print('1', end='')
			else:
				print('-1', end='')
			print(end=' ')


def main():
	num_cases = int(input())
	for case_num in range(1, num_cases + 1):
		solve(case_num)

def solve(case_num):
	n = int(input())
	result = [[0] * n for _ in range(n)]
	for i in range(n):
		for j in range(1, n):
			if n % 2 == 0 and j == n // 2:
				continue
			if j <= (n - 1) // 2:
				result[i][(i + j) % n] = 1
			else:
				result[i][(i + j) % n] = -1
	for i in range(n):
		for j in range(i + 1, n):
			print(result[i][j], end=' ')
	print()
main()


for p in range(int(input())):
	l = []
	n = int(input())
	if n % 2 == 1:
		for i in range(n):
			c = 0
			for j in range(n - i - 1):
				if j < n // 2:
					l.append(1)
				else:
					l.append(-1)
	else:
		for i in range(n):
			q = -1
			c = 0
			if i % 2 == 0:
				l.append(0)
				q = q * -1
				c = 1
			for j in range(n - i - 1 - c):
				l.append(q)
				q = q * -1
	ll = [str(o) for o in l]
	print(' '.join(ll))


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = int(input())
	ans = []
	for a in range(n):
		for b in range(a + 1, n):
			diff = (a - b) % n
			if diff > n / 2:
				ans += [1]
			elif diff == n / 2:
				ans += [0]
			else:
				ans += [-1]
	print(*ans)
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		ans = [-10] * (n * (n - 1) // 2)
		if n % 2 == 0:
			result = [1] * ((n - 1) // 2) + [0] + [-1] * ((n - 1) // 2)
		else:
			result = [1] * ((n - 1) // 2) + [-1] * ((n - 1) // 2)
		i = 0
		for j in range(n - 1):
			ans[i:i + n - j - 1] = result[:n - 1 - j]
			i += n - j - 1
		print(*ans)
main()


T = int(input())
for testcase in range(1, T + 1):
	n = int(input())
	win = (n - 1) // 2
	tie = (n + 1) % 2
	for i in range(n):
		j = i + 1
		for k in range(win):
			if j < n:
				print(1, end=' ')
				j += 1
		for k in range(tie):
			if j < n:
				print(0, end=' ')
				j += 1
		while j < n:
			print(-1, end=' ')
			j += 1
	print('')


t = int(input())
for _ in range(t):
	n = int(input())
	p = n - 1
	ans = []
	d = {i: 0 for i in range(1, n + 1)}
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			if p % 2 != 0 and j == i + 1 and (j % 2 == 0):
				ans.append(0)
			elif d[i] > d[j]:
				ans.append(-1)
				d[i] -= 1
				d[j] += 1
			else:
				ans.append(1)
				d[i] += 1
				d[j] -= 1
	print(*ans)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	if n % 2:
		result = ''
		i = n - 1
		while i > 0:
			for j in range(i):
				if j % 2:
					result += ' -1'
				else:
					result += ' 1'
			i -= 1
		print(result[1:])
		continue
	result = ''
	i = n - 1
	while i > 0:
		for j in range(i):
			if j == 0 and i % 2:
				result += ' 0'
				continue
			if j % 2:
				result += ' 1'
			else:
				result += ' -1'
		i -= 1
	print(result[1:])


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	tot = n * (n - 1) // 2
	(win, draw) = divmod(tot, n)
	mat = [[0] * (n + 1) for i in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(i + 1, i + 1 + win):
			pos = j % n if j != n else n
			if i < pos:
				mat[i][pos] = 1
			else:
				mat[pos][i] = -1
	ans = []
	for i in range(1, n + 1):
		ans += mat[i][i + 1:]
	print(*ans)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
import bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 100
	n = random.randint(2, N)
	k = random.randint(1, 10 ** 4)
	return [n]

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print(inp)
			print('naive', a1)
			print('solve', a2)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
alp = [chr(ord('a') + i) for i in range(26)]
show_flg = False
show_flg = True
ans = 0

def naive(n):
	m = [[2] * n for c in range(n)]
	if n % 2 == 1:
		for i in range(n):
			for t in range(1, n):
				m[(i + t) % n][i] = (-1) ** t
	else:
		m = [[2] * n for c in range(n)]
		for i in range(n):
			for t in range(1, n // 2):
				m[(i + t) % n][i] = (-1) ** t
			for t in range(1, n // 2):
				m[(i - t) % n][i] = (-1) ** (t + 1)
		for i in range(n):
			m[(i + n // 2) % n][i] = 9
	return m
d = {}
d[1] = 3
d[-1] = 0
d[2] = 0
d[9] = 1
for _ in range(I()):
	n = I()
	m = naive(n)
	for i in range(n):
		for j in range(i + 1, n):
			if m[i][j] == 9:
				print(0, end=' ')
			else:
				print(m[i][j], end=' ')
	print()


from math import ceil, floor, log
import sys
from heapq import heappush, heappop
from collections import Counter, defaultdict, deque
input = lambda : sys.stdin.readline().strip()
c = lambda x: 10 ** 9 if x == '?' else int(x)

class node:

	def __init__(self, x, y):
		self.a = [x, y]

	def __lt__(self, b):
		return b.a[0] < self.a[0]

	def __repr__(self):
		return str(self.a[0]) + ' ' + str(self.a[1])

def main():
	for _ in range(int(input())):
		n = int(input())
		l = [0] * (n * (n - 1) // 2)
		t = 1
		k = 0
		if n % 2 == 1:
			for i in range(n * (n - 1) // 2):
				l[i] = t
				t = -t
			print(*l)
		else:
			t = -1
			k = 0
			l1 = [[0] * n for i in range(n)]
			for i in range(n):
				for j in range(i + 1, n):
					if i + 1 == j and i % 2 == 0:
						pass
					else:
						l1[i][j] = t
						t = -t
					l[k] = l1[i][j]
					k += 1
				if i % 2 == 0:
					t = 1
				else:
					t = -1
			print(*l)
main()


import sys

def solve(N):
	team_points = [0] * (N + 1)
	if N == 2:
		return '0'
	res_list = []
	if N % 2 == 1:
		for i in range(1, N):
			for j in range(i + 1, N + 1):
				ered = 2 * ((i + j) % 2) - 1
				res_list.append(str(ered))
	else:
		for i in range(1, N):
			for j in range(i + 1, N + 1):
				if j - i == N / 2:
					ered = 0
					res_list.append('0')
				elif j - i < N / 2:
					ered = 2 * ((i + j) % 2) - 1
					res_list.append(str(ered))
				else:
					ered = -2 * ((i + j) % 2) + 1
					res_list.append(str(ered))
	return ' '.join(res_list)

def run():
	out = ''
	T = int(input())
	for i in range(T):
		N = int(input())
		print(solve(N))
run()


from math import sqrt
import operator
import sys
inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def check_seq(n):
	res = []
	if n == 2:
		return '0'
	g_cnt = n * (n - 1) // 2
	if g_cnt % n == 0:
		for i in range(1, n):
			g_per_team = g_cnt // n
			for j in range(i + 1, n + 1):
				if g_per_team > 0:
					res.append('1')
					g_per_team -= 1
				else:
					res.append('-1')
	else:
		g_left = {}
		g_per_team = g_cnt // n
		for i in range(1, n + 1):
			g_left[i] = 0
		for i in range(0, g_per_team):
			g_left[n - i] = g_per_team - i
		for i in range(1, n):
			g_per_team = g_cnt // n
			for j in range(i + 1, n + 1):
				if g_per_team > 0:
					res.append('1')
					g_per_team -= 1
				elif g_left[j] > 0:
					g_left[j] -= 1
					res.append('-1')
				else:
					res.append('0')
	return ' '.join(res)

def main():
	cnt = read_one_int()
	for _ in range(cnt):
		n = read_one_int()
		res = check_seq(n)
		print(res)
main()


def answer(n):
	if n % 2 == 0:
		for i in range(1, n):
			for j in range(i + 1, n + 1):
				if (i + j) % 2 == 0:
					print(1, end=' ')
				elif (i + j + 1) % 4 == 0 and j == i + 1:
					print(0, end=' ')
				else:
					print(-1, end=' ')
		print('')
	else:
		for i in range(1, n):
			for j in range(i + 1, n + 1):
				if (i + j) % 2 == 0:
					print(-1, end=' ')
				else:
					print(1, end=' ')
		print('')
t = int(input())
for i in range(t):
	n = int(input())
	answer(n)


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for tt in range(t):
	n = int(input())
	if n % 2 == 1:
		t_ans = [1] * (n // 2) + [-1] * (n // 2)
	else:
		t_ans = [1] * (n // 2 - 1) + [0] + [-1] * (n // 2 - 1)
	ans = []
	for i in range(n):
		ans += t_ans[:n - (i + 1)]
	print(*ans)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
MOD = 10 ** 9 + 7

def solve():
	n = int(input())
	m = (n - 1) // 2
	outcome = [[0] * n for _ in range(n)]
	j = 1
	for i in range(n):
		k = 0
		nj = j
		while k < m:
			outcome[i][nj] = 1
			outcome[nj][i] = -1
			nj = (nj + 1) % n
			k += 1
		j = (j + 1) % n
	res = []
	for i in range(n):
		for j in range(i + 1, n):
			res.append(outcome[i][j])
	print(*res)
t = int(input())
for _ in range(t):
	solve()


def solution():
	n = int(input())
	res = ''
	for i in range(n - 1, 0, -1):
		for j in range(i):
			if n % 2:
				res += '-1 ' if j % 2 else '1 '
			else:
				res += '0 ' if i % 2 and j == 0 else '-1 ' if j % 2 else '1 '
	print(res)
for t in range(int(input())):
	solution()


import math
import collections

def read_list() -> list:
	return [int(i) for i in input().strip().split()]

def read_num() -> int:
	return int(input().strip())
t = read_num()
for i in range(t):
	n = read_num()
	num_races = n * (n - 1) // 2
	num_tie = num_races * 3 % n
	avg_points = (num_races * 3 - num_tie) // n
	points = [0] * (n + 1)
	ans = []
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			if points[i] <= avg_points - 3:
				points[i] += 3
				ans.append(1)
			elif points[i] < avg_points:
				ans.append(0)
				points[i] += 1
				points[j] += 1
			else:
				ans.append(-1)
				points[j] += 3
	for i in ans:
		print(i, end=' ')
	print()


def fn(n):
	tab = [0] * 103
	ch = ''
	w = 0
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			if n % 2 == 0 and i + j == n + 1:
				ch += '0 '
				w += 1
			elif tab[i] == 0:
				if tab[j] >= 0:
					tab[i] += 1
					ch += '1 '
					tab[j] -= 1
				else:
					tab[i] -= 1
					ch += '-1 '
					tab[j] += 1
			elif tab[i] < 0:
				tab[i] += 1
				ch += '1 '
				tab[j] -= 1
			else:
				tab[i] -= 1
				ch += '-1 '
				tab[j] += 1
	print(ch)
t = int(input())
for i in range(t):
	n = int(input())
	fn(n)


def solve():
	n = int(input())
	if n == 2:
		print(0)
	elif n % 2 != 0:
		a = [1 for i in range(n // 2)]
		a.extend([-1 for i in range(n // 2)])
		for i in range(1, n):
			for j in range(n - i):
				print(a[j], end=' ')
		print()
	else:
		a = [1 for i in range((n - 1) // 2)]
		a.append(0)
		a.extend([-1 for i in range((n - 1) // 2)])
		for i in range(1, n):
			for j in range(n - i):
				print(a[j], end=' ')
		print()
for _ in range(int(input())):
	solve()


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
from math import log
sa = lambda : input()
sb = lambda : int(input())
sc = lambda : input().split()
sd = lambda : list(map(int, input().split()))
se = lambda : float(input())
sf = lambda : list(input())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7

def hnbhai():
	n = sb()
	d = {}
	x = n * (n - 1) // 2
	rem = x % n
	x = x // n
	for i in range(1, n + 1):
		d[i] = x
	ans = []
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			if rem != 0 and i + n // 2 == j:
				ans.append(0)
			elif d[i] > 0:
				ans.append(1)
				d[i] -= 1
			else:
				d[j] -= 1
				ans.append(-1)
	print(*ans)
for _ in range(sb()):
	hnbhai()


t = int(input())
a = []
for i in range(t):
	b = []
	c = []
	n = int(input())
	n = n - 1
	for j in range(int(n / 2)):
		b.append(1)
	if n % 2 != 0:
		b.append(0)
	for j in range(int(n / 2)):
		b.append(-1)
	m = len(b)
	while m != 0:
		c.extend(list(b[0:m]))
		m -= 1
	a.append(c)
for i in range(t):
	for j in range(len(a[i])):
		print(a[i][j], end=' ')
	print()


for _ in range(int(input())):
	n = int(input()) - 1
	for i in range(n):
		oc = min(n - i, n // 2)
		print('1 ' * oc + '0 ' * (n % 2 and i <= n // 2) + '-1 ' * (n - n % 2 - oc - i), end='')
	print()


import sys
import math
input = sys.stdin.readline
t = int(input())
for w in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l1 = []
		for j in range(n):
			l1.append(-2)
		l += [l1]
	l2 = []
	c = [0] * n
	if n % 2 == 0:
		wins = n // 2 - 1
	else:
		wins = n // 2
	for i in range(n):
		for j in range(n):
			if i != j:
				if c[i] < wins:
					if l[i][j] == -2:
						l[i][j] = 1
						c[i] += 1
						l[j][i] = -1
				elif c[i] == wins:
					if n % 2 == 0:
						if l[i][j] == -2:
							l[i][j] = 0
							l[j][i] = 0
							c[i] += 1
					elif l[i][j] == -2:
						l[i][j] = -1
						l[j][i] = 1
						c[j] += 1
						c[i] += 1
				elif l[i][j] == -2:
					l[i][j] = -1
					c[j] += 1
					l[j][i] = 1
	for i in range(n):
		for j in range(n):
			if l[i][j] != -2:
				l2.append(l[i][j])
				l[j][i] = -2
	print(*l2)


t = int(input())
for i in range(t):
	n = int(input())
	result = []
	if n % 2 == 1:
		for i in range(n):
			for j in range(i + 1, n):
				result.append(1 if (j - i) % 2 == 1 else -1)
	else:
		for i in range(n):
			for j in range(i + 1, n):
				if (j - i) % 2 == 1:
					result.append(0 if i % 2 == 0 and j - i == 1 else -1)
				else:
					result.append(1)
	print(*result)


for s in [*open(0)][1:]:
	n = int(s)
	a = []
	if n & 1:
		for i in range(1, n):
			for j in range(1, n - i + 1):
				a += [2 * (j & 1) - 1]
	else:
		for i in range(1, n):
			a += [i - 1 & 1]
			for j in range(0, n - i - 1):
				a += [2 * (j & 1) - 1]
	print(*a)


answers = []

def solve(n):
	final = []
	limit = n * (n - 1) // 2
	if n == 2:
		answers.append([0])
		return
	if n % 2 == 0:
		wins = (n - 1) // 2
		loss = (n - 1) // 2
		draw = 1
		for i in range(1, n + 1):
			temp = []
			if wins >= 1:
				temp.append([1] * wins)
			if draw == 1:
				temp.append([0])
			if loss >= 1:
				temp.append([-1] * loss)
			for ele in temp:
				final.extend(ele[:])
			loss -= 1
			if loss < 0:
				wins -= 1
				draw = 0
		if len(final) < limit:
			rem = limit - len(final)
			for i in range(rem):
				final.append(1)
		answers.append(final)
	else:
		wins = (n - 1) // 2
		loss = (n - 1) // 2
		for i in range(1, n + 1):
			temp = []
			if wins >= 1:
				temp.append([1] * wins)
			if loss >= 1:
				temp.append([-1] * loss)
			for ele in temp:
				final.extend(ele[:])
			loss -= 1
			if loss < 0:
				wins -= 1
		answers.append(final)
T = int(input())
while T:
	n = int(input())
	solve(n)
	T -= 1
for ans in answers:
	print(*ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	d = {}
	n = int(input())
	total = n * (n - 1) // 2 // n
	for i in range(n):
		d[i] = 0
	ans = [[0] * n for i in range(n)]
	v = set()
	for i in range(n):
		for j in range(i + 1, n):
			if n % 2 == 0 and i + n // 2 == j:
				continue
			if d[i] < total:
				ans[i][j] = 1
				d[i] += 1
			elif d[j] < total:
				ans[i][j] = -1
				d[j] += 1
			else:
				print(i, j, d, total)
				ans[i][j] = 0
	for i in range(n):
		for j in range(i + 1, n):
			print(ans[i][j], end=' ')
	print()


def calc(number_of_teams):
	half_num = (number_of_teams - 1) // 2
	first_row = ['1'] * half_num + ['0'] * (number_of_teams - 1 - 2 * half_num) + ['-1'] * half_num
	for i in range(number_of_teams - 1):
		print(' '.join(first_row), end=' ')
		first_row.pop()
	print()
num_test_cases = int(input())
for _ in range(num_test_cases):
	num_teams = int(input())
	calc(num_teams)


def find_answer(n):
	if n % 2:
		arr = []
		wins = (n - 1) // 2
		for i in range(n):
			c = 0
			for k in range(i + 1, n):
				arr.append(1 if c < wins else -1)
				c += 1
		return arr
	else:
		max_points = 3 * (n - 1) * n // 2
		remainder = max_points % n
		trial = max_points - remainder
		ties = None
		while trial > 0:
			if remainder * 2 % n == 0 and trial % n == 0:
				ties = remainder * 2 // n
				break
			remainder += n
			trial -= n
		arr = []
		wins = (trial // n - ties) // 3
		for i in range(n):
			w = wins
			t = ties
			for k in range(i + 1, n):
				if w:
					arr.append(1)
					w -= 1
				elif t:
					arr.append(0)
					t -= 1
				else:
					arr.append(-1)
		return arr
t = int(input())
for _ in range(t):
	n = int(input())
	print(' '.join(map(str, find_answer(n))))


for _ in range(int(input())):
	n = int(input())
	x = n * (n - 1) // 2
	z = [0] * n
	k = x // n
	y = []
	for i in range(n):
		for j in range(i + 1, n):
			if z[i] < k:
				z[i] += 1
				y.append(1)
			elif n % 2 == 0 and z[i] < k + 1:
				z[i] += 1
				y.append(0)
			else:
				z[j] += 1
				y.append(-1)
	print(*y)


def calc():
	k = 0
	n = int(input())
	wins = (n - 1) / 2
	for i in range(1, n):
		k = 0
		for j in range(i, n):
			k = k + 1
			if k == n // 2 and n % 2 == 0:
				print('0', end=' ')
				continue
			if k < (n + 1) // 2:
				print('1', end=' ')
			else:
				print('-1', end=' ')
	print()
t = int(input())
for i in range(t):
	calc()


def solve(n):
	t = n * (n - 1) // 2
	if n % 2 != 0:
		for i in range(t):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(-1, end=' ')
	else:
		p = 'W'
		for i in range(n):
			for j in range(i + 1, n):
				if i % 2 == 0 and j == i + 1:
					print(0, end=' ')
				elif j == n - 1:
					if p == 'W':
						print(1, end=' ')
					else:
						print(-1, end=' ')
				elif p == 'W':
					print(1, end=' ')
					p = 'L'
				else:
					print(-1, end=' ')
					p = 'W'
for i in range(int(input())):
	n = int(input())
	solve(n)


def print_dp(dp):
	for i in range(len(dp)):
		for j in range(len(dp[i])):
			print(dp[i][j], end=' ')
		print()
	print()
for _ in range(int(input())):
	n = int(input())
	dp = [[0 for _ in range(n)] for _ in range(n)]
	ans = []
	for i in range(n):
		W = True
		_W = dp[i].count('W')
		_L = dp[i].count('L')
		if _W > _L:
			W = False
		for j in range(i, n):
			if i == j:
				dp[i][j] = 0
				continue
			if j == n - i - 1:
				if (n - j) % 2 != 0 and _W == _L:
					dp[i][j] = 'D'
					ans.append('0')
					continue
				elif (n - j) % 2 == 0 and _W != _L:
					dp[i][j] = 'D'
					ans.append('0')
					continue
			if dp[i][j] == 0:
				if W:
					_W += 1
					dp[i][j] = 'W'
					dp[j][i] = 'L'
					ans.append('1')
				else:
					_L += 1
					dp[i][j] = 'L'
					dp[j][i] = 'W'
					ans.append('-1')
			W = not W
	print(' '.join(ans))


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		n = get_int()
		if n % 2 == 1:
			ok = 0
			for i in range(n):
				for j in range(i + 1, n):
					if ok == 0:
						get_print_int_same(1)
					else:
						get_print_int_same(-1)
					ok = not ok
		else:
			maxx = n // 2 - 1
			for i in range(1, n + 1):
				check = 1
				for j in range(i + 1, n + 1):
					if check <= maxx:
						get_print_int_same(1)
					elif check == maxx + 1:
						get_print_int_same(0)
					else:
						get_print_int_same(-1)
					check += 1
		print('')
solve()


for t in range(int(input())):
	n = int(input())
	ans = []
	if n % 2 == 0:
		ans += (n - 2) // 2 * [1]
		ans += [0]
		ans += (n - 2) // 2 * [-1]
	else:
		ans = (n - 1) // 2 * [1]
		ans += (n - 1) // 2 * [-1]
	final = []
	for i in range(n - 1):
		final += ans[:n - i - 1]
	for letter in final:
		print(letter, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	if n == 2:
		print(0)
		continue
	if n % 2 == 1:
		for i in range(n * (n - 1) // 2):
			if i % 2 == 0:
				l.append('1')
			else:
				l.append('-1')
		print(' '.join(l))
	else:
		pre = 'W'
		for i in range(n):
			for j in range(i + 1, n):
				if i % 2 == 0 and j == i + 1:
					l.append('0')
				elif j == n - 1:
					if pre == 'W':
						l.append('1')
					else:
						l.append('-1')
				elif pre == 'W':
					l.append('1')
					pre = 'L'
				else:
					l.append('-1')
					pre = 'W'
		print(' '.join(l))


for i in range(int(input())):
	n = int(input())
	d = n // 2
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			x = (j - i) % n
			if n % 2 == 1:
				if x <= d:
					print(1, end=' ')
				else:
					print(-1, end=' ')
			elif x < d:
				print(1, end=' ')
			elif x == d:
				print(0, end=' ')
			else:
				print(-1, end=' ')
	print()


t = int(input())
for l in range(t):
	n = int(input())
	if n == 2:
		print(0, end=' ')
	elif n % 2 == 0:
		c = 1
		c1 = 0
		for i in range(n):
			for j in range(i + 1, n):
				if j - i == n // 2:
					print(0, end=' ')
				elif j - i < n // 2:
					print(1, end=' ')
				else:
					print(-1, end=' ')
	else:
		t = True
		for i in range(n):
			for j in range(i + 1, n):
				if t:
					print(1, end=' ')
					t = False
				else:
					print(-1, end=' ')
					t = True
	print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	A = []
	ans = []
	if n % 2 == 1:
		(i, j) = (n // 2, n // 2)
		while j > 0:
			A.append((i, j))
			j -= 1
		while i > 0:
			A.append((i, j))
			i -= 1
		for (a, b) in A:
			ans.extend([1] * a + [-1] * b)
	else:
		(i, j, k) = (n // 2 - 1, 1, n // 2 - 1)
		while k > 0:
			A.append((i, j, k))
			k -= 1
		while j > 0:
			A.append((i, j, k))
			j -= 1
		while i > 0:
			A.append((i, j, k))
			i -= 1
		for (a, b, c) in A:
			ans.extend([1] * a + [0] * b + [-1] * c)
	print(*ans)


tests = int(input())
for _ in range(tests):
	n = int(input())
	if n == 2:
		print(0)
	elif n % 2 == 1:
		res = ''
		num_win = int((n - 1) / 2)
		for i in range(1, n + 1):
			cnt = 1
			for j in range(i + 1, n + 1):
				if cnt <= num_win:
					res += '1 '
				else:
					res += '-1 '
				cnt += 1
		print(res.strip())
	else:
		res = ''
		num_win = int(n / 2) - 1
		for i in range(1, n + 1):
			cnt = 1
			for j in range(i + 1, n + 1):
				if cnt <= num_win:
					res += '1 '
				elif cnt == num_win + 1:
					res += '0 '
				else:
					res += '-1 '
				cnt += 1
		print(res.strip())


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		n = ii()
		x = n * (n - 1) // 2

		def check(k):
			tot_sc = (x - k) * 3 + 2 * k
			if tot_sc % n:
				return 0
			return 1
		f = -1
		for i in range(x):
			if check(i):
				f = i
				break
		if f == -1:
			a = [0] * x
			print(*a)
			continue
		tot_sc = (x - f) * 3 + 2 * f
		tot_sc //= n
		n1 = x
		x -= f
		each = [tot_sc] * n
		k = 0
		while k < n - 1:
			j = k + 1
			cur = each[k]
			while j < n:
				if cur < 3 and cur > 0:
					each[j] -= 1
					cur -= 1
					print(0, end=' ')
				elif cur >= 3:
					cur -= 3
					print('1', end=' ')
				else:
					print(-1, end=' ')
					each[j] -= 3
				j += 1
			k += 1
if file:
	if path.exists('tmp/input.txt'):
		sys.stdin = open('tmp/input.txt', 'r')
		sys.stdout = open('tmp/output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


for i in range(int(input())):
	n = int(input())
	g = []
	if n % 2 == 1:
		l = n // 2
		for j in range(1, n):
			for k in range(j + 1, n + 1):
				if k - j <= n // 2:
					g.append(1)
				else:
					g.append(-1)
	else:
		l = (n - 2) // 2
		for j in range(1, n):
			for k in range(j + 1, n + 1):
				if j % 2 == 1 and k == j + 1:
					g.append(0)
				elif (k + j) % 2 == 0:
					g.append(1)
				else:
					g.append(-1)
	print(' '.join(map(str, g)))


def solve(n):
	t = [[None for i in range(n)] for j in range(n)]
	for i in range(n):
		for j in range(i + 1, n):
			if j == i + 1 and n & 1 == 0 and (i & 1 == 0):
				t[i][j] = 0
				t[j][i] = 0
			elif i & 1 == 0:
				if j & 1 == 0:
					t[i][j] = 1
					t[j][i] = -1
				else:
					t[i][j] = -1
					t[j][i] = 1
			elif j & 1 == 1:
				t[i][j] = 1
				t[j][i] = -1
			else:
				t[i][j] = -1
				t[j][i] = 1
	res = []
	for i in range(n):
		for j in range(i + 1, n):
			res.append(t[i][j])
	for x in res:
		print(x, end=' ')
	print()
t = int(input())
for _ in range(t):
	n = int(input())
	solve(n)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect, insort
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
for _ in range(int(input())):
	n = L()[0]
	A = [[0 for i in range(n)] for j in range(n)]
	z = n * (n - 1) // (2 * n)
	win = [0 for i in range(n)]
	for i in range(n):
		for j in range(i + 1, n):
			if n % 2 == 0 and i % 2 == 0:
				if j == i + 1:
					continue
			A[i][j] = 1
			A[j][i] = -1
			win[i] += 1
	for i in range(n):
		if win[i] <= z:
			continue
		j = n - 1
		while win[i] > z and j > i:
			if win[j] < z:
				A[i][j] = -1
				A[j][i] = 1
				win[j] += 1
				win[i] -= 1
			j -= 1
	for i in range(n):
		print(*A[i][i + 1:], end=' ')
	print()
endtime = time.time()


import os
import sys
from io import BytesIO, IOBase
from math import floor, sqrt
from bisect import *

def main():
	for _ in range(int(input())):
		n = int(input())
		if n % 2:
			for i in range(1, n):
				for j in range(i + 1, n + 1):
					if (i + j) % 2:
						print('1', end=' ')
					else:
						print('-1', end=' ')
		else:
			for i in range(1, n):
				f = 1
				for j in range(i + 1, n + 1):
					if f and i % 2:
						print('0', end=' ')
						f = 0
					elif (i + j) % 2:
						print('-1', end=' ')
					else:
						print('1', end=' ')
		print('')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	if n % 2:
		go = True
		for i in range(n * (n - 1) // 2):
			if go:
				print(1, end=' ')
			else:
				print(-1, end=' ')
			go = not go
	else:
		r = ['1 -1', '-1 1']
		do = n // 2
		for i in range((n - 2) // 2):
			do -= 1
			print('0', end=' ')
			for i in range(do):
				print(r[0], end=' ')
			for i in range(do):
				print(r[1], end=' ')
		print('0')


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		if n == 2:
			print(0)
			continue
		z = n - 1
		z = z % 2 + 3 * (z // 2)
		arr = [0] * (n + 1)
		ans = []
		for i in range(1, n + 1):
			for j in range(i + 1, n + 1):
				if z - arr[i] > 1:
					ans.append(1)
					arr[i] += 3
				elif z - arr[i] == 1:
					ans.append(0)
					arr[i] += 1
					arr[j] += 1
				else:
					ans.append(-1)
					arr[j] += 3
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math
import collections
import bisect
import itertools
import decimal
import heapq
INF = 10 ** 20
MOD = 10 ** 9 + 7

def ni():
	return int(sys.stdin.buffer.readline())

def ns():
	return map(int, sys.stdin.buffer.readline().split())

def na():
	return list(map(int, sys.stdin.buffer.readline().split()))

def na1():
	return list(map(lambda x: int(x) - 1, sys.stdin.buffer.readline().split()))

def flush():
	return sys.stdout.flush()

def nicf():
	return int(sys.stdin.readline())

def nscf():
	return map(int, sys.stdin.readline().split())

def nacf():
	return list(map(int, sys.stdin.readline().split()))

def na1cf():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def printer(a):
	res = []
	for i in range(len(a)):
		for j in range(i + 1, len(a)):
			res.append(a[i][j])
	print(*res)

def solve():
	n = ni()
	mat = [[-2] * n for _ in range(n)]
	half = n // 2
	for i in range(n):
		cnt = 0
		for j in range(1, n - i):
			nidx = (i + j) % n
			cnt += 1
			if cnt <= half:
				mat[i][nidx] = 1
				mat[nidx][i] = -1
			else:
				mat[i][nidx] = -1
				mat[nidx][i] = -1
		if n % 2 == 0:
			for i in range(half):
				nidx = (i + half) % n
				mat[i][nidx] = 0
				mat[nidx][i] = 0
	printer(mat)

def main():
	t = ni()
	for ti in range(t):
		solve()
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	b = ''
	if n == 2:
		print(0)
	elif n == 3:
		print(1, -1, 1)
	elif n % 2 == 1:
		for i in range(1, n):
			if i <= (n - 1) // 2:
				a.append('1')
			else:
				a.append('-1')
		while a:
			b = '{} {}'.format(b, ' '.join(a))
			del a[-1]
		print(b[1:])
	else:
		for i in range(1, n):
			if i < n // 2:
				a.append('1')
			elif i == n // 2:
				a.append('0')
			else:
				a.append('-1')
		while a:
			b = '{} {}'.format(b, ' '.join(a))
			del a[-1]
		print(b[1:])


for t in range(int(input())):
	hraci = int(input())
	if hraci % 2 == 1:
		a = hraci // 2 * '1' + hraci // 2 * '2'
	else:
		a = (hraci - 1) // 2 * '1' + '0' + (hraci - 1) // 2 * '2'
	ans = []
	for i in range(hraci - 1):
		if i != 0:
			ans.append(a[:-i])
		else:
			ans.append(a)
	ANS = []
	for i in ans:
		for j in i:
			if j == '1':
				ANS.append('1')
			elif j == '0':
				ANS.append('0')
			else:
				ANS.append('-1')
	print(' '.join(ANS))


import math
import sys
import collections
import bisect
import heapq
ans = []
testcases = int(sys.stdin.readline())
for _ in range(testcases):
	n = int(sys.stdin.readline())
	arr = [[None] * n for i in range(n)]
	if n % 2 == 0:
		x = 1
		y = 0
		for i in range(n // 2):
			arr[y][x] = 0
			arr[x][y] = 0
			x += 2
			y += 2
	num = (n - 1) // 2
	for i in range(n):
		curr = num
		if i % 2 == 0:
			for j in range(i + 1, n):
				if arr[i][j] is None:
					arr[i][j] = 1
					curr -= 1
				if curr == 0:
					break
		else:
			for j in range(n - 1, i, -1):
				if arr[i][j] is None:
					arr[i][j] = 1
					curr -= 1
				if curr == 0:
					break
		if i % 2 == 1:
			num -= 1
	for i in range(n - 1):
		for j in range(i + 1, n):
			if arr[i][j] == None:
				print(-1, end=' ')
			else:
				print(arr[i][j], end=' ')


for _ in range(int(input())):
	n = int(input())
	win = {}
	ties = {}
	k = (n - 1) // 2
	if n % 2 == 0:
		for d in range(1, n + 1):
			ties[d] = 1
	else:
		for d in range(1, n + 1):
			ties[d] = 0
	for d in range(1, n + 1):
		win[d] = k
	ans = []
	points = [0] * n
	for i in range(1, n):
		if i % 2:
			for j in range(i + 1, n + 1):
				if j == n + 1 - i and ties[i] > 0 and (ties[j] > 0):
					ties[i] = 0
					ties[j] = 0
					points[i - 1] += 1
					points[j - 1] += 1
					ans.append(0)
				elif win[i] > 0:
					win[i] -= 1
					points[i - 1] += 3
					ans.append(1)
				else:
					points[j - 1] += 3
					win[j] -= 1
					ans.append(-1)
		else:
			ar = []
			for j in range(n, i, -1):
				if j == n + 1 - i and ties[i] > 0 and (ties[j] > 0):
					ties[i] = 0
					ties[j] = 0
					points[i - 1] += 1
					points[j - 1] += 1
					ar.append(0)
				elif win[i] > 0:
					win[i] -= 1
					points[i - 1] += 3
					ar.append(1)
				else:
					points[j - 1] += 3
					win[j] -= 1
					ar.append(-1)
			ans += ar[::-1]
	print(' '.join(map(str, ans)))


T = int(input())
for t in range(T):
	n = int(input())
	if n % 2 == 1:
		l = []
		for i in range(n // 2):
			l.append(1)
		for j in range(n // 2):
			l.append(-1)
		ind = n - 1
		while ind > 0:
			for i in range(ind):
				if ind != 1:
					print(l[i], end=' ')
				else:
					print(l[i])
			ind -= 1
	else:
		l = []
		N = n - 1
		for i in range(N // 2):
			l.append(1)
		l.append(0)
		for i in range(N // 2):
			l.append(-1)
		ind = n - 1
		while ind > 0:
			for i in range(ind):
				if ind != 1:
					print(l[i], end=' ')
				else:
					print(l[i])
			ind -= 1


import os, sys
from io import BytesIO, IOBase

def some_random_function():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def main():
	for _ in range(int(input())):
		n = int(input())
		if n & 1:
			aa = []
			(x, y) = (n // 2, n // 2)
			for i in range(n - 1):
				aa.extend([1] * x)
				aa.extend([-1] * y)
				if not y:
					x -= 1
				else:
					y -= 1
			print(*aa)
		else:
			aa = []
			(x, y) = ((n - 1) // 2, (n - 1) // 2)
			for i in range(n - 1):
				if not i & 1:
					aa.append(0)
					aa.extend([1] * x + [-1] * y)
				else:
					aa.extend([-1] * y + [1] * x)
				if not i & 1:
					continue
				x -= 1
				y -= 1
			print(*aa)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def some_random_function1():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function2():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function3():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function4():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)
main()


t = int(input())
for t in range(t):
	p = int(input())
	if p == 2:
		print(0)
	else:
		q = 0
		for i in range(p - 1):
			if p % 2 == 1:
				q = 1
			if q == 1:
				for j in range(p - i - 1):
					if j % 2 == 0:
						print(1, end=' ')
					else:
						print(-1, end=' ')
			elif i % 2 == 0:
				print(0, end=' ')
				for j in range(1, p - i - 1):
					if j % 2 != 0:
						print(1, end=' ')
					else:
						print(-1, end=' ')
			else:
				for j in range(p - i - 1):
					if j % 2 != 0:
						print(1, end=' ')
					else:
						print(-1, end=' ')
		print()


def dfs():
	n = int(input())
	for i in range(n):
		start = i + 1
		if n % 2 == 0 and i % 2 == 0:
			print('0 ', end='')
			start += 1
		for j in range(start, n):
			if (i + j) % 2 == 1:
				print('1 ', end='')
			else:
				print('-1 ', end='')
	print()
entrada = int(input())
for i in range(entrada):
	dfs()


import math
t = int(input())
for l in range(t):
	n = int(input())
	if n % 2 == 0:
		a = [1] * ((n - 1) // 2)
		a.append(0)
		b = [-1] * ((n - 1) // 2)
		a.extend(b)
	else:
		a = [1] * ((n - 1) // 2)
		b = [-1] * ((n - 1) // 2)
		a.extend(b)
	for i in range(n - 1):
		print(*a, end=' ')
		a = a[:-1]
	print()


import sys, math
from collections import defaultdict
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	total = n * (n - 1) / 2
	if n & 1:
		win = (n - 1) / 2
		for i in range(1, n):
			for j in range(n - i):
				if j < win:
					print('1 ', end='')
				else:
					print('-1 ', end='')
	else:
		draw = n / 2
		win = (total - draw) / n
		l_win = [0] * (n + 1)
		l_draw = [0] * (n + 1)
		for i in range(1, n + 1):
			for j in range(i + 1, n + 1):
				if l_win[i] < win:
					print('1 ', end='')
					l_win[i] += 1
				elif l_draw[i] == 0:
					print('0 ', end='')
					l_draw[i] = 1
					l_draw[j] = 1
				else:
					print('-1 ', end='')
	print()


import sys, math, queue
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	k = n // 2
	if n % 2 != 0:
		for i in range(n - 1):
			for g in range(i + 1, n):
				if g + k >= n:
					print(-1, end=' ')
				else:
					print(1, end=' ')
			k -= 1
	else:
		for i in range(n - 1):
			for g in range(i + 1, n):
				if g + k == n:
					print(0, end=' ')
				elif g + k >= n:
					print(-1, end=' ')
				else:
					print(1, end=' ')
			k -= 1
	print()


from collections import defaultdict

def fun(n):
	return n * (n - 1) >> 1
for _ in range(int(input())):
	n = int(input())
	x = fun(n)
	arr = []
	curr = n - 1
	for i in range(n - 1):
		temp = [0] * curr
		arr.append(temp)
		curr -= 1
	LASTSE = [-1] * (n - 1)
	times = int(x / n)
	on = 0
	for i in range(times):
		total = n
		for j in range(n - 1):
			if len(arr[j]) > on:
				arr[j][on] = 1
				total -= 1
			else:
				break
		curr = 0
		while total:
			arr[curr][LASTSE[curr]] = -1
			LASTSE[curr] -= 1
			curr += 1
			total -= 1
		on += 1
	ans = []
	for i in arr:
		for j in i:
			ans.append(j)
	print(*ans)


n = int(input())
ans = []
for i in range(n):
	m = int(input())
	if m % 2 == 1:
		mid = (m - 1) // 2
		numlist = [1] * mid + [-1] * mid
		comlist = []
		for j in range(m - 1, 0, -1):
			comlist += numlist[:j]
		ans.append(comlist)
	else:
		mid = (m - 1) // 2
		comlist = []
		for j in range(m // 2):
			comlist += [1] * mid + [0] + [-1] * (mid - j)
		for j in range(m // 2):
			comlist += [1] * (mid - j)
		ans.append(comlist)
for i in ans:
	for j in i:
		print(j, end=' ')
	print('')


t = int(input())

def get_answer(n):
	s = ''
	if n % 2 == 1:
		for i in range(n - 1, 0, -1):
			for j in range(0, i):
				s += '1 ' if j % 2 == 0 else '-1 '
	else:
		for i in range(n - 1, 0, -1):
			for j in range(0, i):
				if i % 2 == 1 and j == 0:
					s += '0 '
				elif j % 2 == 1:
					s += '1 '
				else:
					s += '-1 '
	return s.strip()
for _ in range(t):
	n = int(input())
	print(get_answer(n))


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def floor_sum(n: int, m: int, a: int, b: int) -> int:
	ans = 0
	if a >= m:
		ans += (n - 1) * n * (a // m) // 2
		a %= m
	if b >= m:
		ans += n * (b // m)
		b %= m
	y_max = (a * n + b) // m
	x_max = y_max * m - b
	if y_max == 0:
		return ans
	ans += (n - (x_max + a - 1) // a) * y_max
	ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
	return ans

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n):
		self.BIT = [0] * (n + 1)
		self.num = n

	def query(self, idx):
		res_sum = 0
		while idx > 0:
			res_sum += self.BIT[idx]
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		while idx <= self.num:
			self.BIT[idx] += x
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matrix[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matrix[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matrix[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] + other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] - other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matrix[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matrix[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matrix[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)

class SegmentTree:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, k, x):
		k += self.num
		self.tree[k] = x
		while k > 1:
			self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
			k >>= 1

	def query(self, l, r):
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += self.num
		r += self.num
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.tree[l] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.tree[r - 1] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		elif Rmin != -1:
			pos = Rmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		else:
			return -1

class DualSegmentTree:

	def __init__(self, n, segfunc, ide_ele):
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num

	def update(self, l, r, x):
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				self.tree[l] = self.segfunc(self.tree[l], x)
				l += 1
			if r & 1:
				self.tree[r - 1] = self.segfunc(self.tree[r - 1], x)
			l >>= 1
			r >>= 1

	def __getitem__(self, idx):
		idx += self.num
		res = self.ide_ele
		while idx:
			res = self.segfunc(res, self.tree[idx])
			idx >>= 1
		return res

class LazySegmentTree:
	__slots__ = ['merge', 'merge_unit', 'operate', 'merge_operate', 'operate_unit', 'n', 'data', 'lazy']

	def __init__(self, n, init, merge, merge_unit, operate, merge_operate, operate_unit):
		self.merge = merge
		self.merge_unit = merge_unit
		self.operate = operate
		self.merge_operate = merge_operate
		self.operate_unit = operate_unit
		self.n = (n - 1).bit_length()
		self.data = [merge_unit for i in range(1 << self.n + 1)]
		self.lazy = [operate_unit for i in range(1 << self.n + 1)]
		if init:
			for i in range(n):
				self.data[2 ** self.n + i] = init[i]
			for i in range(2 ** self.n - 1, 0, -1):
				self.data[i] = self.merge(self.data[2 * i], self.data[2 * i + 1])

	def propagate(self, v):
		ope = self.lazy[v]
		if ope == self.operate_unit:
			return
		self.lazy[v] = self.operate_unit
		self.data[v << 1] = self.operate(self.data[v << 1], ope)
		self.data[(v << 1) + 1] = self.operate(self.data[(v << 1) + 1], ope)
		self.lazy[v << 1] = self.merge_operate(self.lazy[v << 1], ope)
		self.lazy[(v << 1) + 1] = self.merge_operate(self.lazy[(v << 1) + 1], ope)

	def propagate_above(self, i):
		m = i.bit_length() - 1
		for bit in range(m, 0, -1):
			v = i >> bit
			self.propagate(v)

	def remerge_above(self, i):
		while i:
			c = self.merge(self.data[i], self.data[i ^ 1])
			i >>= 1
			self.data[i] = self.operate(c, self.lazy[i])

	def update(self, l, r, x):
		l += 1 << self.n
		r += 1 << self.n
		l0 = l // (l & -l)
		r0 = r // (r & -r) - 1
		self.propagate_above(l0)
		self.propagate_above(r0)
		while l < r:
			if l & 1:
				self.data[l] = self.operate(self.data[l], x)
				self.lazy[l] = self.merge_operate(self.lazy[l], x)
				l += 1
			if r & 1:
				self.data[r - 1] = self.operate(self.data[r - 1], x)
				self.lazy[r - 1] = self.merge_operate(self.lazy[r - 1], x)
			l >>= 1
			r >>= 1
		self.remerge_above(l0)
		self.remerge_above(r0)

	def query(self, l, r):
		l += 1 << self.n
		r += 1 << self.n
		l0 = l // (l & -l)
		r0 = r // (r & -r) - 1
		self.propagate_above(l0)
		self.propagate_above(r0)
		res = self.merge_unit
		while l < r:
			if l & 1:
				res = self.merge(res, self.data[l])
				l += 1
			if r & 1:
				res = self.merge(res, self.data[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += 1 << self.n
		r += 1 << self.n
		l0 = l // (l & -l)
		r0 = r // (r & -r) - 1
		self.propagate_above(l0)
		self.propagate_above(r0)
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.data[l][0] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.data[r - 1][0] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		res = -1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				self.propagate(pos)
				if self.data[2 * pos][0] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			res = pos - self.num
		if Rmin != -1:
			pos = Rmin
			while pos < self.num:
				self.propagate(pos)
				if self.data[2 * pos][0] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			if res == -1:
				res = pos - self.num
			else:
				res = min(res, pos - self.num)
		return res
import sys
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
for _ in range(int(input())):
	n = int(input())
	ans = []
	if n % 2 == 1:
		for i in range(1, n + 1):
			for j in range(i + 1, n + 1):
				if (i + j) % 2 == 1:
					ans.append(1)
				else:
					ans.append(-1)
	else:
		for i in range(1, n + 1):
			for j in range(i + 1, n + 1):
				if i % 2 == 1 and j == i + 1:
					ans.append(0)
				elif (i + j) % 2 == 0:
					ans.append(1)
				else:
					ans.append(-1)
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	m = n // 2
	if n % 2 == 1:
		s = [1] * m + [-1] * m
		for i in range(n - 1):
			print(*s[:n - 1 - i], end=' ')
		print('\n')
	else:
		s = [1] * (m - 1) + [0] + [-1] * (m - 1)
		for i in range(n - 1):
			print(*s[:n - 1 - i], end=' ')
		print('\n')


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
from random import *
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from fractions import *
from math import sqrt, ceil, log2, gcd
mod = 10 ** 9 + 7

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	lk = 0
	arr = {}
	while n % 2 == 0:
		n = n // 2
		lk += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		lk = 0
		cc = 0
		while n % ps == 0:
			n = n // ps
			lk += 1
	if n != 1:
		lk += 1
		return False
	return True

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

def pda(n):
	list = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				list.append(i)
			else:
				list.append(n // i)
				list.append(i)
	return list

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

def ii():
	return int(input())

def ilist():
	return [int(x) for x in input().strip().split()]

def islist():
	return list(map(str, input().split().rstrip()))

def inp():
	return input().strip()

def google(test, ans):
	return 'Case #' + str(test) + ': ' + str(ans)

def overlap(x1, y1, x2, y2):
	if x2 > y1:
		return y1 - x2
	if y1 > y2:
		return y2 - x2
	return y1 - x2

def pal(s):
	k = len(s)
	n = len(s) // 2
	for i in range(n):
		if s[i] == s[k - 1 - i]:
			continue
		else:
			return 0
	return 1
t = int(input())
for p in range(t):
	n = ii()
	total = n * (n - 1) // 2
	tie = total % n * 2 // n
	win = lose = (n - 1 - tie) // 2
	wins = [0] * (n + 1)
	loses = [0] * (n + 1)
	ties = [0] * (n + 1)
	for i in range(1, n + 1):
		wins[i] = win
		loses[i] = lose
		ties[i] = tie
	dp = [[0 for i in range(n + 1)] for j in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			if wins[i] > 0:
				dp[i][j] = 1
				wins[i] -= 1
				loses[j] -= 1
			elif ties[i] > 0:
				dp[i][j] = 0
				ties[i] -= 1
				ties[j] -= 1
			elif loses[i] > 0:
				dp[i][j] = -1
				loses[i] -= 1
				wins[j] -= 1
	arr = []
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			arr.append(dp[i][j])
	print(*arr)


def solve(n):
	numOpp = n - 1
	numWinsLosses = numOpp // 2
	numDraws = numOpp % 2
	p1Seq = [1] * numWinsLosses + [0] * numDraws + [-1] * numWinsLosses
	allSeq = []
	for i in range(n):
		allSeq += p1Seq[:n - i - 1]
	return allSeq

def prettyPrint(arr):
	return ' '.join([str(x) for x in arr])

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		out = solve(n)
		print(prettyPrint(out))
main()


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		arr = []
		k = n * (n - 1) // 2
		for i in range(k):
			if i % 2 == 0:
				arr.append(1)
			else:
				arr.append(-1)
		print(*arr)
	else:
		arr = []
		k = (n - 1) // 2
		for i in range(n - 1, 0, -1):
			w = min(k, i)
			d = 0
			l = 0
			if w < i:
				d = 1
			if w + d < i:
				l = i - w - d
			arr += [1] * w + [0] * d + [-1] * l
		print(*arr)


N = int(input())
for i in range(N):
	n = int(input())
	if n % 2 == 0:
		ret = [1] * (n // 2 - 1) + [0] + [-1] * (n // 2 - 1)
	else:
		ret = [1] * (n // 2) + [-1] * (n // 2)
	for i in range(len(ret), 0, -1):
		print(*ret[:i], end=' ')
	print()


import math
t = int(input())
for i in range(0, t):
	n = int(input())
	ans = []
	if n % 2 != 0:
		for i in range(0, n * (n - 1) // 2):
			if i % 2 == 0:
				ans.append(1)
			else:
				ans.append(-1)
	else:
		a = n // 2
		s = 0
		aa = n - 1
		index = 0
		i = 1
		while i <= n * (n - 1) // 2:
			i = i + 1
			s = s + 1
			if s == a and s < aa:
				ans.append(0)
				index = index + 1
				for j in range(s, aa):
					ans.append(-1)
				index = index + j
				i = index + 1
				aa = aa - 1
				s = 0
			elif s == a and s == aa:
				ans.append(0)
				i = index + 1
				break
			else:
				ans.append(1)
		for i in range(0, n * (n - 2) // 8):
			ans.append(1)
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 2:
		print(0)
		continue
	if n % 2 == 0:
		pattern = ['1'] * (n // 2 - 1) + ['0'] + ['-1'] * (n // 2 - 1)
	else:
		pattern = ['1'] * (n // 2) + ['-1'] * (n // 2)
	for i in range(n - 1, -1, -1):
		for j in range(0, i):
			print(pattern[j], end=' ')
	print()


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		sol = [0] * (n * (n - 1) // 2)
		idx = 0
		for i in reversed(range(n)):
			for j in range(i):
				sol[idx] = 1 if j < n // 2 else -1
				if j == (n - 1) // 2 and n % 2 == 0:
					sol[idx] = 0
				idx += 1
		print(*sol)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
t = int(input())
for z in range(t):
	n = int(input())
	ans = []
	if n % 2 == 1:
		for i in range(n * (n - 1) // 2):
			if i % 2 == 0:
				ans.append(1)
			else:
				ans.append(-1)
	else:
		a = []
		for i in range(n * (n - 1) // 2 // n):
			a.append(1)
		a.append(0)
		for i in range(n * (n - 1) // 2 // n):
			a.append(-1)
		for i in range(n - 1, 0, -1):
			ans = ans + a[:i]
	print(*ans)


def read_input(filename: str=None) -> None:
	from sys import stdin
	stdin = open(filename) if filename else stdin
	cases = int(stdin.readline())
	while cases:
		(cases, table) = (cases - 1, [])
		teams = int(stdin.readline())
		for start in range(teams - 1):
			for end in range(start + 1, teams):
				if 2 * (end - start) == teams:
					table.append(0)
				if 2 * (end - start) < teams:
					table.append(1)
				if 2 * (end - start) > teams:
					table.append(-1)
		print(*table)

def main():
	read_input()
main()


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = int(3 * (n - 1) / 2 * n)
		draws = int(s % n)
		wins = s // n // 3
		ans = []
		for i in range(n):
			wins_cnt = 0
			draw_used = False
			for j in range(i + 1, n):
				if wins_cnt < wins:
					result = 1
					wins_cnt += 1
				elif not draw_used and draws > 0:
					result = 0
					draws -= 1
					draw_used = True
				else:
					result = -1
				ans.append(result)
		print(*ans)
main()


import sys
input = sys.stdin.readline

def solve():
	for i in range(int(input())):
		n = int(input())
		a = [[0] * n for i in range(n)]
		for v in range(n):
			for j in range(1, (n - 1) // 2 + 1):
				u = (v + j) % n
				a[v][u] = 1
				a[u][v] = -1
		if n % 2 == 0:
			j = n // 2
			for v in range(n):
				u = (v + j) % n
				a[v][u] = 0
		res = []
		for i in range(n):
			for j in range(i + 1, n):
				res.append(str(a[i][j]))
		print(' '.join(res))
solve()


t = int(input())
for i in range(t):
	n = int(input())
	k = []
	w = (n - 1) // 2
	d = n * (n - 1) // 2
	for j in range(n - 1):
		if (n - 1) % 2 == 0:
			if j < w:
				k.append(1)
			else:
				k.append(-1)
		elif j < w:
			k.append(1)
		elif j == w:
			k.append(0)
		else:
			k.append(-1)
	l = n - 1
	f = n - 1
	u = 0
	for t in range(d):
		if t == f:
			u = t
			l = l - 1
			f = u + l
		print(k[t - u], end=' ')


import math
for _ in range(int(input())):
	n = int(input())
	p = n * (n + 1) // 2
	if n % 2 != 0:
		an = []
		j = 0
		while j < n:
			for i in range(1, n - j):
				if i % 2 != 0:
					an.append(1)
				else:
					an.append(-1)
			j += 1
		print(*an)
	else:
		j = n
		an = []
		while j > 0:
			an.append(0)
			flag = 1
			for i in range(1, j - 1):
				if i < 0:
					break
				an.append(flag)
				flag = flag * -1
			flag = -1
			for i in range(1, j - 1):
				an.append(flag)
				flag = flag * -1
			j -= 2
		print(*an)


t = int(input())
for i in range(t):
	n = int(input())
	v = (n - 1) // 2
	a = []
	if n % 2 == 1:
		ans = [1] * v + [-1] * v
		for j in range(n - 1):
			a += ans[:2 * v - j]
	else:
		ans = [1] * v + [0] + [-1] * v
		for j in range(n - 1):
			a += ans[:2 * v - j + 1]
	print(*a, sep=' ')


try:
	t = int(input())
	while t != 0:
		n = int(input())
		temp = []
		if n % 2 == 1:
			for i in range(n * (n - 1) // 2):
				if i % 2 == 0:
					temp.append(1)
				else:
					temp.append(-1)
		else:
			for i in range(0, n - 1):
				if i % 2 == 1:
					for j in range(i + 1, n):
						if j % 2 == 0:
							temp.append(-1)
						else:
							temp.append(1)
				else:
					for j in range(i + 1, n):
						if j == i + 1:
							temp.append(0)
						elif j % 2 == 0:
							temp.append(1)
						else:
							temp.append(-1)
		print(*temp)
		t -= 1
except EOFError:
	print(' ')


import math
for T in range(int(input())):
	N = int(input())
	a = []
	if N % 2 == 0:
		for i in range(N // 2 - 1):
			a.append(1)
		a.append(0)
		for i in range(N // 2 - 1):
			a.append(-1)
	else:
		for i in range(N // 2):
			a.append(1)
		for i in range(N // 2):
			a.append(-1)
	n = len(a)
	while n > 0:
		for j in range(n):
			print(a[j], end=' ')
		n -= 1
	print()


import sys
input = sys.stdin.readline
import math
t = int(input())
for f in range(t):
	n = int(input())
	ans = []
	if n % 2:
		for i in range(n - 1):
			for j in range(n - i - 1):
				temp = 0
				if j % 2:
					temp = 1
				else:
					temp = -1
				ans.append(temp)
	else:
		for i in range(n - 1):
			flg = -1
			if i % 2 == 0:
				ans.append(0)
				flg = 1
			for j in range(n - i - 1 - (i + 1) % 2):
				if flg == 1:
					ans.append(1)
					flg = -1
				else:
					ans.append(-1)
					flg = 1
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	ans = [[10 ** 18] * (i + 1) for i in range(n - 1)]
	if n % 2 == 0:
		for i in range(0, n, 2):
			ans[i][i] = 0
		f = 1
		for i in range(n - 1):
			for j in range(i + 1):
				if ans[i][j] == 10 ** 18:
					ans[i][j] = int(str(f))
					f *= -1
			f *= -1
	else:
		f = 1
		for i in range(n - 1):
			for j in range(i + 1):
				ans[i][j] = int(str(f))
				f *= -1
	l = []
	for i in range(n - 1):
		for j in range(n - 1):
			try:
				l.append(ans[j][i])
			except:
				pass
	print(*l)


import sys
from sys import stdin, stdout
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def code(n):
	if n % 2 == 0:
		for i in range(1, n // 2 + 2):
			print('1 ' * (n // 2 - 1), end='')
			if i <= n // 2:
				print('0 ', end='')
			print('-1 ' * (n // 2 - i), end='')
		for i in range(1, n // 2 - 1):
			print('1 ' * (n // 2 - i - 1), end='')
	else:
		for i in range(1, n // 2 + 2):
			print('1 ' * (n // 2), end='')
			print('-1 ' * (n // 2 - i + 1), end='')
		for i in range(1, n // 2):
			print('1 ' * (n // 2 - i), end='')
t = int(input())
for i in range(t):
	n = int(input())
	ans = code(n)


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(input())
	res = []
	for i in range(1, n):
		for j in range(min((n - 1) // 2, n - i)):
			res.append(1)
		if n % 2 == 0 and (n - 1) // 2 < n - i:
			res.append(0)
		for j in range((n - 1) // 2 - i + 1):
			res.append(-1)
	print(' '.join(map(str, res)))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


a = int(input())
for x in range(a):
	b = int(input())
	if b % 2 == 1:
		s = '1'
		for y in range(int(b * (b - 1) // 2)):
			print(s, end=' ')
			if s == '1':
				s = '-1'
			else:
				s = '1'
		print()
	elif b == 2:
		print(0)
	else:
		t = []
		for y in range(b - 1):
			if y == (b - 1) // 2:
				t.append(0)
			elif y < (b - 1) // 2:
				t.append(1)
			else:
				t.append(-1)
		count = 0
		for y in range(b - 1):
			for z in range(b - y - 1):
				print(t[z], end=' ')
				count += 1
		print()


test = int(input())

def solve():
	n = int(input())
	for i in range(n):
		start = i + 1
		if n % 2 == 0 and i % 2 == 0:
			print('0 ', end='')
			start += 1
		for j in range(start, n):
			if (i + j) % 2 == 1:
				print('1 ', end='')
			else:
				print('-1 ', end='')
	print()
for i in range(test):
	solve()


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop
from bisect import bisect_right, bisect_left

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
mod = 1000000007
res = ['NO', 'YES']
(test, test_case) = (0, 1)
test_case = ii()
while test < test_case:
	test += 1
	n = ii()
	tot = n * (n - 1) // 2
	gap = tot // n
	f = 0
	if tot % n:
		f = 1
	a = []
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			g = j - i
			x = -1
			if g <= gap:
				x = 1
			elif f and g == gap + 1:
				x = 0
			a.append(x)
	print(*a)


t = int(input())
for q in range(t):
	n = int(input())
	z = -1
	if n % 2 == 0:
		for i in range(1, n + 1):
			for j in range(i + 1, n + 1):
				if i % 2 == 1 and j == i + 1:
					print(0, end=' ')
				elif i % 2 == 0 and j == i + 1:
					print(z, end=' ')
				else:
					if z == 1:
						z = -1
					else:
						z = 1
					print(z, end=' ')
	else:
		for i in range(1, n + 1):
			for j in range(i + 1, n + 1):
				if z == 1:
					z = -1
				else:
					z = 1
				print(z, end=' ')


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
depth = 1000005
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
from math import inf, ceil, sqrt
from collections import defaultdict
from operator import itemgetter
for _ in range(int(input())):
	n = int(input())
	tot = n * (n - 1) // 2
	rem = tot % n
	win = (tot - rem) // n
	matches = [win for _ in range(n + 1)]
	res = []
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			if j - i <= win:
				res.append(1)
			elif n - j + i <= win:
				res.append(-1)
			else:
				res.append(0)
	print(*res)


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd, log
import bisect
import sys
import copy

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	possible_permutation = -1
	total_games = n * (n - 1) // 2
	for i in range(total_games + 1):
		if (3 * (total_games - i) + 2 * i) % n == 0:
			possible_permutation = (3 * (total_games - i) + 2 * i) // n
			break
	wins = possible_permutation // 3
	draws = possible_permutation - wins * 3
	wins_required = [wins] * n
	draws_required = [draws] * n
	for i in range(n):
		for j in range(i + 1, n):
			if wins_required[i]:
				print(1, end=' ')
				wins_required[i] -= 1
			elif draws_required[i] and draws_required[j]:
				print(0, end=' ')
				draws_required[i] -= 1
				draws_required[j] -= 1
			elif wins_required[j]:
				print(-1, end=' ')
				wins_required[j] -= 1
	print()


for testis in range(int(input())):
	n = int(input())
	result = []
	if n % 2 == 1:
		for i in range(n):
			for j in range(i + 1, n):
				result += ['-1' if (i + j) % 2 == 0 else '1']
	else:
		for i in range(n):
			for j in range(i + 1, n):
				if i + j == n - 1:
					result += ['0']
				elif i + j < n - 1:
					result += ['-1' if (i + j) % 2 == 0 else '1']
				else:
					result += ['1' if (i + j) % 2 == 0 else '-1']
	print(*result)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	n -= 1
	ans = [[0 for i in range(n + 1)] for j in range(n + 1)]
	for i in range(n + 1):
		wins = n // 2
		for j in range(1, n + 1):
			if wins > 0:
				ans[i][(i + j) % (n + 1)] = 1
			wins -= 1
	for i in range(n + 1):
		for j in range(i + 1, n + 1):
			if ans[i][j] == 1:
				print(1, end=' ')
			elif ans[j][i] == 1:
				print(-1, end=' ')
			else:
				print(0, end=' ')
	print()


from collections import defaultdict
from itertools import accumulate
import sys
input = sys.stdin.readline
inf = 100000000000000000
mod = 998244353
for CASES in range(int(input())):
	n = int(input())
	A = [[0] * n for i in range(n)]
	for i in range(n):
		half = (n - 1) // 2
		for j in range(i - half, i):
			A[i][(j + n) % n] = -1
		for j in range(i + 1, i + half + 1):
			A[i][j % n] = 1
	for i in range(n):
		for j in range(i + 1, n):
			print(A[i][j], end=' ')
	print()


def main():
	for _ in range(int(input())):
		n = int(input())
		le = n * (n - 1)
		(n2, k, even, l) = (n // 2, 0, 1 - n % 2, ['-1'] * le)
		for i in range(n - 1, 0, -1):
			for j in range(k, k + n2):
				l[j] = '1'
			if even:
				l[j] = '0'
			k += i
		print(' '.join(l[:le // 2]))
main()


for t in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		for i in range(1, n):
			x = 1
			for j in range(i + 1, n + 1):
				print(x, end=' ')
				x *= -1
	else:
		for i in range(1, n):
			if i % 2 == 1:
				print(0, end=' ')
			else:
				print(-1, end=' ')
			x = 1
			for j in range(i + 2, n + 1):
				print(x, end=' ')
				x *= -1
	print('')


a = int(input())
for i in range(a):
	s = int(input())
	if s % 2 == 1:
		for i in range(s * (s - 1) // 2):
			if i % 2 == 1:
				print(1, end=' ')
			else:
				print(-1, end=' ')
	else:
		cnt = 0
		for i in range(1, s + 1):
			if cnt % 2 == 0:
				cnt = 1
			else:
				cnt = 0
			for j in range(i + 1, s + 1):
				if j == i + 1 and i % 2 == 1:
					print(0, end=' ')
				else:
					cnt += 1
					if cnt % 2 == 1:
						print(1, end=' ')
					else:
						print(-1, end=' ')
	print(' ')


T = int(input())
ans_ls = [0] * T
for t in range(T):
	N = int(input())
	if N % 2 == 1:
		ls = [1] * (N // 2) + [-1] * (N // 2)
	else:
		ls = [1] * ((N - 2) // 2) + [0] * 1 + [-1] * ((N - 2) // 2)
	ls_ans = []
	for i in range(N):
		for j in range(N - (i + 1)):
			ls_ans.append(ls[j])
	ans_ls[t] = ls_ans
for ans in ans_ls:
	print(*ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	if n % 2:
		total = n * (n - 1) // 2
		res = []
		for i in range(total):
			if i % 2:
				res.append(-1)
			else:
				res.append(1)
	else:
		start = n - 1
		temp = start
		total = n * (n - 1) // 2
		res = []
		last = 1
		k = 0
		for i in range(total):
			if k % 2 == 0 and temp == start:
				res.append(0)
			elif temp != 1:
				res.append(last)
				if last == 1:
					last = -1
				else:
					last = 1
			else:
				res.append(last)
				start -= 1
				temp = start + 1
				k += 1
			temp -= 1
	print(*res)


for i in range(int(input())):
	n = int(input())
	dp = []
	if n % 2 == 0:
		pointer = False
		for i in range(n - 1):
			if i % 2 == 0:
				if pointer == False:
					dp.append(0)
					for j in range(n - i - 2):
						if j % 2 == 0:
							dp.append(1)
						else:
							dp.append(-1)
					pointer = True
				else:
					dp.append(0)
					for j in range(n - i - 2):
						if j % 2 == 0:
							dp.append(-1)
						else:
							dp.append(1)
					pointer = False
			elif pointer == False:
				for j in range(n - i - 1):
					if j % 2 == 0:
						dp.append(1)
					else:
						dp.append(-1)
				pointer = True
			else:
				for j in range(n - i - 1):
					if j % 2 == 0:
						dp.append(-1)
					else:
						dp.append(1)
				pointer = False
		print(*dp)
	else:
		for i in range(n - 1):
			for j in range(n - i - 1):
				if j % 2 == 0:
					dp.append(1)
				else:
					dp.append(-1)
		print(*dp)


t = int(input())
contador = 0
while contador != t:
	n = int(input())
	listaUtil = []
	funcFloor = n // 2
	if n % 2 != 0:
		for i in range(n):
			for j in range(i + 1, n):
				diff = (j - i) % n
				if diff > funcFloor:
					listaUtil.append(-1)
				elif diff <= funcFloor:
					listaUtil.append(1)
	else:
		valor = 0
		while valor != n:
			for j in range(valor + 1, n):
				diff = (j - valor) % n
				if diff == funcFloor:
					listaUtil.append(0)
				elif diff > funcFloor:
					listaUtil.append(-1)
				elif diff < funcFloor:
					listaUtil.append(1)
			valor += 1
	contador += 1
	print(*listaUtil)


import sys
input = sys.stdin.readline

def solution(n):
	sol = []
	for i in range(n - 1):
		for j in range(i + 1, n):
			if j - i < n / 2:
				sol.append(1)
			elif j - i == n / 2:
				sol.append(0)
			else:
				sol.append(-1)
	print(*sol)
T = int(input())
for t in range(T):
	n = int(input())
	solution(n)