#include <bits/stdc++.h>
using namespace std;
void solution(vector<int> ar, int n) {
  map<int, bool> mp;
  int ans = -1;
  for (int i = 0; i < n; i++) {
    mp[ar[i]] = 1;
  }
  for (int i = 1; i <= 1024; i++) {
    int c = 0;
    for (int j = 0; j < n; j++) {
      int p = ar[j] ^ i;
      if (mp[p] == 1) {
        c++;
      }
    }
    if (c == n) {
      ans = i;
      break;
    }
  }
  cout << ans;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    vector<int> ar(n);
    for (int j = 0; j < n; j++) {
      cin >> ar[j];
    }
    solution(ar, n);
    cout << "\n";
  }
}
