#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  long long int a[n];
  long long int i, j;
  map<long long int, long long int> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    for (j = 40; j >= 0; j--) {
      long long int p = 1LL << j;
      if (a[i] & p) {
        m[j]++;
        break;
      }
    }
  }
  long long int sum = 0;
  for (i = 0; i <= 40; i++) {
    if (m[i] >= 2) {
      sum += ((m[i] * (m[i] - 1)) / 2);
    }
  }
  cout << sum << "\n";
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
