Tonight, Chef would like to hold a party for his $N$ friends.
All friends are invited and they arrive at the party one by one in an arbitrary order. However, they have certain conditions — for each valid $i$, when the $i$-th friend arrives at the party and sees that at that point, strictly less than $A_i$ other people (excluding Chef) have joined the party, this friend leaves the party; otherwise, this friend joins the party.
Help Chef estimate how successful the party can be — find the maximum number of his friends who could join the party (for an optimal choice of the order of arrivals).

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer — the maximum number of Chef's friends who could join the party.

-----Constraints-----
- $1 \le T \le 1,000$
- $1 \le N \le 10^5$
- the sum of $N$ over all test cases does not exceed $10^6$

-----Example Input-----
3
2
0 0
6
3 1 0 0 5 5
3
1 2 3

-----Example Output-----
2
4
0

-----Explanation-----
Example case 1: Chef has two friends. Both of them do not require anyone else to be at the party before they join, so they will both definitely join the party.
Example case 2: At the beginning, friends $3$ and $4$ can arrive and join the party, since they do not require anyone else to be at the party before they join. After that, friend $2$ can arrive; this friend would see that there are two people at the party and therefore also join. Then, friend $1$ will also join, so in the end, there would be $4$ people attending the party.
Example case 3: No one will attend the party because each of Chef's friends will find zero people at the party and leave, regardless of the order in which they arrive.

Source: codechef | Difficulty: EASY
Tags: Sorting


Solutions:
for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	p = 0
	for i in li:
		if p >= i:
			p = p + 1
	print(p)


for xxx in range(int(input(''))):
	n = int(input(''))
	a = list(map(int, input('').split(' ')))
	a = sorted(a)
	going = 0
	for i in a:
		if i == 0:
			going += 1
	while 0 in a:
		a.remove(0)
	for i in range(len(a)):
		current = a[i]
		if going >= current:
			going += 1
			a[i] = -1
	print(going)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	guests = 0
	for i in a:
		if i <= guests:
			guests += 1
	print(guests)


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = []
	d = 0
	if sum(a) == 0:
		print(len(a))
	else:
		for j in range(n):
			if len(c) >= a[j]:
				c.append(a[j])
				d = len(c)
		print(d)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	a.sort()
	for j in range(n):
		if a[j] <= x:
			x += 1
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	cnt = 0
	for i in a:
		if i == 0:
			cnt += 1
		elif i <= cnt:
			cnt += 1
	print(cnt)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ans = 0
	for i in range(n):
		if ans >= l[i]:
			ans += 1
		else:
			break
	print(ans)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	k = 0
	for i in range(len(A)):
		if A[i] <= k:
			k += 1
		else:
			pass
	print(k)


test = int(input())
for _ in range(test):
	n = int(input())
	ls = list(map(int, input().split()))
	ls.sort()
	s = 0
	for i in range(n):
		if s >= ls[i]:
			s = s + 1
		else:
			break
	print(s)


tc = int(input())
for _ in range(tc):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	m = 0
	for i in b:
		if i <= m:
			m += 1
	print(m)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = 0
	for i in range(n):
		if c >= a[i]:
			c += 1
		else:
			break
	print(c)


from collections import Counter
for i in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	s = 0
	l.sort()
	k = Counter(l)
	for i in k:
		if s >= i:
			s += k[i]
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	d = {0: 0}
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	if d[0] == 0:
		print(0)
		continue
	c = d[0]
	for j in d:
		if c >= j and j != 0:
			c += d[j]
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	a.sort()
	for j in range(len(a)):
		if a[j] == 0:
			c = c + 1
		elif c >= a[j]:
			c = c + 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	sum = 0
	list1.sort()
	for i in range(len(list1)):
		if list1[i] <= i:
			sum = sum + 1
		else:
			break
	print(sum)


T = int(input())
ans = []
for _ in range(T):
	N = int(input())
	A = [int(i) for i in input().split()]
	A.sort()
	guest = 0
	for i in range(N):
		if A[i] <= guest:
			guest += 1
	ans.append(guest)
for i in ans:
	print(i)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	arr = sorted(arr)
	for x in range(n):
		if arr[x] <= count:
			count += 1
		else:
			break
	print(count)


cases = int(input())
for _ in range(cases):
	n = int(input())
	arr = sorted(list(map(int, input().split())))
	res = 0
	for i in range(len(arr)):
		if arr[i] == 0:
			res = res + 1
		elif res >= arr[i]:
			res = res + 1
	print(res)


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = b
	c.sort()
	p_in_p = 0
	for i in c:
		if i <= p_in_p:
			p_in_p += 1
		else:
			break
	print(p_in_p)


