#include <bits/stdc++.h>
using namespace std;
vector<long long int> dp;
long long int base(long long int val) {
  long long int l = 0;
  long long int r = dp.size() - 1;
  long long int mid = 0;
  long long int res = 0;
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (dp[mid] <= val) {
      res = dp[mid];
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  for (auto &i : v) cin >> i;
  map<long long int, long long int> mp;
  for (auto i : v) {
    mp[base(i)]++;
  }
  long long int cnt = 0;
  for (auto i : mp) {
    cnt += (i.second * (i.second - 1)) / 2;
  }
  cout << cnt << endl;
}
int main() {
  long long int two = 1;
  for (int i = 0; i <= 30; i++) {
    dp.push_back(two);
    two *= 2;
  }
  int t = 1;
  cin >> t;
  while (t--) solve();
}
