This page is still under construction.

Parts of this page are still being built. What you see may change.

XOR Set Expansion

Time limit1sMemory limit128 MB

Summary
Given an initial integer set, count the expansion rounds that add XORs of current and original elements until the set stops growing.
Level

Medium7 of 10

Topics
Bit manipulation, BFS, Math
Solved
No attempts yet

Problem

A set of numbers S0S_0 is given. The algorithm below widens the set until no new value shows up, and counts how many times it widened the set.

counter = 0
S = S0
loop:
    S' = { a xor b : a in S, b in S0, a != b }
    if every value of S' is already in S:
        print counter and stop
    S = S union S'
    counter = counter + 1
    goto loop

One round collects every result of XOR-ing a value already in SS with a value of the original set S0S_0, and those results form S′S'. Equal values are never paired, so 0 stays out of SS. Once a round yields no new value at all, the algorithm prints the current counter and stops.

For S0S_0 = {1, 2, 4} the algorithm runs like this.

  • start: counter = 0, S = {1, 2, 4}
  • round 1: S' = {3, 5, 6}, S = {1, 2, 3, 4, 5, 6}, counter = 1
  • round 2: S' = {1, 2, 3, 4, 5, 6, 7}, S = {1, 2, 3, 4, 5, 6, 7}, counter = 2
  • round 3: S' = {1, 2, 3, 4, 5, 6, 7} holds no new value, so the algorithm prints 2 and stops.

A set with a single element has no pair to XOR, so S′S' is empty and the answer is 0.

Write a program that reads S0S_0 and computes the counter value the algorithm prints.

Input

The first line has a positive integer TT, the number of test cases. TT is at most 100,000.

Each test case takes two lines. The first line has NN, the size of the initial set S0S_0, and NN is between 1 and 50. The second line has the NN elements of S0S_0, separated by spaces. Every element is an integer between 1 and 500,000, and all elements are different.

Output

For each test case print one line in the form Case #x: R, where xx is the test case number starting at 1 and RR is the counter value the algorithm prints.

Examples1

  1. Example 1

    Input
    10
    5
    9 16 17 21 20
    6
    15 18 27 6 21 7
    7
    9 25 22 10 12 34 33
    8
    27 22 5 15 25 13 8 31
    9
    19 4 15 25 21 18 9 22 20
    5
    33 34 37 36 24
    6
    4 15 6 14 8 16
    7
    16 27 41 19 10 26 20
    8
    16 20 13 11 12 3 24 6
    9
    24 6 44 35 22 1 26 21 17
    
    Expected output
    Case #1: 2
    Case #2: 1
    Case #3: 2
    Case #4: 2
    Case #5: 2
    Case #6: 4
    Case #7: 3
    Case #8: 4
    Case #9: 2
    Case #10: 3