#include <bits/stdc++.h>
using namespace std;
vector<int> in(1024, 0);
bool check(int k) {
  for (int i = 0; i < 1024; i++) {
    if (in[i] && in[i ^ k] == 0) return 0;
  }
  return 1;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      int t;
      cin >> t;
      in[t] = 1;
    }
    int anw = -1;
    for (int i = 1023; i > 0; i--) {
      if (check(i)) anw = i;
    }
    cout << anw << endl;
    in.assign(1024, 0);
  }
}
