#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int ar[n], arr[31];
    memset(arr, 0, sizeof(arr));
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    for (int i = 0; i < n; i++) {
      int k;
      k = (int)log2(ar[i]);
      arr[k + 1]++;
    }
    long long int sum = 0;
    for (int i = 1; i < 31; i++) {
      sum = sum + ((long long int)arr[i] * (arr[i] - 1)) / 2;
    }
    cout << sum << endl;
  }
  return 0;
}
