#include <bits/stdc++.h>
using namespace std;
int FuN(long long n) {
  string s;
  while (n != 0) {
    int ch = (n % 2);
    s += ch + '0';
    n /= 2;
  }
  int x = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') x = i + 1;
  }
  return x;
}
int main() {
  int t, n, i, j;
  t = 1;
  cin >> t;
  while (t--) {
    long long ans = 0, fg = 1, a[200005], cnt = 0, x;
    cin >> n;
    map<long long, long long> m;
    for (i = 1; i <= n; i++) {
      cin >> a[i];
      x = FuN(a[i]);
      m[x]++;
    }
    for (auto it : m) {
      ans += (it.second * (it.second - 1)) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
