#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 0; i < n; i++) cin >> a[i];
    map<int, int> mp;
    if (n & 1) {
      cout << -1 << endl;
      continue;
    }
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) mp[a[i] ^ a[j]]++;
    int ans = -1;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      if (it->second == (n / 2)) {
        ans = it->first;
        break;
      }
    }
    cout << ans << endl;
  }
}
