#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    sort(v.begin(), v.end());
    int result = v[0];
    for (int i = 1; i < n; i++) {
      result = result & v[i];
    }
    cout << result << endl;
  }
  return 0;
}
