#include <bits/stdc++.h>
using namespace std;
void serotonin() {}
int32_t main() {
  serotonin();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long a;
    cin >> a;
    unordered_multiset<long long> mst;
    long long r;
    for (long long i = 0; i < a; i++) {
      cin >> r;
      mst.insert(r);
    }
    long long ans = 0, x = 0, kk = 0;
    for (long long i = 33; i >= 0; i--) {
      x = 0;
      for (auto itr = mst.begin(); itr != mst.end();) {
        kk = *itr;
        if (kk & (1ll << i)) {
          x++;
          auto z = itr;
          z++;
          mst.erase(itr);
          itr = z;
        } else
          itr++;
      }
      ans += x * (x - 1) / 2;
    }
    cout << ans << "\n";
  }
  return 0;
}
