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