There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest.  
There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas.  
When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties.

The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. 

It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, denoting the number of Pokemon trainers.
- The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena.
- The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena.

------ Output Format ------ 

For each test case, output on a new line the number Pokemon trainers who will qualify for the next round.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 10^{5}$
$1 ≤ A_{i}, B_{i} ≤ 10^{9}$
- The elements of array $A$ are distinct.
- The elements of array $B$ are distinct.
- The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$.

----- Sample Input 1 ------ 
4
2
1 2
3 4
2
1 2
2 1
3
1 2 3
1 4 2
5
2 3 5 4 1
4 2 1 5 6
----- Sample Output 1 ------ 
1
2
2
3
----- explanation 1 ------ 
Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify.

Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify.

Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$:
- Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$.
- Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$.
- Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.

Difficulty: MEDIUM_HARD
Tags: Sorting
Skill types: Sorting

Starter code:

Solutions:
t = int(input())
for l in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	nums = []
	for i in range(n):
		nums.append([arr[i], ar[i]])
	nums.sort(key=lambda x: x[0])
	maxil = [None for _ in range(n)]
	maxi = 0
	cnt = 0
	for i in range(n - 1, -1, -1):
		if maxi < nums[i][1]:
			maxi = nums[i][1]
			cnt += 1
	print(cnt)


def solve(n, arr, brr):
	t = []
	for i in range(n):
		t.append((arr[i], brr[i]))
	t.sort(key=lambda x: x[0], reverse=True)
	count = 0
	maxn = 0
	for i in range(0, n):
		a = t[i][0]
		b = t[i][1]
		if b > maxn:
			maxn = b
			count += 1
	print(count)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	solve(n, arr, brr)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ab = sorted([(a[i], b[i]) for i in range(n)])
	(ans, mx) = (0, 0)
	for i in reversed(range(n)):
		if ab[i][1] > mx:
			ans += 1
		mx = max(mx, ab[i][1])
	print(ans)


import numpy as np
from functools import reduce
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = np.argsort(a)
	bar = b[c[n - 1]]
	co = 1
	for i in range(n - 2, -1, -1):
		jump = b[c[i]]
		if jump > bar:
			co += 1
			bar = jump
	print(co)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	Z = list(zip(A, B))
	Z.sort(key=lambda x: x[0])
	ans = 0
	max_ = -1
	for (X, Y) in reversed(Z):
		if Y > max_:
			ans += 1
			max_ = Y
	print(ans)


from bisect import bisect_left
from code import interact
from heapq import heapify, heappush, heappop
from collections import deque
from pydoc import plain
from re import X
import sys
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
input = sys.stdin.readline

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

def ii():
	return int(input())

def ot(in_p, *args, e=' '):
	if type(in_p) == list:
		print(*in_p, end=e)
	if type(in_p) == str or type(in_p) == int:
		print(in_p, end=e)
		for l in args:
			print(l, end=e)
	print()

