#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') {
      f = -1;
    }
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const long long maxnum = 500005;
long long a[maxnum];
map<long long, long long> mp;
signed main() {
  long long T = read();
  while (T--) {
    long long n = read();
    mp.clear();
    for (long long i = 1; i <= n; i++) {
      a[i] = read();
    }
    for (long long i = 1; i <= n; i++) {
      long long MAX = 0;
      for (long long j = 0; j <= 31; j++) {
        if (a[i] & (1 << j)) MAX = j;
      }
      mp[MAX]++;
    }
    long long ans = 0;
    for (auto it : mp) {
      ans += (it.second * (it.second - 1) / 2);
    }
    cout << ans << endl;
  }
  return 0;
}
