#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> vc(n);
  for (auto& it : vc) cin >> it;
  vector<int> hg(n);
  for (int i = 0; i < n; ++i) {
    int x = vc[i];
    for (int j = 30; j >= 0; --j)
      if ((x >> j) & 1) {
        hg[i] = j;
        break;
      }
  }
  long long ans = 0;
  vector<int> cnt(32, 0);
  for (int i = n - 1; i >= 0; --i) {
    ans += cnt[hg[i]]++;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
