#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll _;
  cin >> _;
  while (_--) {
    ll n;
    cin >> n;
    map<ll, ll> mp;
    for (ll i = 0; i < n; ++i) {
      ll u;
      cin >> u;
      ll v = u;
      ll tmp = 0;
      while (v != 0) {
        v >>= 1;
        tmp++;
      }
      mp[tmp]++;
    }
    ll ans = 0;
    for (auto i : mp) {
      ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
