There are $n$ participants in a competition, participant $i$ having a strength of $s_i$.

Every participant wonders how much of an advantage they have over the other best participant. In other words, each participant $i$ wants to know the difference between $s_i$ and $s_j$, where $j$ is the strongest participant in the competition, not counting $i$ (a difference can be negative).

So, they ask you for your help! For each $i$ ($1 \leq i \leq n$) output the difference between $s_i$ and the maximum strength of any participant other than participant $i$.


-----Input-----

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. The descriptions of the test cases follow.

The first line of each test case contains an integer $n$ ($2 \leq n \leq 2\cdot10^5$) — the length of the array.

The following line contains $n$ space-separated positive integers $s_1$, $s_2$, ..., $s_n$ ($1 \leq s_i \leq 10^9$) — the strengths of the participants.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$.


-----Output-----

For each test case, output $n$ space-separated integers. For each $i$ ($1 \leq i \leq n$) output the difference between $s_i$ and the maximum strength of any other participant.


-----Examples-----

Input
5
4
4 7 3 5
2
1 2
5
1 2 3 4 5
3
4 9 4
4
4 4 4 4
Output
-3 2 -4 -2 
-1 1 
-4 -3 -2 -1 1 
-5 5 -5 
0 0 0 0


-----Note-----

For the first test case:

The first participant has a strength of $4$ and the largest strength of a participant different from the first one is $7$, so the answer for the first participant is $4 - 7 = -3$.

The second participant has a strength of $7$ and the largest strength of a participant different from the second one is $5$, so the answer for the second participant is $7 - 5 = 2$.

The third participant has a strength of $3$ and the largest strength of a participant different from the third one is $7$, so the answer for the third participant is $3 - 7 = -4$.

The fourth participant has a strength of $5$ and the largest strength of a participant different from the fourth one is $7$, so the answer for the fourth participant is $5 - 7 = -2$.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Data structures

Implementation


Solutions:
t = int(input())
while t > 0:
	row_row = []
	a = input()
	row = list(map(int, input().split()))
	max_max = max(row)
	bb = row.index(max_max)
	for i in row:
		row_row.append(i - max_max)
	next_row = row
	next_row.pop(bb)
	next_max = max(next_row)
	if next_max == max_max:
		print(' '.join(map(str, row_row)))
	else:
		row_row[bb] = max_max - next_max
		print(' '.join(map(str, row_row)))
	t -= 1


def f():
	T = int(input())
	for _ in range(T):
		_ = input()
		nums = [int(c) for c in input().split()]
		solve(nums)

def solve(nums):
	(largest1, largest2) = firstAndSecondLargest(nums)
	res = []
	for x in nums:
		if x != largest1:
			res.append(x - largest1)
		else:
			res.append(x - largest2)
	print(' '.join([str(x) for x in res]))

def firstAndSecondLargest(nums):
	largest1 = -2 ** 32
	largest2 = -2 ** 32
	for x in nums:
		if x > largest1:
			largest2 = largest1
			largest1 = x
		elif largest2 < x:
			largest2 = x
	if largest2 == -2 ** 32:
		largest2 = largest1
	return (largest1, largest2)
f()


def solve():
	_ = int(input())
	l = list(map(int, input().split()))
	top = 0
	topi = -1
	top2 = 0
	for (i, el) in enumerate(l):
		if el >= top:
			top2 = top
			top = el
			topi = i
		elif el > top2:
			top2 = el
	ret = []
	for (i, el) in enumerate(l):
		if i != topi:
			ret.append(el - top)
		else:
			ret.append(el - top2)
	print(' '.join(map(str, ret)))
t = int(input())
for _ in range(t):
	solve()


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

def solve(a, n):
	m1 = max(a)
	m2 = 0
	if a.count(m1) > 1:
		m2 = m1
	else:
		for x in a:
			if x > m2 and x < m1:
				m2 = x
	b = [x - m1 if x < m1 else x - m2 for x in a]
	return ' '.join(map(str, b))
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(a, n))


for _ in range(int(input())):
	(t, l) = (input(), list(map(int, input().split(' '))))
	l2 = l.copy()
	m1 = max(l2)
	l2.remove(m1)
	m2 = max(l2)
	x = lambda a: str(a - m1) if a != m1 else str(a - m2)
	print(' '.join(list(map(x, l))))


import math

def solution():
	n = int(input())
	nums = [int(i) for i in input().split()]
	max1 = nums[0]
	max2 = -math.inf
	for num in nums[1:]:
		if num >= max1:
			max2 = max1
			max1 = num
		elif num > max2:
			max2 = num
	ans = []
	for num in nums:
		if num == max1:
			ans.append(str(num - max2))
		else:
			ans.append(str(num - max1))
	print(' '.join(ans))
