#include <bits/stdc++.h>
using namespace std;
#define ll 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<unordered_map<int, int>> cnt(B);
for (auto &mp : cnt)
mp.reserve(n / 2);
ll ans = 0;
for (int j = 1; j <= n; j++)
{
int aj = a[j];
for (int k = 0; k < B; k++)
{
int left = (((aj >> (k + 1)) ^ (j >> (k + 1))) << 1);
int right = (((aj >> k) & 1) ^ ((j >> k) & 1) ^ 1);
int key = left | right;
auto it = cnt[k].find(key);
if (it != cnt[k].end())
ans += it->second;
}
for (int k = 0; k < B; k++)
{
if (((aj >> k) & 1) == ((j >> k) & 1))
{
int key = ((aj >> (k + 1)) << 1) | ((j >> k) & 1);
cnt[k][key]++;
}
}
}
cout << ans << '\n';
}
return 0;
}