#include <bits/stdc++.h>
using namespace std;
long long int power[32] = {0};
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  for (long long int j = 0; j < n; j++) cin >> v[j];
  long long int cnt[32] = {0};
  for (long long int j = 0; j < n; j++) {
    long long int h = 0;
    while (power[h] < v[j]) h++;
    if (power[h] > v[j]) h--;
    cnt[h]++;
  }
  long long int res = 0;
  for (long long int j = 0; j < 32; j++) {
    res += (cnt[j] * (cnt[j] - 1)) / 2;
  }
  cout << res << '\n';
  return;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  power[0] = 1;
  for (long long int j = 1; j <= 30; j++) power[j] = power[j - 1] * 2;
  while (t--) {
    solve();
  }
  return 0;
}
