There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.

There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.

You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.

------ Input: ------

First line will contain $T$, number of testcases. Then the testcases follow. 
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.

------ Output: ------
For each testcase, output in a single line answer to the problem.

------ Constraints  ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$  $\forall i > 0$
$C_{i} > C_{i - 1}$  $\forall i > 0$
$F_{i}$  !=  $C_{j}$   $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$

----- Sample Input 1 ------ 
3

2 2

1 3

2 4

3 1

100 200 300

1

1 2

1

100 200
----- Sample Output 1 ------ 
3

2

1
----- explanation 1 ------ 
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.

Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.

Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Sorting

Amortized analysis

Implementation

Ad-hoc


Solutions:
for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	k = 0
	a = 0
	p = 1
	l = 1
	while n != k and m != a:
		if f[k] < c[a]:
			if p == 0:
				l += 1
			k += 1
			p = 1
		else:
			if p:
				l += 1
			a += 1
			p = 0
	print(l)


import sys
from math import gcd, sqrt, ceil, log

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

def si():
	return sys.stdin.readline().split()

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

def ip():
	return input()
for tastcas in range(int(input())):
	(n, m) = li()
	farr = li()
	carr = li()
	lst = []
	lst.append([0, 1])
	for a in farr:
		lst.append([a, 1])
	for b in carr:
		lst.append([b, 2])
	lst.sort()
	cnt = 0
	for i in range(1, len(lst)):
		if lst[i][1] != lst[i - 1][1]:
			cnt += 1
	print(cnt)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	fli = list(map(int, input().split()))
	cli = list(map(int, input().split()))
	lst = list()
	lst.append([0, 1])
	for a in fli:
		lst.append([a, 1])
	for b in cli:
		lst.append([b, 2])
	lst.sort()
	cnt = 0
	for i in range(1, len(lst)):
		if lst[i][1] != lst[i - 1][1]:
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	foot = list(map(int, input().split()))
	cric = list(map(int, input().split()))
	start = 0
	ch = 0
	ans = 0
	(i, j) = (0, 0)
	while i < n and j < m:
		if foot[i] < cric[j]:
			if ch == 1:
				ans += 1
			i += 1
			ch = 0
		else:
			if ch == 0:
				ans += 1
			j += 1
			ch = 1
	if i < n and ch == 1:
		ans += 1
	elif j < m and ch == 0:
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	f = list(map(lambda x: 2 * int(x), input().split()))
	c = list(map(lambda x: 2 * int(x) + 1, input().split()))
	fc = sorted(f + c, key=int)
	k = 0
	c = 0
	for j in fc:
		if (j - k) % 2 == 1:
			c += 1
		k = j
	print(c)


t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split())
	foot = list(map(int, input().split()))
	cric = list(map(int, input().split()))
	chan = 1
	ans = 0
	te = [(i, 1) for i in foot] + [(j, 2) for j in cric]
	te = sorted(te)
	for i in te:
		if i[1] != chan:
			ans += 1
			chan = i[1]
	print(ans)


a = int(input())
while a != 0:
	ans = 0
	now = 1
	(n, m) = map(int, input().split())
	f1 = list(map(int, input().split()))
	f2 = list(map(int, input().split()))
	timeline = [(i, 1) for i in f1] + [(i, 2) for i in f2]
	timeline = sorted(timeline)
	for i in timeline:
		if i[1] != now:
			ans = ans + 1
			now = i[1]
	print(ans)
	a = a - 1


import collections as clts
import math
import heapq

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)

def lcm(x, y):
	return int(x / gcd(x, y) * y)
