#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> st;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      st.push_back(a);
    }
    sort(st.begin(), st.end());
    int k;
    bool flag = false;
    for (int i = 1; i <= 1024; i++) {
      vector<int> new_set;
      for (int j = 0; j < n; j++) {
        new_set.push_back(st[j] ^ i);
      }
      sort(new_set.begin(), new_set.end());
      if (st == new_set) {
        k = i;
        flag = true;
        break;
      }
    }
    if (flag)
      cout << k << endl;
    else
      cout << -1 << endl;
  }
}
