#include <bits/stdc++.h>
using namespace std;
int n, t, a[100005], b[100005];
long long int ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    int j;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      j = 1;
      while (j <= a[i]) {
        j = j << 1;
      }
      b[i] = j - 1;
    }
    map<int, long long int> mp;
    for (int i = 0; i < n; i++) mp[b[i]]++;
    ans = 0;
    for (auto i : mp) {
      ans += (1ll * i.second * (i.second - 1)) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
