#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    v.reserve(1024);
    for (int i = 0; i < n; i++) {
      int p;
      cin >> p;
      v.push_back(p);
    }
    sort(v.begin(), v.end());
    int mn = v[0];
    int mx = v[n - 1];
    if (mn == 0) {
      mn = 1;
    }
    bool flag = true;
    for (int i = 1; i <= 1023; i++) {
      vector<int> v2;
      v2.reserve(1024);
      for (int j = 0; j < n; j++) {
        int g = v[j] ^ i;
        v2.push_back(g);
      }
      sort(v2.begin(), v2.end());
      if (v == v2) {
        flag = false;
        cout << i << endl;
        break;
      }
    }
    if (flag == true) {
      cout << "-1" << endl;
    }
  }
  return 0;
}
