#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
long long int n, a[N];
void solve() {
  map<long long int, long long int> mp;
  cin >> n;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    long long int msb = log2(a[i]) + 1;
    ans += mp[msb];
    mp[msb]++;
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
