Fair Warning (Large)

Given past event times, find the smallest wait y so all shifted times share the largest possible common divisor.

Medium4Number theoryNo attempts yetTime limit5sMemory limit512 MB

Problem

On our planet, Jamcode IX, three Great Events occurred. They happened 26000, 11000 and 6000 slarboseconds ago. In 4000 slarboseconds, the amount of time since each of those events will be a multiple of 5000 slarboseconds, the largest possible amount, and the apocalypse will come.

You are lucky enough to live on Jamcode X. The apocalypse came on Jamcode IX less than a year ago. But Jamcode X has a worrying prophecy of its own: "After the moment of reckoning, on the first optimum anniversary of the NN Great Events, the apocalypse will come. 64 bits will not save you. You have been warned."

The people of Jamcode X are very concerned by this prophecy. All of the Great Events have already happened, and their times have been measured to the nearest slarbosecond, but nobody knows when the optimum anniversary will occur. After studying the diary of a scientist from Jamcode IX, the scientists working on the problem came up with a theory.

The moment of reckoning is now, the moment you solve this problem. At some time y0y \ge 0 slarboseconds from now, the number of slarboseconds since each of the Great Events will be divisible by some maximum number TT. The smallest yy that gives this largest possible TT is the optimum anniversary when the apocalypse will come.

On Jamcode IX, for example, there were 3 Great Events and they happened 26000, 11000 and 6000 slarboseconds before the moment of reckoning. 4000 slarboseconds later, the amount of time since each event was a multiple of T=5000T = 5000 slarboseconds, and the apocalypse came.

Compute the amount of time until the apocalypse comes. Remember the prophecy: the people of Jamcode X have been solving problems for two years and 64-bit integers have always been enough, but they might not be enough now or in the future.

Input

The first line of the input gives the number of test cases CC. CC lines follow. Each line starts with a single integer NN, followed by a space and then NN space-separated integers tit_i, the number of slarboseconds since Great Event ii occurred.

Limits

  • 1C1001 \le C \le 100
  • 2N10002 \le N \le 1000
  • 1ti10501 \le t_i \le 10^{50}
  • titjt_i \ne t_j for at least one pair ii, jj.

Output

For each test case, output one line in the form Case #x: y, where xx is the case number starting from 1 and yy is the minimum number of slarboseconds until ti+yt_i + y is a multiple of the largest possible integer factor TT for every ii.

Note

Fortunately for the peoples of the Jamcode system, "the apocalypse" turned out to be a mistranslation of "the giant party". Nobody from Jamcode IX bothered to pass this along, because they were having so much fun.