#include <bits/stdc++.h>
using namespace std;
void inout();
void solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int final = arr[0];
  for (int i = 1; i < n; i++) {
    final = final & arr[i];
  }
  cout << final << endl;
}
int main() {
  inout();
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
void inout() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
