Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well.

Dr. Chef is treating COVID-19 patients. There is a queue of $N$ patients (numbered from patient $1$ at the front of the queue to patient $N$ at the back) outside his clinic. You, his assistant, found out that for each valid $i$, the $i$-th patient has an *illness level* $A_{i}$.

Chef treats patients based on their health, i.e. a patient with a higher illness level is always treated before any patients with a lower illness level. Chef is also fair, so he treats patients with an equal illness level based on their position in the queue, i.e. a patient ahead in the queue is always treated before a patient with the same illness level that is further behind in the queue.

The first patient to be treated has to wait an hour for Chef to set up his equipment. Treating each patient also takes an hour, and Chef always starts treating the next patient as soon as he is done with the current one.

The patients are a bit impatient. As Chef's assistant, for each patient, find out how long (in hours) this patient needs to wait before Chef starts treating this patient.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.

------  Output ------
For each test case, print a single line containing $N$ space-separated integers. For each valid $i$, the $i$-th of these integers should be the time the $i$-th patient needs to wait.

------  Constraints ------
$1 ≤ T ≤ 5$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ 1,000$ for each valid $i$

----- Sample Input 1 ------ 
4
5
2 3 5 3 4
3
2 2 2
6
2 10 3 3 2 10
4
8 9 8 9
----- Sample Output 1 ------ 
5 3 1 4 2
1 2 3
5 1 3 4 6 2
3 1 4 2
----- explanation 1 ------ 
Example case 1: Patient number $3$ has the highest illness level. Therefore, this patient just waits an hour for Chef to set up his equipment and gets treated immediately after. Patient number $5$ has the next highest illness level, so they go next. They need to wait an hour for patient $3$ to be treated. In total, patient $5$ has to wait $2$ hours. After that, both patients $2$ and $4$ have an equal illness level, but patient $2$ is ahead in the queue, so patient $2$ goes next, followed by patient $4$, and then finally patient $1$.

Example case 2: All three patients have the same illness level, so they are treated according to their position in the queue. Patient $1$ goes first, followed by patient $2$, and then patient $3$.

Example case 3: Patients at positions $2$ and $6$ in the queue have the highest illness level $10$. The patient at position $2$ is ahead in the queue, so this patient is treated first, and then the patient at position $6$ is treated. After this, the patients at positions $3$ and $4$ in the queue have the next highest illness level, so the patient at position $3$ is treated next, followed by the patient at position $4$. Similarly, afterwards, the patient at position $1$ is treated, and then the patient at position $5$ is treated.

Example case 4: Patients at positions $2$ and $4$ in the queue have the highest illness level $9$, so the patient at position $2$ is treated first, followed by the patient at position $4$, then the patient at position $1$ and finally the patient at position $3$.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Implementation


Solutions:
from collections import deque
from collections import defaultdict
for _ in range(int(input())):
	queue = deque()
	maxsick = 0
	n = int(input())
	sickness = list(map(int, input().split()))
	A = [[] for _ in range(1000)]
	for i in range(n):
		A[1000 - sickness[i]] += [i]
	ans = [0] * n
	t = 1
	for i in range(len(A)):
		for j in A[i]:
			ans[j] = t
			t += 1
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	patients = []
	for i in range(n):
		patients.append((a[i], n - i))
	patients.sort(reverse=True)
	wait = [0 for i in range(n)]
	for j in range(n):
		p = patients[j]
		wait[n - p[1]] = j + 1
	print(*wait)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	d = dict()
	arr = ar.copy()
	arr.sort(reverse=True)
	l = []
	for i in range(n):
		l.append([arr[i], i + 1])
	for i in l:
		if i[0] in d:
			d[i[0]].append(i[1])
		else:
			d[i[0]] = [i[1]]
	for i in ar:
		print(d[i].pop(0), end=' ')
	print()


import sys
from collections import Counter, defaultdict, deque
from math import gcd, sqrt, ceil

def li():
	return [int(i) for i in sys.stdin.readline().split()]

def si():
	return sys.stdin.readline().split()

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

def ip():
	return input()
