#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int sr = power(a, b >> 1);
  long long int r = sr * sr;
  if (b & 1) r = a * r;
  return r;
}
void solve() {
  long long int z = power(2, 0);
  cin >> n;
  vector<long long int> v(n);
  long long int ans = 0;
  long long int p = 1;
  for (long long int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  long long int count = 0;
  for (long long int i = 0; i < n; i++) {
    if (v[i] >= z) {
      ans += (count * (count - 1) / 2);
      while (v[i] >= z) {
        z = power(2, p);
        p++;
      }
      count = 0;
    }
    count++;
  }
  ans += (count * (count - 1) / 2);
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int x;
  cin >> x;
  for (long long int i = 1; i <= x; i++) solve();
  return 0;
}
