#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double EXP = 1e-9;
int a[40];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t, n, x;
  cin >> t;
  while (t--) {
    long long cnt = 0;
    memset(a, 0, sizeof a);
    cin >> n;
    for (int i = 0; i < n; ++i) {
      cin >> x;
      for (int j = 31; j >= 0; --j) {
        if ((1 << j) & x) {
          a[j]++;
          break;
        }
      }
    }
    for (int j = 31; j >= 0; --j) {
      cnt += (a[j]) * 1ll * (a[j] - 1) / 2;
    }
    cout << cnt << '\n';
  }
  return 0;
}
