#include<bits/stdc++.h>
#include<vector>
using namespace std;
typedef long long ll;
const int N = 100005;
int a[N];
int ct[N];
void solve() {
int n;
cin >> n;
vector<int> c(n);
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
ct[x]++;
c[x - 1]++;
}
if (n == 1) {
cout << c[0] << '\n';
return;
}
sort(c.begin(), c.end());
int ans = c[n - 1] | c[n - 2] | ;
int now = ((1 << (__lg(c[n - 1] & c[n - 2]))) - 1);
if (now < 0) now = 0;
ans |= now;
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--) {
solve();
}
return 0;
}