for tastcas in range(int(input())):
	n = ii()
	a = li()
	ans = [0] * n
	l = []
	for j in range(n):
		l.append([-a[j], j])
	l.sort()
	curr = 1
	for j in l:
		ans[j[1]] = curr
		curr += 1
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0] * n
	l = []
	for j in range(n):
		l.append([-a[j], j])
	l.sort()
	cur = 1
	for j in l:
		ans[j[1]] = cur
		cur += 1
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = map(int, input().split())
	l = [[] for i in range(1001)]
	for (j, v) in enumerate(a):
		l[v].append(j)
	w = 1
	ans = [0] * n
	for k in range(1000, 0, -1):
		for z in l[k]:
			ans[z] = w
			w += 1
	for x in ans:
		print(x, end=' ')
	print()


T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	illness = [[] for i in range(1001)]
	for (i, val) in enumerate(A):
		illness[val].append(i)
	waiting_time = 1
	ans = [0] * N
	for i in range(1000, 0, -1):
		for patient in illness[i]:
			ans[patient] = waiting_time
			waiting_time += 1
	for i in ans:
		print(i, end=' ')
	print()


for t in range(int(input())):
	n = int(input())
	patient = [int(i) for i in input().split()]
	p = []
	for i in range(n):
		p.append([i, patient[i]])
	p1 = sorted(p, key=lambda x: x[1], reverse=True)
	ill = []
	for i in range(n):
		ill.append([p1[i][0], p1[i][1], i + 1])
	new = sorted(ill, key=lambda x: x[0])
	for i in new:
		print(i[2], end=' ')
	print()


from collections import defaultdict

def main():
	try:
		numtest = int(input())
		for test in range(numtest):
			N = int(input())
			inputValue = list(map(int, input().split()))
			sol = resolve(inputValue)
			print(*sol)
	except EOFError:
		return

def resolve(sequence: list):
	n = len(sequence)
	sol: list = [0] * n
	dic: dict[int, list] = defaultdict(list)
	for i in range(n):
		dic[sequence[i]].append(i)
	sequence.sort()
	for elem in sequence:
		sol[dic[elem].pop()] = n
		n -= 1
	return sol
main()


t = int(input())
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	c = 0
	temp = []
	for i in lis:
		temp.append([i, c])
		c += 1
	temp.sort(key=lambda x: x[0], reverse=True)
	res = [0] * n
	k = 1
	for z in temp:
		res[z[1]] = k
		k += 1
	for obj in res:
		print(obj, end=' ')
	print()


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	h = defaultdict(list)
	for (i, e) in enumerate(a):
		h[e].append(i)
	t = 1
	for e in sorted(h.keys(), reverse=True):
		for v in h[e]:
			a[v] = t
			t += 1
	for i in a:
		print(i, end=' ')
	print()


from collections import defaultdict
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	dic = defaultdict(list)
	for i in range(n):
		dic[arr[i]].append(i)
	arr.sort()
	res = [0] * n
	for i in arr:
		res[dic[i].pop()] = n
		n -= 1
	print(*res)


import numpy as np
T = int(input())
for i in range(T):
	n = int(input())
	l = np.array(list(map(int, input().split())))
	nu = list(range(0, n))
	nu.sort(key=lambda x: l[x], reverse=True)
	nu = np.array(nu)
	ans = np.copy(l)
	for _ in range(n):
		ans[nu[_]] = _ + 1
	for _ in ans:
		print(_, end=' ')
	print()


for t in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	l = sorted(A, reverse=True)
	h = {}
	for i in range(len(l)):
		if not l[i] in h:
			h[l[i]] = i + 1
	for i in A:
		print(h[i], end=' ')
		h[i] = h[i] + 1
	print()


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	time = len(l)
	sl = sorted(l)
	for i in sl:
		d[i] = time
		time -= 1
	for i in l:
		print(d[i], end=' ')
		d[i] += 1
	print()


for oo in range(int(input())):
	x = int(input())
	line = [int(i) for i in input().split()]
	line_copy = sorted(line, reverse=True)
	data = {}
	for i in range(x):
		if line_copy[i] not in data:
			data[line_copy[i]] = i + 1
	for i in range(x):
		time = data[line[i]]
		data[line[i]] += 1
		line[i] = time
	print(*line, sep=' ')


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	r = []
	for i in l:
		r.append(i)
	d = {}
	for i in l:
		d[i] = 0
	l.sort()
	k = n
	for i in l:
		if d[i] == 0:
			d[i] = k
		k -= 1
	r.reverse()
	ans = []
	for i in r:
		ans.append(d[i])
		d[i] -= 1
	ans.reverse()
	print(*ans)
	t -= 1


