#include <bits/stdc++.h>
using namespace std;
int solve() {
  long long int n, m, k, i, j;
  cin >> n;
  set<long long int> arr;
  for (i = 0; i < n; i++) {
    cin >> j;
    arr.insert(j);
  }
  for (i = 1; i <= 1024; i++) {
    set<long long int> arr2;
    for (auto j : arr) {
      arr2.insert(j ^ i);
    }
    if (arr2 == arr) return cout << i << "\n", 0;
  }
  return cout << -1 << "\n", 0;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
