Under construction

Still being built. Things may change

Largest XOR sum subarray

Interview

Time limit10sMemory limit512 MB

Summary
Given a sequence, find the maximum XOR value over all contiguous subarrays of length at least one.
Level

Medium7 of 10

Topics
Bit manipulation, Trie, Prefix sum, Array
Solved
No attempts yet

Problem

You are given a sequence AA of NN numbers. Pick one contiguous subarray of it. The XOR sum of a subarray is the value you get by XOR-ing every element in that subarray.

Given AA, write a program that finds the largest XOR sum over all contiguous subarrays of length at least 1.

Input

The first line contains the number of test cases TT. (1≤T≤101 \le T \le 10)

Each test case takes two lines. The first line contains the size of the sequence NN (1≤N≤100 0001 \le N \le 100\,000), and the second line contains the NN elements of AA separated by spaces. Each element is a non-negative integer that fits in a 32-bit signed integer, so it is an integer between 00 and 231−12^{31}-1.

Output

For each test case, print the largest XOR sum over the contiguous subarrays of AA on its own line.

Examples8

  1. Example 1

    Input
    2
    5
    3 7 7 7 0
    5
    3 8 2 6 4
    
    Expected output
    7
    15
    
  2. Example 2

    Input
    1
    1
    0
    
    Expected output
    0
    
  3. Example 3

    Input
    1
    1
    2147483647
    
    Expected output
    2147483647
    
  4. Example 4

    Input
    1
    6
    0 0 0 0 0 0
    
    Expected output
    0
    
  5. Example 5

    Input
    1
    2
    5 5
    
    Expected output
    5
    
  6. Example 6

    Input
    1
    6
    8 1 2 15 0 8
    
    Expected output
    15
    
  7. Example 7

    Input
    1
    2
    1073741824 1073741823
    
    Expected output
    2147483647
    
  8. Example 8

    Input
    3
    4
    1 2 4 8
    3
    2147483647 2147483647 2147483647
    1
    1
    
    Expected output
    15
    2147483647
    1