#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int base = 257;
const int M = 1e6 + 1;
const int INFI = 1e8;
long long Hash[M], po[M];
long long gethash(long long l, long long r) {
  return ((Hash[r] - Hash[l - 1] * po[r - l + 1] + MOD * MOD) % MOD);
}
void precomputehashing() {
  po[0] = 1;
  for (int i = 1; i <= M; i++) po[i] = (po[i - 1] * base) % MOD;
  string s;
  s = " " + s;
  for (int i = 1; i <= s.size() - 1; i++)
    Hash[i] = (Hash[i - 1] * base + s[i] - '*' + 1) % MOD;
}
long long fac[N], ifac[N];
long long PowerMod(long long a, long long n) {
  long long ret = 1;
  while (n) {
    if (n & 1) {
      ret *= a;
      ret %= MOD;
    }
    a *= a;
    a %= MOD;
    n /= 2;
  }
  return ret;
}
void precomputecombinatoris() {
  int i;
  fac[0] = 1;
  for (i = 1; i < N; i++) {
    fac[i] = (i * fac[i - 1]) % MOD;
  }
  ifac[N - 1] = PowerMod(fac[N - 1], MOD - 2);
  for (i = N - 2; i >= 0; i--) {
    ifac[i] = ((i + 1) * ifac[i + 1]) % MOD;
  }
}
long long C(int r, int n) {
  long long ret = fac[n];
  ret *= ifac[r];
  ret %= MOD;
  ret *= ifac[n - r];
  ret %= MOD;
  return ret;
}
int a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int cur = 1;
    int cnt = 0;
    long long res = 0;
    for (int i = 1; i <= n; i++) {
      while (cur * 2 <= a[i]) {
        cur *= 2;
        cnt = 0;
      }
      res += cnt;
      cnt++;
    }
    cout << res << "\n";
  }
  return 0;
}
