#include <bits/stdc++.h>
using namespace std;
long long add(long long a, long long b) {
  return (a + b + 1000000007) % 1000000007;
}
long long mul(long long x, long long y) { return (1LL * x * y) % 1000000007; }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool compare(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second < b.second;
}
void test_case() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long ans;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    if (!i)
      ans = a[i];
    else
      ans = (ans & a[i]);
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    test_case();
  }
  return 0;
}
