#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>>& adj, vector<bool>& vis, int src) {
  vis[src - 1] = true;
  for (int i = 0; i < adj[src - 1].size(); i++) {
    if (!vis[adj[src - 1][i] - 1]) dfs(adj, vis, adj[src - 1][i]);
  }
  return;
}
void bfs(vector<vector<int>>& adj, vector<bool>& vis, int src) {
  queue<int> q;
  q.push(src);
  while (!q.empty()) {
    int temp = q.front();
    for (int i = 0; i < adj[temp - 1].size(); i++) {
      if (!vis[temp - 1]) q.push(adj[temp - 1][i]);
    }
  }
  return;
}
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> a(n), tp(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      tp[i] = ((long long)(log2(a[i]))) + 1;
    }
    sort(tp.begin(), tp.end());
    long long int cnt = 1;
    long long int ans = 0;
    for (int i = 1; i < n; i++) {
      if (tp[i] != tp[i - 1]) {
        ans += (cnt * (cnt - 1)) / 2;
        cnt = 1;
      } else {
        cnt++;
      }
    }
    ans += (cnt * (cnt - 1)) / 2;
    cout << ans << endl;
  }
  return 0;
}