tests = int(input())
while tests:
	N = int(input())
	arr = input().split(' ')
	dic = {}
	for i in arr:
		try:
			dic[int(i)] += 1
		except:
			dic[int(i)] = 1
	wait = 1
	for i in sorted(dic.keys(), reverse=True):
		temp = dic[i]
		dic[i] = wait
		wait += temp
	for i in arr:
		print(dic[int(i)], end=' ')
		dic[int(i)] += 1
	else:
		print('')
	tests -= 1


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dic = defaultdict(list)
	pat = sorted(a, reverse=True)
	for i in range(n):
		dic[pat[i]].append(i + 1)
	res = []
	for i in range(n):
		res.append(dic[a[i]][0])
		dic[a[i]].pop(0)
	print(*res)


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	h = {}
	for i in range(n):
		if a[i] not in h:
			h[a[i]] = [i]
		else:
			h[a[i]].append(i)
	a.sort(reverse=True)
	s = 0
	ans = [-1] * n
	v = set()
	for i in a:
		if i in v:
			continue
		v.add(i)
		for j in h[i]:
			s += 1
			ans[j] = s
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	k = l.copy()
	l.sort(reverse=True)
	d = {}
	c = 0
	for i in range(n):
		c += 1
		if l[i] in d:
			d[l[i]] += [c]
		else:
			d[l[i]] = [c]
	for i in range(n):
		print(d[k[i]][0], end=' ')
		d[k[i]].pop(0)
	print()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = [0] * n
	dic = {}
	for i in range(n):
		if arr[i] not in dic:
			dic[arr[i]] = [i]
		else:
			dic[arr[i]].append(i)
	crr = sorted(dic)
	crr.reverse()
	count = 1
	for i in crr:
		for j in dic[i]:
			brr[j] = count
			count += 1
	for k in range(n):
		print(brr[k], end=' ')
	print()


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a1 = input().split()
	a = {}
	for i in range(0, n):
		a[i] = int(a1[i])
	s = dict(sorted(a.items(), key=lambda x: x[1], reverse=True))
	b = [0] * n
	k = 1
	for i in list(s.keys()):
		b[i] = k
		k = k + 1
	print(*b)


for _ in range(int(input())):
	n = int(input())
	l = list(enumerate(map(int, input().split())))
	x = sorted(l, key=lambda x: x[1], reverse=True)
	ans = [0 for _ in range(n)]
	for i in range(n):
		ans[x[i][0]] = i + 1
	print(*ans)


try:
	t = int(input())
	for x in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		brr = [0] * n
		dic = {}
		for i in range(n):
			if arr[i] not in dic:
				dic[arr[i]] = [i]
			else:
				dic[arr[i]].append(i)
		crr = sorted(dic)
		crr.reverse()
		count = 1
		for i in crr:
			for j in dic[i]:
				brr[j] = count
				count += 1
		for k in range(n):
			print(brr[k], end=' ')
		print()
except:
	pass


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	x = []
	res = []
	for i in range(n):
		res.append(0)
	for i in range(1, n + 1):
		x.append(i)
	y = zip(x, l)
	y = list(sorted(y, reverse=True, key=lambda y: y[1]))
	p = []
	for i in y:
		p.append(list(i))
	c = 1
	for i in range(n):
		z = p[i]
		res[z[0] - 1] = c
		c += 1
	print(*res)
	t -= 1


t = int(input())
while t != 0:
	n = int(input())
	l = list(map(int, input().split()))
	k = []
	c = 0
	for j in l:
		k.append((j, c))
		c -= 1
	k.sort(reverse=True)
	ans = [0] * n
	p = 1
	for j in range(n):
		ans[-k[j][1]] = p
		p += 1
	print(*ans)
	t = t - 1


import sys

def s_func(k):
	return k[0]
