#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    sort(v.begin(), v.end());
    for (k = 1; k <= 1024; k++) {
      vector<int> a;
      for (int j = 0; j < n; j++) {
        a.push_back(k ^ v[j]);
      }
      sort(a.begin(), a.end());
      int f = 1;
      for (int i = 0; i < n; i++) {
        if (a[i] != v[i]) {
          f = 0;
        }
      }
      if (f == 1) {
        cout << k << endl;
        break;
      }
    }
    if (k > 1024) cout << -1 << endl;
  }
  return 0;
}
