9 5 14
7 1 4 8 5 2 6 9 3
2 8
1 6
5 7
1 3
3 9
1 5
1 8
1 5
1 4
1 8
1 3
1 5
1 5
1 7
1 7
2 3
1 2
1 1
1 2
 6 5 8
1 2 6 3 4 5
2 4
1 3
1 6
3 5
2 5
1 1
1 4
1 1
2 1
2 5
2 2
2 3
1 4
 2 1 3
1 2
1 2
1 1
1 1
1 1

6
9
5
8
1
7
0
0
0
0
0
4
0
 6
5
4
3
 2
1
0

#include <bits/stdc++.h>
using namespace std;
int t, n, a[200005];
long long ans;
vector<int> b[200005];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    b[1].clear();
    ans = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), b[1].push_back(a[i]);
    long long t = 0;
    int cnt = 1;
    for (int i = 29; ~i; i--) {
      long long x = 0, y = 0, o = cnt;
      for (int j = 1; j <= o; j++) {
        vector<int> c, d;
        c.clear(), d.clear();
        for (int it : b[j])
          if ((it >> i + 1) & 1)
            c.push_back(it);
          else
            d.push_back(it);
        if (c.size() && d.size())
          b[j] = c, b[++cnt] = d;
        else if (c.size())
          b[j] = c;
        else
          b[j] = d;
      }
      for (int j = 1; j <= cnt; j++) {
        int k1 = 0, k2 = 0;
        for (int it : b[j])
          if ((it >> i + 1) & 1)
            k1++, y += k2;
          else
            k2++, x += k1;
      }
      if (y < x)
        t += 1 << i, ans += y;
      else
        ans += x;
    }
    printf("%lld %lld\n", ans, t);
  }
  return 0;
}
