#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> v(n);
    map<long long int, long long int> ma, make_pair;
    for (auto &x : v) {
      cin >> x;
      ma[x]++;
    }
    long long int ans = -1;
    for (long long int i = 1; i < 1024; ++i) {
      long long int kp = i;
      make_pair = ma;
      for (auto y : v) {
        if (make_pair.count(y ^ kp) >= 1) {
          make_pair[y ^ kp]--;
          if (make_pair[y ^ kp] == 0) make_pair.erase(y ^ kp);
        }
      }
      if (make_pair.size() == 0) {
        ans = kp;
        break;
      }
    }
    cout << ans << "\n";
  }
}
