#P7459. [2017年杭电多校]Kanade's trio

[2017年杭电多校]Kanade's trio

Kanade's trio

Problem Description

Give you an array A[1..n]A[1..n]£¬you need to calculate how many tuples (i,j,k)(i,j,k) satisfy that (i<j<k)(i<j<k) and ((A[i] xor A[j])<(A[j] xor A[k]))((A[i]~xor~A[j])<(A[j]~xor~A[k])) There are T test cases. 1T201\leq T\leq 20 1n51051\leq \sum n\leq 5*10^5 0A[i]<2300\leq A[i] <2^{30}

Input

There is only one integer T on first line. For each test case , the first line consists of one integer nn ,and the second line consists of nn integers which means the array A[1..n]A[1..n]

Output

For each test case , output an integer , which means the answer.

Sample Input

1
5
1 2 3 4 5

Sample Output

6

Source

2017 Multi-University Training Contest - Team 3

https://acm.hdu.edu.cn/showproblem.php?pid=6059