#include <bits/stdc++.h>
using namespace std;
long long int zero = 0;
long long int arra[2000009];
long long int l, hi, ans = -1, n, m;
map<long long int, long long int> bits;
map<long long int, long long int> scp;
int main() {
  long long int i, j, p, tp = 2, z = 0, cnt = 0, index = -1, one = 1;
  long long int t;
  long long int k, n;
  cin >> t;
  while (t--) {
    cin >> n;
    cnt = 0;
    long long int ze = 0;
    for (i = 1; i <= n; i++) {
      cin >> p;
      arra[i] = p;
      for (j = 32; j >= 1; j--) {
        if (p & (one << (j - 1))) {
          bits[j]++;
          scp[i] = j;
          break;
        }
      }
    }
    sort(arra + 1, arra + n + 1);
    for (i = 1; i <= n; i++) {
      long long int mx = 0;
      if (bits[scp[i]] > 0) {
        cnt = cnt + bits[scp[i]] - 1;
        bits[scp[i]]--;
      }
    }
    cout << cnt << '\n';
    bits.clear();
    scp.clear();
  }
}