def a_pwr_n(a, n, mod):
	if n == 1:
		return a % mod
	if n % 2 == 0:
		val = a_pwr_n(a, n // 2, mod)
		return val % mod * val % mod
	else:
		return a % mod * a_pwr_n(a, n - 1, mod) % mod

def rg(*ag):
	if len(ag) == 3:
		return range(ag[0], ag[1], ag[2])
	elif len(ag) == 2:
		return range(ag[0], ag[1])
	elif len(ag) == 1:
		return range(ag[0])
	else:
		raise 'invalid input'

def ispal(i, j, st):
	while i <= j:
		if st[i] == st[j]:
			i = i + 1
			j = j - 1
		else:
			return False
	return True
mod = 1000000000 + 7
dx = [-1, -2, 1, 2, 2, -2, -1, 1]
dy = [2, 1, 2, 1, -1, -1, -2, -2]
for _ in range(ii()):
	n = ii()
	a = il()
	b = il()
	arr = [[a[i], b[i]] for i in range(n)]
	arr.sort()
	(res, mx) = (0, 0)
	for i in reversed(range(n)):
		if arr[i][1] >= mx:
			res += 1
		mx = max(mx, arr[i][1])
	print(res)


for T in range(int(input())):
	lent = int(input())
	land = list(map(lambda x: int(x), input().split()))
	water = list(map(lambda x: int(x), input().split()))
	count = 0
	l = []
	for i in range(lent):
		l.append([land[i], water[i]])
	l.sort(reverse=True)
	m = 0
	for i in range(len(l)):
		if l[i][1] > m:
			count += 1
			m = l[i][1]
	print(count)


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


T = int(input())
for _ in range(T):
	N = int(input())
	X = list(map(int, input().split()))
	Y = list(map(int, input().split()))
	Z = list(zip(X, Y))
	Z.sort(key=lambda x: x[0])
	answer = 0
	maximum = -1
	for (A, B) in reversed(Z):
		if B > maximum:
			answer += 1
			maximum = B
	print(answer)


import numpy as np
T = int(input())
for tc in range(T):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	A_order = np.argsort(A)
	count = 1
	bar = B[A_order[n - 1]]
	for i in range(n - 2, -1, -1):
		jump = B[A_order[i]]
		if jump > bar:
			count += 1
			bar = jump
	print(count)


for _ in range(int(input())):
	t = int(input())
	count = 1
	gPokemon = list(map(int, input().split()))
	wPokemon = list(map(int, input().split()))
	trainer = zip(gPokemon, wPokemon)
	trainer = sorted(trainer)
	count_max = trainer[-1][1]
	for i in range(t - 2, -1, -1):
		if count_max < trainer[i][1]:
			count += 1
			count_max = trainer[i][1]
	print(count)


for _ in range(int(input())):
	n = int(input())
	G = list(map(int, input().split()))
	W = list(map(int, input().split()))
	tup = []
	res = 1
	for i in range(n):
		tup.append((G[i], W[i]))
	tup.sort(key=lambda x: x[0], reverse=True)
	for i in range(1, n):
		j = i - 1
		flag = 1
		while j >= 0:
			if tup[j][1] > tup[i][1]:
				flag = 0
				break
			j -= 1
		if flag == 1:
			res += 1
	print(res)


import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os

def values():
	return tuple(map(int, sys.stdin.readline().split()))

def inlsts():
	return [int(i) for i in sys.stdin.readline().split()]

def inp():
	return int(sys.stdin.readline())

def instr():
	return sys.stdin.readline().strip()

def words():
	return [i for i in sys.stdin.readline().strip().split()]

def chars():
	return [i for i in sys.stdin.readline().strip()]

def solve():
	n = inp()
	l1 = inlsts()
	l2 = inlsts()
	z = sorted(zip(l1, l2))
	ans = 1
	tmp = z[-1][1]
	for i in range(n - 2, -1, -1):
		if z[i][1] > tmp:
			ans += 1
			tmp = z[i][1]
	print(ans)
for i in range(inp()):
	solve()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a = [(a[i], b[i]) for i in range(n)]
	a.sort(key=lambda x: x[0])
	s = 1
	cm = a[-1][1]
	for i in range(n - 2, -1, -1):
		if a[i][1] > cm:
			s += 1
			cm = a[i][1]
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = []
	for i in range(n):
		x.append([a[i], b[i]])
	x.sort(key=lambda x: x[0])
	mx = 0
	ans = 0
	for i in range(n - 1, -1, -1):
		if x[i][1] > mx:
			ans += 1
			mx = x[i][1]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr3 = [(arr1[i], arr2[i]) for i in range(n)]
	arr3.sort()
	(ans, temp) = (0, 0)
	for i in range(n - 1, -1, -1):
		if arr3[i][1] > temp:
			ans += 1
			temp = arr3[i][1]
	print(ans)


from collections import OrderedDict
for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	d1 = {}
	d2 = {}
	for i in range(n):
		d1[x[i]] = i
		d2[y[i]] = i
	d1 = OrderedDict(sorted(d1.items()))
	d2 = OrderedDict(sorted(d2.items()))
	d1 = list(d1.values())
	d2 = list(d2.values())
	(z1, z2) = (0, 0)
	m = [0 for i in range(n)]
	for i in range(n):
		m[d1[i]] |= z1
		z1 = z1 | 1 << d1[i]
		m[d2[i]] |= z2
		z2 = z2 | 1 << d2[i]
	ans = 0
	mask = (1 << n) - 1
	for i in m:
		z = mask ^ i
		if not z & z - 1:
			ans += 1
	print(ans)


x = int(input())
for i in range(x):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	b = []
	vect = []
	k = 1
	for i in range(n):
		vect.append([A[i], B[i]])
	vect = sorted(vect)
	for i in range(n):
		b.append(vect[i][1])
	c = [0] * n
	max = b[n - 1]
	for i in range(n - 1, -1, -1):
		if b[i] > max:
			c[i] = 1
			max = b[i]
		else:
			pass
	for i in range(n):
		if c[i] == 1:
			k = k + 1
	print(k)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	nl = []
	for i in range(n):
		nl.append((l1[i], l2[i]))
	nl.sort()
	mx = 0
	cn = 0
	for i in range(n - 1, -1, -1):
		if nl[i][1] > mx:
			cn += 1
		mx = max(mx, nl[i][1])
	print(cn)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	d = {}
	for i in range(n):
		d[A[i]] = B[i]
	mx = 0
	count = 0
	for i in reversed(sorted(d.keys())):
		if mx < d[i]:
			count += 1
			mx = d[i]
	print(count)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = [(a[i], b[i]) for i in range(n)]
	l = sorted(l, key=lambda l: l[0])
	m1 = l[-1][1]
	answer = 1
	for i in range(n - 2, -1, -1):
		if l[i][1] > m1:
			answer += 1
			m1 = max(m1, l[i][1])
	print(answer)


T = int(input())
for m in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	d = {}
	for i in range(N):
		d[A[i]] = B[i]
	d = sorted(d.items(), reverse=True)
	count = 1
	mx = d[0][1]
	for i in d:
		if i[1] > mx:
			count += 1
			mx = i[1]
	print(count)


for _ in range(int(input())):
	N = int(input())
	land = list(map(int, input().split()))
	water = list(map(int, input().split()))
	zipArr = sorted(zip(land, water))
	tempTuple = zip(*zipArr)
	(newLand, newWater) = [list(element) for element in tempTuple]
	newLand = newLand[::-1]
	newWater = newWater[::-1]
	ans = 1
	maxWater = newWater[0]
	for i in range(1, N):
		if newWater[i - 1] > maxWater:
			maxWater = newWater[i - 1]
		if newWater[i] > maxWater:
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = list(map(int, input().split()))[:n]
	c = []
	for i in range(len(a)):
		d = 0
		for j in range(n):
			if a[i] > a[j] or b[i] > b[j]:
				d = d + 1
			elif a[i] < a[j] and b[i] < b[j]:
				break
		c.append(d)
	z = c.count(max(c))
	t = t - 1
	print(z)


from bisect import *
for _ in range(int(input())):
	n = int(input())
	ground = list(map(int, input().split()))
	water = list(map(int, input().split()))
	temp = []
	len1 = len(ground)
	for i in range(len1):
		temp.append([ground[i], water[i]])
	temp.sort(key=lambda x: x[0], reverse=True)
	ans = []
	n = len(temp)
	ss = []
	for i in range(n):
		strength1 = n - (i + 1)
		ind = bisect(ss, temp[i][1])
		strength2 = ind - 0
		insort(ss, temp[i][1])
		ans.append(strength1 + strength2)
	maxm = max(ans)
	print(ans.count(maxm))


import math
for tc in range(int(input())):
	n = int(input())
	ground = list(map(int, input().split()))
	water = list(map(int, input().split()))
	s = sorted(zip(ground, water))
	cnt = 1
	curr_max = s[-1][1]
	for i in range(n - 2, -1, -1):
		if curr_max < s[i][1]:
			cnt += 1
			curr_max = s[i][1]
	print(cnt)


for testcases in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append([l1[i], l2[i]])
	l.sort(reverse=True)
	m = 0
	c = 0
	for i in range(n):
		if l[i][1] > m:
			c += 1
			m = l[i][1]
	print(c)


t = int(input())
for _ in range(t):
	length = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a = [(a[i], b[i]) for i in range(length)]
	a.sort(key=lambda x: x[0])
	ans = 1
	curr_max = a[-1][1]
	for i in range(length - 2, -1, -1):
		if a[i][1] > curr_max:
			ans += 1
			curr_max = a[i][1]
	print(ans)


for i in range(int(input())):
	n = 0
	n = int(input())
	everyones_win = []
	max1 = 1
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		win_proper = 0
		for j in range(n):
			if a[i] < a[j] and b[i] < b[j]:
				break
			elif a[i] > a[j] or b[i] > b[j]:
				win_proper += 1
		everyones_win.append(win_proper)
	print(everyones_win.count(max(everyones_win)))


def sort_by_wtr_pwr(arr):
	return arr[1]

def find_qualifiers(no_of_pokemons, gnd_pwr, wtr_pwr):
	pokemon_pwr = [(gnd_pwr[i], wtr_pwr[i]) for i in range(no_of_pokemons)]
	pokemon_pwr.sort(key=sort_by_wtr_pwr, reverse=False)
	no_of_qualifiers = 1
	max_gnd_pwr_a_pokemon_has_had = pokemon_pwr[no_of_pokemons - 1][0]
	for i in range(no_of_pokemons - 1, -1, -1):
		if pokemon_pwr[i][0] > max_gnd_pwr_a_pokemon_has_had:
			no_of_qualifiers += 1
			max_gnd_pwr_a_pokemon_has_had = pokemon_pwr[i][0]
	return no_of_qualifiers
for _ in range(int(input())):
	no_of_pokemons = int(input())
	gnd_pwr = list(map(int, input().split()))
	wtr_pwr = list(map(int, input().split()))
	print(find_qualifiers(no_of_pokemons, gnd_pwr, wtr_pwr))


from collections import Counter
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [(A[i], B[i]) for i in range(N)]
	C.sort()
	(ans, mx) = (0, 0)
	for i in reversed(range(N)):
		if C[i][1] > mx:
			ans += 1
		mx = max(mx, C[i][1])
	print(ans)


from sys import stdin

def pokeman(n, arr1, arr2):
	arr = [(arr1[i], arr2[i]) for i in range(n)]
	arr.sort(key=lambda x: x[0])
	maxo = -1
	count = 0
	for i in range(n - 1, -1, -1):
		if arr[i][1] > maxo:
			count += 1
			maxo = arr[i][1]
	return count
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	arr1 = [int(x) for x in stdin.readline().strip().split()]
	arr2 = [int(x) for x in stdin.readline().strip().split()]
	print(pokeman(n, arr1, arr2))


for i in range(int(input())):
	n_trainer = int(input())
	pokemon_trainer_powers = [(i, j) for (i, j) in zip(map(int, input().split()), map(int, input().split()))]
	pokemon_trainer_powers = sorted(pokemon_trainer_powers, key=lambda x: x[0])
	pokemon_trainer_qualifiers = 0
	mx_b = 0
	for ptp in pokemon_trainer_powers[::-1]:
		if ptp[1] > mx_b:
			pokemon_trainer_qualifiers += 1
			mx_b = ptp[1]
	print(pokemon_trainer_qualifiers)


import math
for i in range(int(input())):
	N = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	C = [(A[i], B[i]) for i in range(N)]
	C.sort()
	ans = 0
	highest = 0
	for i in range(N - 1, -1, -1):
		if C[i][1] > highest:
			ans += 1
			highest = C[i][1]
	print(ans)


def pokemon(n, a, b):
	count = 0
	for i in range(len(a)):
		flag = True
		for j in range(len(a)):
			if i == j:
				pass
			elif a[i] < a[j] and b[i] < b[j]:
				flag = False
				break
		if flag:
			count += 1
	return count
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(pokemon(n, a, b))


import numpy as np
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a = [(a[i], b[i]) for i in range(n)]
	a.sort(key=lambda x: x[0])
	ans = 1
	curr_max = a[-1][1]
	for i in range(n - 2, -1, -1):
		if a[i][1] > curr_max:
			ans += 1
			curr_max = a[i][1]
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = sorted(zip(a, b))
	ans = 1
	m = l[-1][1]
	for i in range(n - 2, -1, -1):
		if l[i][1] > m:
			ans += 1
			m = l[i][1]
	print(ans)


import math as m

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return abs(a)

def ncr(N, R):
	return m.factorial(N) // (m.factorial(R) * m.factorial(N - R))

def getL():
	return [int(i) for i in input().split(' ')]

def getInt():
	return int(input())

def solve():
	n = getInt()
	a = getL()
	b = getL()
	anb = [[i, j] for (i, j) in zip(a, b)]
	anb.sort(key=lambda a: a[0])
	ans = 0
	mx = -1
	for i in range(n - 1, -1, -1):
		if anb[i][1] > mx:
			mx = anb[i][1]
			ans += 1
	print(ans)
for _ in range(getInt()):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	gp = list(map(int, input().split(' ')))
	wp = list(map(int, input().split(' ')))
	lst = [i for i in range(n)]
	p = list(zip(gp, lst))
	p.sort(key=lambda x: x[0])
	q = [g[1] for g in p]
	x = n - 2
	cnt = 1
	maxi = wp[q[n - 1]]
	while x >= 0:
		j = x + 1
		if wp[q[x]] > max(maxi, wp[q[j]]):
			cnt += 1
			maxi = wp[q[x]]
		else:
			cnt += 0
		x = x - 1
	print(cnt)


t = int(input())
for i in range(0, t):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [(A[i], B[i]) for i in range(0, N)]
	(ans, mxn) = (0, 0)
	C.sort()
	for i in reversed(range(0, N)):
		if C[i][1] > mxn:
			ans += 1
		mxn = max(mxn, C[i][1])
	print(ans)


t = int(input())
count = 0
for i in range(t):
	N = int(input())
	a = list(map(int, input().strip().split()))[:N]
	b = list(map(int, input().strip().split()))[:N]
	c = [(a[i], b[i]) for i in range(N)]
	c.sort()
	(ans, mx) = (0, 0)
	for i in range(N - 1, -1, -1):
		if c[i][1] > mx:
			ans += 1
		mx = max(mx, c[i][1])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sorted([(a[i], b[i]) for i in range(n)], reverse=True)
	_max = c[0][1]
	counter = 1
	for _c in c:
		if _c[1] > _max:
			_max = _c[1]
			counter += 1
	print(counter)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [[a[i], b[i]] for i in range(n)]
	c.sort(key=lambda x: x[0])
	a = [c[i][0] for i in range(n)]
	b = [c[i][1] for i in range(n)]
	total = 0
	max_ = 0
	for i in range(n - 1, -1, -1):
		if b[i] > max_:
			total += 1
		max_ = max(max_, b[i])
	print(total)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append((a[i], b[i]))
	c.sort()
	s = 1
	m = c[n - 1][1]
	for i in reversed(range(n)):
		if c[i][1] > m:
			s += 1
			m = c[i][1]
	print(s)


for t in range(int(input())):
	l = int(input())
	l1 = [int(i) for i in input().split()]
	l2 = [int(j) for j in input().split()]
	z = [x for (_, x) in sorted(zip(l1, l2))]
	z.reverse()
	m = z[0]
	c = 1
	for i in range(1, l):
		if m < z[i]:
			c += 1
			m = z[i]
	print(c)


from heapq import heappop, heappush, heapify
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	z = []
	for j in range(len(x)):
		z.append([x[j], y[j]])
	z.sort(reverse=True)
	a = z[0][1]
	ans = 1
	for j in range(1, len(z)):
		if z[j][1] > a:
			ans += 1
			a = z[j][1]
	print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	g = list(map(int, input().split()))
	w = list(map(int, input().split()))
	wd = defaultdict(int)
	for i in range(n):
		wd[g[i]] = w[i]
	g.sort(reverse=True)
	ans = 1
	a = wd[g[0]]
	for i in range(1, n):
		if wd[g[i]] > a:
			ans += 1
			a = wd[g[i]]
	print(ans)


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


for t in range(int(input())):
	n = int(input())
	l1 = [int(i) for i in input().split()]
	l2 = [int(j) for j in input().split()]
	l = [[l1[i], l2[i]] for i in range(n)]
	l.sort()
	z = [x[1] for x in l]
	z.reverse()
	m = z[0]
	c = 1
	for i in range(1, n):
		if m < z[i]:
			c += 1
			m = z[i]
	print(c)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = [(a[i], b[i]) for i in range(n)]
	p = sorted(p, key=lambda x: x[0])
	mx = p[n - 1][1]
	ans = 1
	for i in reversed(range(n)):
		if p[i][1] > mx:
			ans += 1
		mx = max(p[i][1], mx)
	print(ans)


n = int(input())
for i in range(n):
	p = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = []
	for i in range(len(a)):
		d.append([a[i], b[i]])
	d.sort(key=lambda x: x[0], reverse=True)
	c = 1
	ma = d[0][1]
	for i in range(len(d)):
		if d[i][1] > ma:
			c += 1
			ma = d[i][1]
	print(c)


cases = int(input())
while cases:
	cases -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ab = []
	for i in range(n):
		ab.append([a[i], b[i]])
	ab.sort(key=lambda x: x[0], reverse=True)
	ans = 1
	leftMax = ab[0][1]
	for i in range(1, n):
		if ab[i][1] > leftMax:
			ans += 1
			leftMax = ab[i][1]
	print(ans)


def strength(n, A, B):
	c = [(A[i], B[i]) for i in range(n)]
	c.sort()
	mx = 0
	count = 0
	for i in reversed(range(n)):
		if c[i][1] > mx:
			count += 1
		mx = max(mx, c[i][1])
	print(count)
for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	strength(n, A, B)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(([A[i], B[i]] for i in range(N)))
	C.sort()
	ans = 0
	mx = 0
	for i in range(N - 1, -1, -1):
		if C[i][1] > mx:
			ans += 1
			mx = max(mx, C[i][1])
	print(ans)


from heapq import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(h1, h2) = ([], [])
	res = 0
	for i in range(n):
		heappush(h2, [-a[i], -b[i]])
	heappush(h1, 0)
	for i in range(n):
		if h2[0][1] < h1[0]:
			res += 1
		p = h2[0][1]
		heappop(h2)
		heappush(h1, p)
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = sorted(zip(map(int, input().split()), map(int, input().split())), reverse=True)
	ans = 1
	mx = a[0][1]
	for (i, j) in a:
		if j > mx:
			ans += 1
			mx = j
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	ground = list(map(int, input().split(' ')))
	water = list(map(int, input().split(' ')))
	power = [(ground[i], water[i]) for i in range(n)]
	power.sort()
	(ans, mx) = (0, 0)
	for i in reversed(range(n)):
		if power[i][1] > mx:
			ans += 1
		mx = max(mx, power[i][1])
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(x) for x in input().split()]
	a = tuple(zip(a, b))
	a = sorted(a)
	mx = a[-1][1]
	cnt = 1
	for i in range(n - 2, -1, -1):
		if a[i][1] > mx:
			cnt += 1
			mx = max(mx, a[i][1])
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append([a[i], b[i]])
	l.sort(key=lambda x: x[0])
	m_b = l[-1][1]
	count = 1
	for i in range(n - 2, -1, -1):
		if l[i][1] > m_b:
			count += 1
			m_b = max(m_b, l[i][1])
	print(count)


