#include <bits/stdc++.h>
using namespace std;
long long int setBitNumber(long long int n) {
  n |= n >> 1;
  n |= n >> 2;
  n |= n >> 4;
  n |= n >> 8;
  n |= n >> 16;
  n = n + 1;
  return (n >> 1);
}
int main() {
  long long int t, n, i;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int a[n], v, c = 0;
    map<long long int, long long int> m;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      v = setBitNumber(a[i]);
      if (m.find(v) == m.end())
        m[v] = 1;
      else
        m[v]++;
    }
    for (auto it = m.begin(); it != m.end(); it++) {
      v = it->second;
      v--;
      c = c + ((v * (v + 1)) / 2);
    }
    cout << c << "\n";
  }
  return 0;
}
