# https://github.com/robe2222555/atcoder-lib/blob/main/template/python/main.py import sys input = lambda: sys.stdin.readline().rstrip() def LI(): return list(map(int, input().split())) def II(): return int(input()) INF = 1<<60 def solve(): N = II() A = LI() if N==1: print(max(1, A[0])) return init = [0]*(N+1) for a in A: if a>=N+1: a = 0 init[a] += 1 cnt = [0]*(N+1) need = [0]*(N+1) ok = 0 ng = N+2 while ng-ok>1: mid = (ok+ng)//2 for i in range(mid): cnt[i] = init[i] need[i] = 1 for i in range(mid, N+1): cnt[0] += init[i] cnt[i] = 0 tmp = 0 for i in range(1, mid)[::-1]: need[i] += tmp if need[i] > N: need[0] += N+10 break if cnt[i] >= need[i]: cnt[i] -= need[i] cnt[0] += cnt[i] cnt[i] = 0 continue else: tmp += need[i]-cnt[i] continue need[0] += tmp if cnt[0] >= need[0]: ok = mid else: ng = mid continue print(ok) return def main(): T = II() for _ in range(T): solve() return if __name__ == '__main__': main()