#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  vector<int> count(32, 0);
  for (int i = 0; i < n; i++) {
    int bit = 0;
    while ((1 << (bit + 1)) <= nums[i]) {
      bit++;
    }
    count[bit]++;
  }
  long long ans = 0;
  for (int bit = 0; bit < 32; bit++) {
    ans += (long long)count[bit] * (count[bit] - 1) / 2;
  }
  cout << ans << endl;
  return;
}
int main() {
  int test;
  cin >> test;
  while (test--) solve();
  return 0;
}
