#include <bits/stdc++.h>
using namespace std;
long long int powOfPositive(long long int n) {
  long long int pos = floor(log2(n));
  return pos;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> arr(n);
    for (long long int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    vector<long long int> dp(30, 0);
    long long int ans = 0;
    for (long long int i = 0; i < n; i++) {
      if (arr[i] == 1) {
        dp[0]++;
        continue;
      }
      long long int x = powOfPositive(arr[i]);
      dp[x]++;
    }
    for (long long int i = 0; i < 30; i++) {
      if (dp[i] > 0) {
        ans += ((dp[i]) * (dp[i] - 1)) / 2;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
