#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
void coutv(vector<long long> v) {
  for (auto it : v) cout << it << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    bool f = false;
    long long n, mn = LLONG_MAX;
    cin >> n;
    vector<long long> a(n), b;
    for (auto &i : a) cin >> i;
    sort((a).begin(), (a).end());
    b = a;
    long long start = 0;
    while (start <= 2020) {
      for (int i = 0; i < b.size(); i++) b[i] = b[i] ^ start;
      sort((b).begin(), (b).end());
      if (b == a && start != 0)
        break;
      else
        start++;
      b = a;
    }
    cout << (start <= 1024 ? start : -1) << endl;
  }
}
