#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long mem[34] = {}, ans = 0;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      ans += mem[(int)log2(x)];
      mem[(int)log2(x)]++;
    }
    cout << ans << endl;
  }
  return 0;
}
