#include <bits/stdc++.h>
using namespace std;
const int N = 1200;
int a[N];
void solve() {
  int n, flag;
  cin >> n;
  vector<int> ve;
  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (int k = 1; k <= 1024; k++) {
    flag = k;
    for (int j = 1; j <= n; j++) {
      if (mp[a[j] ^ k] == 0) {
        flag = 0;
        break;
      }
    }
    if (flag > 0) {
      break;
    }
  }
  if (flag == 0) {
    cout << "-1" << endl;
  } else
    cout << flag << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
