Majestic Segments#12301

Majestic Segments

2 seconds
256 megabytes
Hard

You're given an array of size , you must find the number of majestic ranges (l,r) (1 \le l \le r \le n).

A range (l,r) is considered majestic if and only if the bitwise AND of all the elements in the range equals the length of the range, i.e.

a_l \ \& \ a_{l+1} \ \& \ a_{l+2} \ \& \ ... \ \& \ a_r = r-l+1

must hold.

Input

The first line of the input contains an integer (1 \le t \le 2 \cdot 10^5) — the number of testcases.

The description for the test cases follows.

The first line of each test case contains a single integer (1 \le n \le 2 \cdot 10^5) — the size of the array .

The second line of each test case contains integers a_1 , a_2 , ... , a_n (0 \le a_i \le 10^9) — the elements of the array .

It is guaranteed that the sum of over all test cases does not exceed 2 \cdot 10^5.

Output

For each test case output a single integer, the number of majestic ranges.

Examples

Example 1

Loading
Loading

Note

In the first test case, the majestic segments are:

  1. : a_1=1 and its length is and its bitwise is as well so it's majestic.

  2. : a_2 \ \& \ a_3=2 \ \& \ 3=2 and the length is so it's majestic.

In the second test case, the majestic segments are:

  1. : a_1 \ \& \ a_2 \ \& \ a_3 \ \& \ a_4=4 \ \& \ 12 \ \& \ 6 \ \& \ 5=4 and the length is so it's majestic.

  2. : a_5=1 and its length is and its bitwise is as well so it's majestic.

Scoring

  • Subtask ( points): (\sum n \le 1000)

  • Subtask ( points): (a_i=a_j) for all (1 \le i,j \le n)

  • Subtask ( points): No additional constraints