#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
void solve() {
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s.insert(a);
  }
  for (int cnt = 1; cnt <= 1023; cnt++) {
    bool vis[1025];
    memset(vis, 0, sizeof(vis));
    bool h = 1;
    for (auto x : s) {
      if (vis[x ^ cnt] || s.count(x ^ cnt) == 0) {
        h = 0;
        break;
      }
      vis[x ^ cnt] = 1;
    }
    if (h) {
      cout << cnt;
      return;
    }
  }
  cout << -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
}
