#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, n, j, m, elem;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> a(n);
    vector<long long> si(n);
    for (i = 0; i < n; i++) {
      cin >> elem;
      long long z = 1;
      long long k = 0;
      while (z <= elem) {
        k++;
        z *= 2;
      }
      a[i] = elem;
      si[i] = k;
    }
    sort(si.begin(), si.end());
    long long k = 0;
    long long rez = 0;
    for (i = 1; i < n; i++) {
      if (si[i] == si[i - 1]) {
        k++;
      } else {
        rez += k * (k + 1) / 2;
        k = 0;
      }
    }
    rez += k * (k + 1) / 2;
    cout << rez << endl;
  }
  return 0;
}
