#include <bits/stdc++.h>
using namespace std;
long long getMSB(long long n) {
  n |= n >> 1;
  n |= n >> 2;
  n |= n >> 4;
  n |= n >> 8;
  n |= n >> 16;
  n = n + 1;
  return (n >> 1);
}
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
void solve() {
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (auto &a : arr) {
    cin >> a;
  }
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    long long check = getMSB(arr[i]);
    if (isPowerOfTwo(check)) {
      if (m.find(check) == m.end())
        m[check] = 1;
      else
        m[check] += 1;
    }
  }
  long long cnt = 0;
  for (auto a : m) {
    if (a.second > 1) {
      long long x = a.second;
      cnt += (x * (x - 1)) / 2;
    }
  }
  cout << cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << '\n';
  }
  return 0;
}
