#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, i, j, temp1, flag;
    cin >> n;
    vector<int> vec;
    bool arr[1024] = {0};
    for (i = 0; i < n; i++) {
      cin >> temp1;
      arr[temp1] = true;
      vec.push_back(temp1);
    }
    for (i = 1; i < 1024; i++) {
      flag = 1;
      for (j = 0; j < n; j++) {
        if (!arr[vec[j] ^ i]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        break;
      }
    }
    if (flag)
      cout << i << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