for _ in range(int(input())):
	N = int(input())
	A = sorted(list(map(int, input().split())))
	count = 0
	if A[0] != 0:
		print(0)
	else:
		for a in A:
			if a == 0 or a <= count:
				count += 1
			else:
				break
		print(count)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	f = 0
	for i in range(n):
		if l[i] <= f:
			f = f + 1
		else:
			break
	print(f)


for _ in range(int(input())):
	x = int(input())
	l1 = list(map(int, input().split()))
	c = 0
	l1.sort()
	for i in range(x):
		if l1[i] <= c:
			c += 1
		else:
			pass
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = sorted([int(x) for x in input().split()])
	cur = 0
	for i in a:
		if i <= cur:
			cur += 1
	print(cur)


a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, str(input()).split(' ')))
	c.sort()
	n = 0
	for j in range(b):
		if int(c[j]) <= j:
			n += 1
		else:
			break
	print(n)


for _ in range(int(input())):
	n = int(input())
	ppl = 0
	l = sorted(map(int, input().split()))
	for i in l:
		if i <= ppl:
			ppl += 1
		else:
			break
	print(ppl)


def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		arr = list(map(int, input().split(' ')))[:N]
		arr.sort()
		cnt = 0
		for i in range(N):
			if arr[i] == 0:
				cnt += 1
			elif arr[i] <= cnt:
				cnt += 1
		print(cnt)
main()


for i in range(int(input())):
	input()
	nums = list(map(int, input().split()))
	res = []
	for num in sorted(nums):
		if len(res) >= num:
			res.append(num)
	print(len(res))


for i in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	list1.sort()
	people_at_party = 0
	for x in list1:
		if x <= people_at_party:
			people_at_party += 1
	print(people_at_party)


t = int(input())
for i in range(t):
	n = int(input())
	friend = input().split(' ')
	for j in range(n):
		friend[j] = int(friend[j])
	friend.sort()
	at_party = 0
	for x in range(n):
		if at_party >= friend[x]:
			at_party += 1
		else:
			break
	print(at_party)


for _ in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	l.sort()
	c = 0
	for i in l:
		if i <= c:
			c += 1
	print(c)


n = int(input())
for i in range(n):
	N = int(input())
	N1 = list(map(int, input().split()))
	N1.sort()
	N2 = N1
	ans = 0
	for i in range(len(N2)):
		if N2[i] == 0:
			ans = ans + 1
		elif ans >= N2[i]:
			ans = ans + 1
	print(ans)


for u in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	l.sort()
	s = 0
	for i in l:
		if s >= i:
			s += 1
		else:
			break
	print(s)


t = 0
try:
	t = int(input())
except:
	pass
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	already_present = 0
	for requirement in a:
		if already_present >= requirement:
			already_present += 1
	print(already_present)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	count = 0
	for item in a:
		if item <= count:
			count = count + 1
	print(count)


test_case = int(input())
while test_case:
	n = int(input())
	friends_req = list(map(int, input().strip().split()))
	friends_req.sort()
	current_friends = 0
	for i in range(n):
		if friends_req[i] <= current_friends:
			current_friends += 1
		else:
			break
	print(current_friends)
	test_case -= 1


for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	ar.sort()
	s = 0
	an = 0
	for i in range(n):
		if ar[i] <= s:
			s += 1
			an += 1
		else:
			break
	print(an)


value = int(input())
for i in range(value):
	cnt = int(input())
	res = list(map(int, input().split()))
	res.sort()
	count = 0
	for i in range(len(res)):
		if res[i] <= count or res[i] == 0:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if 0 not in arr:
		print(0)
	elif arr.count(0) == len(arr):
		print(n)
	else:
		c = 0
		arr.sort()
		for k in arr:
			if c >= k:
				c += 1
			else:
				break
		print(c)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	r = 0
	for i in range(n):
		if l[i] == 0:
			r = r + 1
		elif r >= l[i]:
			r = r + 1
	print(r)


t = int(input())
for z in range(t):
	n = int(input())
	l = map(int, input().split())
	tg = 0
	for i in sorted(l):
		if i <= tg:
			tg += 1
	print(tg)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l1.sort()
	c = 0
	for i in l1:
		if c >= i:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	sum = 0
	l = [int(item) for item in input().split()]
	l.sort()
	for i in range(n):
		if l[i] == 0:
			sum = sum + 1
		elif l[i] <= sum:
			sum = sum + 1
	print(sum)