t = int(input())
while t:
	solution()
	t -= 1


def get_res(s):
	max_s = max(s)
	max_s_index = s.index(max_s)
	res = [s[i] - max_s if i != max_s_index else -1000000000.0 - 2 for i in range(len(s))]
	res[max_s_index] = abs(max(res))
	return res

def main():
	t = int(input())
	data = []
	for i in range(t):
		elements_count = int(input())
		s = list(map(int, input().split()))
		data.append(s)
	for i in range(t):
		res = get_res(data[i])
		print(' '.join([str(r) for r in res]))
main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
test_cases = inp()
inp_arr = []
for i in range(test_cases):
	num = inp()
	nums = inlt()
	inp_arr.append(nums)

def findResult(nums):
	(m, s) = (0, 0)
	for num in nums:
		if num > m:
			s = m
			m = num
		elif num > s:
			s = num
	result = []
	for num in nums:
		if num == m:
			result.append(str(num - s))
		else:
			result.append(str(num - m))
	return ' '.join(result)
result = [findResult(cheeses) for cheeses in inp_arr]
for m in result:
	print(m)


def find_advantage(lst):
	highest_strength = -float('inf')
	second_highest_strength = -float('inf')
	for strength in lst:
		if strength > highest_strength:
			second_highest_strength = highest_strength
			highest_strength = strength
		elif strength > second_highest_strength:
			second_highest_strength = strength
	diffs = []
	for strength in lst:
		if strength != highest_strength:
			diffs.append(strength - highest_strength)
		else:
			diffs.append(strength - second_highest_strength)
	return diffs
t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	print(' '.join(map(str, find_advantage(lst))))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	c = [x - b[-1] for x in a]
	i = a.index(b[-1])
	c[i] = a[i] - b[-2]
	print(' '.join(map(str, c)))


def solve():
	a = int(input())
	b = input()
	b = b.split()
	l = []
	x = []
	for i in b:
		l.append(int(i))
	m = max(l)
	found = 0
	for i in range(0, a):
		if m == l[i]:
			if found == 0:
				c = l.copy()
				del c[i]
				n = max(c)
				j = l[i] - n
				x.append(str(j))
				found = 1
			else:
				j = l[i] - m
				x.append(str(j))
		else:
			j = l[i] - m
			x.append(str(j))
	x = ' '.join(x)
	return x
tc = int(input())
for i in range(0, tc):
	print(solve())


T = int(input(''))
for i in range(T):
	n = input('')
	str1 = input('')
	l1 = [int(c) for c in str1.split()]
	l2 = [c for c in l1]
	highest = max(l1)
	l2.remove(highest)
	second = max(l2)
	ans = []
	for element in l1:
		if element != highest:
			ans.append(element - highest)
		else:
			ans.append(element - second)
	finalAns = ' '.join((str(c) for c in ans))
	print(finalAns)


def getStrength(inputs):
	outputs = []
	inputs = list(map(lambda x: int(x), inputs))
	generalMax = max(inputs)
	temp = list(inputs)
	temp.pop(temp.index(generalMax))
	tempmax = max(temp)
	for i in range(len(inputs)):
		if inputs[i] != generalMax:
			outputs.append(str(inputs[i] - generalMax))
		else:
			outputs.append(str(inputs[i] - tempmax))
	return outputs
numberOfTestCases = int(input())
outputs = []
for i in range(numberOfTestCases):
	numberOfInputs = int(input())
	Inputs = input().split(' ')
	outputs.append(getStrength(Inputs))
for out in outputs:
	print(' '.join(out))


num_tests = int(input())
for test in range(num_tests):
	array_len = int(input())
	arr = [int(x) for x in input().split(' ')]
	sarr = sorted(arr)
	m1 = sarr[-1]
	m2 = sarr[-2]
	print(' '.join([str(i - m1) if i != m1 else str(m1 - m2) for i in arr]))


t = int(input())
for x in range(t):
	n = input()
	s = list(map(int, input().split()))
	maxi = max(s)
	c = s.copy()
	ind = s.index(maxi)
	c.pop(ind)
	maxim = max(c)
	pr = []
	for i in s:
		if i != maxi:
			pr.append(i - maxi)
		else:
			pr.append(i - maxim)
	if x != t - 1:
		print(' '.join((str(i) for i in pr)), end=' \n')
	else:
		print(' '.join((str(i) for i in pr)))
pass


testcases = int(input())
for i in range(testcases):
	n = int(input())
	input_l = input().split()
	strength_list = list(map(int, input_l))
	m = 1
	m2 = 1
	ind_m = 0
	for j in range(n):
		s = strength_list[j]
		if s > m:
			m2 = m
			m = s
			ind_m = j
		elif s > m2:
			m2 = s
	output = [x - m for x in strength_list]
	output[ind_m] = m - m2
	print(' '.join(map(str, output)))


