#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int arr[n];
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    s.insert(arr[i]);
  }
  for (int i = 1; i < 1024; i++) {
    set<int> t;
    for (auto x : s) {
      t.insert(x ^ i);
    }
    if (t == s) {
      cout << i << "\n";
      return;
    }
  }
  cout << -1 << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
