#include <bits/stdc++.h>
using namespace std;
const int LARGE_INT = 1000000007;
const long long LARGE_LONG = 1L << 60;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int tc = 0; tc < t; tc++) {
    int n;
    cin >> n;
    set<int> os;
    for (int i = 0; i < n; i++) {
      int pla;
      cin >> pla;
      os.insert(pla);
    }
    bool works = false;
    for (int i = 1; i < 1024; i++) {
      set<int> ns;
      for (int j : os) {
        ns.insert(j ^ i);
      }
      if (os == ns) {
        works = true;
        cout << i << endl;
        break;
      }
    }
    if (!works) {
      cout << -1 << endl;
    }
  }
  return 0;
}
