#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long N = 200005, INF = 2000000000000000000;
const long long SIX = 1000000;
void solve() {
  long long n;
  cin >> n;
  vector<long long> ar(n);
  long long i = 0;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
  }
  long long ans = 0;
  for (long long i = 0; i < 30; i++) {
    long long cnt = 0;
    for (long long j = 0; j < n; j++) {
      if (ar[j] >= (1 << i) && ar[j] < (1 << (i + 1))) {
        cnt++;
      }
    }
    ans += (cnt * (cnt - 1)) / 2;
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