t = int(input())
for i in range(t):
	n = int(input())
	jada = list(map(int, input().split()))
	maksimum = max(jada)
	new_list = []
	k = 0
	for j in jada:
		if j < maksimum:
			new_list.append(str(j - maksimum))
		elif j == k:
			new_list.append(str(maksimum - k))
		else:
			new_jada = list(jada)
			new_jada.remove(maksimum)
			k = max(new_jada)
			new_list.append(str(maksimum - k))
	print(' '.join(new_list))


for _ in (input() for _ in range(int(input()))):
	xs = list(map(int, input().split()))
	(*_, scd, fst) = sorted(xs)
	print(' '.join((str(x - fst if x != fst else x - scd) for x in xs)))


t = int(input())
for i in range(t):
	n = int(input())
	participants = list(map(int, input().split()))
	(m1, m2) = (0, 0)
	for j in range(n):
		if participants[j] > m1:
			m2 = m1
			m1 = participants[j]
		elif m2 <= participants[j] <= m1:
			m2 = participants[j]
	print(' '.join(map(str, [participants[j] - m2 if participants[j] == m1 else participants[j] - m1 for j in range(n)])))


import string
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
t = int(input())
for _ in range(t):
	n = int(input())
	S2 = list(map(int, input().split()))
	m = max(S2)
	S = S2[:]
	S2.remove(m)
	m2 = max(S2)
	r = []
	for i in range(n):
		v = S[i]
		if v != m:
			r.append(v - m)
		else:
			r.append(v - m2)
	print(' '.join(map(str, r)))


import math

def inp():
	return int(input())

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

def inchar():
	return list(input().split())

def insr():
	s = input()
	return list(s)

def invr():
	return map(int, input().split())
a = inp()
for _ in range(a):
	m = 0
	mm = 0
	kkkk = inp()
	s = inlt()
	for i in s:
		if i > m:
			mm = m
			m = i
		elif i > mm:
			mm = i
	for i in range(kkkk):
		if s[i] == m:
			s[i] -= mm
		else:
			s[i] -= m
	print(' '.join(map(str, s)))


for _ in range(int(input())):
	n = input()
	s = list(map(int, input().split()))
	(m2, m1) = sorted(s)[-2:]
	res = []
	for i in s:
		if i == m1:
			res.append(str(i - m2))
		else:
			res.append(str(i - m1))
	print(' '.join(res))


import itertools
import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def solve(arr):
	maximum = max(arr)
	d = [str(i - maximum) for i in arr]
	d[arr.index(maximum)] = str(maximum - sorted(arr)[-2])
	print(' '.join(d))
for i in range(inp()):
	length = invr()
	arr = inlt()
	solve(arr)


import sys

def main():
	t = sys.stdin.readline().split()
	t = int(t[0])
	lines = sys.stdin.readlines()
	for index in range(len(lines) // 2):
		line_0 = lines[2 * index]
		n = int(line_0)
		participants = list(map(int, lines[2 * index + 1].split(' ')))
		if participants[0] > participants[1]:
			(max_0, max_1) = (0, 1)
		else:
			(max_0, max_1) = (1, 0)
		for i in range(2, n):
			if participants[i] >= participants[max_0]:
				(max_0, max_1) = (i, max_0)
			elif participants[i] > participants[max_1]:
				max_1 = i
		res = [0] * n
		for i in range(n):
			if i != max_0:
				res[i] = participants[i] - participants[max_0]
			else:
				res[i] = participants[i] - participants[max_1]
		print(' '.join(list(map(str, res))))
main()


for tc in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	c = max(a)
	temp = a.copy()
	temp.pop(temp.index(c))
	max_temp = max(temp)
	for i in range(n):
		if a[i] != c:
			ans.append(a[i] - c)
		else:
			ans.append(c - max_temp)
	main_ans = ' '.join((str(i) for i in ans))
	print(main_ans)


tests = int(input())
for i in range(tests):
	length = int(input())
	participants = [int(x) for x in input().split(' ')]
	l = participants.copy()
	max1 = max(l)
	l.remove(max1)
	max2 = max(l)
	for i in range(len(participants)):
		if participants[i] != max1:
			participants[i] -= max1
		else:
			participants[i] -= max2
	diffs = ' '.join((str(x) for x in participants))
	print(diffs)


def req(s):
	b = sorted(s)
	(x, y) = (b[-1], b[-2])
	d = []
	for i in s:
		if i == x:
			d.append(i - y)
		else:
			d.append(i - x)
	return list(map(str, d))
t = int(input())
while t != 0:
	a = input()
	s = list(map(int, input().split()))
	r = req(s)
	print(' '.join(r))
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	nums = input().split()
	nums = list(map(int, nums))
	ins_li = []
	sort = sorted(nums)
	for i in nums:
		if i == sort[-1]:
			ins_li.append(i - sort[-2])
		else:
			ins_li.append(i - sort[-1])
	ins_li = list(map(str, ins_li))
	print(' '.join(ins_li))


t = int(input())

def solve(arr):
	sorted_ = sorted(arr)
	max_ = sorted_[-1]
	res = []
	for i in arr:
		if i == max_:
			res.append(i - sorted_[-2])
		else:
			res.append(i - max_)
	return ' '.join(list(map(str, res)))
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	print(solve(arr))


def solve(n, nums):
	sortedNums = sorted(nums)[::-1]
	maxNum = sortedNums[0]
	secNum = sortedNums[1]
	return ' '.join([str(i - maxNum) if i < maxNum else str(i - secNum) for i in nums])
T = int(input())
for t in range(T):
	n = int(input())
	nums = list(map(int, input().split()))
	print(solve(n, nums))


t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(i) for i in input().split()]
	m = [max(s[0], s[1]), min(s[0], s[1])]
	for i in range(2, n):
		if s[i] > m[0]:
			m = [s[i], m[0]]
		elif s[i] > m[1]:
			m[1] = s[i]
	print(' '.join([str(i - m[0]) if i - m[0] else str(i - m[1]) for i in s]))


