#include using namespace std; using ll=long long; #define rep(i,n) for(ll i=0; i<(n); i++) #define repi(i,a,b) for(ll i=(a); i<(b); i++) #define all(x) (x).begin(),(x).end() #define arr(x) (x).rbegin(),(x).rend() template bool chmin(T&a,const S&b){ return a>b?a=b,1:0; } template bool chmax(T&a,const S&b){ return a; using P=pair; using vvi=vector; using vll=vector; using vvll=vector; using vp=vector

; using i128=__int128_t; #define sz(a) (ll)(size(a)) const ll inf=2e18; void solve(int test){ int n;cin >> n; vi a(n); rep(i,n)cin >> a[i]; if(n==1){ cout << a[0] << endl; return; } vll cnt(n); auto f=[&](int wj){ rep(i,n)cnt[i]=0; rep(i,n){ if(a[i]>=wj)cnt[0]++; else cnt[a[i]]++; } ll x=1; for(int i=wj-1; i>=0; i--){ /* if(wj==5){ cout<< i << " " << x << " "<< cnt[i] << endl; } */ if(i==0){ if(cnt[i]>=x)return true; else return false; } if(x>n){ return false; } if(cnt[i]>=x){ cnt[0]+=cnt[i]-x; } else { x+=x-cnt[i]; } } return true; }; int ac=0,wa=n+1; while(wa-ac>1){ int wj=(wa+ac)/2; if(f(wj))ac=wj; else wa=wj; } cout << ac << endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int t=1;cin>> t; rep(test,t)solve(test); }