#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<bool> b(1024, false);
    for (int j = 0; j < n; j++) {
      cin >> a[j];
      b[a[j]] = true;
    }
    int ans;
    for (int j = 1; j < 1024; j++) {
      ans = j;
      for (int k = 0; k < n; k++) {
        if (!b[a[k] ^ j]) {
          ans = -1;
          break;
        }
      }
      if (ans != -1) {
        break;
      }
    }
    cout << ans << "\n";
  }
}
