#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, flag = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    sort(v.begin(), v.end());
    if (v[0] == 0) {
      vector<int> v1(n);
      for (int k = 1; k < 2000; k++) {
        for (int i = 0; i < n; i++) {
          v1[i] = (v[i] ^ k);
        }
        sort(v1.begin(), v1.end());
        if (v1 == v) {
          cout << k << endl;
          flag++;
          break;
        }
      }
    } else {
      vector<int> v1(n);
      for (int k = 1; k < 2000; k++) {
        for (int i = 0; i < n; i++) {
          v1[i] = (v[i] ^ k);
        }
        sort(v1.begin(), v1.end());
        if (v1 == v) {
          cout << k << endl;
          flag++;
          break;
        }
      }
    }
    if (flag == 0) {
      cout << "-1" << endl;
    }
  }
}