for i in range(int(input())):
	s = int(input())
	q = list(map(int, input().split(' ')))
	w = sorted(q)
	spis = []
	for j in q:
		if j != w[-1]:
			spis.append(str(j - w[-1]))
		else:
			spis.append(str(j - w[-2]))
	print(' '.join(spis))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = max(a)
	if a.count(m) == 1:
		p = list(set(a))
		p.sort()
		x1 = p[-2]
		res = []
		for i in a:
			if i == m:
				res.append(i - x1)
			else:
				res.append(i - m)
		print(' '.join(map(str, res)))
	else:
		res = []
		for i in a:
			if i == m:
				res.append(0)
			else:
				res.append(i - m)
		print(' '.join(map(str, res)))


t = int(input())
for _ in range(t):
	res = []
	val = int(input())
	arr = list(map(int, input().split()))
	sarr = sorted(arr)
	mx = sarr[-1]
	smx = sarr[-2]
	j = -1
	for i in arr:
		if i != mx:
			res.append(str(i - mx))
		else:
			res.append(str(i - smx))
	print(' '.join(res))


def ans(n, s):
	t = sorted(s)
	d1 = t[n - 1]
	d2 = t[n - 2]
	i = 0
	while i < n:
		if s[i] == d1:
			s[i] = s[i] - d2
		else:
			s[i] = s[i] - d1
		i = i + 1
	return s
T = int(input())
r = []
for i in range(T):
	n = int(input())
	s = list(map(int, input().split()))
	c = ans(n, s)
	r.append(c)
for i in range(T):
	print(' '.join(map(str, r[i])))


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	mx = b[-2:]
	ans = []
	for c in a:
		if c == mx[1]:
			ans.append(c - mx[0])
		else:
			ans.append(c - mx[1])
	print(' '.join(map(str, ans)))


for i in range(int(input())):
	n = int(input())
	forces = list(map(int, input().split()))
	max_force = 0
	prev_max_force = 0
	ans = [0] * n
	for j in range(n):
		if forces[j] > max_force:
			prev_max_force = max_force
			max_force = forces[j]
		elif forces[j] > prev_max_force:
			prev_max_force = forces[j]
	for j in range(n):
		if forces[j] != max_force:
			ans[j] = forces[j] - max_force
		else:
			ans[j] = max_force - prev_max_force
	print(' '.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	kek = max(s)
	kekw = False
	anslist = []
	if s.count(kek) > 1:
		kekw = True
	for i in range(n):
		if s[i] < kek:
			anslist.append(s[i] - kek)
		elif kekw:
			anslist.append(0)
		else:
			anslist.append(kek - list(sorted(s))[-2])
	print(' '.join((str(i) for i in anslist)))


n = int(input())
for i in range(n):
	tmp = int(input())
	tmp_list = list(map(int, input().split()))
	num_list = [i for i in tmp_list]
	tmp_list.sort()
	two_big = tmp_list[len(tmp_list) - 2]
	big = tmp_list[len(tmp_list) - 1]
	dd = []
	for num in num_list:
		if num == big:
			dd.append(str(num - two_big))
		else:
			dd.append(str(num - big))
	print(' '.join(dd))
	dd = []


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = a.copy()
	k.sort()
	c = k[n - 1]
	m = k[n - 2]
	for i in range(n):
		if a[i] == c:
			a[i] = a[i] - m
		else:
			a[i] = a[i] - c
	print(' '.join(map(str, a)))


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	x = sorted(lst)
	y = []
	z = max(lst)
	for j in lst:
		if j == z:
			y.append(j - x[n - 2])
		else:
			y.append(j - z)
	print(' '.join(map(str, y)))


for _ in range(int(input())):
	n = int(input())
	x = []
	x = list(map(int, input().split()))
	y = []
	y = x[:]
	y.sort()
	n1 = y[n - 1]
	n2 = y[n - 2]
	for i in range(n):
		if x[i] == n1:
			x[i] = n1 - n2
		else:
			x[i] = x[i] - n1
	j = ' '.join([str(ele) for ele in x])
	print(j)


import math
t = int(input(''))
for i in range(t):
	n = int(input(''))
	s = [int(x) for x in input('').split(' ')]
	ss = [*s]
	ss.sort()
	m = ss[len(s) - 1]
	sm = ss[len(s) - 2]
	res = [0] * len(s)
	for (ind, v) in enumerate(s):
		if v == m:
			res[ind] = v - sm
		else:
			res[ind] = v - m
	print(' '.join([str(x) for x in res]))


t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(x) for x in input().split()]
	s_srt = sorted(s)
	dif = []
	for i in range(n):
		if s[i] == s_srt[-1]:
			dif.append(s[i] - s_srt[-2])
		else:
			dif.append(s[i] - s_srt[-1])
	print(' '.join([str(x) for x in dif]))


