cswork / OAOpen practice workspace

MicrosoftOA #56

Product of XOR of All Good Pairs

Estimated MediumJudge-ready

Topics (AI-labelled)HashingBits & Math

For all 0≤i<j<N, compute A[i] XOR A[j], multiply all these results together, and take the product modulo 1000000007. Each test case is independent. An old importer mistakenly removed the text containing the less-than sign, and this site has restored it.

This site uses a standard input/output protocol.

Input

The first line contains T (1..10). Each test case consists of one line with N (2..100000), followed by one line with N integers (1..3000).

Output

For each test case, output one line with the product modulo 1000000007.

Example 1

Input:

1
4
1 2 3 7

Output:

720

Example 2

Input:

1
3
4 3 7

Output:

84

Example 3

Input:

2
2
2 2
2
1 2

Output:

0
3

Example notes

Example 1: the six factors 3, 2, 6, 1, 5, 4 multiply to 720. Example 2: the three factors 7, 3, 4 multiply to 84. Example 3: in the first test case, equal values XOR to 0, so output 0; in the second, the only factor is 3, so output 3.

Editorial

Loading solution…