Rubik’s cube was a very popular puzzle game in the eighties. It is a cube (of course!) that is divided into three segments which are parallel to the surfaces, and each segment can be rotated independently as shown below: Since there are six possible rotations, each rotation is labeled by a number from 1 through 6. Since we can rotate each segment independently, by rotation 1 we mean rotating the top segment anti-clockwise by 90 degrees (keeping the rest of the cube fixed). Similarly, rotation 2 means to rotate the bottom segment anti-clockwise by 90 degrees. From the above figure you can figure out that rotations 3, 4, 5 and 6 are the anti-clockwise rotations of right, left, back, and front segments respectively. Just to make the problem interesting, by rotation -1 we mean the same rotation but in the clockwise direction. Similarly -2, -3, -4, -5 and -6 indicate rotations of the corresponding surfaces but in clockwise direction. You probably already have noticed that rotation 1 followed by rotation 1 followed by rotation 1 is actually rotation -1! The original Rubik’s cube had a different color on each surface and as you would rotate the different segments, the colors would be all mixed up. The goal of the puzzle was to bring back all the original colors to their original surfaces (which was not easy!). For this problem we keep things simple and label every small square with a number as shown in the figure. As you can see the small squares of the top surface are labeled by the numbers 1 through 8. The center square is not labeled be- cause no matter which segment is rotated the center squares never change position. The bottom surface is labeled by the numbers 9 through 16 (sorry, you can not see this in the figure), the right surface by 17 through 24, the left surface by 25 through 32 (which you cannot see), the back surface by 33 through 40 (which you cannot see) and the front surface by 41 through 48. Just to make sure that you have understood the labeling scheme properly note that the eight corners are composed of 3 smaller squares and the numbers on them are:
2/2 1-29-39, 3-17-37, 5-23-47, 7-31-45, 9-19-35, 11-27-33, 13-25-43, 15-21-41 Similarly the middle section of each edge is composed of 2 small squares, there are 12 of them as follows: 2-38, 4-24, 6-46, 8-30, 10-34, 12-26, 14-42,16-20, 18-36, 22-48, 28-40 and 32-44. If we start with an unscrambled Rubik’s cube the label of the small squares of the six surfaces are in this order: 1 2 3 4 5 6 7 8 Top Surface 9 10 11 12 13 14 15 16 Bottom Surface 17 18 19 20 21 22 23 24 Right Surface 25 26 27 28 29 30 31 32 Left Surface 33 34 35 36 37 38 39 40 Back Surface 41 42 43 44 45 46 47 48 Front Surface Now you are ready to rotate the segments and see what happens! Input The input file may contain multiple test cases, each case contains one line with integers -6 through 6 (excluding 0) indicating rotation of different segments. The positive numbers indicate anti-clockwise rotations and the negative numbers indicate clockwise rotations. Each test case is terminated with a zero. Output For each test case in the input there should be six rows of 8 integers indicating the orders of the labels of the six surfaces in following order: top, bottom, right, left, back and front. Print a blank line between two successive test cases. Sample Input 1 3 -2 0 -4 6 5 0 Sample Output 3 4353623 8 1 2 31 48 41 10 11 12 13 14 1920 74243464718 33 34 15 28 37 38 39 32 21224516 9241740 252627442930 5 6 252627 421222340 17 18 19 44 29 30 31 16 33 2 32045141524 3932 9104328 5 6 35 36 37 38 11 12 13 34 7 8 14647484142