result = []
t = int(input())
for i in range(t):
	r = int(input())
	s_L = input().split(' ', -1)
	int_s_L = list(map(int, s_L))
	s_L_sorted = sorted(int_s_L)
	no1 = s_L_sorted[r - 1]
	no2 = s_L_sorted[r - 2]
	result_1 = []
	for j in s_L:
		if int(j) == no1:
			result_1.append(str(int(j) - no2))
		else:
			result_1.append(str(int(j) - no1))
	result.append(result_1)
for p in range(t):
	print(' '.join(result[p]))


t = int(input())
for i in range(t):
	n = int(input())
	L2 = list(map(int, input().split()))
	L2sort = sorted(L2)
	(max, max2) = (L2sort[-1], L2sort[-2])
	L1 = []
	for i in range(n):
		if L2[i] == max:
			L1.append(max - max2)
		else:
			L1.append(L2[i] - max)
	ans = ' '.join([str(elem) for elem in L1])
	print(ans)


import sys
from collections import *
sys.setrecursionlimit(10 ** 5)
itr = (line for line in sys.stdin.read().strip().split('\n'))
INP = lambda : next(itr)

def ni():
	return int(INP())

def nl():
	return [int(_) for _ in INP().split()]

def solve(n, a):
	pass
t = ni()
for case in range(t):
	n = ni()
	a = nl()
	comp = a[:]
	comp.sort()
	out = []
	for s in a:
		if s != comp[-1]:
			out.append(s - comp[-1])
		else:
			out.append(s - comp[-2])
	print(' '.join(map(str, out)))


h = int(input())
for i in range(h):
	p = int(input())
	l = list(map(int, input().split()))
	t = l.copy()
	t.sort()
	m = t[p - 1]
	m2 = t[p - 2]
	for j in range(p):
		if l[j] == m:
			l[j] = l[j] - m2
		else:
			l[j] = l[j] - m
	print(' '.join([str(elem) for elem in l]))


total = int(input())
list1 = []
for i in range(total):
	n = int(input())
	members = list(map(int, input().split()))
	maximum = max(members)
	maxindex = members.index(maximum)
	members.pop(maxindex)
	maximum2 = max(members)
	members = list(map(lambda x: x - maximum, members))
	maximum = maximum - maximum2
	members.insert(maxindex, maximum)
	list1.append(members)
for i in range(len(list1)):
	print(*list1[i])


t = int(input())
max = 0
max2 = 0
count = 0
for i in range(t):
	n = int(input())
	s = list(map(int, input().strip().split()))
	s1 = []
	for i in range(n):
		if s[i] > max:
			max = s[i]
	for i in range(n):
		if s[i] == max:
			continue
		elif s[i] > max2:
			max2 = s[i]
	for i in range(n):
		if s[i] == max:
			count += 1
	if count > 1:
		max2 = max
	if max2 == 0:
		max2 = max
	for i in range(n):
		if s[i] == max:
			s1.append(s[i] - max2)
		else:
			s1.append(s[i] - max)
	print(' '.join((str(z) for z in s1)))
	count = 0
	max = 0
	max2 = 0


from copy import deepcopy
n = int(input())
for i in range(n):
	input()
	strengths = list(map(int, input().split()))
	strengths_copy = deepcopy(strengths)
	max_strength = max(strengths)
	strengths_copy.remove(max_strength)
	second_max = max(strengths_copy)
	ans = []
	for strength in strengths:
		if strength != max_strength:
			ans.append(str(strength - max_strength))
		else:
			ans.append(str(strength - second_max))
	print(' '.join(ans))


