#include <bits/stdc++.h>
using namespace std;
long long check(long long x) {
  long long i = 0, ans = 0;
  while (x > 0) {
    if ((x & (1)) == 1) {
      ans = max(ans, i);
    }
    x = x >> 1;
    i++;
  }
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n + 1];
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mp[check(a[i])]++;
  }
  long long ans = 0;
  for (auto x : mp) {
    if (x.second > 1) ans += ((x.second) * (x.second - 1)) / 2;
  }
  cout << ans << endl;
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
