#C3557. Emilia's Sequence Transformation

    ID: 46997 Type: Default 1000ms 256MiB

Emilia's Sequence Transformation

Emilia's Sequence Transformation

You are given an array of integers. Your task is to compress the array by reducing contiguous blocks of the same value to a single occurrence. This operation is defined as:

Given an array \(a = [a_1, a_2, \dots, a_n]\), produce a reduced array \(b = [b_1, b_2, \dots, b_k]\) where each \(b_i = a_{j}\) and for each maximal contiguous block of equal numbers in \(a\), only the first element is kept. Then, repeatedly apply this compression until the array stops changing. The final array is the answer.

Note: The process stops when applying the compressing operation results in no change. This is equivalent to repeatedly applying the transformation until \(reduce(a) = a\).

inputFormat

The first line contains an integer \(T\) representing the number of test cases. Each test case consists of two lines. The first line contains an integer \(n\) (the length of the array). The second line contains \(n\) space-separated integers, representing the array elements.

outputFormat

For each test case, output the final reduced array. Each test case's output should be on a separate line. The numbers in each array should be printed in order, separated by a single space.

## sample
3
7
1 1 2 2 2 3 3
5
4 4 4 4 4
8
1 1 2 3 3 3 2 2
1 2 3

4 1 2 3 2

</p>