#include <bits/stdc++.h>
using namespace std;
int most_sig_digit(int n) {
  if (n == 0) return 0;
  int msb = 0;
  n = n / 2;
  while (n != 0) {
    n = n / 2;
    msb++;
  }
  return msb;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, f, anss = 0;
    cin >> n;
    vector<long long> a(n), H(51, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (long long i = 0; i < n; i++) {
      f = most_sig_digit(a[i]);
      H[f]++;
    }
    for (int i = 0; i < 50; i++) {
      anss += H[i] * (H[i] - 1) / 2;
    }
    cout << anss << "\n";
  }
  return 0;
}
