CF1862B.Sequence Game

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

Sequence Game

Tema and Vika are playing the following game.

First, Vika comes up with a sequence of positive integers aa of length mm and writes it down on a piece of paper. Then she takes a new piece of paper and writes down the sequence bb according to the following rule:

  • First, she writes down a1a_1.
  • Then, she writes down only those aia_i (2im2 \le i \le m) such that ai1aia_{i - 1} \le a_i. Let the length of this sequence be denoted as nn.

For example, from the sequence a=[4,3,2,6,3,3]a=[4, 3, 2, 6, 3, 3], Vika will obtain the sequence b=[4,6,3]b=[4, 6, 3].

She then gives the piece of paper with the sequence bb to Tema. He, in turn, tries to guess the sequence aa.

Tema considers winning in such a game highly unlikely, but still wants to find at least one sequence aa that could have been originally chosen by Vika. Help him and output any such sequence.

Note that the length of the sequence you output should not exceed the input sequence length by more than two times.

Input

Each test consists of multiple test cases. The first line of input data contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. This is followed by a description of the test cases.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the length of the sequence bb.

The second line of each test case contains nn integers b1,b2,b3,,bnb_1, b_2, b_3, \dots, b_n (1bi1091 \le b_i \le 10^9) — the elements of the sequence.

The sum of the values of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output two lines. In the first line, output a single integer mm — the length of the sequence (nm2nn \le m \le 2 \cdot n). In the second line, output mm integers a1,a2,a3,,ama_1, a_2, a_3, \dots, a_m (1ai1091 \le a_i \le 10^9) — the assumed sequence that Vika could have written on the first piece of paper.

If there are multiple suitable sequences, you can output any of them.

Note

The first sample is explained in the problem statement.

In the second sample, Vika could have chosen the original sequence.

Samples

6
3
4 6 3
3
1 2 3
5
1 7 9 5 7
1
144
2
1 1
5
1 2 2 1 1
6
4 3 2 6 3 3
3
1 2 3
6
1 7 9 3 5 7
1
144
2
1 1
6
1 2 2 1 1 1

在线编程 IDE

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