x = int(input())
for i in range(x):
	friends = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	tot = 0
	for ele in arr:
		if ele <= tot:
			tot += 1
	print(tot)


buddy = int(input())
for i in range(buddy):
	kanna = int(input())
	janu = list(map(int, input().split()))
	janu.sort()
	vi = 0
	for i in range(len(janu)):
		if janu[i] == 0:
			vi = vi + 1
		elif vi >= janu[i]:
			vi = vi + 1
	print(vi)


t = int(input())

def party(n, arr):
	if 0 not in arr:
		return 0
	arr.sort()
	count = 0
	for el in arr:
		if el == 0:
			count += 1
		elif count >= el:
			count += 1
		else:
			break
	return count
for i in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(party(n, arr))


n = int(input())
for _ in range(n):
	k = int(input())
	lis = list(map(int, input().split()))
	lis.sort()
	count = 0
	for i in lis:
		if i <= count:
			count += 1
	print(count)


for i in range(int(input())):
	a = int(input())
	b = sorted(list(map(int, input().split())))
	n = []
	for j in b:
		if len(n) >= j:
			n.append(j)
	print(len(n))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	for i in range(len(a)):
		if a[i] == 0:
			ans = ans + 1
		elif ans >= a[i]:
			ans = ans + 1
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	people = 0
	arr.sort()
	for e in arr:
		if people >= e:
			people += 1
		else:
			break
	print(people)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	number_of_people = 0
	for a in A:
		if number_of_people >= a:
			number_of_people += 1
	print(number_of_people)


for _ in range(int(input())):
	n = int(input())
	arr = sorted([int(i) for i in input().split()])
	g = 0
	for i in arr:
		if i <= g:
			g += 1
	print(g)


for _ in range(int(input())):
	n = int(input())
	arr = sorted(tuple(map(int, input().split())))
	count = 0
	for x in arr:
		if x <= count:
			count += 1
		else:
			break
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	a.sort()
	for num in a:
		if c >= num:
			c += 1
	print(c)


def chef_party():
	t = int(input())
	for _ in range(t):
		N = int(input())
		array = input()
		array = array.split()
		array = list(map(int, array))
		num_of_frnds = 0
		array.sort()
		for i in range(N):
			if array[i] <= i:
				num_of_frnds += 1
			else:
				break
		print(num_of_frnds)
		num_of_frnds = 0
chef_party()


for __ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	(f, c) = (0, 0)
	for i in l:
		if i <= f:
			c += 1
			f += 1
	print(c)


for _ in range(int(input())):
	input()
	L = sorted(list(map(int, input().split())))
	count = 0
	for i in range(len(L)):
		if L[i] <= i:
			count += 1
		else:
			break
	print(count)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	r = 0
	for i in range(n):
		if a[i] == 0:
			r += 1
		elif r >= a[i]:
			r += 1
	print(r)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = a.count(0)
	for i in range(c, n):
		if a[i] <= c:
			c += 1
	print(c)


def solve():
	n = int(input())
	l = []
	l = list(map(int, input().split()))
	l.sort()
	c = 0
	if l[0] == 0:
		c = 1
	for i in range(1, len(l)):
		if l[i] <= c:
			c += 1
	print(c)
t = int(input())
i = 0
while i < t:
	solve()
	i += 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a.count(0)
	ans = 0
	for i in sorted(a):
		if i <= x:
			ans += 1
			if i != 0:
				x += 1
	print(ans)


a = int(input())
while a != 0:
	a -= 1
	p = int(input())
	q = list(map(int, input().split()))
	q = sorted(q)
	new = []
	for i in q:
		if len(new) >= i:
			new.append(i)
	print(len(new))


for tc in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	p = 0
	arr.sort()
	for ele in arr:
		if ele == 0 or ele <= p:
			p += 1
		else:
			break
	print(p)


for t in range(int(input())):
	n = int(input())
	people_require = list(map(int, input().split()))
	guest = 0
	people_require.sort()
	if people_require[0] != 0:
		print(guest)
	else:
		for i in range(0, n):
			if people_require[i] <= guest:
				guest += 1
		print(guest)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	a = list(a)
	s = 0
	for i in range(n):
		if a[i] == 0:
			s += 1
		elif s >= a[i]:
			s += 1
	print(s)