#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> adj;
map<long, bool> vis, viss;
vector<long long> rnk, parent, sz;
long long int setBitNumber(long long int n) {
  if (n == 0) return 0;
  long long int msb = 0;
  n = n / 2;
  while (n != 0) {
    n = n / 2;
    msb++;
  }
  return (1 << msb);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v;
    long long temp;
    map<long long, long long> mp;
    bool bl = false;
    for (long long i = 0; i < n; i++) {
      cin >> temp;
      v.push_back(temp);
      mp[setBitNumber(temp)]++;
    }
    long long ans = 0;
    for (auto x : mp) {
      long long s = x.second;
      ans = ans + s * (s - 1) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
