#include <bits/stdc++.h>
using namespace std;
const int GO_MAX = 26;
const int ESP = 1e-9;
const int MAX = 101001;
const int INF = 1e9;
const int H_val = 37;
const int mod = 1000000;
const double PI = 3.14159265359;
int n, m, k, t, p, q;
int arr[MAX * 5];
int chk[1500];
int main() {
  scanf("%d", &t);
  while (t--) {
    vector<int> vec;
    memset(chk, 0, sizeof chk);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      scanf("%d", &arr[i]);
      chk[arr[i]]++;
    }
    if (n % 2) {
      printf("-1\n");
      continue;
    }
    int ans = -1;
    for (int i = 1; i < 1024; ++i) {
      bool trig = true;
      for (int j = 0; j < n && trig; ++j) {
        int temp = arr[j] ^ i;
        if (chk[temp] == 0) trig = false;
      }
      if (trig) {
        ans = i;
        break;
      }
    }
    printf("%d\n", ans);
  }
}
