#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 998244353;
template <class T>
inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ans = 0;
  for (int k = 30; k >= 0; --k) {
    int f = 1;
    for (int i = 0; i < n; ++i) {
      f &= (a[i] >> k & 1);
    }
    if (f) ans += 1 << k;
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
