#K86792. Rearranging Plants

    ID: 36943 Type: Default 1000ms 256MiB

Rearranging Plants

Rearranging Plants

You are given a preliminary assignment of plants to consecutive sections of a garden. Each section is assigned a type denoted by an integer. Your task is to determine whether it is possible to rearrange the plants so that no two adjacent sections contain the same type.

For each test case, you are provided with an integer \(N\) and an array \(a_1, a_2, \dots, a_N\) representing the types of plants assigned to each section. You must check through the array and if you find any two consecutive sections with the identical plant type, output Impossible X, where \(X\) is the 1-indexed position (specifically, the index of the second occurrence) where the conflict is first detected. If there is no conflict, output Possible.

Note: When scanning the array starting from the second section, if a conflict is found at index \(j+1\) (with \(j\) being the index of the first occurrence in that pair using 0-indexing), output Impossible j because the solution prints the value of j (starting from 1) upon detection of a conflict.

inputFormat

The input begins with a single integer \(T\) (number of test cases). For each test case:

  • The first line contains an integer \(N\) (the number of sections).
  • The second line contains \(N\) space-separated integers corresponding to the preliminary assignment of plant types.

Constraints: \(1 \leq T \leq 10\) and \(1 \leq N \leq 10^5\).

outputFormat

For each test case, output a single line:

  • If an adjacent conflict is found, print Impossible X where \(X\) is the 1-indexed position of the second section in the first conflicting pair.
  • If no conflict is found, print Possible.
## sample
4
5
1 2 1 2 1
4
1 1 2 2
3
2 1 2
2
1 2
Possible

Impossible 1 Possible Possible

</p>