We need to solve: given T test cases, each with even n (2 ≤ n ≤ 100) and list of non-zero integers a_i (|a_i| ≤ 100, a_i ≠ 0). Need to find non-zero integers b_i (|b_i| ≤ 100) such that sum a_i b_i = 0. Additionally, b_i must be non-zero. Guarantee existence.
We need to produce any valid b_i.
Observation: Because n is even, we can pair up the a_i's. A simple constructive approach: For i=1..n/2, pair (a_{2i-1}, a_{2i}). For each pair (x, y) we can assign b_{2i-1}= y, b_{2i}= -x. Then contribution: xy + y(-x)=0. So total sum zero. However, need to ensure b_i are non-zero: if x or y is zero? But a_i are non-zero, so x and y are non-zero. Then b's are y and -x, which are non-zero because a_i ≠ 0. Also absolute values: |y| ≤ 100? a_i are ≤100, so y can be up to 100, similarly x up to 100. But wait: b_i must be ≤100 in absolute value. The construction yields b_{2i-1}= y, b_{2i}= -x. Since |y| ≤ 100 and |x| ≤ 100, indeed |b_i| ≤ 100. So this construction works! However, careful: Input says all a_i are nonzero and do not exceed 100 by absolute value. So indeed |a_i| ≤ 100. Then b_i = y or -x have absolute values ≤100. So that's valid.
But wait: Are there any constraints that b_i must also be non-zero? Yes, they are non-zero because a_i are non-zero. So the simple pairing works.
But check example: first door: n=2, a=[1,100]. Our construction: pair (1,100) gives b1=100, b2=-1 => [100, -1]. But example output is [-100, 1]. That's also valid, just sign swapped? Actually, with our construction b1=100, b2=-1 yields sum = 1100 + 100(-1)=100-100=0. That works, and both b_i are non-zero and within bounds. However, the example used [-100,1] which is also sum 1*(-100)+100*1=0. Both valid. So we can output our constructed. But need to ensure absolute values ≤100: 100 and -1 are okay. So we can output 100 -1? Wait: Output format expects space separated integers, presumably in order. So for that test, output "100 -1". But the example output is "-100 1". Both correct.
Thus the problem seems trivial with that pairing. But maybe there is a catch? Check the second example: n=4, a=[1,2,3,6]. Our construction: pair (1,2) gives b1=2, b2=-1; pair (3,6) gives b3=6, b4=-3. So b = [2, -1, 6, -3]. Sum = 12 + 2(-1) + 36 + 6(-3) = 2 -2 + 18 -18 = 0. That works. Output would be "2 -1 6 -3". But example output is "1 1 1 -1". Both are valid. So it's fine.
But wait: Is there any requirement that b_i must also be non-zero and |b_i| ≤ 100. Our construction always yields b_i = a_j for some j (or its negative). Since |a_j| ≤ 100, yes.
Thus solution: For each test case, read n, read list a of length n. Then for i from 0 to n-1 step 2, set b[i] = a[i+1], b[i+1] = -a[i]. Output b list.
Edge cases: n is even, so step 2 works. Also ensure that we don't accidentally produce a b_i that is zero: if any a_i were zero then b could be zero, but a_i non-zero. So okay.
However, is there any scenario where a_i = a_{i+1}? Then b_i = a_{i+1} is non-zero, fine.
Thus the problem is trivial. But maybe there is an alternative: Some constraints about b_i must be non-zero and bounded, but we must output any solution. This construction works.
But wait, think: The problem statement says "All energies a_i are nonzero and do not exceed 100 by absolute value. Also, n is even." So our solution is fine.
Thus we can just implement accordingly.
But why is this problem given? Maybe there is a hidden twist: Could it be that a_i can be up to 100 in absolute value, and b_i must also not exceed 100. Our construction yields b_i that may be exactly 100 if a_j = 100, so okay. But what about if a_j = -100? Then b_i = -100 (or positive 100) also within range. So fine.
Thus answer: For each test case, output b_i = a_{i+1} and b_{i+1} = -a_i for i odd? Actually indexing: if a[0..n-1], then for each pair (a[2k], a[2k+1]), output b[2k]=a[2k+1], b[2k+1] = -a[2k].
Alternatively, we can output the negation: b[2k]= -a[2k+1], b[2k+1]= a[2k] also works. But sign pattern must produce sum zero.
Thus solution.
But wait, is there any requirement that b_i must be non-zero? Already satisfied.
Now, double-check: Could there be a case where the sum of a_i b_i exceeds typical integer range? Not needed, we just compute output.
Implementation: For T test cases, read n, then read list a of n ints. Then compute b list of same length. Then output space-separated.
But careful: Input format: The first line contains T. The other lines contain descriptions. Each description: a line with n, then a line with n numbers. So we can just read accordingly.
Edge Cases: T up to 1000, n up to 100, so total numbers up to 100k, fine.
Thus solution is extremely simple.
But wait, I recall that in some problems like this, they might require that b_i be also non-zero and within range, and that there is always a solution. The pairing method is standard.
Thus answer: implement.
Now, to produce the final answer, I'll write code in C++? The problem statement doesn't specify language but we are to provide solution explanation and code. Usually we provide solution in C++ for speed. But we can also provide Python. Since constraints are small, Python works too.
I'll produce Python solution for simplicity.
But maybe the judge expects fast I/O? Not necessary.
Thus final.
Now, I'll produce a final response with explanation and code.
But I must also include a note about why this works.
Let's craft final.
Also note: In output, ensure no trailing spaces.
Implementation:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
it = iter(data)
T = int(next(it))
out_lines = []
for _ in range(T):
n = int(next(it))
a = [int(next(it)) for _ in range(n)]
b = [0]*n
for i in range(0, n, 2):
b[i] = a[i+1]
b[i+1] = -a[i]
out_lines.append(' '.join(map(str, b)))
sys.stdout.write('\n'.join(out_lines))
That's it.
But check if any issue: n even, so i+1 always valid.
Thus final answer.
But is there any possibility that b_i equals 0? No, because a_i are nonzero, so b_i are either a_j (non-zero) or -a_i (non-zero). So fine.
Thus answer.
Now, consider if a_i can be negative? Yes, then b_i may be negative, which is allowed.
Thus fine.
Now, write final response. We can construct a solution using a simple pairing approach. Since n is even, we can split the seals into pairs. For each pair (a_{2k-1}, a_{2k}), set b_{2k-1} = a_{2k} and b_{2k} = -a_{2k-1}. Then the contribution of this pair to the sum is a_{2k-1}·a_{2k} + a_{2k}·(-a_{2k-1}) = 0. Summing over all pairs gives zero.
All a_i are non‑zero and satisfy |a_i| ≤ 100, therefore all b_i are also non‑zero and |b_i| ≤ 100. This meets all requirements, and a solution always exists.
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
T = int(next(it))
out_lines = []
for _ in range(T):
n = int(next(it))
a = [int(next(it)) for _ in range(n)]
b = [0] * n
for i in range(0, n, 2):
b[i] = a[i + 1]
b[i + 1] = -a[i]
out_lines.append(' '.join(map(str, b)))
sys.stdout.write('\n'.join(out_lines))
if __name__ == "__main__":
solve()