#include <bits/stdc++.h>
using namespace std;
void func(long long int n) {
  long long int arr[n];
  long long int count = 0;
  long long int c;
  unordered_map<long long int, long long int> m;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    c = (long long int)log2(arr[i]) + 1;
    m[c]++;
  }
  for (auto x : m) {
    count = count + ((x.second) * (x.second - 1)) / 2;
  }
  cout << count;
  return;
}
int main() {
  long long int t, n;
  cin >> t;
  for (long long int it = 0; it < t; it++) {
    cin >> n;
    func(n);
    cout << endl;
  }
  return 0;
}