def main():
	n = int(input())
	for i in range(n):
		input()
		a = [int(x) for x in input().split()]
		b = a.copy()
		mx = max(a)
		b.remove(mx)
		mx1 = max(b)
		print(*[i - mx if mx != i else mx - mx1 for i in a])
main()


for i in range(int(input())):
	n = int(input())
	mass = list(map(int, input().split()))
	maximum = max(mass)
	ind = mass.index(maximum)
	otv = []
	for i in range(ind):
		otv.append(mass[i] - maximum)
	mass.pop(ind)
	otv.append(maximum - max(mass))
	for i in mass[ind:]:
		otv.append(i - maximum)
	print(*otv)


for i in range(int(input())):
	ans = []
	(s, mas) = (int(input()), list(map(int, input().split())))
	ind = mas.index(max(mas))
	b = mas.pop(ind)
	for j in mas:
		ans.append(j - b)
	ans = ans[:ind] + [b - max(mas)] + ans[ind:]
	print(*ans)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = list(map(int, input().split()))
		max_power = max(s[0], s[1])
		second_max_power = min(s[0], s[1])
		for i in range(2, n):
			if s[i] > max_power:
				(max_power, second_max_power) = (s[i], max_power)
			elif s[i] > second_max_power:
				second_max_power = s[i]
		for i in range(n):
			if max_power != s[i]:
				s[i] -= max_power
			else:
				s[i] -= second_max_power
		print(*s)
main()


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	x = int(input())
	n = list(map(int, input().split()))
	m = max(n)
	s = m
	f = n.index(m)
	n.remove(m)
	l = []
	for i in range(x - 1):
		l.append(n[i] - m)
	m = max(n)
	l.insert(f, s - m)
	print(*l)


tests = int(input())
for _ in range(tests):
	first_max = second_max = 0
	n = int(input())
	arr = list(map(int, input().split()))
	for num in arr:
		if num > first_max:
			second_max = first_max
			first_max = num
		elif num > second_max:
			second_max = num
	print(*[x - first_max if x != first_max else x - second_max for x in arr])


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	q = int(input())
	l = list(map(int, input().split()))
	m = max(l)
	var = m
	inde = l.index(m)
	l.remove(m)
	li = []
	for i in range(q - 1):
		li.append(l[i] - m)
	m = max(l)
	li.insert(inde, var - m)
	print(*li)


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = max(l)
	x = m
	y = l.index(m)
	l.remove(m)
	zz = []
	for i in range(n - 1):
		zz.append(l[i] - m)
	mx = max(l)
	zz.insert(y, x - mx)
	print(*zz)


def solve():
	(mx, s_mx) = (0, 0)
	n = int(input())
	l = list(map(int, input().split()))
	for num in l:
		if num >= mx:
			(mx, s_mx) = (num, mx)
		elif num >= s_mx:
			s_mx = num
	for num in l:
		if num == mx:
			print(num - s_mx, end=' ')
		else:
			print(num - mx, end=' ')
	print()
t = int(input())
for _ in range(t):
	solve()


n = int(input())
for i in range(n):
	tamanho = int(input())
	lista = []
	lista.append(input().split())
	maior = 0
	segundo = 0
	indice = 0
	respostas = []
	for j in range(tamanho):
		if int(lista[0][j]) > maior:
			segundo = maior
			maior = int(lista[0][j])
			indice = j
		elif int(lista[0][j]) > segundo:
			segundo = int(lista[0][j])
	for k in range(tamanho):
		if k != indice:
			respostas.append(str(int(lista[0][k]) - maior))
		else:
			respostas.append(str(int(lista[0][k]) - segundo))
	print(' '.join(respostas))


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

def task():
	n = int(input())
	a = read()
	best = max(a)
	best_i = a.index(best)
	next_best = max(a[0:best_i] + a[best_i + 1:])
	for i in range(n):
		if i == best_i:
			print(-next_best + a[i], end=' ')
			continue
		print(-best + a[i], end=' ')
	print()
t = int(input())
for i in range(t):
	task()


n = int(input())
for i in range(n):
	arr = int(input())
	l = list(map(int, input().split()))
	ll = l.copy()
	maxx = max(l)
	l.remove(maxx)
	second = max(l)
	for i in ll:
		if i == maxx:
			print(maxx - second, end=' ')
		else:
			print(i - maxx, end=' ')
	print()


w = int(input())
for roma in range(w):
	a = int(input())
	q = list(map(int, input().split()))
	mx = max(q)
	q[q.index(mx)] = 0
	mx2 = max(q)
	q[q.index(0)] = mx
	for i in q:
		if i != mx:
			print(i - mx, end=' ')
		else:
			print(mx - mx2, end=' ')
	print()


