#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n;
  long long temp, ans;
  cin >> t;
  while (t--) {
    cin >> n;
    long long ary[n];
    for (int i = 0; i < n; i++) {
      cin >> ary[i];
    }
    ans = ary[0];
    for (int i = 1; i < n; i++) {
      ans = ans & ary[i];
    }
    cout << ans << endl;
  }
}
