#P1811C. Restore the Array

    ID: 8374 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>constructive algorithmsgreedy*1100

Restore the Array

No submission language available for this problem.

Description

Kristina had an array aa of length nn consisting of non-negative integers.

She built a new array bb of length n1n-1, such that bi=max(ai,ai+1)b_i = \max(a_i, a_{i+1}) (1in11 \le i \le n-1).

For example, suppose Kristina had an array aa = [3,0,4,0,53, 0, 4, 0, 5] of length 55. Then she did the following:

  1. Calculated b1=max(a1,a2)=max(3,0)=3b_1 = \max(a_1, a_2) = \max(3, 0) = 3;
  2. Calculated b2=max(a2,a3)=max(0,4)=4b_2 = \max(a_2, a_3) = \max(0, 4) = 4;
  3. Calculated b3=max(a3,a4)=max(4,0)=4b_3 = \max(a_3, a_4) = \max(4, 0) = 4;
  4. Calculated b4=max(a4,a5)=max(0,5)=5b_4 = \max(a_4, a_5) = \max(0, 5) = 5.
As a result, she got an array bb = [3,4,4,53, 4, 4, 5] of length 44.

You only know the array bb. Find any matching array aa that Kristina may have originally had.

The first line of input data contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains one integer nn (2n21052 \le n \le 2 \cdot 10^5) — the number of elements in the array aa that Kristina originally had.

The second line of each test case contains exactly n1n-1 non-negative integer — elements of array bb (0bi1090 \le b_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5, and that array bb was built correctly from some array aa.

For each test case on a separate line, print exactly nn non-negative integers — the elements of the array aa that Kristina originally had.

If there are several possible answers — output any of them.

Input

The first line of input data contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains one integer nn (2n21052 \le n \le 2 \cdot 10^5) — the number of elements in the array aa that Kristina originally had.

The second line of each test case contains exactly n1n-1 non-negative integer — elements of array bb (0bi1090 \le b_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5, and that array bb was built correctly from some array aa.

Output

For each test case on a separate line, print exactly nn non-negative integers — the elements of the array aa that Kristina originally had.

If there are several possible answers — output any of them.

Sample Input 1

11
5
3 4 4 5
4
2 2 1
5
0 0 0 0
6
0 3 4 4 3
2
10
4
3 3 3
5
4 2 5 5
4
3 3 3
4
2 1 0
3
4 4
6
8 1 3 5 10

Sample Output 1

3 0 4 0 5
2 2 1 1
0 0 0 0 0
0 0 3 4 3 3
10 10
3 3 3 1
4 2 2 5 5
3 3 3 3
2 1 0 0
2 4 4
8 1 1 3 5 10

Note

The first test case is explained in the problem statement.

In the second test case, we can get array bb = [2,2,12, 2, 1] from the array aa = [2,2,1,12, 2, 1, 1]:

  • b1=max(a1,a2)=max(2,2)=2b_1 = \max(a_1, a_2) = \max(2, 2) = 2;
  • b2=max(a2,a3)=max(2,1)=2b_2 = \max(a_2, a_3) = \max(2, 1) = 2;
  • b3=max(a3,a4)=max(1,1)=1b_3 = \max(a_3, a_4) = \max(1, 1) = 1.

In the third test case, all elements of the array bb are zeros. Since each bib_i is the maximum of two adjacent elements of array aa, array aa can only consist entirely of zeros.

In the fourth test case, we can get array bb = [0,3,4,4,30, 3, 4, 4, 3] from the array aa = [0,0,3,4,3,30, 0, 3, 4, 3, 3] :

  • b1=max(a1,a2)=max(0,0)=0b_1 = \max(a_1, a_2) = \max(0, 0) = 0;
  • b2=max(a2,a3)=max(0,3)=3b_2 = \max(a_2, a_3) = \max(0, 3) = 3;
  • b3=max(a3,a4)=max(3,4)=4b_3 = \max(a_3, a_4) = \max(3, 4) = 4;
  • b4=max(a4,a5)=max(4,3)=4b_4 = \max(a_4, a_5) = \max(4, 3) = 4;
  • b5=max(a5,a6)=max(3,3)=3b_5 = \max(a_5, a_6) = \max(3, 3) = 3.