def solve():
	n = int(input())
	s = list(map(int, input().split()))
	(mx2, mx1) = sorted(s)[-2:]
	print(*[i - mx1 if i != mx1 else mx1 - mx2 for i in s])
for _ in range(int(input())):
	solve()


import math
import sys
for i in range(int(input())):
	x = int(input())
	a = list(map(int, input().split()))
	b = a
	arr = []
	f = max(a)
	p = a.index(f)
	b.remove(f)
	s = max(b)
	b.insert(p, f)
	for i in range(x):
		if a[i] != f:
			arr.append(a[i] - f)
		else:
			arr.append(a[i] - s)
	print(*arr)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	maximum = max(arr)
	max_ind = arr.index(maximum)
	arr[max_ind] = -arr[max_ind]
	second_max = max(arr)
	for i in range(n):
		if i != max_ind:
			arr[i] = arr[i] - maximum
		else:
			arr[i] = maximum - second_max
	print(*arr)


import math
for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	max1 = nums[0]
	max2 = -math.inf
	for num in nums[1:]:
		if num >= max1:
			max2 = max1
			max1 = num
		elif num > max2:
			max2 = num
	ans = []
	for num in nums:
		if num == max1:
			ans.append(num - max2)
		else:
			ans.append(num - max1)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	if len(s) == 1:
		l = ['0'] * n
		print(*l)
	else:
		m = max(s)
		if l.count(m) > 1:
			m1 = m
		else:
			s.remove(m)
			m1 = max(s)
		lst = []
		for i in l:
			if i == m:
				lst.append(m - m1)
			else:
				lst.append(i - m)
		print(*lst)


def main(s):
	(first, second) = (-1, -1)
	for ss in s:
		if ss >= first:
			second = first
			first = ss
		elif ss >= second:
			second = ss
	for x in s:
		if x == first:
			print(x - second, end=' ')
		else:
			print(x - first, end=' ')
	print()
t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	main(s)


t = int(input())
for i in range(t):
	l = []
	n = int(input())
	s = list(map(int, input().split()))
	a = max(s)
	for j in s:
		l.append(j - a)
	q = l.index(max(l))
	l.remove(max(l))
	l.insert(q, -1 * max(l))
	print(*l)


