#include <bits/stdc++.h>
const long long N = 1e6 + 10;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1);
using namespace std;
namespace geo {
long long sgn(double x) {
  if (fabs(x) < eps) return 0;
  if (x < 0)
    return -1;
  else
    return 1;
}
struct point {
  double x, y;
  point() {}
  point(double xx, double yy) {
    x = xx;
    y = yy;
  }
  point operator+(point b) { return point(x + b.x, y + b.y); }
  point operator-(point b) { return point(x - b.x, y - b.y); }
  double operator^(point b) { return x * b.y - y * b.x; }
  double operator*(point b) { return x * b.x + y * b.y; }
  point operator*(double b) { return point(x * b, y * b); }
  double gettan() { return atan2(y, x); }
  void read() { scanf("%lf%lf", &x, &y); }
};
struct line {
  point s, e, l;
  line() {}
  line(point ss, point ee) {
    s = ss;
    e = ee;
    l = e - s;
  }
  void read() {
    s.read(), e.read();
    l = e - s;
  }
  double gettan() { return atan2(e.y - s.y, e.x - s.x); }
};
struct circle {
  point o;
  double r;
  circle() {}
  circle(point oo, double rr) {
    o = oo;
    r = rr;
  }
};
double dis2(point a, point b) { return (b - a) * (b - a); }
double dis(point a, point b) { return sqrt(dis2(a, b)); }
bool onseg(line l, point p) {
  bool x1 = sgn((l.s - p) ^ (l.e - p)) == 0;
  bool x2 = sgn((l.s - p) * (l.e - p)) <= 0;
  return x1 && x2;
}
point spin(point p, double a) {
  return point(p.x * cos(a) - p.y * sin(a), p.y * cos(a) + p.x * sin(a));
}
double len(point a) { return sqrt(a * a); }
point projection(line l, point p) {
  return l.s + l.l * ((l.l * (p - l.s)) / ((l.l) * (l.l)));
}
bool judge(line l1, line l2) {
  point a = l1.s, b = l1.e, c = l2.s, d = l2.e;
  bool x1 = sgn((c - a) ^ l1.l) * sgn((d - a) ^ l1.l) <= 0;
  bool x2 = sgn((a - c) ^ l2.l) * sgn((b - c) ^ l2.l) <= 0;
  return x1 && x2 && max(l1.s.x, l1.e.x) >= min(l2.s.x, l2.e.x) &&
         max(l2.s.x, l2.e.x) >= min(l1.s.x, l1.e.x) &&
         max(l1.s.y, l1.e.y) >= min(l2.s.y, l2.e.y) &&
         max(l2.s.y, l2.e.y) >= min(l1.s.y, l1.e.y);
}
point getcross(line l1, line l2) {
  double s1 = ((l2.s - l1.s) ^ (l2.e - l1.s));
  double s2 = ((l2.e - l1.e) ^ (l2.s - l1.e));
  if (s1 + s2 == 0) return point{inf, inf};
  return l1.s + l1.l * (s1 / (s1 + s2));
}
double dis_pl(point p, line l) {
  point v = p - l.s;
  double ans = (v ^ l.l) / sqrt(l.l * l.l);
  return fabs(ans);
}
double askarea(point d[], long long n) {
  d[n + 1] = d[1];
  double area = 0;
  for (long long i = 1; i <= n; i++) area += (d[i] ^ d[i + 1]);
  area /= 2;
  return fabs(area);
}
long long cmp(line a, line b) {
  double t1 = a.gettan(), t2 = b.gettan();
  if (sgn(t1 - t2) == 0) return (a.l ^ (b.e - a.s)) > 0;
  return t1 < t2;
}
long long onright(line a, line b, line c) {
  point p = getcross(b, c);
  return (a.l ^ (p - a.s)) < 0;
}
void hpi(line li[], long long n) {
  line que[N];
  sort(li + 1, li + n + 1, cmp);
  long long l = 1, r = 1, cnt = 0, i;
  for (i = 1; i < n; i++)
    if (sgn(li[i].gettan() - li[i + 1].gettan())) li[++cnt] = li[i];
  li[++cnt] = li[n];
  for (i = 1; i <= cnt; i++) {
    while (r - l > 1 && onright(li[i], que[r - 1], que[r - 2])) r--;
    while (r - l > 1 && onright(li[i], que[l], que[l + 1])) l++;
    que[r++] = li[i];
  }
  while (r - l > 1 && onright(que[l], que[r - 1], que[r - 2])) r--;
  while (r - l > 1 && onright(que[r - 1], que[l], que[l + 1])) l++;
}
}  // namespace geo
long long a[N], b[40];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, j, ans = 0;
    cin >> n;
    memset(b, 0, sizeof(b));
    for (i = 1; i <= n; i++) {
      cin >> a[i];
      for (j = 1; j < 33; j++)
        if ((a[i] >> j) == 0) {
          ans += b[j];
          b[j]++;
          break;
        }
    }
    cout << ans << endl;
  }
  return 0;
}
