#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
int a[maxn];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    set<int> q;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      q.insert(a[i]);
    }
    int ans = -1;
    for (int i = 1024; i > 0; i--) {
      set<int> qq;
      for (int j = 1; j <= n; j++) {
        qq.insert((i ^ a[j]));
      }
      if (q == qq) {
        ans = i;
      }
    }
    printf("%d\n", ans);
  }
}
