#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    unordered_set<long long> s;
    vector<long long> a(n);
    for (long long i = 0, x; i < n; i++) {
      cin >> x;
      a[i] = x;
      s.insert(x);
    }
    for (long long i = 1; i < 1026; i++) {
      unordered_set<long long> sol;
      for (long long j = 0; j < n; j++) {
        long long temp = i ^ a[j];
        if (s.count(temp))
          sol.insert(temp);
        else
          break;
      }
      if (sol.size() == n) {
        cout << i << '\n';
        break;
      } else if (i == 1025)
        cout << -1 << '\n';
    }
  }
  return 0;
}