for _ in range(int(input())):
	(N, M) = list(map(int, input().split()))
	F = list(map(int, input().split()))
	C = list(map(int, input().split()))
	(i, j) = (0, 0)
	switches = 0
	current = 'F'
	while True:
		if i <= N - 1 and j <= M - 1 and (F[i] > C[j]) and (current == 'F'):
			switches += 1
			current = 'C'
		if i <= N - 1 and j <= M - 1 and (C[j] > F[i]) and (current == 'C'):
			switches += 1
			current = 'F'
		if current == 'F' and i <= N - 1:
			i += 1
		if current == 'C' and j <= M - 1:
			j += 1
		if i == N or j == M:
			break
	if j <= M - 1 and current == 'F':
		switches += 1
	if i <= N - 1 and current == 'C':
		switches += 1
	print(switches)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	foot = list(map(int, input().split()))
	cric = list(map(int, input().split()))
	now = 1
	ans = 0
	timeline = [(i, 1) for i in foot] + [(i, 2) for i in cric]
	timeline = sorted(timeline, key=lambda x: x[0])
	for curr in timeline:
		if curr[1] != now:
			ans += 1
			now = curr[1]
	print(ans)


def integer_list():
	return list(map(int, input().split()))

def main():
	f.sort(reverse=True)
	c.sort(reverse=True)
	swich = 0
	s = True
	while f and c:
		if f[-1] < c[-1] and s:
			f.pop()
		elif f[-1] <= c[-1] and (not s):
			f.pop()
			s = not s
			swich += 1
		elif c[-1] < f[-1] and (not s):
			c.pop()
		elif c[-1] <= f[-1] and s:
			c.pop()
			s = not s
			swich += 1
	if f and (not s):
		swich += 1
	if c and s:
		swich += 1
	print(swich)
t = int(input())
for _ in range(t):
	(fn, cm) = integer_list()
	f = integer_list()
	c = integer_list()
	main()


t = int(input())
for i in range(t):
	n = list(map(int, input().split()))
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = {}
	ft = 0
	for i in f:
		d[i] = 0
	for i in c:
		d[i] = 1
	l = list(d.keys())
	l.sort()
	count = 0
	for i in l:
		if d[i] == ft:
			pass
		else:
			count += 1
			ft = d[i]
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	a = [(it, 0) for it in f]
	a += [(it, 1) for it in c]
	a.sort()
	curr = 0
	turn = 0
	for (event, sport) in a:
		if sport != curr:
			turn += 1
			curr = sport
	print(turn)


for cases in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	cric = list(map(int, input().split()))
	d = {}
	current_pos = 'f'
	change = 0
	for i in range(n):
		d[arr[i]] = 'f'
	for j in range(m):
		d[cric[j]] = 'c'
		arr.append(cric[j])
	arr.sort()
	for ele in arr:
		if d[ele] != current_pos:
			change += 1
			current_pos = d[ele]
	print(change)


n = int(input())
for i in range(n):
	(f, c) = map(int, input().split())
	foo = list(map(int, input().split()))
	cri = list(map(int, input().split()))
	count = 0
	e = {}
	for i in range(f):
		e[foo[i]] = 0
	for i in range(c):
		e[cri[i]] = 1
	e = dict(sorted(e.items(), key=lambda x: x[0]))
	keys = list(e.keys())
	temp = 0
	for i in range(len(keys)):
		if e[keys[i]] != temp:
			temp = e[keys[i]]
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(N, M) = map(int, input().split())
	fb = list(map(int, input().split()))
	ct = list(map(int, input().split()))
	first = 'fb'
	count = 0
	for i in range(N + M):
		if fb != [] and ct != []:
			if fb[0] < ct[0]:
				present = 'fb'
				fb.pop(0)
			else:
				present = 'ct'
				ct.pop(0)
		elif fb == []:
			present = 'ct'
		elif ct == []:
			present = 'fb'
		if first != present:
			first = present
			count += 1
	print(count)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	ftb = list(map(int, input().split()))
	crc = list(map(int, input().split()))
	d = {}
	count = 0
	for i in range(n):
		d[ftb[i]] = 'f'
	for i in range(m):
		d[crc[i]] = 'c'
	d = dict(sorted(d.items(), key=lambda x: x[0]))
	temp = 'f'
	dkeys = list(d.keys())
	for i in range(len(d)):
		if d[dkeys[i]] != temp:
			count += 1
			temp = d[dkeys[i]]
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	pre = 'F'
	count = 0
	for i in range(n + m):
		if f != [] and c != []:
			if f[0] < c[0]:
				imp = 'F'
				f.pop(0)
			else:
				imp = 'C'
				c.pop(0)
		elif f == []:
			imp = 'C'
			c.pop(0)
		elif c == []:
			imp = 'F'
			f.pop(0)
		if pre != imp:
			pre = imp
			count += 1
	print(count)


