#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using LL = long long;
constexpr int N = 100001;
int b[33];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= 32; i++) b[i] = 0;
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      int x = 0;
      while (temp) {
        x++;
        temp >>= 1;
      }
      b[x]++;
    }
    LL ans = 0;
    for (int i = 1; i <= 32; i++) ans += (LL)b[i] * (b[i] - 1) / 2;
    cout << ans << "\n";
  }
  return 0;
}
