#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, a, s, x, y;
  cin >> t;
  vector<long long> v;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a;
      v.push_back(a);
    }
    sort(v.begin(), v.end());
    s = 0;
    y = 0;
    for (long long i = 2; i <= v[v.size() - 1] * 2; i *= 2) {
      x = 0;
      while (y < v.size() && v[y] < i) {
        y++;
        x++;
      }
      s += x * (x - 1) / 2;
    }
    cout << s << endl;
    while (v.size()) v.pop_back();
  }
}
