Code Sequence

Given N consecutive terms of a sequence built from unknown coefficients over GF(10007), find the next term or print UNKNOWN.

Medium7MathNumber theoryBrute forceNo attempts yetTime limit5sMemory limit512 MB

Problem

You want the next number in a sequence SS that a secret code generated. The code built the sequence by this procedure.

First, for each kk from 0 to 29, pick a number CkC_k between 0 and 10006, inclusive.

Then, for each integer nn from 0 to 10910^9, inclusive:

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

You are given several consecutive values of SS. You do not know where in the sequence your numbers begin, although you do know that at least one more number follows them, and you do not know which values of CkC_k were chosen.

Find the next number in the sequence. If the input data cannot determine it, print UNKNOWN.

Input

The first line contains an integer TT, the number of test cases.

Each test case takes two lines.

  • The first line contains an integer NN, the number of elements of SS that you know.
  • The second line contains the NN known elements, separated by single spaces. Each element is between 0 and 10006, inclusive.

Limits

  • 1T201 \le T \le 20
  • 1N301 \le N \le 30
  • Each test case is a consecutive block of some sequence produced by the procedure above, and at least one more number follows that block.

Output

For each test case, print one line containing "Case #XX: YY", where XX is the test case number starting from 1 and YY is the next number in the sequence. If the next number cannot be determined, write UNKNOWN in place of YY.

Note

In the first sample case, C0C_0, C1C_1 and C2C_2 might have been 1, 2 and 4, with the given values starting at n=1n = 1. If that is what happened, C3C_3 is unknown, so the next number could be anything, and the answer is UNKNOWN.

In the second sample case you cannot recover every value of CkC_k, and you cannot tell what nn is either. Even so, in any sequence produced this way, if 1, 10, 11, 200 occur in this order, the next value is always 201.