#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long MOD = 1e9 + 7;
const long long INF = LONG_LONG_MAX;
const long long MINF = LONG_LONG_MIN;
const int N = 2e5 + 1;
template <typename T>
inline T abs(T x) {
  return x < 0 ? -x : x;
}
inline long long pow_mod(long long x, long long n) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * x) % MOD;
    x = (x * x) % MOD;
    n >>= 1;
  }
  return r;
}
inline long long pow_(long long x, long long n) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * x);
    x = (x * x);
    n >>= 1;
  }
  return r;
}
inline void solve() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  if (n == 1) {
    printf("%d\n", 0);
    return;
  }
  long long lg[35] = {};
  for (int i = 0; i < n; ++i) ++lg[(int)log2(a[i])];
  long long cnt = 0;
  for (int i = 0; i < 35; ++i)
    if (lg[i]) cnt += (lg[i] * (lg[i] - 1)) / 2;
  printf("%I64d\n", cnt);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  scanf("%d", &t);
  while (t--) solve();
}
