#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXNODES = 30 * 300001;
int Next[2][MAXNODES]; // child pointers: Next[bit][node]
bool created[MAXNODES]; // whether node exists
ll EndCnt[MAXNODES]; // number of values ending at this node
ll SubCnt[MAXNODES]; // number of values passing through this node
int sz;
ll answer;
int BITLEN = 30;
void insert_val(int x) {
int v = 0;
for (int b = BITLEN - 1; b >= 0; --b) {
int c = (x >> b) & 1;
if (!created[ Next[c][v] ]) {
Next[c][v] = ++sz;
created[ sz] = true;
}
v = Next[c][v];
SubCnt[v]++;
}
EndCnt[v]++;
}
// count how many y inserted satisfy y > Q
void search(int X, int Q) {
int v = 0;
for (int b = BITLEN - 1; b >= 0; --b) {
//if (!created[v]) return;
int xb = (X >> b) & 1;
int qb = (Q >> b) & 1;
int yb = qb ^ 1;
if (xb == 0) {
int alt = Next[yb][v];
if (created[alt]) answer += SubCnt[alt];
if(!created[Next[yb^1][v]])break;
v = Next[yb^1][v];
} else {
v = Next[yb][v];
if(!created[v])break;
}
}
// if (created[v]) answer += EndCnt[v];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i) cin >> a[i];
// Reset trie
sz = 0;
answer = 0;
int nodes = BITLEN * N + 5;
for (int i = 0; i <= nodes; ++i) {
created[i] = false;
Next[0][i] = Next[1][i] = 0;
SubCnt[i] = EndCnt[i] = 0;
}
for (int i = N - 1; i >= 0; --i) {
int xi = i + 1;
int fi = xi ^ a[i];
search(fi, xi);
insert_val(fi);
}
cout << answer << '\n';
}
return 0;
}