#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
  int fl = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') fl = -fl;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= fl;
}
template <class T>
inline void wr(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x < 10) {
    putchar(x + '0');
    return;
  }
  int tmp[40] = {0}, cnt = 0;
  while (x) tmp[cnt++] = x % 10, x /= 10;
  for (register int i = cnt - 1; i >= 0; --i) putchar(tmp[i] + '0');
}
const int N = 105;
int T, n, ans = 1e9 + 1, a[N], b[N];
int main() {
  rd(T);
  while (T--) {
    rd(n);
    ans = 1e9 + 1;
    for (register int i = 1; i <= n; ++i) rd(a[i]);
    ans = a[1];
    for (register int i = 2; i <= n; ++i) ans &= a[i];
    wr(ans);
    puts("");
  }
  return 0;
}
