#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 10;
const int M = 100000 + 10;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
long long n, cnt[32] = {0};
long long ep[31];
void init() {
  ep[0] = 1;
  for (int i = 1; i < 31; i++) ep[i] = ep[i - 1] * 2;
}
inline void Count(int x) {
  for (int i = 30; i >= 0; i--) {
    if (x < ep[i] && x >= ep[i - 1]) cnt[i]++;
  }
}
int main() {
  long long t, x;
  cin >> t;
  init();
  while (t--) {
    long long ans = 0;
    memset(cnt, 0, sizeof(cnt));
    scanf("%I64d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%I64d", &x);
      Count(x);
    }
    for (int i = 0; i < 32; i++) {
      if (cnt[i] > 1) ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
