13601360 SUSTech Online Judge
Problem 1360 --[Medium I] Skylar Playing Ancient Spider

## 1360: [Medium I] Skylar Playing Ancient Spider

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 0
[Submit][Status][Web Board]

## Description

Ancient Spider is a very popular card game, and Skylar loves playing it. Today she wants to play Ancient Spider again, but she changes the rule to make it more interesting. At the beginning of the game, Skylar has an empty slot on the table. There are $$n$$ different cards numbered from $$1$$ to $$n$$, and Skylar will receive them one by one in a given order and put the cards onto the top of the slot. At any time, Skylar can pick up a card from the top of slot and discard it. If Skylar discards all $$n$$ cards, the game is over. Skylar wants you to help her find the smallest lexicographical order among all possible discarding orders at the end of the game.

If you don't know the concept of lexicographical order, you can see the reference in the following link: https://en.wikipedia.org/wiki/Lexicographical_order

## Input

The first line is an integer $$T$$, which is the number of test cases.

Each test case contains two lines. The first line has an integer $$n$$.

The second line contains a sequence $$\{A\}$$ of length $$n$$, which is a permutation of $$1$$ to $$n$$, representing the order Skylar receives the cards.

$$1 \leq T \leq 5, 1 \leq n \leq 300000$$

## Output

For each test case, print $$n$$ integers in a line, which is the order discarding the card with the smallest lexicographical order.

## Sample Input

2
3
1 3 2
4
3 4 1 2

## Sample Output

1 2 3
1 2 4 3

[Submit][Status]