#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t) {
    int n, mx = 0, i, j, flag1 = 1;
    cin >> n;
    vector<int> v(2048);
    int a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      v[a[i]]++;
    }
    if (n == 1)
      cout << -1 << "\n";
    else {
      sort(a, a + n);
      for (i = 1; i <= 2 * a[n - 1]; i++) {
        int flag = 1;
        for (j = 0; j < n; j++) {
          if (v[a[j] ^ i] == 0) {
            flag = 0;
            break;
          }
        }
        if (flag == 1) {
          flag1 = 0;
          mx = i;
          break;
        }
      }
      if (flag1 == 0)
        cout << mx << "\n";
      else
        cout << -1 << "\n";
    }
    t--;
  }
  return 0;
}
