#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    bool f = false;
    set<int> v1;
    int n, ans = -1;
    cin >> n;
    int a[n];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      v1.insert(a[i]);
    }
    for (int i = 1; i <= 1024; i++) {
      long long count = 0;
      for (int j = 0; j < n; j++) {
        int m = a[j] ^ i;
        v1.insert(a[j] ^ i);
        if (v1.size() > n) {
          count++;
          v1.erase(v1.find(m));
          break;
        }
      }
      if (count == 0) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