ans = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans.clear()
	x = max(a)
	same = 0
	for i in a:
		if i == x:
			same += 1
			ans.append(-1000000001)
		else:
			ans.append(i - x)
	if same == n:
		for i in range(n):
			print(0, end=' ')
		print()
	elif same == 1:
		y = max(ans)
		for i in range(n):
			if ans[i] == -1000000001:
				ans[i] = -y
				break
		print(*ans)
	else:
		for i in range(n):
			if ans[i] == -1000000001:
				ans[i] = 0
		print(*ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	if n == 2:
		print(l[0] - l[1], end=' ')
		print(l[1] - l[0])
	else:
		k = l[:]
		max1 = max(k)
		k.remove(max1)
		max2 = max(k)
		for i in l:
			if i == max1:
				print(i - max2, end=' ')
			else:
				print(i - max1, end=' ')
		print()


def solve(n, l):
	max_1 = max(l[0], l[1])
	max_2 = min(l[0], l[1])
	for i in range(2, n):
		if l[i] > max_1:
			max_2 = max_1
			max_1 = l[i]
		elif l[i] > max_2:
			max_2 = l[i]
	for i in l:
		if i == max_1:
			print(i - max_2, end=' ')
		else:
			print(i - max_1, end=' ')
	print()
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	solve(n, l)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	max1 = max(a)
	max2 = max(a[:a.index(max1)] + a[a.index(max1) + 1:])
	for j in a:
		if j != max1:
			b.append(j - max1)
		else:
			b.append(j - max2)
	print(*b)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = a.copy()
	m = max(l)
	l.remove(m)
	m2 = max(l)
	for i in range(n):
		if a[i] == m:
			a[i] = a[i] - m2
		else:
			a[i] = a[i] - m
	print(*a)


import sys

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		n = int(sys.stdin.readline())
		arr = list(map(int, sys.stdin.readline().split()))
		(mx_1, mx_2) = (0, 0)
		(mx1, mx2) = (0, 0)
		for i in range(n):
			if arr[i] > mx_1:
				mx_2 = mx_1
				mx_1 = arr[i]
				mx2 = mx1
				mx1 = i
			elif arr[i] > mx_2:
				mx_2 = arr[i]
				mx2 = i
		ans = [0] * n
		for i in range(n):
			if i == mx1:
				ans[i] = arr[i] - arr[mx2]
			else:
				ans[i] = arr[i] - arr[mx1]
		print(*ans)
main()


t = int(input())
for i in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	mx = max(d)
	j = d.index(max(d))
	d1 = d.copy()
	d.remove(mx)
	mx1 = max(d)
	for k in range(n):
		if k != j:
			d1[k] = d1[k] - mx
		else:
			d1[k] = mx - mx1
	print(*d1)


n = int(input())
while n != 0:
	size = int(input())
	p_list = [int(i) for i in input().split()]
	maxi = max(p_list)
	indexi = p_list.index(maxi)
	p_list.remove(maxi)
	diff = maxi - max(p_list)
	for i in range(len(p_list)):
		p_list[i] -= maxi
	p_list.insert(indexi, diff)
	print(*p_list)
	n -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	maxi = max(l)
	k = l.index(maxi)
	l.remove(maxi)
	for i in range(len(l)):
		l[i] = l[i] - maxi
	if len(l) > 1:
		l.insert(k, abs(max(l)))
	else:
		l.insert(k, abs(l[0]))
	print(*l)


def whomax(val):
	sub = []
	val_int = [int(i) for i in val]
	val_int_copy = val_int.copy()
	var = max(val_int)
	val_int_copy.remove(var)
	var_2 = max(val_int_copy)
	for i in val_int:
		if i != var:
			sub.append(i - var)
		else:
			sub.append(i - var_2)
	return sub
test_size = int(input())
final = []
for i in range(test_size):
	size = input()
	temp = input().split()
	final.append(whomax(temp))
for i in final:
	print(*i)


n = int(input())
for i in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	l1 = list(l)
	j = max(l)
	l1.remove(j)
	k = max(l1)
	w = [0] * m
	for i in range(len(l)):
		if l[i] == j:
			w[i] = l[i] - k
		else:
			w[i] = l[i] - j
	print(*w, sep=' ')


def inv_test(l):
	mx = 0
	mx2 = 0
	imx = -1
	imx2 = -1
	for i in range(len(l)):
		if l[i] >= mx:
			mx2 = mx
			imx2 = imx
			mx = l[i]
			imx = i
		elif l[i] >= mx2:
			mx2 = l[i]
			imx2 = i
	for i in range(len(l)):
		if i != imx:
			l[i] -= mx
		else:
			l[i] -= mx2
t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(x) for x in input().split()]
	inv_test(s)
	print(*s)


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	if len(set(x)) == 1:
		z = []
		for i in range(n):
			z.append(0)
		print(*z)
	else:
		z = max(x)
		a = []
		for j in range(n):
			a.append(x[j] - z)
		for j in range(n):
			if a[j] == 0:
				x.pop(j)
				a[j] = z - max(x)
				break
		print(*a)


def secondlargest(arr):
	m = max(arr)
	sm = 0
	for j in range(n):
		if a[j] > sm and a[j] < m:
			sm = a[j]
	return sm
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(sep=' ')))
	m = max(a)
	if a.count(m) > 1:
		sm = m
	else:
		sm = secondlargest(a)
	for j in range(n - 1):
		if a[j] != m:
			print(a[j] - m, end=' ')
		else:
			print(a[j] - sm, end=' ')
	if a[n - 1] == m:
		print(a[n - 1] - sm)
	else:
		print(a[n - 1] - m)


import sys
input = sys.stdin.readline

def solution():
	T = int(input())
	for t in range(T):
		N = int(input())
		num = list(map(int, input().split()))
		(first, second) = (0, 0)
		for i in num:
			if i >= first:
				second = first
				first = i
			elif i >= second:
				second = i
		for i in range(N):
			if num[i] == first:
				num[i] -= second
			else:
				num[i] -= first
		for i in num:
			print(i, end=' ')
		print()
solution()


def solve(n, arr):
	res = [None] * n
	s = sorted(arr)
	for (i, num) in enumerate(arr):
		if num == s[-1]:
			res[i] = num - s[-2]
		else:
			res[i] = num - s[-1]
	return res
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(*solve(n, arr))


t = int(input())
for i in range(t):
	a = int(input())
	arr = list(map(int, input().split()))
	n = max(arr)
	s = sorted(arr)[::-1]
	d = []
	for j in arr:
		if j == n:
			d.append(j - s[1])
		else:
			d.append(j - n)
	print(*d)


t = int(input())
for i in range(0, t):
	n = int(input())
	s = list(map(int, input().split()))
	temp = s.copy()
	a = max(temp)
	temp.remove(a)
	b = max(temp)
	for i in range(0, n):
		if s[i] == a:
			print(a - b, end=' ')
		else:
			print(s[i] - a, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	sil_max = max(s)
	silac = s.index(sil_max)
	for i in range(n):
		if i == silac:
			print(sil_max - max(s[0:silac] + s[silac + 1:]), end=' ')
		else:
			print(s[i] - sil_max, end=' ')
	print()