T = int(sys.stdin.readline().rstrip())
for _ in range(T):
	N = int(sys.stdin.readline().rstrip())
	arr = sys.stdin.readline().rstrip().split()
	arr_ind = [(int(arr[i]), i) for i in range(N)]
	arr_ind.sort(reverse=True, key=s_func)
	for i in range(N):
		arr[arr_ind[i][1]] = str(i + 1)
	print(' '.join(arr))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = {}
	pos = {}
	b = list(a)
	b.sort(reverse=True)
	for i in range(0, n):
		pos[b[i]] = i + 1
		if b[i] not in count.keys():
			count[b[i]] = 1
		else:
			count[b[i]] += 1
	for i in range(n):
		if count[a[i]] != 0:
			print(pos[a[i]] - count[a[i]] + 1, end=' ')
			count[a[i]] -= 1
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dic = {}
	m = sorted(a, reverse=True)
	c = 0
	for i in m:
		if i in dic:
			dic[i].append(c + 1)
			c += 1
		else:
			dic[i] = []
			dic[i].append(c + 1)
			c += 1
	for i in a:
		s = dic[i].pop(0)
		print(s, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	k = [0] * n
	r = sorted(list(set(a)), reverse=True)
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = [i]
		else:
			d[a[i]].append(i)
	cnt = 1
	for i in r:
		for j in d[i]:
			k[j] = cnt
			cnt += 1
	print(' '.join(map(str, k)))


import sys
import math
try:
	t = int(input())
	for x in range(t):
		n = int(input())
		arr = [int(x) for x in input().split()]
		dic = {}
		for i in range(len(arr)):
			if arr[i] in dic:
				dic[arr[i]] += [i]
			else:
				dic[arr[i]] = [i]
		wait = 1
		for k in sorted(dic.keys(), reverse=True):
			for i in dic[k]:
				arr[i] = wait
				wait += 1
		print(*arr)
except:
	pass


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l = list(enumerate(l))
	l = sorted(l, key=lambda x: x[1], reverse=True)
	l2 = [0] * len(l)
	rank = 1
	for i in l:
		l2[i[0]] = rank
		rank += 1
	print(*l2)


t = int(input())
while t:
	n = int(input())
	pat = list(map(int, input().split()))
	posArray = {}
	for i in range(len(pat)):
		posArray[pat[i]] = []
	for i in range(len(pat)):
		posArray[pat[i]].append(i)
	pat.sort(reverse=True)
	res = [0] * n
	timer = 1
	for i in range(n):
		res[posArray[pat[i]][0]] = timer
		del posArray[pat[i]][0]
		timer += 1
	for i in range(len(res)):
		print(res[i], end=' ')
	print(' ')
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	line = list(map(int, input().split()))
	line_copy = sorted(line, reverse=True)
	data = {}
	for i in range(n):
		if line_copy[i] not in data:
			data[line_copy[i]] = i + 1
	for i in range(n):
		time = data[line[i]]
		data[line[i]] += 1
		line[i] = time
	print(*line, sep=' ')


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

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

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

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

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = inp()
	l = li()
	x = list(set(l))
	x.sort(reverse=True)
	p = Counter(l)
	d = {}
	d[x[0]] = 1
	for i in range(1, len(x)):
		d[x[i]] = p[x[i - 1]] + 1
		p[x[i]] += p[x[i - 1]]
	for i in l:
		prl(d[i])
		d[i] += 1
	print()
for _ in range(inp()):
	solve()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
for _ in range(int(input())):
	(n,) = inp()
	a = inp()
	arr = []
	for i in range(n):
		arr.append([a[i], i])
	arr.sort(key=lambda x: (-x[0], x[1]))
	res = [0] * n
	time = 1
	for (val, ind) in arr:
		res[ind] = time
		time += 1
	print(*res)


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


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		n = int(input())
		out = [0] * n
		l = list(map(int, input().split()))
		l1 = list(enumerate(l))
		l2 = sorted(l1, key=lambda a: a[1], reverse=True)
		for i in range(n):
			out[l2[i][0]] = i + 1
		for j in out:
			print(j, end=' ')
		print()
main()


for i in range(int(input())):
	p = int(input())
	a = list(map(int, input().strip().split()))
	b = a.copy()
	a.sort(reverse=True)
	d = {}
	for i in range(1000):
		d[i + 1] = []
	for i in range(len(a)):
		d[a[i]].append(i + 1)
	for i in b:
		print(d[i].pop(0), end=' ')
	print()


import sys
from collections import *
import math
import bisect

def input():
	return sys.stdin.readline()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dic = defaultdict(list)
	for i in range(n):
		dic[a[i]].append(i)
	cnt = 1
	ind = [0 for _ in range(n)]
	ll = sorted(list(dic.keys()), reverse=True)
	for i in ll:
		for j in dic[i]:
			ind[j] = cnt
			cnt += 1
	print(*ind)


t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	reqli = sorted(li, reverse=True)
	c = 1
	freq = {}
	for i in reqli:
		if i in freq:
			freq[i].append(c)
		else:
			freq[i] = [c]
		c = c + 1
	ans = []
	for i in li:
		ans.append(freq[i][0])
		freq[i].remove(freq[i][0])
	for i in ans[:len(ans) - 1]:
		print(i, end=' ')
	print(ans[-1])


t = int(input())
results = []
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [[x, a[x]] for x in range(n)]
	b.sort(key=lambda x: x[1], reverse=True)
	T = [None] * n
	for i in range(n):
		T[b[i][0]] = i + 1
	results.append([n, T])
for i in range(t):
	for j in range(results[i][0]):
		print(results[i][1][j], end=' ')
	print('')


t = int(input())
for _ in range(t):
	n = int(input())
	ai = list(map(int, input().split()))
	N = max(ai)
	a = [0] * 1002
	b = [0] * 1002
	for i in ai:
		a[i] += 1
	for j in range(N, -1, -1):
		b[j] = a[j] + b[j + 1]
	for i in ai:
		print(b[i] - a[i] + 1, end=' ')
		a[i] -= 1
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	size = len(a)
	d = {}
	t = 1
	for i in sorted(a, reverse=True):
		if i in d:
			d[i].append(t)
		else:
			d[i] = [t]
		t += 1
	for i in a:
		print(d[i].pop(0), end=' ')
	print()


T = int(input())
while T > 0:
	T = T - 1
	n = int(input())
	arr = list(map(int, input().split()))
	tempArr = []
	for i in range(n):
		tempArr.append([arr[i], i])
	tempArr.sort(key=lambda x: x[1])
	tempArr.sort(key=lambda x: x[0], reverse=True)
	k = 1
	ans = [0] * n
	for i in tempArr:
		ans[i[1]] = k
		k += 1
	ansStr = ''
	for i in ans:
		ansStr += str(i) + ' '
	print(ansStr)


for t in range(int(input())):
	N = int(input())
	ills = list(map(int, input().split()))
	mp = {}
	c = 1
	pills = sorted(ills, reverse=True)
	for i in range(len(pills)):
		if pills[i] not in mp.keys():
			mp[pills[i]] = c
		c += 1
	ans = []
	for i in ills:
		print(mp[i], end=' ')
		mp[i] += 1
	print()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = sorted(arr)
	brr.reverse()
	md = dict()
	for i in range(n):
		if brr[i] not in md:
			md[brr[i]] = 999999
		md[brr[i]] = min(md[brr[i]], i)
	k = Counter(arr)
	p = 1
	for i in range(n):
		print(md[arr[i]] + 1, end=' ')
		md[arr[i]] += 1
	print()


import copy
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = []
	i = input()
	i = i.split()
	for j in i:
		arr.append(int(j))
	d = {}
	_arr = copy.deepcopy(arr)
	arr.sort(reverse=True)
	for i in range(n):
		if arr[i] in d:
			d[arr[i]].append(i)
		else:
			d[arr[i]] = [i]
	ans = []
	for i in range(n):
		ans.append(d[_arr[i]][0] + 1)
		d[_arr[i]].pop(0)
	for i in range(n):
		ans[i] = str(ans[i])
	s = ' '.join(ans)
	print(s)


import operator
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	t = [i for i in range(1, n + 1)]
	d = s = dict(zip(t, l))
	d = dict(sorted(d.items(), key=operator.itemgetter(1), reverse=True))
	res = [0] * n
	z = 0
	for i in d.keys():
		res[i - 1] = t[z]
		z += 1
	print(*res)


from collections import *
for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(list)
	k = sorted(l, reverse=True)
	for i in range(n):
		d[k[i]].append(i + 1)
	ka = []
	for i in range(n):
		ka.append(d[l[i]][0])
		d[l[i]].pop(0)
	print(*ka)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	CountArr = 1001 * [0]
	ValueArr = 1001 * [0]
	m = 0
	for j in range(n):
		CountArr[a[j]] += 1
		if a[j] > m:
			m = a[j]
	aa = 0
	for k in range(m, 0, -1):
		if CountArr[k] != 0:
			ValueArr[k] = aa + CountArr[k]
			aa += CountArr[k]
	for l in range(n):
		v = a[l]
		if CountArr[v] == 1:
			print(ValueArr[v], end=' ')
		else:
			print(ValueArr[v] - CountArr[v] + 1, end=' ')
			CountArr[v] -= 1
	print()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	rev = sorted(a, reverse=True)
	d = {}
	s = set()
	hours = 0
	for i in rev:
		hours += 1
		if i not in d:
			d[i] = hours
	for i in range(n):
		if a[i] not in s:
			s.add(a[i])
			a[i] = d[a[i]]
		else:
			d[a[i]] += 1
			a[i] = d[a[i]]
	print(*a)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] = (arr[i], i)
	arr.sort()
	new_arr = list()
	start = 0
	end = 1
	while end <= n - 1:
		while end <= n - 1 and arr[start][0] == arr[end][0]:
			end += 1
		new_arr = arr[start:end] + new_arr
		start = end
	result = [0] * n
	for i in range(n):
		result[new_arr[i][1]] = i + 1
	for i in result:
		print(i, end=' ')
	print()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	lv = []
	for i in range(n):
		lv.append([a[i], i])
	lv = sorted(lv, key=lambda x: [-x[0], x[1]])
	ans = 1
	for i in lv:
		a[i[1]] = ans
		ans += 1
	return a
