#include <bits/stdc++.h>
using namespace std;
long long t, n, a[100010], b[100010], c[100], w, e;
long long ans = 0;
void init() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= 90; i++) c[i] = 0;
  sort(a + 1, a + n + 1);
  w = 1;
  for (int i = 1; i <= n; i++) {
    while (a[i] > ((1 << w) - 1)) w++;
    b[i] = w;
    c[w]++;
  }
  ans = 0;
  for (int i = 1; i <= w; i++) ans = ans + (c[i] - 1) * c[i] / 2;
  cout << ans << endl;
}
int main() {
  cin >> t;
  for (int q = 1; q <= t; q++) init();
  return 0;
}
