#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x = 0, y = 0, i;
  cin >> n;
  vector<int> arr(n);
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (i = 1; i < n; i++) arr[i] = arr[i] & arr[i - 1];
  cout << arr[n - 1];
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
}
