Log Set (Large)

Recover the original integer multiset from the frequency table of all its subset sums, breaking ties by lexicographic order.

Hard8GreedySortingHash mapNo attempts yetTime limit5sMemory limit512 MB

Problem

The power set of a set S is the set of all subsets of S, including the empty set and S itself. Going from a set to its power set is easy. This problem goes the other way.

We started with a set S of integers, which do not have to be distinct. We took its power set, then replaced every member of the power set, that is every subset, with the sum of the elements of that subset, which gave a new set S'. For example, if S = {-1, 1}, then the power set of S is {{}, {-1}, {1}, {-1, 1}}, so S' = {0, -1, 1, 0}. S' may contain repeated values, so if S has N elements, then S' always has exactly 2N2^N elements.

You are given the values that appear in S' and how many times each one appears. Recover the original set S. S is guaranteed to exist. If several sets S produce the same S', the original set is the earliest of them. To decide which of two sets S1 and S2 with the same number of elements is earlier, sort each one into nondecreasing order and find the leftmost position where they differ. The set with the smaller value at that position is earlier.

Input

The first line has the number of test cases T. T test cases follow. Each test case has three lines. The first line has one integer P. The second line has the P distinct values E1,E2,,EPE_1, E_2, \dots, E_P that appear in S', in ascending order. The third line has the counts F1,F2,,FPF_1, F_2, \dots, F_P. That is, the value EiE_i appears FiF_i times in S'.

Limits

  • 1T1001 \le T \le 100
  • 1P100001 \le P \le 10000
  • Fi1F_i \ge 1
  • S has between 1 and 60 elements.
  • 1010Ei1010-10^{10} \le E_i \le 10^{10}
  • F1+F2++FP=2NF_1 + F_2 + \dots + F_P = 2^N, where N is the number of elements of S.

Output

For each test case, print one line containing "Case #x: " followed by the elements of the original set S in nondecreasing order, separated by single spaces. Here x is the test case number, starting from 1. List the elements of S directly instead of splitting them into a value line and a count line the way S' is given.

Notes

S' does not always pin down S. For example, {-2, 1, 1} and {2, -1, -1} produce the same S'. In that case the answer is the earlier one, {-2, 1, 1}.