#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> const &v) {
  return os << '(' << v.ff << ", " << v.ss << ')';
}
template <typename T>
void bug(T const &var) {
  cout << var << '\n';
}
template <typename Type, typename... Args>
void bug(Type const &var, Args const &...args) {
  cout << var << ' ';
  bug(args...);
}
double const pi = acos(-1);
int const maxn = 1e5 + 3;
int a[maxn];
void _main() {
  int n;
  cin >> n;
  long long ans = 0;
  map<int, int> cnt;
  for (int i = (1); i <= (n); ++i) cin >> a[i];
  for (int i = (1); i <= (n); ++i) {
    for (int j = (29); j >= (0); --j) {
      if (a[i] & (1 << j)) {
        ans += cnt[j];
        cnt[j]++;
        break;
      }
    }
  }
  bug(ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  if (1) cin >> t;
  while (t--) {
    _main();
  }
  return 0;
}