for _ in range(int(input())):
	print(' '.join(map(str, solve())))


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	hash = {}
	copy = [i for i in lis]
	copy.sort()
	copy.reverse()
	ctr = 1
	for i in copy:
		if i not in hash:
			hash[i] = [ctr]
		else:
			hash[i].append(ctr)
		ctr += 1
	ans = []
	for i in lis:
		ans.append(hash[i][0])
		hash[i].pop(0)
	print(*ans)


T = int(input())
for _ in range(T):
	N = int(input())
	Alist = list(map(int, input().split()))
	A = [[Alist[i], i] for i in range(N)]
	B = sorted(A, key=lambda x: (-x[0], x[1]))
	wait = 1
	for i in range(N):
		Alist[B[i][1]] = wait
		wait += 1
	print(*Alist)


n = int(input())
for i in range(n):
	N = int(input())
	l = [int(i) for i in input().split()]
	N = max(l)
	a = [0] * (N + 1)
	o = [0] * (N + 2)
	for i in l:
		a[i] += 1
	for i in range(N, -1, -1):
		o[i] = a[i] + o[i + 1]
	for i in l:
		print(o[i] - a[i] + 1, end=' ')
		a[i] -= 1
	print()


for _ in range(int(input())):
	n = int(input())
	patients = list(map(int, input().split()))
	dict = {}
	patient = sorted(patients, reverse=True)
	count = 0
	for i in patient:
		if i in dict:
			dict[i].append(count + 1)
			count = count + 1
		else:
			dict[i] = []
			dict[i].append(count + 1)
			count = count + 1
	for i in patients:
		s = dict[i].pop(0)
		print(s, end=' ')
	print()


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	l = sorted(a, reverse=True)
	s = set(a)
	dic = {}
	for i in range(n):
		if l[i] not in dic.keys():
			dic[l[i]] = i + 1
	j = 0
	for i in range(n):
		if a[i] in s:
			print(dic[a[i]], end='')
			s.remove(a[i])
		else:
			print(dic[a[i]] + 1, end='')
			dic[a[i]] = dic[a[i]] + 1
		if i < n - 1:
			print(' ', end='')
	print()


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	arr = [[a[i] * -1, i] for i in range(n)]
	arr.sort()
	res = [0] * n
	for i in range(n):
		res[arr[i][1]] = i + 1
	for i in res:
		print(i, end=' ')
	print()


