#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
long long fun(long long n) {
  string s;
  while (n != 0) {
    s.push_back(n % 2 + '0');
    n /= 2;
  }
  long long pos = -1;
  long long i;
  for (i = 0; i < s.length(); i++)
    if (s[i] == '1') pos = i;
  return pos;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long i, j, n;
    cin >> n;
    vector<long long> a(n);
    for (i = 0; i < n; i++) cin >> a[i];
    map<long long, long long> m;
    for (auto in : a) {
      long long tmp = fun(in);
      m[tmp]++;
    }
    long long tot = 0;
    for (auto in : m) tot += (in.second * (in.second - 1)) / 2;
    cout << tot << endl;
  }
}
