MKnez wants to construct an array $s_1,s_2, \ldots , s_n$ satisfying the following conditions:

Each element is an integer number different from $0$;

For each pair of adjacent elements their sum is equal to the sum of the whole array.

More formally, $s_i \neq 0$ must hold for each $1 \leq i \leq n$. Moreover, it must hold that $s_1 + s_2 + \cdots + s_n = s_i + s_{i+1}$ for each $1 \leq i < n$.

Help MKnez to construct an array with these properties or determine that it does not exist.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 100$). The description of the test cases follows.

The only line of each test case contains a single integer $n$ ($2 \leq n \leq 1000$) — the length of the array.


-----Output-----

For each test case, print "YES" if an array of length $n$ satisfying the conditions exists. Otherwise, print "NO". If the answer is "YES", on the next line print a sequence $s_1,s_2, \ldots, s_n$ satisfying the conditions. Each element should be a non-zero integer in the range $[-5000,5000]$, i. e. $-5000 \leq s_i \leq 5000$ and $s_i \neq 0$ should hold for each $1 \leq i \leq n$.

It can be proved that if a solution exists then there also exists one which satisfies the additional constraints on the range.

If there are several correct answers, print any of them.


-----Examples-----

Input
2
2
3
Output
YES
9 5
NO


-----Note-----

In the first test case, $[9,5]$ is a valid answer since $9+5$ (the sum of the two adjacent elements $s_1+s_2$) is equal to $9+5$ (the sum of all elements). Other solutions include $[6,-9], [-1,-2], [-5000,5000], \ldots$

For the second test case, let us show why some arrays do not satisfy the constraints:

$[1,1,1]$  — $s_1+s_2 = 1+1 = 2$ and $s_1+s_2+s_3=1+1+1 = 3$ differ;

$[1,-1,1]$  — $s_1+s_2=1+(-1)=0$ and $s_1+s_2+s_3=1+(-1)+1 = 1$ differ;

$[0,0,0]$  — The array $s$ cannot contain a $0$.

This is not a proof, but it can be shown that the answer is "NO".

Difficulty: EASY
Tags: Mathematics

Constructive algorithms

Starter code:

