#include <bits/stdc++.h>
using namespace std;
void init() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
int main() {
  init();
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    sort(arr, arr + n);
    int sol[n];
    int ans = -1;
    for (int j = 1; j <= 1024; j++) {
      for (int i = 0; i < n; i++) {
        sol[i] = arr[i] ^ j;
      }
      sort(sol, sol + n);
      int a = 0;
      for (a; a < n; a++) {
        if (arr[a] != sol[a]) break;
      }
      if (a == n) {
        ans = j;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
