#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, i, k = 1;
  cin >> n;
  int a[n], b[n];
  int p;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  while (k < 1024) {
    p = 1;
    for (i = 0; i < n; i++) b[i] = (a[i] ^ k);
    sort(b, b + n);
    for (i = 0; i < n; i++)
      if (a[i] != b[i]) {
        p = 0;
        break;
      }
    if (p == 1) {
      cout << k << '\n';
      return;
    } else
      k++;
  }
  cout << -1 << '\n';
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
