#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long count = 0;
  long long b[32] = {0};
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    long long c = 0;
    while (x > 0) {
      x = x / 2;
      c++;
    }
    b[c - 1]++;
  }
  for (long long i = 0; i < 32; i++) {
    if (b[i] >= 2) count = count + (b[i] * (b[i] - 1) / 2);
  }
  cout << count << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
