#include <bits/stdc++.h>
using namespace std;
long long solve(int N, const vector<int>& A) {
  long long res = 0;
  vector<int> freq(32);
  for (int x : A) {
    int hsb = (sizeof(int) * 8 - 1 - __builtin_clz((x)));
    res += freq[hsb];
    ++freq[hsb];
  }
  return res;
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int TC;
  cin >> TC;
  for (int tc = (1), _b = (TC); tc <= _b; ++tc) {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0, _n = (N); i < _n; ++i) cin >> A[i];
    long long res = solve(N, A);
    cout << res << '\n';
  }
  return 0;
}
