#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n];
    set<long long> s;
    long long flaga = 0, ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      s.insert(arr[i]);
    }
    for (int i = 1; i < 1024; i++) {
      long long flag = 0;
      for (int j = 0; j < n; j++) {
        long long val = i ^ arr[j];
        if (s.find(val) == s.end()) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        flaga = 1;
        ans = i;
        break;
      }
    }
    if (flaga == 1)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
