#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int cnt[32];
int main() {
  std::ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n, t, cur;
    cin >> n;
    memset(cnt, 0, sizeof(cnt));
    long long res = 0;
    for (int i = 0; i < n; i++) {
      cin >> t;
      for (int j = 31; j >= 0; j--)
        if (t & (1 << j)) {
          cur = j;
          break;
        }
      res += cnt[cur]++;
    }
    cout << res << endl;
  }
  return 0;
}
