#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 ^ X) >= Q
void query_count(int X, int Q) {
int v = 0;
for (int b = BITLEN - 1; b >= 0; --b) {
if (v == 0 && !created[v]) return;
int xb = (X >> b) & 1;
int qb = (Q >> b) & 1;
if (qb == 1) {
// must go to branch where (y_bit ^ xb) == 1
int nb = xb ^ 1;
int nxt = Next[nb][v];
if (!created[nxt]) return;
v = nxt;
} else {
// qb == 0: any branch with (y_bit ^ xb)==1 gives >Q
int nb = xb ^ 1;
int cnode = Next[nb][v];
if (created[cnode]) answer += SubCnt[cnode];
// continue down equal branch (y_bit ^ xb)==0
int eb = xb;
int nxt = Next[eb][v];
if (!created[nxt]) return;
v = nxt;
}
}
// matched full prefix => XOR == Q => >= Q
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];
// transform: f[i] = (i+1) ^ a[i]
for (int i = 0; i < N; ++i) {
a[i] ^= (i + 1);
}
// reset trie
sz = 0;
answer = 0;
for (int i = 0; i <= BITLEN * N; ++i) {
created[i] = false;
Next[0][i] = Next[1][i] = 0;
SubCnt[i] = EndCnt[i] = 0;
}
created[0] = true;
// sweep i=N-1..0: count f_j with (f_j ^ (i+1)) > f_i
for (int i = N - 1; i >= 0; --i) {
int X = i + 1;
int Qi = a[i] + 1;
query_count(X, Qi);
insert_val(a[i]);
}
cout << answer << "\n";
}
return 0;
}