Fill the Cuboid

Can you fill an (a ∗ b ∗ c) cuboid with exactly n cubes? The cubes may touch, but cannot overlap and each cell inside the (a ∗ b ∗ c) cuboid should be covered by exactly one cube. You may use cubes of different dimensions and for each positive integer p, you can use as many (p ∗ p ∗ p) cubes as you like. For example, a (2∗2∗3) cuboid can be filled with five cubes: four (1∗1∗1) cubes and one (2∗2∗2) cube. It can also be filled with twelve (1 ∗ 1 ∗ 1) cubes. To make this problem slightly more difficult, m of the cells in the cuboid are already filled and cannot be filled by another cube. Your job is to find out the possible values of n such that the remaining cells inside the cuboid, can be filled by exactly n cubes. Input There will be at most 300 test cases. Each test case begins with four integers a, b, c, m (2 ≤ a, b, c ≤ 20, a ∗ b ∗ c ≤ 125, 0 ≤ m < a ∗ b ∗ c). Each of the next m lines contains three integers x, y, z (1 ≤ x ≤ a, 1 ≤ y ≤ b, 1 ≤ z ≤ c), that means the cell (x, y, z) is already filled. No cell will be mentioned twice. There will be at least one non-filled cell. The input is terminated by a line containing four zeroes. Output For each test case, print the case number and the list of possible answers in increasing order. There is a single space before each number in the output. Look at the output for sample input for details. Sample Input 2230 2232 111 223 0000 Sample Output Case 1: 5 12 Case 2: 10