#include <bits/stdc++.h>
using namespace std;
int t, n, tmp;
set<int> S1;
set<int> S2;
int main() {
  int tot = 0;
  for (int i = 0; i <= 10; ++i) tot += pow(2, i);
  cin >> t;
  while (t--) {
    cin >> n;
    S1.clear();
    for (int i = 1; i <= n; ++i) {
      cin >> tmp;
      S1.insert(tmp);
    }
    int flag = 1, x = 1;
    for (x = 1; x <= 1024; ++x) {
      flag = 1;
      S2.clear();
      set<int>::iterator it;
      for (it = S1.begin(); it != S1.end(); ++it) {
        int OR = *it ^ x;
        if (S1.find(OR) != S1.end())
          S2.insert(OR);
        else {
          flag = 0;
          break;
        }
      }
      if (S1.size() == S2.size()) break;
      if (flag) break;
    }
    if (flag)
      cout << x << endl;
    else
      cout << -1 << endl;
  }
}