try:
	from debug import debug, timer
except ImportError:
	pass
from sys import stdin
input = stdin.readline

def rii():
	return range(int(input().strip()))

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

def mii():
	return map(int, input().strip().split(' '))

def lmii():
	return list(map(int, input().strip().split(' ')))

def si():
	return str(input().strip())

def getvals():
	while True:
		yield from input().split()

def tri(n):
	return n * (n + 1) // 2

def smallest_first(m, n):
	return (min(m, n), max(m, n))
from itertools import groupby

def solve(*args):
	(n, m, f, c) = args
	ans = sorted([(0, 0)] + [(0, x) for x in f] + [(1, x) for x in c], key=lambda y: y[1])
	return len([x for (x, y) in groupby([y for (y, z) in ans])]) - 1

def do_codechef():
	for t in rii():
		(n, m) = mii()
		f = lmii()
		c = lmii()
		print(solve(n, m, f, c))
do_codechef()
exit()


for t in range(int(input())):
	(nF, nC) = map(int, input().split())
	F = [int(i) for i in input().split()]
	C = [int(i) for i in input().split()]
	present = 'F'
	count = 0
	for i in range(nF + nC):
		if F != [] and C != []:
			if F[0] < C[0]:
				imp = 'F'
				F.pop(0)
			else:
				imp = 'C'
				C.pop(0)
		elif F == []:
			imp = 'C'
			C.pop(0)
		elif C == []:
			imp = 'F'
			F.pop(0)
		if present != imp:
			present = imp
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(f, c, pf, pc, prev) = (list(map(int, input().split())), list(map(int, input().split())), [0 for _ in range(0, n)], [1 for _ in range(0, m)], 0)
	(xf, xc) = (dict(zip(f, pf)), dict(zip(c, pc)))
	xc.update(xf)
	(y, x) = (sorted(f + c), 0)
	for i in y:
		if xc[i] != prev:
			(x, prev) = (x + 1, xc[i])
	print(x)


t = int(input())
while t != 0:
	(n, m) = list(map(int, input().split()))
	foot = list(map(int, input().split()))
	cric = list(map(int, input().split()))
	switches = 0
	chanel = 0
	event = []
	for i in foot:
		event.append([i, 0])
	for j in cric:
		event.append([j, 1])
	event = sorted(event, key=lambda x: x[0])
	i = 0
	while i < len(event):
		if event[i][1] != chanel:
			switches += 1
			chanel = 1 - chanel
		i += 1
	print(switches)
	t -= 1


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	football = list(map(int, input().split()))
	cricket = list(map(int, input().split()))
	count = 0
	f = 0
	c = 0
	curren = 'F'
	while f < N and c < M:
		if football[f] < cricket[c]:
			if curren != 'F':
				count += 1
				curren = 'F'
			f += 1
		elif cricket[c] < football[f]:
			if curren != 'C':
				count += 1
				curren = 'C'
			c += 1
	if f != N and curren == 'C':
		count += 1
	if c != M and curren == 'F':
		count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	ans = 0
	if f[0] < c[0]:
		curr = 0
		i = 1
		j = 0
	else:
		ans += 1
		curr = 1
		i = 0
		j = 1
	while i < n and j < m:
		if f[i] < c[j]:
			if curr == 1:
				ans += 1
			curr = 0
			i += 1
		elif c[j] < f[i]:
			if curr == 0:
				ans += 1
			curr = 1
			j += 1
	if i < n:
		if curr == 1:
			ans += 1
	elif curr == 0:
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append((f[i], 'f'))
	for j in range(m):
		l.append((c[j], 'c'))
	prev = 'f'
	l.sort()
	c = 0
	for i in range(n + m):
		try:
			if l[i][1] != prev:
				c += 1
		except IndexError:
			pass
		prev = l[i][1]
	print(c)


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	Lf = [int(x) for x in input().split()]
	Lc = [int(x) for x in input().split()]
	k = 0
	f = 0
	c = 0
	current = 'F'
	while f < n and c < m:
		if Lf[f] < Lc[c]:
			if current != 'F':
				k += 1
				current = 'F'
			f += 1
		elif Lc[c] < Lf[f]:
			if current != 'C':
				k += 1
				current = 'C'
			c += 1
	if f != n and current == 'C':
		k += 1
	if c != m and current == 'F':
		k += 1
	print(k)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	flst = list(map(int, input().split()))
	clst = list(map(int, input().split()))
	s = 0
	d = {}
	(a, b) = (0, 0)
	for i in range(len(flst) + len(clst)):
		try:
			if flst[a] < clst[b]:
				d[flst[a]] = 'f'
				a += 1
			else:
				d[clst[b]] = 'c'
				b += 1
		except:
			if len(flst) == a:
				for i in clst[b:]:
					d[i] = 'c'
			else:
				for i in flst[a:]:
					d[i] = 'f'
			break
	prev = 'f'
	for i in d:
		if d[i] != prev:
			s += 1
			prev = d[i]
	print(s)


