#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, i, x, mini, maxi, k;
  cin >> t;
  while (t--) {
    maxi = 0;
    k = 1;
    x = 0;
    cin >> n;
    vector<long long> v(n);
    unordered_set<int> s;
    bool flag = 1;
    for (i = 0; i < n; i++) {
      cin >> v[i];
      s.insert(v[i]);
      maxi = max(maxi, v[i]);
    }
    while (k <= 1023) {
      int count = 0;
      for (i = 0; i < n; i++) {
        if (s.count(k ^ v[i])) {
          count++;
        }
      }
      if (count == n) {
        break;
      }
      k++;
    }
    if (k == 1024) {
      cout << -1 << endl;
      continue;
    }
    cout << k << endl;
  }
}
