#include <bits/stdc++.h>
using i64 = long long;
using PII = std::pair<int, int>;
void solve() {
int n, a;
std::cin >> n;
int ans = (1 << 30) - 1;
for (int i = 1; i <= n; ++ i) {
std::cin >> a;
if (a != i - 1) ans &= a;
}
std::cout << ans << '\n';
}
int main() {
freopen("and_sorting.in", "r", stdin);
freopen("and_sorting.out", "w", stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t --) solve();
return 0;
}