#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int largest_set_bit(int x) {
  if (x == 0) return -1;
  return (31 - __builtin_clz(x));
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    ll total = 0;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      int a, x;
      cin >> a;
      x = largest_set_bit(a);
      total += mp[x]++;
    }
    cout << total << endl;
  }
}