Solutions:
out = []
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		out.append('YES')
		out.append('-1 1 ' * (n // 2))
	elif n == 3:
		out.append('NO')
	else:
		b = n - 1
		a = 3 - n
		out.append('YES')
		out.append(f'{a} {b} ' * (n // 2) + str(a))
for i in out:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 != 0:
		print('YES')
		k = n // 2
		print(f'-{k - 1} {k} ' * (n // 2) + f'-{k - 1}')
	else:
		print('YES')
		print(('1 -1 ' * (n // 2))[:-1])


t = int(input())
ans_lines = []
for _ in range(t):
	n = int(input())
	if n == 3:
		ans_lines.append('NO')
	elif n % 2 == 0:
		ans_lines.append('YES')
		ans_lines.append('-1 1 ' * (n // 2))
	else:
		ans_lines.append('YES')
		n_half = n // 2 - 1
		ans_lines.append('{} {} '.format(-n_half, n_half + 1) * (n_half + 1) + str(-n_half))
for ans_line in ans_lines:
	print(ans_line)


t = int(input())
for i in range(t):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		print('-1 1 ' * (n // 2))
	elif n == 3:
		print('NO')
	else:
		k = n // 2 + 1
		print('YES')
		ans = (str(2 - k) + ' ' + str(1 - 2 + k) + ' ') * (n // 2) + str(2 - k)
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		a = '-1 1 ' * (n // 2)
		print(a)
	elif n == 3:
		print('NO')
	else:
		print('YES')
		x = str((n - 1) // 2)
		y = str(-(n - 3) // 2)
		b = f'{y} {x} ' * (int(n - 1) // 2) + f'{y}'
		print(b)


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		print((n // 2 * '-1 1 ')[:-1])
	else:
		p = n // 2
		if p == 1:
			print('NO')
		else:
			print('YES')
			print(p * (str(1 - p) + ' ' + str(p) + ' ') + str(1 - p))


t = int(input())
for k in range(t):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2:
		print('YES')
		z = int((n - 1) / 2)
		y = ' ' + str(-z) + ' ' + str(z - 1)
		print(str(z - 1) + y * z)
	else:
		print('YES')
		print(('-1 1 ' * int(n / 2))[:-1])


problems = []
n = int(input())
for i in range(n):
	problems.append(int(input()))
for a in problems:
	if a % 2 == 0:
		print('YES')
		print('-1 1 ' * (a // 2))
	elif a // 2 - 1 != 0:
		print('YES')
		print(f'{1 - a // 2} {a // 2} ' * (a // 2) + f'{1 - a // 2}')
	else:
		print('NO')


def solution(n):
	if n % 2 == 0:
		print('YES')
		print('1 -1 ' * (n // 2))
	else:
		na = (n - 1) // 2
		nb = na - 1
		if nb == 0:
			print('NO')
			return
		else:
			print('YES')
			a = nb
			b = -na
			print(f'{a} {b} ' * na + f'{a}')
t = int(input())
for _ in range(t):
	n = int(input())
	solution(n)


for _ in range(int(input())):
	n = int(input())
	if n == 3:
		print('NO')
	else:
		print('YES')
		if n % 2:
			print(' '.join([str(n // 2 - 1), str(-(n // 2))] * (n // 2) + [str(n // 2 - 1)]))
		else:
			print(' '.join([str(1), str(-1)] * (n // 2)))


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		print('1 -1 ' * (n // 2))
	elif n > 3:
		x = (n - 1) // 2
		print('YES')
		print((str(x - 1) + ' ' + str(-x) + ' ') * (n // 2) + str(x - 1))
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2:
		print('YES')
		print(' '.join([str(n // 2 - 1), str(-n // 2 + 1)] * (n // 2)), str(n // 2 - 1))
	else:
		print('YES')
		print(' '.join(['1', '-1'] * (n // 2)))


class Solution:

	def solve(n: int):
		if n == 3:
			print('NO')
			return
		print('YES')
		if not n % 2:
			print('1 -1 ' * int(n // 2))
			return
		positive = int((n - 3) / 2)
		negative = '-' + str(int(positive + 1))
		result = (str(positive) + ' ' + negative + ' ') * int(n // 2) + str(positive)
		print(result)

	def MKnezTask():
		for i in range(int(input())):
			size = int(input())
			Solution.solve(size)
Solution.MKnezTask()


for _ in range(int(input())):
	n = int(input())
	if n == 3:
		print('NO')
		continue
	print('YES')
	if n % 2 == 0:
		print('1 -1 ' * (n // 2))
	else:
		a = (n - 3) // 2
		b = -a - 1
		print(f'{a} {b} ' * (n // 2) + f'{a}')


def fnc(n):
	if n == 3:
		return 'NO'
	elif n % 2 == 0:
		print('YES')
		return int(n / 2) * '1 -1 '
	else:
		a = int((n - 1) / 2)
		b = int((3 - n) / 2)
		c = str(b) + ' ' + str(a) + ' '
		print('YES')
		return a * c + str(b)
n = int(input())
for i in range(0, n):
	x = int(input())
	print(fnc(x))


n = int(input())
for i in range(n):
	k = int(input())
	if k % 2 and k != 3:
		print('YES')
		n = k // 2
		b = -n
		a = n - 1
		print(f'{a} {b} ' * n + f'{a}')
	elif k == 3:
		print('NO')
	else:
		print('YES')
		print(('1 -1 ' * (k // 2)).strip())


for t in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		(x, y) = (-1, 1)
	elif n // 2 - 1 == 0:
		print('NO')
		continue
	else:
		for x in range(-2500, 2500):
			y = x * (1 - n + n // 2) / (n // 2 - 1)
			if y - int(y) == 0:
				break
		else:
			print('NO')
			continue
	print('YES')
	print((f'{x} {int(y)} ' * (n // 2)).strip() + f' {x}' * (n % 2))


import sys

def solve():
	inp = sys.stdin.readline
	n = int(inp())
	if n == 3:
		print('NO')
	elif n % 2 == 1:
		print('YES')
		x = -(n // 2 - 1)
		y = n // 2
		print(' '.join([str(x), str(y)] * (n // 2) + [str(x)]))
	else:
		print('YES')
		print(' '.join(['-1', '1'] * (n // 2)))

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


t = int(input())
for i in range(t):
	n = int(input())
	if n == 3:
		print('NO')
		continue
	if n % 2 == 1:
		print('YES')
		y = n // 2
		x = y - 1
		y = -1 * y
		ans = (str(x) + ' ' + str(y) + ' ') * (n // 2) + str(x)
		print(ans)
	else:
		print('YES')
		ans = '1 -1 ' * (n // 2)
		print(ans.strip())


def get_seq(n: int):
	if n == 3:
		print('NO')
		return
	if n % 2 == 0:
		print('YES')
		print(' '.join(['1' if i % 2 == 0 else '-1' for i in range(n)]))
	else:
		print('YES')
		print(' '.join([str(n - 3) if i % 2 == 0 else f'-{n - 1}' for i in range(n)]))
t = int(input())
for _ in range(t):
	get_seq(int(input()))


import heapq
import math
t = int(input())
for _ in range(t):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 == 0:
		print('YES')
		print(' '.join(map(str, [1, -1] * (n // 2))))
	else:
		print('YES')
		pos = n // 2
		neg = 1 - n // 2
		print(' '.join(map(str, [neg, pos] * (n // 2) + [neg])))


t = int(input())
for i in range(t):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		list = [-1, 1]
		x = int(n / 2) * list
		print(' '.join([str(elem) for elem in x]))
	elif n >= 5:
		print('YES')
		list = [-(n // 2 - 1), n // 2]
		x = int(n // 2) * list
		print(' '.join([str(elem) for elem in x]), -(n // 2 - 1))
	else:
		print('NO')


num_of_tests = int(input())
for _ in range(num_of_tests):
	length = int(input())
	if length % 2 == 0:
		print('YES')
		print(' '.join(['-1 1' for i in range(length // 2)]))
	elif length <= 3:
		print('NO')
	else:
		(odd, even) = (1, -2)
		extra = (length - 5) // 2
		odd += extra
		even -= extra
		res = []
		for i in range(length):
			if i % 2 == 0:
				res.append(str(odd))
			else:
				res.append(str(even))
		print('YES')
		print(' '.join(res))


T = int(input())
for t in range(T):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		s = '-1 1 ' * (n // 2)
		print(s)
	elif n in [1, 3]:
		print('NO')
	else:
		print('YES')
		m = (n + 1) // 2
		s1 = -(m - 1)
		s0 = m - 2
		s = (str(s0) + ' ' + str(s1) + ' ') * (m - 1)
		s += str(s0)
		print(s)


t = int(input(''))
for _ in range(t):
	n = int(input(''))
	if n == 1:
		print('YES\n9')
	elif n % 2 == 0:
		print('YES')
		s = ''
		for i in range(n // 2):
			s += '1 -1 '
		print(s[:-1])
	elif n == 3:
		print('NO')
	else:
		print('YES')
		h = n // 2
		s = ''
		for i in range(h):
			s += '%i %i ' % (h - 1, -h)
		print(s + str(h - 1))


T = int(input())
for t in range(T):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 == 0:
		print('YES')
		print(' '.join(map(str, [1, -1] * (n // 2))))
	else:
		print('YES')
		first_num = -(n // 2 - 1)
		second_num = n // 2
		print(' '.join(map(str, [first_num, second_num] * (n // 2))) + ' ' + str(first_num))


t = int(input())
for i in range(t):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		ans = ''
		for j in range(n // 2):
			ans += '1 -1 '
		ans = ans.strip(' ')
		print(ans)
	elif n == 3:
		print('NO')
	else:
		x = (n - 2) // 2
		y = x + 1
		print('YES')
		ans = ''
		for j in range(n // 2):
			ans += '%s %s ' % (-x, y)
		ans += '%s' % -x
		print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		print('-1 1 ' * int(n / 2))
	elif n == 3:
		print('NO')
	else:
		k = int((n - 1) / 2)
		x = k - 1
		y = str(x) + ' ' + str(-k) + ' '
		print('YES')
		print(y * int(n / 2) + str(x))


def solve():
	if n == 3:
		print('NO')
		return
	print('YES')
	ans = []
	if n % 2:
		val = n // 2
		for i in range(n):
			val = 1 - val
			ans.append(val)
	else:
		val = 1
		for i in range(n):
			val = 0 - val
			ans.append(val)
	print(' '.join(map(str, ans)))
	return
T = int(input())
for t in range(T):
	n = int(input())
	solve()


for _ in range(int(input())):
	n = int(input())
	x = []
	if n == 3:
		print('NO')
		continue
	elif n % 2 == 0:
		print('YES')
		for i in range(n // 2):
			x.append('1')
			x.append('-1')
		print(' '.join(x))
		continue
	else:
		print('YES')
		y = n // 2
		for i in range(n // 2):
			x.append(str(1 - y))
			x.append(str(y))
		x.append(str(1 - y))
		print(' '.join(x))
		continue


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		print(' '.join([str([1, -1][i % 2]) for i in range(n)]))
	else:
		if n == 3:
			print('NO')
			continue
		i = n // 2
		l = [-i + 1, i] * i + [-i + 1]
		print('YES')
		print(' '.join([str(j) for j in l]))


t = int(input())
res = []
for _ in range(t):
	n = int(input())
	if n == 3:
		res.append('NO')
	elif n % 2 != 0:
		res.append('YES')
		x = n // 2
		ans = []
		for i in range(x):
			ans.append(x - 1)
			ans.append(-x)
		ans.append(x - 1)
		res.append(' '.join(map(str, ans)))
	else:
		res.append('YES')
		ans = []
		for i in range(n // 2):
			ans.append(1)
			ans.append(-1)
		res.append(' '.join(map(str, ans)))
for i in res:
	print(i)


def hdl(x):
	if x % 2 == 1 and x <= 3:
		print('NO')
	elif x % 2 == 1 and x > 3:
		print('YES\n%s' % ' '.join([str(-(x // 2 - 1)) if it % 2 == 1 else str(x // 2) for it in range(1, x + 1)]))
	else:
		print('YES\n%s' % ' '.join(['1' if it % 2 == 1 else '-1' for it in range(1, x + 1)]))
	return 114514
n = int(input())
cas = list([hdl(int(input().strip())) for item in range(n)])


t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	if n == 3:
		print('NO')
		continue
	elif n % 2 == 0:
		print('YES')
		for j in range(n // 2):
			arr.append('-1')
			arr.append('1')
		print(' '.join(arr))
		continue
	else:
		print('YES')
		x = n // 2
		for i in range(x):
			arr.append(str(1 - x))
			arr.append(str(x))
		arr.append(str(1 - x))
		print(' '.join(arr))
		continue


import sys

def solve():
	n = int(input())
	if n == 3:
		return 'NO'
	print('YES')
	seq = []
	if n % 2 == 0:
		for i in range(1, n + 1):
			seq.append((-1) ** i)
	else:
		k = n // 2
		for i in range(n):
			if i % 2 == 0:
				seq.append(1 - k)
			else:
				seq.append(k)
	ans = ' '.join(map(str, seq))
	return ans
T = int(input())
for t in range(T):
	ans = solve()
	print(ans)


def helper(n):
	if n == 3:
		return 'NO'
	ans = [0 for i in range(n)]
	if n % 2 == 0:
		for i in range(0, len(ans), 2):
			ans[i] = 1
			ans[i + 1] = -1
	elif n % 2 == 1:
		x = n // 2
		for i in range(0, len(ans), 2):
			if i == len(ans) - 1:
				break
			(ans[i], ans[i + 1]) = (1 - x, x)
		ans[-1] = 1 - x
	ans = list(map(str, ans))
	return ' '.join(ans)
for i in range(int(input())):
	res = helper(int(input()))
	if res == 'NO':
		print(res)
	else:
		print('YES')
		print(res)


t = int(input())
for ii in range(t):
	x = int(input())
	if x % 2 == 0:
		ans = []
		y = x // 2
		for i in range(y):
			ans.append(str(1))
			ans.append(str(-1))
		print('YES')
		print(' '.join(ans))
	else:
		ans = []
		y = x // 2
		for i in range(y):
			ans.append(str(y - 1))
			ans.append(str(-y))
		ans.append(str(y - 1))
		if '0' not in ans:
			print('YES')
			print(' '.join(ans))
		else:
			print('NO')


import sys

def gen_even_array(array_length):
	array = []
	value = 1
	for i in range(array_length):
		array.append(value)
		value *= -1
	return array

def gen_odd_array(array_length):
	k = int(array_length / 2)
	array = []
	a = k - 1
	b = -k
	for i in range(array_length):
		if i % 2 == 0:
			array.append(a)
		else:
			array.append(b)
	return array
lines = int(input())
test_case_array_length = []
for i in range(lines):
	test_case_array_length.append(int(input()))
for array_length in test_case_array_length:
	if array_length % 2 == 0:
		print('YES')
		print(' '.join((str(x) for x in gen_even_array(array_length))))
		continue
	if array_length < 5:
		print('NO')
		continue
	else:
		print('YES')
		print(' '.join((str(x) for x in gen_odd_array(array_length))))
		continue


import heapq
import math
eps = 10 ** (-9)

def solve():
	n = int(input())
	if n == 1:
		print('YES')
		print('1')
		return
	if n == 3:
		print('NO')
		return
	print('YES')
	if n % 2 == 0:
		res = ''
		for _ in range(n // 2):
			res += '-1 1 '
		print(res[:-1])
		return
	else:
		b = n - 1
		a = -(n - 3) * b // (n - 1)
		res = ''
		for _ in range(n // 2):
			res += str(a) + ' ' + str(b) + ' '
		res += str(a)
		print(res)
	return
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	length = int(input())
	result = []
	if length % 2 == 0:
		print('YES')
		for i in range(length):
			if i % 2 == 0:
				result.append(-1)
			else:
				result.append(1)
		print(' '.join(map(str, result)))
	elif length > 4:
		print('YES')
		k = int(length / 2)
		for i in range(length):
			if i % 2 == 0:
				result.append(k - 1)
			else:
				result.append(-k)
		print(' '.join(map(str, result)))
	else:
		print('NO')


roll = int(input())
for ink in range(roll):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 == 0:
		print('YES')
		s = ''
		for i in range(int(n / 2)):
			s += '1 -1 '
		print(s[0:len(s) - 1])
	else:
		print('YES')
		a = int((n - 3) / 2)
		b = int((1 - n) / 2)
		s = ''
		for i in range(int((n - 1) / 2)):
			s += str(a) + ' ' + str(b) + ' '
		s += str(a)
		print(s)


tests = int(input())
for test in range(tests):
	n = int(input())
	if n == 3:
		print('NO')
		continue
	elif n % 2 == 0:
		a = 1
		b = -1
	else:
		a = n // 2 - 1
		b = -a - 1
	ans = [a] * n
	for i in range(n // 2):
		ans[i * 2 + 1] = b
	print('YES')
	print(' '.join([str(t) for t in ans]))


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve(n):
	if n == 3:
		return []
	a = []
	if n % 2 == 0:
		d = [-1, 1]
	else:
		d = [-n + 3, n - 1]
	for i in range(n):
		a.append(d[i % 2])
	return a
t = int(input())
for _ in range(t):
	n = int(input())
	res = solve(n)
	if not res:
		print('NO')
	else:
		print('YES')
		print(' '.join(map(str, res)))


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		t = ''
		print('YES')
		for __ in range(n // 2):
			t += '1 -1 '
		print(t)
	elif n == 3:
		print('NO')
	else:
		print('YES')
		t = ''
		for i in range(n // 2):
			t += str(1 - n // 2) + ' ' + str(n // 2) + ' '
		t += str(1 - n // 2)
		print(t)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		if n == 3:
			print('NO')
		elif n % 2 == 0:
			print('YES')
			s = ''
			for i in range(n - 1):
				if i % 2 == 0:
					s += '1 '
				else:
					s += '-1 '
			s += '-1'
			print(s)
		else:
			print('YES')
			s = ''
			q = (n - 1) // 2
			for i in range(n - 1):
				if i % 2 == 0:
					s += str(q - 1) + ' '
				else:
					s += str(-q) + ' '
			s += str(q - 1)
			print(s)
main()


n = int(input())
for i in range(n):
	x = int(input())
	ans = ''
	if x % 2 == 0:
		print('YES')
		for j in range(x):
			if j % 2 == 0:
				ans += '1 '
			else:
				ans += '-1 '
		print(ans)
	elif x == 3:
		print('NO')
	else:
		y = x // 2
		z = 1 - y
		print('YES')
		for k in range(x):
			if k % 2 == 0:
				ans += str(z)
				ans += ' '
			else:
				ans += str(y)
				ans += ' '
		print(ans)


t = int(input())

def play(n):
	if n == 1:
		return [1]
	elif n % 2 == 0:
		return [(-1) ** (x + 1) for x in range(n)]
	elif n == 3:
		return None
	else:
		k = n // 2 + 1
		y = 1
		x = y * (k - 2)
		res = []
		for i in range(n):
			if i % 2 == 0:
				res.append(-x)
			else:
				res.append(x + y)
		return res
for _ in range(t):
	n = int(input())
	result = play(n)
	if result is None:
		print('NO')
	else:
		print('YES')
		print(' '.join([str(x) for x in result]))


for _ in range(int(input())):
	n = int(input())
	L = []
	if n == 3:
		print('NO')
		continue
	if n % 2 == 0:
		for j in range(n):
			if j % 2 == 0:
				L.append(1)
			else:
				L.append(-1)
		print('YES')
		print(' '.join(map(str, L)))
	else:
		L1 = []
		for j in range(n):
			if j % 2 == 0:
				L1.append(3 - n)
			else:
				L1.append(n - 1)
		print('YES')
		print(' '.join(map(str, L1)))


import math
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		s = ''
		for i in range(n // 2):
			s += '1 -1' + ' '
		print('YES')
		print(s)
	elif n == 3:
		print('NO')
	else:
		s = ''
		for i in range(n // 2):
			s += str((n // 2 - 1) * -1) + ' ' + str(n // 2) + ' '
		s += str((n // 2 - 1) * -1)
		print('YES')
		print(s)


import math
t = int(input())
for i in range(t):
	n = int(input())
	if n == 3:
		print('NO')
	else:
		print('YES')
		s = ''
		if n % 2 == 0:
			n1 = 1
			n2 = -1
			s = ''
			for i in range(n):
				if i % 2 == 0:
					s += str(n1) + ' '
				else:
					s += str(n2) + ' '
		else:
			n1 = -1 * (n // 2)
			n2 = n // 2 - 1
			s = ''
			for i in range(n):
				if i % 2 == 0:
					s += str(n2) + ' '
				else:
					s += str(n1) + ' '
		print(s)


for run in range(int(input())):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 == 1:
		print('YES')
		st = ''
		for i in range(n):
			if i % 2 == 0:
				st += f'-{n // 2 - 1} '
			else:
				st += f'{n // 2} '
		st = st[:len(st) - 1]
		print(st)
	else:
		print('YES')
		st = '1'
		for i in range(1, n):
			if i % 2 == 0:
				st += ' 1'
			else:
				st += ' -1'
		print(st)


def lights(n):
	sp_ar = []
	if n == 1 or n == 3:
		print('NO')
	elif n % 2 == 0:
		for i in range(n):
			sp_ar.append(str((-1) ** i))
		print('YES')
		print(' '.join(sp_ar))
	else:
		zahl_1 = n // 2
		zahl_2 = (zahl_1 - 1) * -1
		for i in range(n):
			if i % 2 == 0:
				sp_ar.append(str(zahl_2))
			else:
				sp_ar.append(str(zahl_1))
		print('YES')
		print(' '.join(sp_ar))
tests = int(input())
for i in range(tests):
	lights(int(input()))


t = int(input())
for x in range(t):
	array = []
	n = int(input())
	if n % 2 == 0:
		print('YES')
		for x in range(n):
			if x % 2 == 0:
				array.append('1')
			else:
				array.append('-1')
		print(' '.join(array))
	elif n >= 5:
		print('YES')
		for x in range(n):
			if x % 2 == 0:
				array.append(str(int(-1 - (n - 5) / 2)))
			else:
				array.append(str(int((-1 - (n - 5) / 2) * -1 + 1)))
		print(' '.join(array))
	else:
		print('NO')


def solve():
	n = int(input())
	if n == 3:
		out = 'NO'
	else:
		out = 'YES\n'
		(a, b) = (1, -1)
		if n % 2 != 0:
			a = int((n - 1) / 2 - 1)
			b = int((1 - n) / 2)
		for i in range(0, n):
			if i % 2 == 0:
				out += str(a)
			else:
				out += str(b)
			out += ' '
	print(out)
t = int(input())
for i in range(0, t):
	solve()


import sys

def read(func=int):
	return func(sys.stdin.readline().strip())

def read_array(func=int):
	return list(map(func, read(str).split()))
t = read()
for _ in range(t):
	n = read()
	if n % 2:
		if n < 5:
			print('NO')
		else:
			print('YES')
			k = (n - 1) // 2

			def ki(i):
				if i % 2:
					return -k
				return k - 1
			print(' '.join([str(ki(i)) for i in range(n)]))
	else:
		print('YES')
		print(' '.join([str((-1) ** (i + 1)) for i in range(n)]))


def solve():
	n = int(input())
	s = ''
	if n % 2 == 0:
		print('YES')
		while n:
			a = (-1) ** n
			s = f'{s}{a} '
			n -= 1
		print(s)
	elif n == 3:
		print('NO')
	else:
		a = int((n - 1) / 2 - 1)
		b = int(-((n - 1) / 2))
		n -= 1
		s = f'{a} '
		while n:
			s = f'{s}{b} {a} '
			n -= 2
		print('YES')
		print(s)
t = 1
t = int(input())
while t:
	solve()
	t -= 1


n = int(input())
for i in range(n):
	k = int(input())
	if k % 2 == 0:
		print('YES')
		l = []
		for i in range(k):
			l.append(str((-1) ** i))
		o = ' '.join(l)
		print(o)
	elif k % 2 != 0 and k > 3:
		print('YES')
		e = []
		for i in range(k):
			if i % 2 == 0:
				e.append(str((k - 2) // 2))
			else:
				e.append(str(-(k // 2)))
		u = ' '.join(e)
		print(u)
	elif k % 2 != 0 and k < 5:
		print('NO')


t = int(input())

def verify(arr):
	s = sum(arr)
	for i in range(len(arr) - 1):
		if arr[i] + arr[i + 1] != s:
			return False
	return True
for _ in range(t):
	n = int(input())
	if n == 3:
		print('NO')
	else:
		print('YES')
		arr = []
		if n % 2 == 0 or n == 1:
			arr = [1]
			while len(arr) != n:
				arr += [arr[-1] * -1]
		else:
			a = -1
			b = 2
			l = n // 2
			while a * (l + 1) + b * l != b + a:
				b += 1
				a -= 1
			while len(arr) != n - 1:
				arr += [a, b]
			arr += [a]
		print(' '.join([str(v) for v in arr]))


t = int(input())
while t > 0:
	n = int(input())
	if n % 2 != 0:
		if n == 3:
			print('NO')
		else:
			x = n - 1
			y = abs(3 - n)
			index = 2
			while index <= x and index <= y:
				if x % index == 0 and y % index == 0:
					while x % index == 0 and y % index == 0:
						x = x // index
						y = y // index
				else:
					index += 1
			a = x
			b = -y
			if x > 5000:
				print('NO')
			else:
				print('YES')
				r = ''
				for i in range(n):
					if i % 2 == 0:
						r += str(b) + ' '
					else:
						r += str(a) + ' '
				print(r)
	else:
		print('YES')
		r = ''
		index = 1
		for i in range(n):
			r += str(index) + ' '
			index = -index
		print(r[:-1])
	t -= 1


for i in range(int(input())):
	n = int(input())
	s = ''
	if n == 3:
		print('NO')
		continue
	if n % 2 != 0:
		for i in range(n):
			if i % 2 == 0:
				s += str(-(int(n / 2) - 1)) + ' '
			else:
				s += str(int(n / 2)) + ' '
	else:
		for i in range(n):
			if i % 2 == 0:
				s += '1 '
			else:
				s += '-1 '
	print('YES')
	print(s)


t = int(input())
out = []
for i in range(t):
	n = int(input())
	if n == 3:
		out.append('NO')
		continue
	elif n % 2 == 1:
		a = ' '.join([f'{1 + 2 * (-1) ** (j + 1) + n * (-1) ** j}' for j in range(1, n + 1)])
	else:
		a = ' '.join([f'{(-1) ** j}' for j in range(n)])
	out.append(f'YES\n{a}')
for i in out:
	print(i)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	if n == 3:
		print('NO')
	else:
		print('YES')
		str1 = ''
		for i in range(n):
			if i % 2 == 1:
				str1 += '1 ' if n % 2 == 0 else str((n - 1) // 2) + ' '
			else:
				str1 += '-1 ' if n % 2 == 0 else str(-1 * ((n - 1) // 2 - 1)) + ' '
		print(str1)


t = int(input())
for i in range(t):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 == 0:
		print('YES')
		s = ''
		for j in range(int(n / 2)):
			s += '1 '
			s += '-1 '
		print(s)
	elif n % 2 != 0:
		print('YES')
		k = int(int(n) / int(2))
		s = ''
		for j in range(int(n / 2)):
			s += str(k - 1)
			s += ' '
			s += str(-k)
			s += ' '
		s += str(k - 1)
		print(s)


T = int(input())
for _ in range(T):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 == 0:
		print('YES')
		for i in range(n // 2 - 1):
			print('-1 1 ', end='')
		print('-1 1')
	else:
		print('YES')
		v1 = n // 2 - 1
		v2 = -(n // 2)
		for i in range(n // 2):
			print('{} {} '.format(v1, v2), end='')
		print(v1)


for i in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		print('YES')
		n = n // 2
		l = [1, -1] * n
		print(*l)
	elif n == 3:
		print('NO')
	else:
		print('YES')
		n = n // 2
		l = [n - 1, -n] * n
		l.append(n - 1)
		print(*l)


a = int(input())
q = []
YES = 'YES'
NO = 'NO'
for _ in range(a):
	b = int(input())
	if b == 3:
		q.append([NO])
	elif b % 2 != 0:
		a = (b - 2) // 2 * -1
		x = b - 2 + a
		c = [a, x] * (b // 2)
		c.append(a)
		q.append([YES])
		q.append(c)
	else:
		c = [1, -1] * (b // 2)
		q.append([YES])
		q.append(c)
for i in q:
	print(*i)


def find_array(length: int):
	if length % 2 == 0:
		proof = [1 + i % 2 * -2 for i in range(1, length + 1)]
		return (proof, 'YES')
	elif length > 3:
		proof = [-int(length / 2) + i % 2 * (int(length / 2) * 2 - 1) for i in range(1, length + 1)]
		return (proof, 'YES')
	return (None, 'NO')
tests = int(input())
for case in range(tests):
	(result, str_res) = find_array(int(input()))
	print(str_res)
	if result:
		print(' '.join((str(item) for item in result)))


tt = int(input())
for _ in range(tt):
	n = int(input())
	if n == 3:
		print('NO')
	else:
		print('YES')
		if n % 2 == 0:
			print(*[-1, 1] * (n // 2))
		else:
			a = -(n - 3) // 2
			b = (n - 1) // 2
			print(*[a, b] * (n // 2), end=' ')
			print(a)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 != 0:
		print('YES')
		ans = []
		ele = n // 2
		e = ele - 1
		b = ele
		a = -e
		for j in range(ele):
			ans.append(a)
			ans.append(b)
		ans.append(a)
		print(*ans)
	else:
		print('YES')
		ans = []
		for j in range(n // 2):
			ans.append(-1)
			ans.append(1)
		print(*ans)


for _ in range(int(input())):
	n = int(input())
	if n == 3:
		print('NO')
	elif n % 2 == 0:
		print('YES')
		res = [1, -1] * (n // 2)
		print(*res)
	else:
		a = n // 2 - 1
		res = [-a, 1 + a] * (n // 2)
		res += [-a]
		print('YES')
		print(*res)


for i in range(int(input())):
	j = int(input())
	if j % 2 == 0:
		print('YES')
		l = []
		for k in range(int(j / 2)):
			l.append(1)
			l.append(-1)
		print(*l)
	elif j == 3:
		print('NO')
	else:
		print('YES')
		l = []
		b = int(j / 2)
		for k in range(b):
			l.append(-(b - 1))
			l.append(b)
		l.append(-(b - 1))
		print(*l)


t = int(input())
while t:
	t -= 1
	n = int(input())
	if n == 3:
		print('NO')
		continue
	elif n % 2 == 0:
		arr = [1] * n
		for i in range(0, n, 2):
			arr[i] = -arr[i]
		print('YES')
		print(*arr)
	else:
		arr = [n // 2] * n
		for i in range(0, n, 2):
			arr[i] = 1 - n // 2
		print('YES')
		print(*arr)


for t in range(int(input())):
	n = int(input())
	if n % 2 != 0:
		a = n // 2
		b = a - 1
		if a == 0 or b == 0:
			print('NO')
		else:
			print('YES')
			for i in range(n // 2):
				print(b, end=' ')
				print(a * -1, end=' ')
			print(b)
	else:
		print('YES')
		for i in range(n // 2 - 1):
			print('1 -1', end=' ')
		print('1 -1')


test = int(input())
while test:
	n = int(input())
	if n == 3:
		print('NO')
	else:
		print('YES')
		if n % 2 == 0:
			a = 1
			b = -1
			for i in range(n // 2):
				print(a, b, end=' ')
			print()
		else:
			a = -((n - 2) // 2)
			s = 1
			for i in range(n // 2):
				print(a, s - a, end=' ')
			print(a)
	test -= 1


def solution():
	n = int(input())
	if n % 2 == 1:
		if n == 3:
			print('NO')
		else:
			print('YES')
			b = n // 2
			a = -(b - 1)
			for i in range(n // 2):
				print(a, b, end=' ')
			print(a)
	else:
		print('YES')
		for i in range(n // 2):
			print(-1, 1, end=' ')
		print()

def main():
	t = int(input())
	while t:
		solution()
		t -= 1
main()


import pdb

def solve(n):
	if n == 3:
		print('NO')
		return
	r = []
	if n % 2 == 0:
		for _ in range(0, n, 2):
			r += ['1', '-1']
	else:
		num = (n - 3) // 2
		even_pos = True
		for _ in range(n):
			if even_pos:
				r.append(str(num))
			else:
				r.append(str(-(num + 1)))
			even_pos = not even_pos
	print('YES')
	print(' '.join(r))
t = int(input())
for _ in range(t):
	n = int(input())
	solve(n)