#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, n, t, j = 0, p, x, a = 0, b, l = 0, r = 0, y, k, c, sum = 0,
                         m, d;
  cin >> t;
  while (t--) {
    cin >> n;
    int ara[n], ar[n];
    for (i = 0; i < n; i++) {
      cin >> ara[i];
    }
    sort(ara, ara + n);
    for (k = 1; k <= 1024; k++) {
      l = 0;
      for (i = 0; i < n; i++) {
        ar[i] = ara[i] ^ k;
      }
      sort(ar, ar + n);
      for (i = 0; i < n; i++) {
        if (ar[i] != ara[i]) {
          l = 1;
          break;
        }
      }
      if (l == 0) {
        break;
      }
    }
    if (l == 0) {
      cout << k << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return EXIT_SUCCESS;
}
