#include <bits/stdc++.h>
using namespace std;
int n;
long long got[100];
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i <= 30; i++) got[i] = 0;
    long long cur = 0;
    for (int i = 1; i <= n; i++) {
      int a;
      cin >> a;
      int mx = 0;
      while (a > 0) {
        a /= 2;
        if (a > 0) mx++;
      }
      got[mx]++;
    }
    long long ans = 0;
    for (int i = 0; i <= 30; i++) {
      long long tmp = got[i] - 1;
      ans = ans + got[i] * tmp / (long long)2;
    }
    cout << ans << endl;
  }
}
