#include <bits/stdc++.h>
using namespace std;
long long msb(long long n) {
  long long cnt = 0;
  while (n / 2 > 0) {
    n /= 2;
    cnt++;
  }
  return cnt;
}
long long a[100001];
int main() {
  long long t, n, loss;
  cin >> t;
  while (t--) {
    map<long long, long long> mp;
    map<long long, long long>::iterator it;
    cin >> n;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      mp[msb(a[i])]++;
    }
    long long res = 0;
    for (it = mp.begin(); it != mp.end(); it++) {
      long long x = it->second;
      res += ((x - 1) * x) / 2;
    }
    cout << res << endl;
  }
  return 0;
}
