#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
long long ans = 0;
o_set<pair<int, int>> st;
for (int i = 1; i <= n; ++i)
{
int x;
cin >> x;
int d = (i ^ x);
ans += st.order_of_key({d, INT_MAX});
st.insert({d, i});
}
cout << ans << '\n';
}
return 0;
}