#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct Trie {
static const int rangeSize = 2; // for 0 and 1 (0, 1)
struct node {
node *next[rangeSize];
bool completedNum;
int cnt;
node() {
completedNum = false;
cnt = 0;
for (int i = 0; i < rangeSize; i++)
next[i] = nullptr;
}
} *root;
Trie() {
root = new node();
}
void trieInsert(const string &s) {
node *cur = root;
for (char ch : s) {
int x = ch - '0'; //
if (cur->next[x] == nullptr) {
cur->next[x] = new node();
}
cur = cur->next[x];
cur->cnt += 1;
}
cur->completedNum = true;
}
ll trieSearch(const string &s1, const string &s2) {
ll ans = 0;
node *cur = root;
for (int i = 0; i < s1.size(); i++) {
int x = s1[i] - '0';
int y = s2[i] - '0';
if(x == 0)
{
if(y == 0)
{
if(cur->next[1] != nullptr)ans += cur->next[1]->cnt;
}
else{
if(cur->next[0] != nullptr)ans += cur->next[0]->cnt;
}
if(cur->next[y] != nullptr)
{
cur = cur->next[y];
}
else{
return ans;
}
}
else{
if(y == 0)
{
if(cur->next[1] != nullptr)
{
cur = cur->next[1];
}
else{
return ans;
}
}
else{
if(cur->next[0] != nullptr)
{
cur = cur->next[0];
}
else{
return ans;
}
}
}
}
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); // Delete all nodes
root = new node(); // Re-initialize root node for reuse
}
~Trie() { // Destructor
reset(root);
}
} trie;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int tc = 1;
cin >> tc;
while (tc--) {
trie.clear(); // <===
int n, q;
cin >> n;
vector<int>v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
ll ans = 0;
for(int i = n; i >= 1; i--)
{
int val = (v[i - 1] ^ i);
string s1 = bitset<31> (val).to_string();
string s2 = bitset<31> (i).to_string();
ans += trie.trieSearch(s1, s2);
trie.trieInsert(s1);
}
cout << ans << endl;
}
return 0;
}