#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t, n, k, a, b, z, d;
  cin >> t;
  while (t--) {
    d = -1;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for (int j = 1; j <= (1 << 10); j++) {
      z = 1;
      for (int i = 0; i < n; i++) {
        if ((*(lower_bound(a.begin(), a.end(), a[i] ^ (j)))) != (a[i] ^ (j)))
          z = 0;
      }
      if (z == 1) {
        d = j;
        break;
      }
    }
    cout << d;
    cout << "\n";
  }
  return 0;
}
