#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long x;
  cin >> x;
  for (int i = 0; i < n - 1; i++) {
    long long y;
    cin >> y;
    x = x & y;
  }
  cout << x << "\n";
}
int main(void) {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
