#717
Unrated
The Best Lineup
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John has NN (1N2105)(1 \leq N \leq 2 \cdot 10^5) cows in a line aa. The ii'th cow from the front of line aa is labeled an integer aia_i (1aiN1 \leq a_i \leq N). Multiple cows may be labeled the same integer.

FJ will construct another line bb in the following manner: Initially, bb is empty. While aa is nonempty, remove the cow at the front of aa and potentially add that cow to the back of bb.

FJ wants to construct line bb such that the sequence of labels in bb from front to back is lexicographically greatest (see the footnote).

Before FJ constructs line bb, he can perform the following operation at most once:

Choose a cow in line aa and move it anywhere before its current position.

Given that FJ optimally performs the aforementioned operation at most once, output the lexicographically greatest label sequence of bb he can achieve.

Each input will consist of TT (1T1001 \leq T \leq 100) independent test cases.

입력

The first line contains TT.

The first line of each test case contains NN.

The second line of each test case contains NN space-separated integers a1,a2,,aNa_1, a_2, \ldots, a_N.

It is guaranteed that the sum of NN over all test cases does not exceed 10610^6.

출력

For each test case, output the lexicographically greatest bb on a new line.

예제 입력 1

3
5
4 3 2 1 3
6
5 1 2 6 3 4
6
4 1 3 2 1 1

예제 출력 1

4 3 3 2 1
6 5 4
4 3 2 1 1

점수

Inputs 2-4: N100N \leq 100 Inputs 5-8: N750N \leq 750 Inputs 9-18: No additional constraints

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.