#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
bool check(ll k,ll a[],ll n){
ll b[n];
ll i;
for(i=0;i<n;i++){
b[i]=a[i]^k;
}
// Checking
ll s[2050];
for(i=0;i<2050;i++){
s[i]=0;
}
for(i=0;i<n;i++){
s[a[i]]++;
s[b[i]]--;
}
for(i=0;i<2050;i++){
if(s[i]!=0){
return false;
}
}
return true;
}
int main() {
FIO;
test{ // 1000
ll n,i,x,flag=0;
cin>>n;
ll a[n];
for(i=0;i<n;i++){
cin>>a[i];
}
for(i=1;i<=1024;i++){ // 1000 * 1024
bool res=check(i,a,n); // 1000 * 1024 * 2050
if(res==true){
cout<<i<<endl;
flag=1;
i=1034;
}
}
if(flag==0){
cout<<-1<<endl;
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBGSU8gaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7Y2luLnRpZSgwKTtjb3V0LnRpZSgwKQojZGVmaW5lIG1vZCAxMDAwMDAwMDA3CiNkZWZpbmUgdGVzdCBsbCB0OyBjaW4+PnQ7IHdoaWxlKHQtLSkKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwpib29sIGNoZWNrKGxsIGssbGwgYVtdLGxsIG4pewogICAgbGwgYltuXTsKICAgIGxsIGk7CiAgICBmb3IoaT0wO2k8bjtpKyspewogICAgICAgIGJbaV09YVtpXV5rOwogICAgfQogICAgLy8gQ2hlY2tpbmcKICAgIGxsIHNbMjA1MF07CiAgICBmb3IoaT0wO2k8MjA1MDtpKyspewogICAgICAgIHNbaV09MDsKICAgIH0KICAgIGZvcihpPTA7aTxuO2krKyl7CiAgICAgICAgc1thW2ldXSsrOwogICAgICAgIHNbYltpXV0tLTsKICAgIH0KICAgIGZvcihpPTA7aTwyMDUwO2krKyl7CiAgICAgICAgaWYoc1tpXSE9MCl7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKfQppbnQgbWFpbigpIHsKICAgIEZJTzsKICAgIHRlc3R7IC8vIDEwMDAKICAgICAgICBsbCBuLGkseCxmbGFnPTA7CiAgICAgICAgY2luPj5uOwogICAgICAgIGxsIGFbbl07CiAgICAgICAgZm9yKGk9MDtpPG47aSsrKXsKICAgICAgICAgICAgY2luPj5hW2ldOwogICAgICAgIH0KICAgICAgICBmb3IoaT0xO2k8PTEwMjQ7aSsrKXsgLy8gMTAwMCAqIDEwMjQKICAgICAgICAgICAgYm9vbCByZXM9Y2hlY2soaSxhLG4pOyAvLyAxMDAwICogMTAyNCAqIDIwNTAKICAgICAgICAgICAgaWYocmVzPT10cnVlKXsKICAgICAgICAgICAgICAgIGNvdXQ8PGk8PGVuZGw7CiAgICAgICAgICAgICAgICBmbGFnPTE7CiAgICAgICAgICAgICAgICBpPTEwMzQ7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoZmxhZz09MCl7CiAgICAgICAgICAgIGNvdXQ8PC0xPDxlbmRsOwogICAgICAgIH0KICAgIH0KCXJldHVybiAwOwp9Cg==