#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
template <class T>
inline void array_input(T a[], size_t n) {
  for (size_t i = 0; i < n; i++) cin >> a[i];
}
template <class T>
inline void array_init(T a[], size_t n, T value) {
  for (size_t i = 0; i < n; i++) a[i] = value;
}
template <class a, class b, class c>
inline bool bool_print(a flag, b toprint1, c toprint2) {
  if (flag)
    cout << toprint1;
  else
    cout << toprint2;
  return flag;
}
template <class T>
T binExp(T a, T b) {
  T res = 1;
  while (b) {
    if (b % 2) res *= a;
    a *= a;
    b /= 2;
  }
  return res;
}
int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
vector<long long> dp(1000000, INF);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int a[n];
    array_input(a, n);
    int an[100] = {0};
    for (int i = 0; i < n; i++) {
      an[(int)log2(a[i]) + 1]++;
    }
    long long ans = 0;
    for (auto i : an) {
      ans += (long long)i * (i - 1) / 2;
    }
    cout << ans;
    cout << '\n';
  }
  return 0;
}