import sys
from math import sqrt, gcd
from collections import deque, Counter, OrderedDict
I = lambda : int(input())
S = lambda : input().strip()
M = lambda : map(int, input().strip().split())
L = lambda : list(map(int, input().strip().split()))
mod = 1000000007
for _ in range(I()):
	(n, m) = M()
	f = L()
	c = L()
	arr = [[i, 0] for i in f] + [[i, 1] for i in c]
	arr.sort(key=lambda x: x[0])
	k = 0
	ans = 0
	for (i, v) in arr:
		if v != k:
			ans += 1
			k ^= 1
	print(ans)


T = int(input())
for tj in range(T):
	(N, M) = list(map(int, input().split()))
	Football = list(map(int, input().split()))
	Cricket = list(map(int, input().split()))
	controller = 0
	count = 0
	i = 0
	j = 0
	while i < N and j < M:
		if Cricket[j] < Football[i]:
			if controller == 0:
				controller = 1
				count += 1
			j += 1
		elif Football[i] < Cricket[j]:
			if controller == 1:
				controller = 0
				count += 1
			i += 1
	if i < N and controller == 1:
		count += 1
	elif j < M and controller == 0:
		count += 1
	print(count)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	start = 'football'
	count = 0
	i = j = 0
	while True:
		if start == 'football':
			if c[i] < f[j]:
				start = 'cricket'
				count += 1
			else:
				j += 1
		elif f[j] < c[i]:
			start = 'football'
			count += 1
		else:
			i += 1
		if i == m or j == n:
			print(count + 1)
			break


def solve(n, m, football, cricket):
	switches = 0
	football_bool = True
	f_index = 0
	c_index = 0
	while f_index < n and c_index < m:
		if football[f_index] < cricket[c_index]:
			if not football_bool:
				switches += 1
			football_bool = True
			f_index += 1
		else:
			if football_bool:
				switches += 1
			c_index += 1
			football_bool = False
	if f_index < n and (not football_bool) or (c_index < m and football_bool):
		switches += 1
	return switches

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		football = list(map(int, input().split()))
		cricket = list(map(int, input().split()))
		print(solve(n, m, football, cricket))
main()


def hs(s, t):
	g = 0
	a = 0
	(i, j) = (0, 0)
	while i < len(s) and j < len(t):
		if s[i] < t[j]:
			if g == 1:
				a = a + 1
				g = 0
			i = i + 1
		else:
			if g == 0:
				a = a + 1
				g = 1
			j = j + 1
	if i == len(s):
		a = a + 1
	if j == len(t):
		a = a + 1
	return a
