题目描述
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$.
输入格式
见题面
输出格式
见题面