#include <bits/stdc++.h>
using namespace std;
signed main() {
  int_fast64_t T;
  scanf("%lld", &T);
  while (T--) {
    int_fast64_t N;
    scanf("%lld", &N);
    map<int_fast64_t, int_fast64_t> f;
    int_fast64_t ans{};
    for (int_fast64_t i = 0; i < N; ++i) {
      int_fast64_t X;
      scanf("%lld", &X);
      ans += f[__builtin_clz(X)]++;
    }
    printf("%lld\n", ans);
  }
}
