#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
const int B = 30;
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<map<int, int>> cnt(B + 1);
int ans = 0;
for (int j = 1; j <= n; j++)
{
int aj = a[j];
for (int k = 0; k < B; k++)
{
int pfx = (aj >> (k + 1)) ^ (j >> (k + 1));
int bit = ((aj >> k) & 1) ^ ((j >> k) & 1) ^ 1;
int key = (pfx << 1) | bit;
auto mp = cnt[k];
auto it = mp.find(key);
if (it != mp.end())
ans += it->second;
}
for (int k = 0; k < B; k++)
{
if (((aj >> k) & 1) == ((j >> k) & 1))
{
int pfx = aj >> (k + 1);
int key = (pfx << 1) | ((j >> k) & 1);
cnt[k][key]++;
}
}
}
cout << ans << '\n';
}
return 0;
}