The fat sheep and his tiger friend is given a tower of $$$N$$$ distinct Jenga blocks stacked vertically. The blocks are numbered from bottom to top, and the weight of the $$$i$$$-th block from the bottom is $$$w_i$$$. All weights are distinct.
You want to build a second tower by repeatedly removing blocks from the original tower.
A block is considered stable if:
You repeatedly perform the following operation until the original tower becomes empty:
Let the resulting second tower be described from bottom to top by the sequence of weights of the removed blocks in the order they were placed.
Your task is to determine the lexicographically greatest possible second tower (from bottom to top) that can be achieved.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases.
Each test case consists of two lines:
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
Print $$$N$$$ integers representing the lexicographically greatest possible second tower from bottom to top.
1410 6 9 5
6 5 9 10
433 10 8314 5 161 2 3 4 5 61100
8 10 31 5 146 5 4 3 2 1100
| Название |
|---|


