#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  long long a[n], b[n], c = 0, ans = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int m = a[n - 1], x = 1;
  while (m / x != 1) {
    x = x * 2;
  }
  while (x > 0) {
    c = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] / x == 1) c++;
    }
    ans += c * (c - 1) / 2;
    x = x / 2;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long testCases = 1;
  cin >> testCases;
  while (testCases--) {
    solve();
  }
  return 0;
}
