#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    unordered_map<long long int, long long int> m1, m2;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      m1[a[i]] = 1;
      m2[a[i]] = 1;
    }
    long long int ans = -1;
    for (long long int i = 1; i <= 2049; i++) {
      long long int cnt = 0;
      for (long long int j = 0; j < n; j++) {
        long long int g = a[j] ^ i;
        if (m1[g] == 1) {
          m1[g] = 2;
          cnt++;
        } else
          break;
      }
      if (cnt == n) {
        ans = i;
        break;
      }
      m1 = m2;
    }
    cout << ans << "\n";
  }
}
