#include <bits/stdc++.h>
using namespace std;
string s, s1, s2;
vector<int> v, v1, v0;
long long int i, j, k, l, m, n, p, q, z, sump, sumq, sum, cntq, cntp, cnt, mn,
    mx, t, d, r, x, y, gcd;
double f;
char c;
long long a[2000000 + 10], b[20000000 + 10];
long long dp[2000000 + 10];
long long int GCD(long int A, long int B) {
  if (B == 0)
    return A;
  else
    return GCD(B, A % B);
}
long long ll_min(long long x, long long y) {
  if (x > y)
    return y;
  else
    return x;
}
long long ll_max(long long x, long long y) {
  if (x > y)
    return x;
  else
    return y;
}
vector<long long int> adjlist[1000000 + 10];
int visited[1000000 + 10];
vector<pair<long long int, long long int>> pairs, pair1;
int main() {
  cin >> t;
  for (z = 1; z <= t; z++) {
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    i = 0;
    j = 1;
    cnt = 0;
    sum = 0;
    while (i < n) {
      if (a[i] >= j) {
        sum = sum + cnt * (cnt - 1) / 2;
        cnt = 0;
        while (a[i] >= j) {
          j = j * 2;
        }
      }
      if (a[i] < j && a[i] >= j / 2) {
        cnt++;
      }
      i++;
    }
    if (cnt != 0) {
      sum += cnt * (cnt - 1) / 2;
    }
    cout << sum << endl;
  }
  return 0;
}
