#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
struct Trie {
static const int rangeSize = 2;
static const char startingChar = '0';
struct node {
node *next[rangeSize];
int cnt;
node() {
cnt = 0;
for (int i = 0; i < rangeSize; i++)
next[i] = nullptr;
}
} *root;
Trie() {
root = new node();
}
void Insert(const string &s) {
node *cur = root;
for (char ch : s) {
int x = ch - startingChar;
if (cur->next[x] == nullptr) {
cur->next[x] = new node();
}
cur = cur->next[x];
cur->cnt += 1;
}
}
int Search(const string &s1, const string &s2) {
node *cur = root;
int ans = 0;
for(int p = 0; p < s1.size(); p++) {
int x = s1[p] - '0';
int i = s2[p] - '0';
if(x == 0) {
if(cur->next[i ^ 1] != nullptr) ans += cur->next[i ^ 1]->cnt;
if(cur->next[i] == nullptr) return ans;
cur = cur->next[i];
}
else {
if(cur->next[i ^ 1] == nullptr) return ans;
cur = cur->next[i ^ 1];
}
}
return ans;
}
void reset(node* cur) {
for(int i = 0; i < rangeSize; i++)
if(cur->next[i])
reset(cur->next[i]);
delete cur;
}
void clear() {
reset(root);
root = new node();
}
~Trie() { // Destructor
reset(root);
}
} trie;
// ai ^ i < (aj ^ i) ^ j
// ai ^ i < aj ^ j ^ i
// let, x = ai ^ i, y = aj ^ j
// x < y ^ i
void solve() {
int n;
cin >> n;
vector<int> a(n);
for(auto &i: a) cin >> i;
ll ans = 0;
trie.clear();
for(int i = n; i >= 1; i--) {
int x = a[i - 1] ^ i;
string s1 = bitset<30> (x).to_string();
string s2 = bitset<30> (i).to_string();
ans += trie.Search(s1, s2);
trie.Insert(s1); // update y
}
cout << ans << endl;
return;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case " << t << ": ";
solve();
}
return 0;
}