#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    map<int, int> m;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      if (m.find(log2(a[i])) != m.end()) ans += m[log2(a[i])];
      m[log2(a[i])]++;
    }
    cout << ans << endl;
  }
}
