#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const long long N = (long long)2e5 + 100;
long long dr[4] = {0, 0, 1, -1};
long long dc[4] = {1, -1, 0, 0};
long long ddr[8] = {0, 0, 1, -1, 1, -1, 1, -1};
long long ddc[8] = {1, -1, 0, 0, 1, -1, -1, 1};
long long ddr1[8] = {1, 1, -1, -1, 2, 2, -2, -2};
long long ddc1[8] = {2, -2, 2, -2, 1, -1, 1, -1};
int32_t main() {
  fast();
  long long t, z;
  cin >> t;
  for (long long z = 1; z < t + 1; z++) {
    long long n, x, y;
    cin >> n;
    map<long long, long long> m;
    for (long long i = 0; i < n; i++) {
      cin >> x;
      y = log2(x);
      y++;
      m[y]++;
    }
    vector<long long> ans;
    for (auto i : m) {
      ans.emplace_back(i.second);
    }
    long long nn = ans.size();
    long long cnt = 0;
    for (long long i = 0; i < nn; i++) {
      long long temp = ans[i] * (ans[i] - 1);
      cnt += temp / 2;
    }
    cout << cnt << "\n";
  }
}
