#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int a[maxn], d[maxn], b[maxn][34], c[34];
int T, k, t, n;
void sovle() {
  for (int i = 1; i <= 33; ++i) c[i] = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= 33; ++j) b[i][j] = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    k = 0;
    t = a[i];
    while (t != 0) {
      ++k;
      b[i][k] = t % 2;
      t = t / 2;
    }
  }
  for (int i = 1; i <= n; ++i) {
    int j;
    for (j = 33; j >= 1; --j)
      if (b[i][j]) break;
    c[j]++;
    d[i] = j;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += c[d[i]] - 1;
  }
  ans = ans / 2;
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    sovle();
  }
  return 0;
}
