#include <bits/stdc++.h>
using namespace std;
bool comp(int x, int y) { return x > y; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  long long m, n, k;
  string a, b;
  while (t--) {
    cin >> n;
    vector<long long> vec(n);
    for (long long i = 0; i < n; i++) cin >> vec[i];
    map<long long, long long> mp;
    for (long long i = 0; i < n; i++) {
      long long k = (long long)(log2(vec[i]));
      mp[k] += 1;
    }
    map<long long, long long>::iterator it = mp.begin();
    long long ans = 0;
    while (it != mp.end()) {
      ans += ((it->second) * (it->second - 1)) / 2;
      ++it;
    }
    cout << ans << '\n';
  }
}
