#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  unordered_set<int> s;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    s.insert(x);
  }
  if (s.size() % 2) {
    cout << -1 << "\n";
    return;
  }
  vector<int> vk;
  auto it = s.begin();
  int p = *it;
  it++;
  for (; it != s.end(); it++) vk.push_back(p ^ *it);
  sort(vk.begin(), vk.end());
  for (auto k : vk) {
    unordered_set<int> t;
    for (auto x : s) t.insert(x ^ k);
    if (t == s) {
      cout << k << "\n";
      return;
    }
  }
  cout << -1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
