#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int cnt[MAXN + 5];
int bin(int n) {
  int i = 0;
  while (n) {
    n /= 2;
    ++i;
  }
  return i;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    memset(cnt, 0, sizeof(cnt));
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      int a;
      scanf("%d", &a);
      ++cnt[bin(a)];
    }
    long long ans = 0;
    for (int i = 1; i < MAXN; ++i) {
      if (cnt[i] > 1) {
        ans += 1ll * (cnt[i] - 1) * cnt[i] / 2;
      }
    }
    printf("%lld\n", ans);
  }
}
