#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt = 1;
  cin >> tt;
  int ii = 0;
  while (tt-- && ++ii) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    bool flag = false;
    for (int i = 1; i <= 1024; i++) {
      vector<int> b(a);
      for (auto &x : b) x ^= i;
      sort(b.begin(), b.end());
      if (a == b) {
        cout << i << "\n";
        flag = true;
        break;
      }
    }
    if (!flag) cout << -1 << "\n";
  }
  return 0;
}
