#include <bits/stdc++.h>
using namespace std;
map<int, int> num;
int main() {
  int t;
  cin >> t;
  while (t--) {
    num.clear();
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      pair<int, int> p = make_pair(x, 1);
      num.insert(p);
    }
    int ans = -1;
    for (int i = 1; i < 1024; ++i) {
      map<int, int>::iterator it;
      bool fi = true;
      for (it = num.begin(); it != num.end(); it++) {
        int tmp = i ^ (it->first);
        if (num.find(tmp) == num.end()) {
          fi = false;
          break;
        }
      }
      if (fi) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
