#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long i, a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    long long f = 0;
    sort(a, a + n);
    for (i = 1; i <= 1024; i++) {
      vector<long long> v;
      for (long long j = 0; j < n; j++) {
        long long x = i ^ a[j];
        v.push_back(x);
      }
      sort(v.begin(), v.end());
      for (long long j = 0; j < n; j++) {
        if (a[j] != v[j]) {
          f = 1;
          break;
        }
      }
      v.clear();
      if (f == 1) {
        f = 0;
        continue;
      }
      if (f == 0) {
        cout << i << "\n";
        f = 2;
        break;
      }
    }
    if (f != 2) cout << "-1\n";
  }
  return 0;
}