t = int(input())
for _ in range(t):
	(f, c) = map(int, input().split())
	s = list(map(int, input().split()))
	t = list(map(int, input().split()))
	print(hs(s, t))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if 0 in l1 or 0 in l2:
		continue
	c = 0
	flag = 0
	sm = l1[0]
	ptr1 = 0
	ptr2 = 0
	while ptr1 < n and ptr2 < m:
		if l1[ptr1] < l2[ptr2]:
			if flag == 1:
				c = c + 1
				flag = 0
			ptr1 = ptr1 + 1
		else:
			if flag == 0:
				c = c + 1
				flag = 1
			ptr2 = ptr2 + 1
	if ptr1 < n and flag == 1:
		c = c + 1
	elif ptr2 < m and flag == 0:
		c = c + 1
	print(c)


from math import *
import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	l = [(0, 1)]
	for i in f:
		l.append((i, 1))
	for i in c:
		l.append((i, 2))
	l.sort()
	ans = 0
	for i in range(1, n + m + 1):
		if l[i][1] != l[i - 1][1]:
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 'f'
	d = 0
	x = y = 0
	while True:
		if c == 'f':
			if b[y] < a[x]:
				d += 1
				c = 'c'
			else:
				x += 1
		elif a[x] < b[y]:
			d += 1
			c = 'f'
		else:
			y += 1
		if x == n or y == m:
			print(d + 1)
			break


try:
	from sys import stdin, stdout
	rl = lambda : stdin.readline()
	wl = lambda s: stdout.write(s)
	tc = int(rl())
	for _ in range(tc):
		(n, m) = map(int, rl().split())
		F = list(map(int, rl().split()))
		C = list(map(int, rl().split()))
		r = f = c = p = 0
		while f < n and c < m:
			if F[f] < C[c]:
				if p == 1:
					p = 0
					r += 1
				f += 1
			else:
				if p == 0:
					p = 1
					r += 1
				c += 1
		wl(str(r + 1) + '\n')
except:
	pass


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = f + c
	d.sort()
	x = 0
	z = {}
	for i in range(n):
		z[f[i]] = 1
	for i in range(m):
		z[c[i]] = 0
	for i in range(len(d)):
		if z[d[i]] == 0 and x % 2 == 0:
			x += 1
		if z[d[i]] == 1 and x % 2 == 1:
			x += 1
	print(x)


import sys
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	f = [int(x) for x in sys.stdin.readline().split()]
	c = [int(x) for x in sys.stdin.readline().split()]
	o = 0
	s = 'f'
	while len(c) != 0 and len(f) != 0:
		if c[0] < f[0]:
			c.pop(0)
			if s == 'f':
				o += 1
				s = 'c'
		else:
			f.pop(0)
			if s == 'c':
				o += 1
				s = 'f'
	print(o + 1)


import heapq
for i in range(int(input())):
	(n, m) = map(int, input().split())
	n1 = list(map(int, input().split()))
	m1 = list(map(int, input().split()))
	ans = 1
	football = True
	heapq.heapify(n1)
	heapq.heapify(m1)
	while n1 and m1:
		if n1[0] < m1[0]:
			mi = heapq.heappop(n1)
			if not football:
				ans += 1
				football = True
		else:
			mi = heapq.heappop(m1)
			if football:
				ans += 1
				football = False
	print(ans)


for _ in range(int(input())):
	(n, q) = map(int, input().split(' '))
	w = list(map(int, input().split(' ')))
	e = list(map(int, input().split(' ')))
	z = 0
	f = 0
	c = 0
	p = 0
	while f < n and c < q:
		if w[f] < e[c]:
			if p == 1:
				p = 0
				z += 1
			f += 1
		else:
			if p == 0:
				p = 1
				z += 1
			c += 1
	print(str(z + 1))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	i = 0
	j = 0
	curr = 'F'
	res = 0
	while i < n and j < m:
		if f[i] < c[j]:
			if curr == 'C':
				res += 1
				curr = 'F'
			i += 1
		elif f[i] == c[j]:
			if curr == 'C':
				res += 1
				curr = 'F'
			elif curr == 'F':
				res += 1
				curr = 'C'
			i += 1
			j += 1
		else:
			if curr == 'F':
				res += 1
				curr = 'C'
			j += 1
	if i < n:
		if curr == 'C':
			res += 1
	if j < m:
		if curr == 'F':
			res += 1
	print(res)


