#include <bits/stdc++.h>
using namespace std;
int solve() {
  int n;
  cin >> n;
  set<int> s;
  int* a = new int[n];
  int temp;
  int largest = 0;
  bool zero = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) zero = true;
    s.insert(a[i]);
    largest = max(a[i], largest);
  }
  if (n & 1) {
    return -1;
  }
  if (zero) {
    if (n == 2) return largest;
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
      set<int> s2;
      if (a[i] == 0) continue;
      int j = 0;
      for (; j < n; j++) {
        s2.insert(a[j] ^ a[i]);
      }
      if (s2 == s) {
        return a[i];
      }
    }
  } else {
    for (int i = 1; i <= 1024; i++) {
      set<int> s2;
      int j = 0;
      for (; j < n; j++) {
        s2.insert(a[j] ^ i);
      }
      if (s2 == s) return i;
    }
  }
  return -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cout << solve();
    cout << "\n";
  }
  return 0;
}
