#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  int freq[31];
  while (t--) {
    int n;
    cin >> n;
    int arr[n + 1];
    memset(freq, 0, sizeof(freq));
    long long tot = 0;
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
      for (int j = 30; j >= 0; j--) {
        if (arr[i] & (1 << j)) {
          tot += freq[j];
          freq[j]++;
          break;
        }
      }
    }
    cout << tot << "\n";
  }
}
