Powerful Magic Squares

You may already know magic squares. Here we introduce a more powerful one. Suppose we have a 5×5 square filled with numbers from 1 to 25, every number appear EXACTLY once, like this: the sum of every row, every col, every diagonal (including non-main diagonals) are ALL the same. for example, 14 + 20 + 21 + 2 + 8 = 19 + 8 + 22 + 11 + 5 = 1 + 24 + 17 + 15 + 8 = 19 + 2 + 15 + 23 + 6 = 65. You may calculate these 20 sums yourself, then, you’ll know I am talking about. This kind of squares (20 sums are ALL the same) is called POWERFUL MAGIC SQUARES. Your task is: given a uncompleted square, count the number of powerful magic squares that can be obtained by completing the square. Input The first line of the input contains a single integer n (1 ≤ n ≤ 15000), the number of test cases followed. For each case, there are five lines containing the uncompleted squares. Blank squares are represented as ‘--’. Filled numbers are always between 1 and 25. every test case is followed by a blank line except the last one. The input format is always correct. Output For each test case, print the case number and the number of squares obtained, like shown below. Sample Input 2 1 71319-- 142021 2-- 22 3 915-- 10 11 17 23 --

2/2 -- -- -- -- -- 1 2 3---- 4 5 6---- 7 8 9----



Sample Output Case 1: 1 Case 2: 0