#include <bits/stdc++.h>
void solve();
int main(int argc, char* argv[]) {
  int tc;
  scanf("%d", &tc);
  while (tc--) solve();
  return 0;
}
void solve() {
  int n;
  scanf("%d", &n);
  std::vector<int> a(n);
  for (int& x : a) scanf("%d", &x);
  int s[66] = {};
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int x = a[i];
    int j = 30;
    while (j >= 0 && !((x >> j) & 1)) --j;
    ans += s[j]++;
  }
  printf("%lld\n", ans);
}
