#include <bits/stdc++.h>
using namespace std;
const long long MAX_SIZE = 1000001;
int invertBits(int num) {
  int x = log2(num) + 1;
  for (int i = 0; i < x; i++) num = (num ^ (1 << i));
  return num;
}
void solve() {
  int n;
  cin >> n;
  int ar[100000];
  map<int, bool> mtp;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    mtp[ar[i]] = true;
  }
  sort(ar, ar + n);
  int b = ar[n - 1];
  int m = log2(b) + 1;
  b = pow(2, m);
  bool ans = false;
  for (int i = 1; i <= b; i++) {
    ans = true;
    for (int j = 0; j < n; j++) {
      int g = i ^ ar[j];
      if (!mtp[g]) {
        j = n + 1;
        ans = false;
      }
    }
    if (ans) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
