Code Sequence (Large)

Given consecutive terms of a binary-additive sequence with unknown coefficients, output the next term or UNKNOWN if it is not forced.

Hard8MathBit manipulationNumber theoryNo attempts yetTime limit5sMemory limit512 MB

Problem

A sequence SS is generated from a secret code, and you have to work out its next term. The code was built as follows.

First, for each kk from 00 to 2929, a number CkC_k between 00 and 1000610006 inclusive was chosen.

Then, for every integer nn from 00 to 10910^9 inclusive:

  • Write nn in binary.
  • Collect CkC_k for every bit kk that is set in that binary representation. For n=5n = 5, bits 0 and 2 are set, so C0C_0 and C2C_2 are collected.
  • Add the collected values, divide by 1000710007, and let the remainder be SnS_n.

You are given several consecutive terms of SS. You do not know where in the sequence they start, though you do know that at least one more term follows them, and you do not know which CkC_k were chosen.

Print the term that comes right after the given ones. If the input does not pin it down to a single value, print UNKNOWN.

Input

The first line contains the number of test cases TT.

Each test case takes two lines.

  • The first line contains NN, the number of known terms.
  • The second line contains the NN known terms, separated by single spaces. Each term is between 00 and 1000610006.

Limits

  • 1T201 \le T \le 20
  • 1N10001 \le N \le 1000
  • Every test case is a consecutive block of some sequence the procedure above can produce, and at least one more term follows the last given one. That is, there are C0,,C29C_0, \dots, C_{29} and an index mm with 0m109N0 \le m \le 10^9 - N such that the given terms are Sm,Sm+1,,Sm+N1S_m, S_{m+1}, \dots, S_{m+N-1} in this order.

Output

For each test case print one line in the form Case #XX: YY, where XX is the test case number starting from 1 and YY is the next term. Write UNKNOWN in place of YY when the next term is not determined.

Notes

In the first test case of the sample input, C0,C1,C2C_0, C_1, C_2 could have been 1, 2 and 4, with the given terms starting at n=1n = 1. Read that way, C3C_3 is unknown, so the next term could be anything and the answer is UNKNOWN.

In the second test case neither the full list of CkC_k nor the starting index can be recovered. Even so, whenever 1, 10, 11, 200 occur consecutively in this order, the next value is always 201.