#include <bits/stdc++.h>
using namespace std;
long long val(long long n) {
  long long no = floor(log2(n)) + 1;
  return ((1 << no) - 1) ^ n;
}
long long abso(long long n) {
  if (n >= 0)
    return n;
  else
    return -n;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
start:
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> arr(n);
    for (long long i = 0; i < n; i++) cin >> arr[i];
    sort(arr.begin(), arr.end());
    vector<long long> v(n);
    for (long long i = 1; i <= 1024; i++) {
      for (long long j = 0; j < n; j++) {
        v[j] = (i ^ arr[j]);
      }
      sort(v.begin(), v.end());
      if (v == arr) {
        cout << i << endl;
        goto start;
      }
      for (long long j = 0; j < n; j++) v[j] = 0;
    }
    cout << "-1" << endl;
  }
  return 0;
}
