The Miser’s Puzzle

There once was an old miser who had hoarded up a quantity of fve, ten and twenty-dollar gold pieces. Before starving to death, the miser used to count his gold using a peculiar method. He used to take his coins and form 4 piles with them, such that each pile had the same amount of 5, 10 and 20-dollar pieces. Not only that, but he could also divide his gold into 5 groups, also alike (with the same number of coins of each type). Finally he repeated the process, this time splitting the gold into 6 alike groups. Assuming that each of the piles he made had a positive number of gold pieces of each type, what is the minimum amount of gold that the miser could have had? Let’s say that the miser was able to divide his gold in N diferent ways, and for each method of partitioning he was able to form Mi similar groups (for 1 ≤ i ≤ N). You are asked now to determine the minimum amount of gold he had. Input Tell how much the miser has Input starts with a positive integer T, that denotes the number of test cases. Each case starts with an integer N in a single line. The next line contains N integers, representing the set M1, M2, ..., MN. T≤2000;1≤N≤8;2≤M1<M2<M3<...<MN ≤100 Output For each test case, print the case number, followed by the the minimum amount of gold that the miser could have. Sample Input 2 3 456 4 10 14 15 35 Sample Output Case 1: 2100 Case 2: 7350