#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    long long ans = 0;
    for (int i = 30; i >= 0; i--) {
      vector<int> v1;
      int cnt1 = 0, cnt2 = 0;
      for (int x : v) {
        if (x & (1 << i)) {
          cnt1++;
        } else {
          cnt2++;
          v1.push_back(x);
        }
      }
      ans += (1LL * cnt1 * (cnt1 - 1));
      int len = v.size();
      while (len--) v.pop_back();
      for (int x : v1) v.push_back(x);
    }
    cout << ans / 2 << "\n";
    ;
  }
  return 0;
}