for _ in range(int(input())):
	(noOfFoot, noOfCric) = map(int, input().split(' '))
	footImpEvents = list(map(int, input().split(' ')))
	cricImpEvents = list(map(int, input().split(' ')))
	r = f = c = p = 0
	while f < noOfFoot and c < noOfCric:
		if footImpEvents[f] < cricImpEvents[c]:
			if p == 1:
				p = 0
				r += 1
			f += 1
		else:
			if p == 0:
				p = 1
				r += 1
			c += 1
	print(str(r + 1))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr3 = arr1 + arr2
	c = 1
	switches = 0
	for i in range(n):
		arr1[i] = (arr1[i], 1)
	for j in range(m):
		arr2[j] = (arr2[j], 2)
	arr3 = arr1 + arr2
	arr3.sort()
	for i in arr3:
		if i[1] != c:
			switches += 1
			c = i[1]
	print(switches)


T = int(input())
for i in range(T):
	(N, M) = input().split()
	N = int(N)
	M = int(M)
	F = list(map(int, input().split()))
	C = list(map(int, input().split()))
	D = F + C
	D.sort()
	val = 0
	F1 = {}
	for i in range(N):
		F1[F[i]] = 1
	for i in range(M):
		F1[C[i]] = 0
	for i in range(len(D)):
		if F1[D[i]] == 0 and val % 2 == 0:
			val += 1
		if F1[D[i]] == 1 and val % 2 == 1:
			val += 1
	print(val)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	t = list(map(int, input().split()))
	d = {}
	for j in l:
		d[j] = 0
	for j in t:
		d[j] = 1
	c = 0
	f = 0
	for j in sorted(d.keys()):
		if d[j] == 0 and f == 1:
			f = 0
			c = c + 1
		if d[j] == 1 and f == 0:
			f = 1
			c = c + 1
	print(c)


import heapq as hq
T = int(input())
c = []
for i in range(T):
	[N, M] = [int(k) for k in input().split()]
	a = input().split()
	b = input().split()
	for i in range(N):
		hq.heappush(c, (int(a[i]), 1))
	for i in range(M):
		hq.heappush(c, (int(b[i]), 2))
	w = 1
	cnt = 0
	for i in range(len(c)):
		x = hq.heappop(c)
		if x[1] != w:
			cnt = cnt + 1
			w = x[1]
	print(cnt)


def ans():
	ans = i = j = p = 0
	while i < n and j < m:
		if f[i] < c[j]:
			if p != 0:
				p = 0
				ans += 1
			i += 1
		else:
			if p == 0:
				p = 1
				ans += 1
			j += 1
	print(ans + 1)
for i in range(int(input())):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	ans()


tot = int(input())
for _ in range(tot):
	(nf, nc) = map(int, input().split())
	foot = set(map(int, input().split()))
	crick = set(map(int, input().split()))
	ev = list(foot.union(crick))
	ev.sort()
	chan = 'foot'
	s = 0
	for i in ev:
		if i in crick and chan != 'crick':
			s += 1
			chan = 'crick'
		elif i in foot and chan != 'foot':
			s += 1
			chan = 'foot'
	print(s)


t = int(input())
for i in range(t):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	i = 0
	j = 0
	p = 1
	c = 0
	while i < n and j < m:
		if a[i] < b[j]:
			if p == 1:
				i += 1
				continue
			else:
				c += 1
				p = 1
				i += 1
		elif p == 2:
			j += 1
			continue
		else:
			c += 1
			p = 2
			j += 1
	print(c + 1)


t = int(input())
while t != 0:
	(n, m) = list(map(int, input().split()))
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	fd = list(map(lambda x: (x, 'f'), f))
	cd = list(map(lambda x: (x, 'c'), c))
	main = fd + cd
	main.sort()
	toSwitch = 'c'
	switches = 0
	for i in range(len(main)):
		if toSwitch == main[i][1]:
			switches = switches + 1
			if toSwitch == 'c':
				toSwitch = 'f'
			else:
				toSwitch = 'c'
	print(switches)
	t = t - 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	foot = set(map(int, input().split()))
	cric = set(map(int, input().split()))
	array = list(foot.union(cric))
	array.sort()
	temp = 'football'
	count = 0
	for i in array:
		if i in cric and temp != 'cricket':
			count += 1
			temp = 'cricket'
		elif i in foot and temp != 'football':
			count += 1
			temp = 'football'
	print(count)