tcase = int(input())
while tcase > 0:
	n = int(input())
	levels = list(map(int, input().split()))
	count = [0] * max(levels)
	for i in range(n):
		count[levels[i] - 1] += 1
	sorted_l = sorted(levels)
	sumi = 0
	for i in range(len(count) - 1, -1, -1):
		temp = count[i]
		if count[i] != 0:
			count[i] = sumi + 1
		else:
			count[i] = sumi
		sumi += temp
	for i in range(n):
		print(count[levels[i] - 1], end=' ')
		count[levels[i] - 1] += 1
	print()
	tcase -= 1


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

def mapIn():
	return map(int, input().split())
for ii in range(int(input())):
	n = int(input())
	a = arrIn()
	d = {}
	arr = a[:]
	x = [0] * (max(a) + 2)
	for i in range(n):
		x[a[i]] += 1
		d[a[i]] = []
	c = 1
	for i in range(max(a) + 1, -1, -1):
		for j in range(x[i]):
			d[i].append(c)
			c += 1
	for i in d:
		d[i] = d[i][::-1]
	for i in range(n):
		z = d[a[i]].pop()
		print(z, end=' ')
	print()


try:
	t = int(input())
	from itertools import groupby
	for i in range(0, t):
		n = int(input())
		a = list(map(int, input().split(' ')))
		b = a.copy()
		b.sort(reverse=True)
		l = {}
		c = 1
		for i in range(0, len(b)):
			if b[i] not in l:
				l[b[i]] = c
			c += 1
		kl = []
		for i in a:
			kl.append(l[i])
			l[i] += 1
		print(*kl, sep=' ')
