#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (auto &x : a) cin >> x;
  map<long long, long long> m;
  for (auto &x : a) {
    long long t = x;
    t = t / 2;
    long long msb = 0;
    while (t > 0) {
      t = t / 2;
      msb++;
    }
    m[msb]++;
  }
  long long ans = 0LL;
  for (auto &x : m) ans += (x.second * (x.second - 1LL) / 2LL);
  cout << ans;
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
    cout << endl;
  }
  return 0;
}