for _ in range(int(input())):
	msn = int(input())
	ground = list(map(int, input().split()))
	water = list(map(int, input().split()))
	msl = [(ground[i], water[i]) for i in range(msn)]
	msl.sort()
	c = 1
	mx = msl[msn - 1][1]
	for j in range(msn - 2, -1, -1):
		a = msl[j][1]
		if a > mx:
			c += 1
			mx = a
	print(c)


def sol():
	n = int(input())
	ground = list(map(int, input().split()))
	water = list(map(int, input().split()))
	c = [(ground[i], water[i]) for i in range(n)]
	c.sort()
	(ans, mx) = (0, 0)
	for i in range(n - 1, -1, -1):
		if c[i][1] > mx:
			ans += 1
		mx = max(mx, c[i][1])
	print(ans)
t = int(input())
while t:
	sol()
	t -= 1


for _ in range(int(input())):
	length = int(input())
	arena1 = list(map(int, input().split()))
	arena2 = list(map(int, input().split()))
	combined = [(arena1[i], arena2[i]) for i in range(length)]
	combined.sort()
	ans = 1
	curr_max_seen = combined[length - 1][1]
	for i in range(length - 2, -1, -1):
		if combined[i][1] > curr_max_seen:
			curr_max_seen = combined[i][1]
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = []
	for i in range(n):
		k += [[a[i], b[i]]]
	k.sort(reverse=True)
	tr = 1
	g = k[0][1]
	for i in range(1, n):
		if k[i][1] > g:
			tr += 1
			g = k[i][1]
	print(tr)


t = int(input())
for i in range(t):
	tra = 0
	wtr = 0
	n = int(input())
	array_g = list(map(int, input().split()))
	array_w = list(map(int, input().split()))
	f = list(zip(array_g, array_w))
	f.sort()
	for i in range(-1, -n - 1, -1):
		if f[i][1] > wtr:
			wtr = f[i][1]
			tra += 1
	print(tra)


def pBattles(n, a, b):
	trainers = list(zip(a, b))
	trainers.sort()
	maxWaterPower = 0
	nextRoundTrainers = 0
	for i in reversed(range(n)):
		if trainers[i][1] > maxWaterPower:
			maxWaterPower = trainers[i][1]
			nextRoundTrainers += 1
	return nextRoundTrainers
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(pBattles(n, a, b))


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	l = list(zip(l1, l2))
	l.sort()
	max = 0
	ans = 0
	for i in reversed(range(n)):
		if l[i][1] > max:
			ans += 1
			max = l[i][1]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	b = [x for (_, x) in sorted(zip(a, b))]
	a.sort()
	ans = 1
	mx = b[n - 1]
	for i in range(n - 2, -1, -1):
		if b[i] > mx:
			ans += 1
			mx = b[i]
	print(ans)