#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    map<long long int, long long int> mp;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      int c = floor(log2(a[i])) + 1;
      if (mp.find(c) != mp.end()) {
        mp[c]++;
      } else {
        mp[c] = 1;
      }
    }
    long long int ans = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      ans += ((it->second) * (it->second - 1)) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
