As the Chief Weapons Officer of an Imperial Star Destroyer, one of your duties is the routine maintenance of laser turret panels. Each panel is a square of $n \times n$ turret sockets, exactly $n$ of which house a turret. To keep the panel circuits from wearing unevenly, turrets are regularly moved between sockets.
The key constraint is that turrets must never conflict — that is, they must never be able to shoot one another. Two turrets conflict when they share the same row, the same column, or the same diagonal. So in every valid configuration, no two turrets lie on the same horizontal, vertical, or diagonal line.
To reduce placement errors, every socket exchange must be performed as a rotation or reflection of an existing configuration, because the no-conflict property is invariant under such transformations.
Given a valid (conflict-free) $n \times n$ configuration, there are three clockwise rotations — 90°, 180°, and 270° — together with four mirror planes:
This gives eight approved configurations. Some of them may coincide when the configuration is itself symmetric under a 90° or 180° rotation.
Because a valid configuration has exactly one turret per row, it can be written as a one-dimensional vector giving the column of the turret in each row. The top row has index $0$ (screen-coordinate style, increasing downward), and columns are indexed from $0$ at the left.
Given one valid configuration, output the other seven configurations produced by these rotations and reflections, in the same one-dimensional form. Print the configurations in exactly this order: first the configuration you were given, then the 90°, 180°, and 270° clockwise rotations, and finally the reflections in the order vertical mirror, anti-diagonal mirror, horizontal mirror, diagonal mirror.
The input contains an indeterminate number of panels. Each panel is described on one line: the first integer is the panel size $n$, followed by $n$ integers giving the column of the turret in each row, from the top row down. A panel size of $0$ marks the end of the input and is not processed; every other panel satisfies $4 \le n \le 20$. Integers may be separated by arbitrary white space.
For each panel, print eight lines giving the approved configurations in the order specified above. On every line the numbers are right-justified in fields of three characters (each value occupies three characters, padded with leading spaces). Separate the output of consecutive panels with a single blank line.