#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 9;
long long g(long long n) {
  string s = "";
  while (n) {
    s += (n % 2) + '0';
    n /= 2;
  }
  long long pos = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      pos = i;
    }
  }
  return pos;
}
void slv() {
  long long n;
  cin >> n;
  long long ans = 0LL;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    mp[g(a)]++;
  }
  for (long long i = 0; i <= 32; i++) {
    if (mp[i]) ans += (mp[i] * (mp[i] - 1)) / 2;
  }
  cout << ans << endl;
}
int main() {
  long long t;
  cin >> t;
  long long cs = 1;
  while (t--) {
    slv();
  }
  return 0;
}
