Mystical Matrix

It was rumored that the first person who solves the Mystical Matrix will get a free Mystical Chicken dinner from the Mystical Restaurant. Of course, Jack is eager to get that Mystical Chicken dinner. The Mystical Matrix is a matrix with 3 rows and N columns, with 1, 2, . . . , 3N each occupying one cell. Furthermore, all rows have the same sum and all columns have the same sum. Help Jack construct such a Mystical Matrix. Input The input contains several lines. Each line contains a single positive integer N. You may assume N is a multiple of 3 and it is less than 1000. The input is terminated by a single integer ‘0’. Output Output a valid Mystical Matrix. If non-exists, output ‘IMPOSSIBLE’ (without quotes). A valid Mystical Matrix should take 3 lines, with each line consisting of N integers separated by spaces. For example, a 3 × 9 matrix should look like: Sample Input 3 0 Sample Output 816 357 492 A1 A2 A3 A4 A5 A6 A7 A8 A9 B1 B2 B3 B4 B5 B6 B7 B8 B9 C1 C2 C3 C4 C5 C6 C7 C8 C9