#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(10);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int mx = 1024;
    set<int> v;
    for (int i = 0; i < (int)(n); ++i) {
      int a;
      cin >> a;
      v.insert(a);
    }
    bool ok = false;
    for (int i = 1; i <= (int)(mx); ++i) {
      set<int> w;
      for (auto s : v) {
        w.insert(s ^ i);
      }
      if (w == v) {
        ok = true;
        cout << i << "\n";
        break;
      }
    }
    if (!ok) cout << -1 << "\n";
  }
}
