#include <bits/stdc++.h>
using namespace std;
long long x, y, z, i, j, n, m, k, s1, s2, s3, s4, s5, mod, l, r, t, maxx, minn,
    sx, so, sum, ans, puk;
double u, v, w, x1, x2, x3, z1, z2, z3, h, huh;
long long a[1000045];
long long b[1000045];
long long c[1000045];
long long d[1000045];
pair<long long, long long> aa[300045];
deque<long long> qu;
string s;
vector<long long> vc;
map<long long, long long> mp;
int main() {
  scanf("%lld", &t);
  for (l = 1; l <= t; l++) {
    scanf("%lld", &n);
    for (i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
    }
    if (n % 2 == 1) {
      printf("-1\n");
      continue;
    }
    sort(a + 1, a + n + 1);
    z = 0;
    for (i = 1; i <= 1024; i++) {
      for (j = 1; j <= n; j++) {
        b[j] = a[j] ^ i;
      }
      sort(b + 1, b + n + 1);
      x = 0;
      for (j = 1; j <= n; j++) {
        if (a[j] == b[j]) x++;
      }
      if (x == n) {
        printf("%lld\n", i);
        z = 1;
        break;
      }
    }
    if (z == 0) printf("-1\n");
  }
}
