#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
void solve() {
  int n;
  cin >> n;
  vector<int> v[32];
  for (int i = 0; i < n; i++) {
    long long num;
    cin >> num;
    for (int i = 31; i >= 0; i--) {
      if (num & (1LL << i)) {
        v[i].push_back(num);
        break;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 32; i++) {
    ans += (v[i].size() * 1LL * (v[i].size() - 1)) / 2;
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
