#include <bits/stdc++.h>
using namespace std;
int T, n, a[110];
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> a[1];
    int ans = a[1];
    for (int i = 2; i <= n; i++) {
      cin >> a[i];
      ans &= a[i];
    }
    cout << ans << endl;
  }
}