except:
	pass


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	d1 = {}
	temp = sorted(l)
	temp.reverse()
	for j in range(0, len(temp)):
		d1.setdefault(temp[j], []).append(j + 1)
	ans = []
	for j in l:
		f = d1[j]
		ans.append(str(f[0]))
		if len(f) > 1:
			d1[j] = f[1:]
	print(' '.join(ans))
	t = t - 1


try:
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		arr2 = sorted(arr)
		arr2.reverse()
		d = {}
		for i in range(len(arr2)):
			if arr2[i] in d:
				d[arr2[i]].append(i + 1)
			else:
				d[arr2[i]] = [i + 1]
		l = []
		for i in arr:
			if len(d[i]) == 1:
				l.append(d[i][0])
			else:
				l.append(d[i][0])
				d[i] = [] + d[i][1:]
		for i in range(len(l)):
			if i != len(l) - 1:
				print(l[i], end=' ')
			else:
				print(l[i])
except:
	pass


T = int(input())
while T:
	N = int(input())
	A = list(map(int, input().split()))
	v = dict()
	res = []
	for i in range(N):
		res.append(0)
		if A[i] in v:
			v[A[i]].append(i)
		else:
			v[A[i]] = [i]
	A.sort()
	A.reverse()
	index = 1
	temp = 100000007
	for x in A:
		if temp != x:
			temp = x
			for j in v[x]:
				res[j] = index
				index += 1
		else:
			continue
	for i in res:
		print(i, sep=' ', end=' ')
	print('\n')
	T = T - 1


import operator
t = int(input())
for i in range(t):
	n = int(input())
	ill = [int(i) for i in input().split(' ')]
	pno = [int(i) for i in range(1, n + 1)]
	mydict = dict(zip(pno, ill))
	sorted_tuples = sorted(mydict.items(), key=operator.itemgetter(1), reverse=True)
	sorted_dict = {k: v for (k, v) in sorted_tuples}
	tim = [1]
	for j in range(1, n + 1):
		tim.append(tim[j - 1] + 1)
	res = [0 for klj in range(n)]
	ll = 0
	for kl in sorted_dict.keys():
		res[kl - 1] = tim[ll]
		ll = ll + 1
	print(*res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = set(a)
	b = sorted(b)
	res = ''
	c = 1
	d = dict()
	for (i, v) in enumerate(a):
		if v not in d:
			d[v] = [i]
		else:
			d[v].append(i)
	for _ in range(len(b)):
		x = b.pop()
		for i in d[x]:
			a[i] = str(c)
			c += 1
	for i in a:
		res += i + ' '
	print(res)


n = int(input())
for i in range(n):
	p = int(input())
	l = [int(i) for i in input().split()]
	a = [0] * 1005
	o = [0] * 1005
	for i in l:
		a[i] += 1
	for i in range(1000, -1, -1):
		o[i] = a[i] + o[i + 1]
	for i in l:
		print(o[i] - a[i] + 1, end=' ')
		a[i] -= 1
	print()


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	time = 1
	ps = []
	for i in range(max(l) + 1):
		ps.append([])
	c = Counter(l)
	m = set(l)
	m = list(m)
	m.sort()
	m.reverse()
	for j in range(len(m)):
		for r in range(c[m[j]]):
			ps[m[j]].append(time)
			time += 1
	for j in range(n):
		if len(ps[l[j]]) > 0:
			l[j] = ps[l[j]].pop(0)
	for j in range(n):
		print(l[j], end=' ')
	print()