#include <bits/stdc++.h>
using namespace std;
const long double Pi = 3.141592653;
const unsigned long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long n, i, j, k, a[35], ans = 0, r;
    cin >> n;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) {
      cin >> j;
      k = log2(j);
      a[k]++;
    }
    for (i = 0; i <= 30; i++) {
      if (a[i] > 1) {
        r = a[i] * (a[i] - 1) / 2;
        ans += r;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
