Tirth and Badminton

5

1 votes
Easy-Medium
Problem

Tirth and Souvik play Badminton a lot. Everytime they play with each other, Souvik wins. Tirth doesn't like losing. So he comes up with his own rule.

Tirth gives Souvik an array of size n. Souvik will win if he is able to score equal to the number of distinct Magic numbers of all possible contiguous subarrays of the given array. So Souvik needs to find the total points he has to score to win.

Magic number of an array is the bitwise and of all elements.

Input

First line contains the number of test cases t. The description of t test cases follows.

First line of each test case contains a single integer n denoting the size of the array.

The second line contains n space-separated integers representing elements of the array.

Output

For each testcase, print a single line containing the required output.

Constraints

1 <= t <= 3
1 <= n <= 10^5
0 <= A[i] <= 10^6

40% score :
1 <= n <= 1000

100% score :
Original constraints

Sample Input
2
3
2 1 3
4
5 2 8 4
Sample Output
4
5
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Test case 1 :
For all six contiguous subarrays, corresponding AND's are shown.
[2] -> 2 , [1] -> 1 , [3] -> 3 , [2,1] -> 0 , [1,3] -> 1 , [2,1,3] -> 0
Hence, 4 distinct numbers.

Editor Image

?