#include <bits/stdc++.h>
using namespace std;
int f(int n, vector<int> &a);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i <= n - 1; i++) {
      cin >> a[i];
    }
    cout << f(n, a) << "\n";
  }
  return 0;
}
int f(int n, vector<int> &a) {
  sort(a.begin(), a.end());
  bool flag = 0;
  for (int k = 1; k <= 1023; k++) {
    flag = 0;
    for (int i = 0; i <= n - 1; i++) {
      int x = a[i] ^ k;
      if (!binary_search(a.begin(), a.end(), x)) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      return k;
    }
  }
  return -1;
}
