#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, x;
    cin >> n;
    long long int a[n + 2];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long int s[n + 2];
    for (int i = 0; i < n; i++) {
      s[i] = -1;
    }
    for (int i = 0; i < n; i++) {
      x = 1;
      for (int j = 32; j >= 0; j--) {
        if ((x << j) & a[i]) {
          s[i] = j;
          break;
        }
      }
    }
    unordered_map<long long int, long long int> umap;
    for (int i = 0; i < n; i++) {
      if (!(s[i] + 1)) continue;
      umap[s[i]]++;
    }
    long long int total = 0;
    for (auto it = umap.begin(); it != umap.end(); it++) {
      total += (it->second * (it->second - 1) / 2);
    }
    cout << total << "\n";
  }
}
