CF2044D.Harder Problem

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Harder Problem

Given a sequence of positive integers, a positive integer is called a mode of the sequence if it occurs the maximum number of times that any positive integer occurs. For example, the mode of [2,2,3][2,2,3] is 22. Any of 99, 88, or 77 can be considered to be a mode of the sequence [9,9,8,8,7,7][9,9,8,8,7,7].

You gave UFO an array aa of length nn. To thank you, UFO decides to construct another array bb of length nn such that aia_i is a mode of the sequence [b1,b2,,bi][b_1, b_2, \ldots, b_i] for all 1in1 \leq i \leq n.

However, UFO doesn't know how to construct array bb, so you must help her. Note that 1bin1 \leq b_i \leq n must hold for your array for all 1in1 \leq i \leq n.

Input

The first line contains tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains an integer nn (1n21051 \leq n \leq 2 \cdot 10^5) — the length of aa.

The following line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ain1 \leq a_i \leq n).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output nn numbers b1,b2,,bnb_1, b_2, \ldots, b_n (1bin1 \leq b_i \leq n) on a new line. It can be shown that bb can always be constructed. If there are multiple possible arrays, you may print any.

Note

Let's verify the correctness for our sample output in test case 22.

  • At i=1i = 1, 11 is the only possible mode of [1][1].
  • At i=2i = 2, 11 is the only possible mode of [1,1][1, 1].
  • At i=3i = 3, 11 is the only possible mode of [1,1,2][1, 1, 2].
  • At i=4i = 4, 11 or 22 are both modes of [1,1,2,2][1, 1, 2, 2]. Since ai=2a_i = 2, this array is valid.

Samples

4
2
1 2
4
1 1 1 2
8
4 5 5 5 1 1 2 1
10
1 1 2 2 1 1 3 3 1 1
1 2
1 1 2 2
4 5 5 1 1 2 2 3
1 8 2 2 1 3 3 9 1 1

在线编程 IDE

建议全屏模式获得最佳体验