数据结构

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Background

QQ 发明了一种数据结构。

Description

QQ 上课的时候学了栈和队列,于是他发明了一种数据结构。

这个数据结构有三种操作:

  • 1入栈:如果当前还有数没有被放入过栈中,那么就把剩下的腮雷中编号最小的放到栈中(作为新的栈顶)。
  • 2出栈:如果当前栈中有数,那么就把栈顶(即栈中最后被放入的)的数取出来。
  • 3打开阀门:如果当前栈中有数,那么就把栈底(即栈中最先被放入的)的数取出来。

QQ 给你一个序列,他想知道这个序列按照出栈顺序排成一排,字典序最小是多少。

Format

Input

一行一个 TT 表示数据组数。

然后 TT 组数据,每组数据一个整数 nn,代表这个序列。

接下来 nn 个数字,表示这个序列。

Output

每组数据 nn 个整数,代表最小字典序序列。

Samples

2
3
1 2 3
4
1 3 4 2
1 2 3
1 2 3 4

Limitation

1T51 \leq T \leq 5

1n1051\leq n \leq 10^5

1ai1091 \leq a_i \leq 10^9

非常好看

Not Attended
Status
Done
Rule
Ledo
Problem
40
Start at
2025-1-24 16:45
End at
2025-4-18 0:45
Duration
2000 hour(s)
Host
Partic.
17