#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int inf = 1e8;
const int mod = 1e9 + 7;
long long num[33];
int main() {
  int Tcase;
  cin >> Tcase;
  while (Tcase--) {
    memset(num, 0, sizeof(num));
    int n;
    scanf("%d", &n);
    int k;
    long long sum = 0;
    for (int i = (0); i < (n); ++i) {
      scanf("%d", &k);
      int w = 0;
      while (k > 0) {
        w++;
        k >>= 1;
      }
      num[w]++;
    }
    for (int i = (0); i <= (32); ++i) {
      sum += num[i] * (num[i] - 1) / 2;
    }
    printf("%lld\n", sum);
  }
  return 0;
}
