#K11311. Flower Arrangement Grid

    ID: 23441 Type: Default 1000ms 256MiB

Flower Arrangement Grid

Flower Arrangement Grid

You are given a rectangular grid with r rows and c columns. Your task is to arrange flowers in each cell so that no two adjacent cells (sharing a common edge) contain the same type of flower. You have f different types of flowers, represented by the first f uppercase letters of the English alphabet. If it is impossible to arrange the flowers under the given constraints, output Impossible.

Note: Two cells are considered adjacent if they share an edge (horizontal or vertical). For each valid grid, print r lines with exactly c characters (without spaces) representing the arrangement.

The grid should be constructed such that the flower placed at position (i, j) is determined by the formula:

\(\text{flower}(i,j)=\text{Letter}\Bigl[((i+j) \bmod f)\Bigr]\)

If the given number of flower types is insufficient to ensure adjacent cells differ (i.e. when f < 2 and the grid is not 1x1), the output should be Impossible.

inputFormat

The input begins with an integer t representing the number of test cases. Each of the next t lines contains three space-separated integers: r, c, and f — the number of rows, the number of columns, and the number of different flower types, respectively.

outputFormat

For each test case, if it is possible to arrange the flowers according to the rules, print the grid as r lines with c characters each (without spaces). Otherwise, print Impossible. Outputs for different test cases should be printed sequentially.## sample

2
3 3 3
2 2 2
ABC

BCA CAB AB BA

</p>