#include <bits/stdc++.h>
using namespace std;
vector<int> v;
void solve() {
  sort(v.begin(), v.end(), greater<int>());
  int n = v.size();
  for (int i = 0; i < n - 1; i++) {
    v[n - 1] = v[i] & v[n - 1];
  }
  cout << v[n - 1] << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    v = vector<int>(n);
    for (int &i : v) cin >> i;
    solve();
  }
}