try:
	t = int(input())
	for i in range(t):
		(n, m) = [int(itm) for itm in input().split()]
		ma = {}
		f = [int(itm) for itm in input().split()]
		c = [int(itm) for itm in input().split()]
		for itm in f:
			ma[itm] = 'F'
		for itm in c:
			ma[itm] = 'C'
		mt = {0: 'F'}
		for itm in sorted(ma.keys()):
			mt[itm] = ma[itm]
		check = 'F'
		count = 0
		for itm in mt.keys():
			if mt[itm] != check:
				count += 1
				check = mt[itm]
		print(count)
except EOFError:
	exit()


T = int(input())
for i in range(0, T):
	(N, M) = map(int, input().split(' '))
	array_FE = set(map(int, input().split(' ')))
	array_CE = set(map(int, input().split(' ')))
	array = list(array_FE.union(array_CE))
	array.sort()
	b = 'football'
	c = 0
	for event in array:
		if event in array_CE and b != 'cricket':
			c = c + 1
			b = 'cricket'
		elif event in array_FE and b != 'football':
			c = c + 1
			b = 'football'
	print(c)


def solve(A, n, B, m):
	C = [(i, 0) for i in A]
	C += [(i, 1) for i in B]
	C.sort()
	change = 0
	curr = 0
	for (tim, sport) in C:
		if curr != sport:
			change += 1
		curr = sport
	return change
for case in range(int(input())):
	(n, m) = map(int, input().split())
	F = list(map(int, input().split()))
	C = list(map(int, input().split()))
	ans = solve(F, n, C, m)
	print(ans)


t = int(input())
for z in range(t):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	i = 0
	j = 0
	k = 0
	count = 0
	while i < n and j < m:
		if f[i] < c[j]:
			if k == 1:
				k = 0
				count += 1
			i += 1
		elif c[j] < f[i]:
			if k == 0:
				k = 1
				count += 1
			j += 1
		else:
			i += 1
			j += 1
	if i < n:
		if k == 1:
			k = 0
			count += 1
	if j < m:
		if k == 0:
			k = 1
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = []
	f = list(map(int, input().split()))
	c = list(map(int, input().split()))
	current = 'f'
	count = 0
	for i in range(n):
		l.append((f[i], 'f'))
	for i in range(m):
		l.append((c[i], 'c'))
	l.sort()
	for i in range(len(l)):
		if l[i][1] != current and current == 'f':
			count = count + 1
			current = 'c'
			continue
		if l[i][1] != current and current == 'c':
			count = count + 1
			current = 'f'
	print(count)


from math import *
R = lambda : list(map(int, input().split()))
MOD = 1000000007
for _ in range(int(input())):
	(n, m) = R()
	f = R()
	c = R()
	(l, r) = (0, 0)
	(flag, cnt) = (0, 0)
	while l < n and r < m:
		if flag and f[l] < c[r]:
			cnt += 1
			flag = 0
			l += 1
		elif flag == 0 and c[r] < f[l]:
			cnt += 1
			flag = 1
			r += 1
		elif f[l] < c[r]:
			l += 1
		else:
			r += 1
	cnt += 1
	print(cnt)


for T in range(int(input())):
	(N, M) = map(int, input().split())
	F = list(map(int, input().split()))
	C = list(map(int, input().split()))
	Channel = 'F'
	result = 0
	for i in range(int(N + M)):
		if len(F) != 0 and len(C) != 0:
			if F[0] < C[0]:
				del F[0]
				if Channel != 'F':
					result += 1
					Channel = 'F'
			else:
				del C[0]
				if Channel != 'C':
					result += 1
					Channel = 'C'
		else:
			result += 1
			break
	print(result)