#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int i, n, j;
    cin >> n;
    int arr[n], a[n];
    set<int> s1, s2;
    int flag = 0, p = 0;
    for (i = 0; i < n; i++) {
      cin >> arr[i];
      a[i] = arr[i];
      s2.insert(arr[i]);
      if (arr[i] == 0) flag = 1;
    }
    sort(a, a + n);
    if (flag == 1) {
      p == 0;
      for (i = 0; i < n; i++) {
        s1.clear();
        if (a[i] != 0) {
          for (j = 0; j < n; j++) {
            int p = (a[i] ^ arr[j]);
            s1.insert(p);
          }
        }
        if (s2 == s1) {
          p = 1;
          cout << a[i] << "\n";
          break;
        }
      }
      if (p == 0) cout << "-1\n";
    } else {
      p = 0;
      for (i = 1; i < 1025; i++) {
        s1.clear();
        for (j = 0; j < n; j++) {
          s1.insert(i ^ arr[j]);
        }
        if (s2 == s1) {
          p = 1;
          cout << i << "\n";
          break;
        }
      }
      if (p == 0) cout << "-1\n";
    }
  }
}
