Square of Primes

Figure 1 shows a square. Each row, each column and the two diagonals can be read as a five digit prime number. Both diagonals are read from left to right. 11351 33203 30323 14033 33311 Figure 1 - Example square of primes. Using the data in the input file, write a program that constructs such squares. • The prime numbers must have the same digit sum (11 in the example). • The digit in the top left-hand corner of the squares is pre-determined (1 in the example). • A prime number may be used more than once in the same square. • If there are several solutions, all must be present. Input The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. The input file contains two lines. The first line contains a single integer which is the digit sum of the prime numbers. The second contains the digit in the top left corner of the square. Output For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. In the output, write five lines for each solution found, where each line in turn consists of a five digit prime number. The solutions must be in ascending order, separated by an empty line. (the above example has three solutions) Sample Input 1 11 1

2/2 Sample Output 11351 14033 30323 53201 13313 11351 33203 30323 14033 33311 13313 13043 32303 50231 13331