#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n;
    cin >> n;
    map<int64_t, int64_t> mp;
    for (int64_t i = 0; i < n; i++) {
      int64_t x;
      cin >> x;
      bitset<32> kk = x;
      for (int64_t j = 31; j > -1; j--) {
        if (kk[j] == 1) {
          mp[j]++;
          break;
        }
      }
    }
    int64_t ans = 0;
    for (auto i : mp) {
      ans += ((i.second - 1) * (i.second) / 2);
    }
    cout << ans << "\n";
  }
  return 0;
}
