Gildong's town has a train system that has $100$ trains that travel from the bottom end to the top end and $100$ trains that travel from the left end to the right end. The trains starting from each side are numbered from $1$ to $100$, respectively, and all trains have the same speed. Let's take a look at the picture below.

The train system can be represented as coordinates on a 2D plane. The $i$-th train starting at the bottom end is initially at $(i,0)$ and will be at $(i,T)$ after $T$ minutes, and the $i$-th train starting at the left end is initially at $(0,i)$ and will be at $(T,i)$ after $T$ minutes. All trains arrive at their destinations after $101$ minutes.

However, Gildong found that some trains scheduled to depart at a specific time, simultaneously, are very dangerous. At this time, $n$ trains are scheduled to depart from the bottom end and $m$ trains are scheduled to depart from the left end. If two trains are both at $(x,y)$ at the same time for some $x$ and $y$, they will crash into each other. Therefore, he is asking you to find the minimum number of trains that should be cancelled to prevent all such crashes.


-----Input-----

Each test contains one or more test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$).

Each test case contains three lines. The first line of each test case consists of two integers $n$ and $m$ ($1 \le n, m \le 100$) — the number of trains scheduled to depart from the bottom end, and the number of trains scheduled to depart from the left end, respectively.

The second line of each test case contains $n$ integers. Each integer is a train number that is scheduled to start from the bottom end. The numbers are given in strictly increasing order, and are between $1$ and $100$, inclusive.

The third line of each test case contains $m$ integers. Each integer is a train number that is scheduled to start from the left end. The numbers are given in strictly increasing order, and are between $1$ and $100$, inclusive.


-----Output-----

For each test case, print a single integer: the minimum number of trains that should be canceled in order to prevent all crashes.


-----Examples-----

Input
3
1 2
1
3 4
3 2
1 3 4
2 4
9 14
2 7 16 28 33 57 59 86 99
3 9 14 19 25 26 28 35 41 59 85 87 99 100
Output
0
1
3


-----Note-----

In the first case, we can show that there will be no crashes if the current schedule is followed. Therefore, the answer is zero.

In the second case, at $T=4$, there will be a crash, as can be seen in the picture below. We can prove that after canceling one of these trains, the remaining trains will not crash. Therefore, the answer is one.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	nl = [int(i) for i in input().split()]
	ml = [int(i) for i in input().split()]
	count = 0
	for i in nl:
		if i in ml:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	st1 = set(map(int, input().split()))
	st2 = set(map(int, input().split()))
	ans = st1.intersection(st2)
	print(len(ans))


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	s = [int(i) for i in input().split()]
	count = 0
	for i in range(n):
		if w[i] in s:
			count += 1
	print(count)


for u in range(int(input())):
	s = list(map(int, input().split()))
	be = s[0]
	le = s[1]
	c = 0
	b = list(map(int, input().split()))
	l = list(map(int, input().split()))
	m = max(le, be)
	for i in range(le):
		if l[i] in b:
			c = c + 1
	print(c)


for loop in range(int(input())):
	(n, m) = map(int, input().split())
	bt = set(map(int, input().split()))
	lr = set(map(int, input().split()))
	if len(bt.intersection(lr)) > 0:
		print(len(bt.intersection(lr)))
	else:
		print('0')


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


t = int(input(''))
for i in range(t):
	(n, m) = map(int, input('').split())
	a = list(map(int, input('').split()))
	b = list(map(int, input('').split()))
	dem = 0
	for i in range(len(a)):
		if b.count(a[i]) == 1:
			dem += 1
	print(dem)


t = int(input())
for i in range(t):
	x = input()
	n = int(x.split()[0])
	m = int(x.split()[1])
	a = input()
	b = input()
	a1 = a.split()
	b1 = b.split()
	for j in range(n):
		a1[j] = int(a1[j])
	for j in range(m):
		b1[j] = int(b1[j])
	k = 0
	for j in a1:
		if j in b1:
			k = k + 1
	print(k)


for test in range(0, int(input())):
	(n, m) = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	ar1 = list(map(int, input().split()))
	ans = 0
	for i in ar1:
		if i in ar:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = 0
	for x in a:
		if x in b:
			p += 1
	print(p)


a = int(input())
for i in range(0, a):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	count = 0
	for i in arr:
		if i in brr:
			count = count + 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l1 = set(map(int, input().split()))
	l2 = set(map(int, input().split()))
	count = 0
	for i in l1:
		if i in l2:
			count += 1
	print(count)


for j in range(int(input())):
	(n, m) = map(int, input().split())
	count = 0
	n_arr = list(map(int, input().split()))
	m_arr = list(map(int, input().split()))
	for i in m_arr:
		if i in n_arr:
			count += 1
	print(count)


a = int(input())
b = 0
while b < a:
	c = list(map(int, input().split()))
	c = set(map(int, input().split()))
	d = list(map(int, input().split()))
	e = list(c.intersection(d))
	print(len(e))
	b += 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arrN = list(map(int, input().split()))
	arrM = list(map(int, input().split()))
	print(len(list(set(arrN).intersection(arrM))))


for _ in range(int(input())):
	(col, row) = [int(i) for i in input().split()]
	col_t = [int(i) for i in input().split()]
	row_t = [int(i) for i in input().split()]
	col_t = set(col_t)
	row_t = set(row_t)
	r = col_t.intersection(row_t)
	print(len(r))


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	a = set(input().split())
	b = set(input().split())
	print(len(a.intersection(b)))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	st1 = set(map(int, input().split()))
	st2 = set(map(int, input().split()))
	st1.intersection_update(st2)
	print(len(st1))


def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		ans = 0
		for i in a:
			if i in b:
				ans += 1
				b.remove(i)
		print(ans)
main()


for t in range(int(input())):
	(n, m) = map(int, input().split())
	an = list(map(int, input().split()))
	am = list(map(int, input().split()))
	f = [0] * 105
	for i in an:
		f[i] += 1
	for i in am:
		f[i] += 1
	s = 0
	for i in f:
		if i == 2:
			s += 1
	print(s)


t = int(input())
res = []
for i in range(t):
	(bot, left) = map(int, input().split(' '))
	l1 = list(map(int, input().split(' ')))
	l2 = list(map(int, input().split(' ')))
	common = len(set(l1) & set(l2))
	res.append(common)
[print(i) for i in res]


for _ in range(int(input(''))):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	k = list(map(int, input().split()))
	s = []
	for i in l:
		if i in k:
			s.append(i)
	print(len(s))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))[:n]
	b = list(map(int, input().split()))[:m]
	uniques = list(set(a).intersection(b))
	print(len(uniques))


t = int(input())
count = 0
for i in range(t):
	count = 0
	d = dict()
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	lstN = list(map(int, input().rstrip().split()))
	lstM = list(map(int, input().rstrip().split()))
	d = dict.fromkeys(lstN, 1)
	for j in lstM:
		if j in d:
			d[j] = d[j] + 1
	for x in d:
		if d[x] > 1:
			count = count + 1
	print(count)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	print(len(a & b))
	t = t - 1


import sys

def rr():
	return sys.stdin.readline().rstrip()
rp = print

def print(*args, **kwargs):
	rp('DBG:# ', *args, **kwargs, file=sys.stderr)

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))

def rrle():
	return (line.rstrip() for line in sys.stdin.readlines())

def rrtl():
	return [tuple(map(int, l.split())) for l in rrle()]
from collections import defaultdict

def mus(d=lambda : 0):
	return defaultdict(lambda : defaultdict(d))

def dd0(d=lambda : 0):
	return defaultdict(d)

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def ppl(a=0, x=[1]):
	x[0] = a or x[0] + 1
	print('-' + '- -' * 14 + '-# ' + str(x[0] - 2) + ' #-' + '- -' * 14 + '-')

def fltn(a):
	(i for sub in a for i in sub)

def yn(x):
	return 'YES' if x else 'NO'
from itertools import tee
from itertools import accumulate
from itertools import groupby
from itertools import permutations

def pairwise(iterable):
	(a, b) = tee(iterable)
	next(b, None)
	return zip(a, b)

def grp(x, key=None):
	return ((i, sum((1 for _ in g))) for (i, g) in groupby(x, key=key))
import math

def rnar():
	return (*rrl(), rrl())

def rn():
	return (*rrl(),)

def dpp(a, b=''):
	print('#| {} |#:^ {} ^:'.format(a, b))

def str_join(i, sep=' '):
	return sep.join(map(str, i))
MOD17 = 10 ** 9 + 7

def read():
	rrl()
	return (rrl(), rrl())

def solve(a, b):
	ans = len(set(a).intersection(set(b)))
	return ans
test_count = rri()
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	rp(result)


def Cancel_the_Trains():
	for _ in range(int(input())):
		a = input()
		b = input().split()
		c = input().split()
		n = 0
		for i in b:
			if i in c:
				n += 1
		print(n)
Cancel_the_Trains()


t = int(input())
for _ in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	x = [int(i) for i in input().split()][:n]
	y = [int(i) for i in input().split()][:m]
	count = 0
	if n > m:
		for i in range(len(y)):
			if y[i] in x:
				count += 1
	else:
		for i in range(len(x)):
			if x[i] in y:
				count += 1
	print(count)


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	(n, m) = map(int, ip().split())
	arrn = list(map(int, ip().split()))
	arrm = list(map(int, ip().split()))
	i = j = ans = 0
	while i < n and j < m:
		if arrn[i] < arrm[j]:
			i += 1
		elif arrm[j] < arrn[i]:
			j += 1
		else:
			i += 1
			j += 1
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	b = [int(x) for x in input().split()][:n]
	l = [int(x) for x in input().split()][:m]
	cnt = 0
	for i in range(n):
		if b[i] in l:
			cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	nli = list(map(int, input().split()))
	mli = list(map(int, input().split()))
	oli = set(nli)
	tli = set(mli)
	q = oli & tli
	print(len(q))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	x = set(arr)
	y = set(arr1)
	ans = list(x.intersection(y))
	print(len(ans))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	cancel = 0
	for i in l1:
		if i in l2:
			cancel = cancel + 1
	print(cancel)


t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split())
	bottom = [int(b) for b in input().split()]
	left = [int(l) for l in input().split()]
	print(len(bottom + left) - len(set(bottom + left)))


def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		print(len(set([int(i) for i in input().split()]).intersection([int(i) for i in input().split()])))
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	an = list(map(int, input().split()))
	am = list(map(int, input().split()))
	c = 0
	for i in an:
		if i in am:
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	(n, m) = (int(i) for i in input().split())
	a = (int(i) for i in input().split())
	b = set((int(i) for i in input().split()))
	res = sum((i in b for i in a))
	print(res)


for _ in [0] * int(input()):
	(n, m) = map(int, input().split())
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	print(len(a.intersection(b)))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	s = 0
	for i in a:
		if i in b:
			count += 1
	for i in b:
		if i in a:
			s += 1
	print(min(s, count))


I = lambda : set(map(int, input().split()))
for i in '*' * int(input()):
	input()
	(a, b) = (I(), I())
	print(len(a & b))


import math
from sys import stdin
from heapq import *
from itertools import permutations
from collections import Counter, OrderedDict, deque
inp = lambda : stdin.readline().strip()
ii = lambda : int(inp())
si = lambda : map(int, inp().split())
sf = lambda : map(float, inp().split())
li = lambda : list(si())
lf = lambda : list(sf())
lin = lambda : list(inp())
liin = lambda : [int(c) for c in inp()]
infy = float('inf')
mod = int(1000000000.0) + 7
test = ii()
for _ in range(test):
	(n, m) = si()
	a = set(li())
	b = set(li())
	v = a.intersection(b)
	print(len(v))


t = int(input())
while t > 0:
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = 0
	for i in a:
		if i in b:
			ans += 1
	print(ans)
	t -= 1


test_cases = int(input())
while test_cases:
	(m, n) = list(map(int, input().split()))
	arr1 = set(list(map(int, input().split())))
	arr2 = set(list(map(int, input().split())))
	print(len(arr1.intersection(arr2)))
	test_cases -= 1


z = int(input())
for i in range(z):
	(x, y) = map(int, input().split())
	st1 = set(map(int, input().split()))
	st2 = set(map(int, input().split()))
	ans = st1.intersection(st2)
	print(len(ans))


for i in range(int(input())):
	count = 0
	bla1 = input()
	arr1 = [int(arr1) for arr1 in input().split()]
	arr2 = [int(arr2) for arr2 in input().split()]
	for i in arr1:
		if i in arr2:
			count = count + 1
	print(count)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	for item in a:
		for ii in b:
			if ii == item:
				ans += 1
	print(ans)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [value for value in a if value in b]
	print(len(c))


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


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	l = input().split()
	vis = [0] * 101
	ans = 0
	for i in range(n):
		x = int(l[i])
		vis[x] = 1
	l = input().split()
	for i in range(m):
		x = int(l[i])
		if vis[x]:
			ans += 1
	print(ans)


def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	for x in a:
		ans += x in b
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
result = []
for i in range(0, t):
	(n, m) = [int(s) for s in input().split()]
	n_trains = [int(s) for s in input().split()]
	m_trains = [int(s) for s in input().split()]
	cancel = 0
	for j in n_trains:
		if j in m_trains:
			cancel += 1
	result.append(str(cancel))
print('\n'.join(result))


test = int(input())
while test != 0:
	test -= 1
	(n, m) = tuple(map(int, input().split()))
	n = set(input().split())
	m = set(input().split())
	print(len(n.intersection(m)))


t = int(input())
for _ in range(t):
	(n, m) = tuple(map(int, input().split()))
	bottom = set(map(int, input().split()))
	left = set(map(int, input().split()))
	z = bottom.intersection(left)
	print(len(z))


t = int(input())
while t:
	t = t - 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = set()
	for i in a:
		s.add(i)
	for i in b:
		s.add(i)
	print(n + m - len(s))


t = int(input())
for i in range(t):
	count = 0
	(la, db) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in a:
		if i in b:
			count += 1
	print(count)


t = int(input())
for k in range(t):
	input()
	x = set(input().split(' '))
	y = set(input().split(' '))
	print(len(x.intersection(y)))


t = int(input())
for i in range(t):
	_ = input()
	nt = set(map(int, input().split()))
	mt = set(map(int, input().split()))
	print(len(nt.intersection(mt)))


testCase = int(input())
for i in range(testCase):
	info = input()
	arr1 = input()
	arr1 = arr1.split(' ')
	arr2 = input()
	arr2 = arr2.split(' ')
	count = 0
	for j in range(len(arr1)):
		if arr1[j] in arr2:
			count += 1
	print(count)


import math

def main():
	(n, m) = map(int, input().split())
	down = list(map(int, input().split()))
	up = list(map(int, input().split()))
	cnt = 0
	for i in up:
		if i in down:
			cnt += 1
	print(cnt)
t = int(input())
for i in range(t):
	main()


from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	c = 0
	for i in range(len(l1)):
		if l1[i] in l2:
			c += 1
	print(c)


t = int(input())
x = []
y = []
c = 0
for r in range(t):
	(n, m) = map(int, input().split())
	x = input().split()
	y = input().split()
	for i in x:
		if i in y:
			c += 1
	print(c)
	c = 0


t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = list(set().union(a, b))
	print(n + m - len(c))


cases = int(input())
result = []
for i in range(cases):
	(n, m) = map(int, input().split())
	sn = set(map(int, input().split()))
	sm = set(map(int, input().split()))
	val = len(sn.intersection(sm))
	result.append(val)
for i in result:
	print(i)


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from array import array
from collections import Counter as ctr
from collections import deque as dq
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])

def solve():
	for _ in range(int(input())):
		(n, m) = li()
		b = set(li())
		l = set(li())
		print(len(b.intersection(l)))
solve()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	cnt = 0
	i = 0
	j = 0
	while i < len(a) or j < len(b):
		if a[i] == b[j]:
			cnt += 1
			if i + 1 >= len(a) and j + 1 >= len(b):
				break
			if i + 1 < len(a):
				i += 1
			if j + 1 < len(b):
				j += 1
		elif a[i] < b[j]:
			if i + 1 < len(a):
				i += 1
			else:
				break
		elif j + 1 < len(b):
			j += 1
		else:
			break
	print(cnt)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a += list(map(int, input().split()))
	print(len(a) - len(set(a)))


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = 0
	for i in range(1, 101):
		if i in a and i in b:
			ans += 1
	print(ans)


t = int(input())
while t:
	count = 0
	(n, m) = map(int, input().split(' '))
	n_list = list(map(int, input().split()))
	m_list = list(map(int, input().split()))
	for i in n_list:
		if i in m_list:
			count += 1
	print(count)
	t -= 1


n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	o = input().rstrip().split(' ')
	r = input().rstrip().split(' ')
	ans = 0
	for j in range(0, len(o)):
		if o[j] in r:
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	li1 = list(map(int, input().split()))
	res = list(set(li).intersection(set(li1)))
	print(len(res))


import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = [0] * T
for t in range(T):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans[t] = N + M - len(set(A) | set(B))
print(*ans, sep='\n')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	ans = 0
	if n < m:
		l = l1
	else:
		l = l2
	for i in range(len(l)):
		if l[i] in l2 and l[i] in l1:
			ans = ans + 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = set(map(int, input().split()))
	ans = 0
	for x in map(int, input().split()):
		if x in s:
			ans += 1
	print(ans)


t = int(input())
s = []
for i in range(t):
	s1 = input().split(' ')
	s2 = input().split(' ')
	s3 = input().split(' ')
	(n, m) = (int(s1[0]), int(s1[1]))
	x = n + m
	s2.extend(s3)
	y = len(set(s2))
	z = x - y
	s.append(z)
for j in range(t):
	print(s[j])


for _ in range(int(input())):
	input()
	print(len(set(list(input().split())).intersection(set(list(input().split())))))


inn = lambda : int(input())
inm = lambda : map(int, input().split())
ins = lambda : str(input())
ina = lambda : list(map(int, input().split()))

def solve():
	(n, m) = inm()
	a = ina()
	b = ina()
	b = set(b)
	cnt = 0
	for i in a:
		if i in b:
			cnt += 1
	print(cnt)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


t = int(input())
for i in range(0, t):
	(m, n) = map(int, input().split())
	arr = list(map(int, input().strip().split()))[:m]
	arr1 = list(map(int, input().strip().split()))[:n]
	l1 = arr + arr1
	s1 = set(l1)
	y = len(s1)
	ans = m + n - y
	print(ans)


def get_primeFactor(n):
	res = [1]
	x = 2
	while x * x <= n:
		while n % x == 0:
			res.append(x)
			n //= x
		x += 1
	if n > 1:
		res.append(n)
	return res

def getFactor(n):
	res = {1}
	x = 2
	while x * x <= n:
		if n % x == 0:
			res.add(x)
			res.add(n // x)
		x += 1
	return res
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	count = 0
	for i in a:
		if i in b:
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	b = list(map(int, input().split()))
	l = list(map(int, input().split()))
	count = 0
	i = 0
	j = 0
	while i < n and j < m:
		if b[i] > l[j]:
			j += 1
		elif b[i] < l[j]:
			i += 1
		else:
			i += 1
			j += 1
			count += 1
	print(count)


for _ in range(int(input())):
	input()
	c = 0
	a1 = tuple(map(int, input().split()))
	a2 = tuple(map(int, input().split()))
	for x in a1:
		if x in a2:
			c += 1
	print(c)


tests = int(input())
for test in range(tests):
	(trains_bottom_count, trains_left_count) = map(int, input().split())
	trains_bottom = set([int(x) for x in input().split()])
	trains_left = set([int(x) for x in input().split()])
	print(len(trains_bottom & trains_left))


import sys
T = int(sys.stdin.readline())
for i in range(T):
	(n, m) = map(int, sys.stdin.readline().split())
	bottom_nums = list(map(int, sys.stdin.readline().split()))
	left_nums = list(map(int, sys.stdin.readline().split()))
	answer = 0
	for j in bottom_nums:
		answer += j in left_nums
	print(answer)


tests = int(input())
i = 0
while i < tests:
	(bottom_train_count, left_train_count) = (int(x) for x in input().split())
	bottom_trains = [int(x) for x in input().split()]
	left_trains = [int(x) for x in input().split()]
	del_trains = 0
	if bottom_train_count < left_train_count:
		for_train = bottom_trains
		where_train = left_trains
	else:
		for_train = left_trains
		where_train = bottom_trains
	j = 0
	while j < len(for_train):
		if for_train[j] in where_train:
			del_trains += 1
		j += 1
	print(del_trains)
	i += 1


t = int(input())
for i in range(0, t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	count = 0
	for element in a:
		if element in b:
			count = count + 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = set(map(int, input().split()))
	B = set(map(int, input().split()))
	ans = 0
	for a in A:
		ans += a in B
	print(ans)


import math
for i in range(0, int(input())):
	p = list(map(int, input().split()))
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	n.extend(m)
	print(len(n) - len(set(n)))


a = int(input())
arr_g = []
arr_v = []
for i in range(a):
	(t, b) = map(int, input().split())
	arr_g.append(list(map(int, input().split())))
	arr_v.append(list(map(int, input().split())))
for i in range(a):
	k = 0
	for elem in arr_g[i]:
		if elem in arr_v[i]:
			k += 1
	print(k)


t = int(input())
while t:
	(n, m) = [int(i) for i in input().split()]
	listn = [int(i) for i in input().split()]
	listm = [int(i) for i in input().split()]
	intersect = set(listn).intersection(set(listm))
	print(len(intersect))
	t -= 1


counter = 0
for i in range(int(input())):
	poop = input()
	l = [int(x) for x in input().split()]
	[l.append(int(x)) for x in input().split()]
	print(len(l) - len(set(l)))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = set(a) & set(b)
	print(len(ans))


T = int(input())
for t in range(T):
	_ = input()
	nset = set(input().split())
	mset = set(input().split())
	print(len(nset & mset))


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


import sys
infile = sys.stdin
next(infile)
for line in infile:
	l = list(map(int, line.split()))
	n = l[0]
	m = l[1]
	tn = list(map(int, infile.readline().split()))
	tm = list(map(int, infile.readline().split()))
	a = []
	count = 0
	i = 0
	j = 0
	while i < n and j < m:
		if tn[i] == tm[j]:
			a.append(tn[i])
			count += 1
			i += 1
			j += 1
		elif tn[i] < tm[j]:
			i += 1
		else:
			j += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	(a1, a2) = (list(map(int, input().split())), list(map(int, input().split())))
	print(n + m - len(set(a1) | set(a2)))


for t in range(int(input())):
	(d, l) = input().split()
	li1 = [int(i) for i in input().split()]
	li2 = [int(i) for i in input().split()]
	s1 = set(li1)
	s2 = set(li2)
	s = s1.intersection(s2)
	print(len(s))
	t -= 1


t = int(input())
for i in range(t):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	be = input().split()
	le = input().split()
	b = set(be)
	l = set(le)
	a = list(b.intersection(l))
	print(len(a))


for y in range(int(input())):
	(n, m) = map(int, input().split())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	cnt = 0
	for i in lst1:
		if i in lst2:
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	x = input()
	a = input().split()
	b = input().split()
	print(len(set(a).intersection(b)))


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	q = list(map(int, input().split()))
	print(b + c - len(set(l + q)))


x = int(input())
for i in range(x):
	(back, left) = map(int, input().split())
	st1 = set(map(int, input().split()))
	st2 = set(map(int, input().split()))
	ans = st1.intersection(st2)
	print(len(ans))


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


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	z = 0
	for i in y:
		z += x.count(i)
	print(z)


for i in range(int(input())):
	a = input().split()
	(*x,) = map(int, input().split())
	(*y,) = map(int, input().split())
	ans = 0
	for i in x:
		ans += i in y
	print(ans)


def main():
	from sys import stdin
	from random import randint, choice, shuffle
	from functools import lru_cache
	input = stdin.readline
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		print(len(set(map(int, input().split())) & set(map(int, input().split()))))
main()


import math

def readGenerator():
	while True:
		tokens = input().split(' ')
		for t in tokens:
			yield t
reader = readGenerator()

def readWord():
	return next(reader)

def readInt():
	return int(next(reader))

def readFloat():
	return float(next(reader))

def readLine():
	return input()

def fib(n, f1, f2, i):
	if n <= f1:
		return i
	return fib(n, f2, f1 + f2, i + 1)

def bin(a, num):
	left = 0
	right = len(a) - 1
	while right - left > 1:
		mid = (right + left) // 2
		if a[mid] < num:
			left = mid
		else:
			right = mid
	return a[left] == num or a[right] == num

def solve(n, m, b, l):
	k = 0
	for i in range(n):
		for j in range(m):
			if b[i] < l[j]:
				break
			if b[i] == l[j]:
				k += 1
				break
	return k
t = readInt()
for _ in range(t):
	(n, m) = [readInt() for _ in range(2)]
	b = [readInt() for _ in range(n)]
	l = [readInt() for _ in range(m)]
	print(solve(n, m, b, l))


for _ in range(int(input())):
	(R, B) = map(int, input().split())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	no = 0
	for i in A:
		if i in B:
			no += 1
	print(no)


def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		x = [int(i) for i in input().split()]
		y = [int(i) for i in input().split()]
		print(len(x + y) - len(set(x + y)))
main()


s = ''
for x in range(int(input())):
	(n, y) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	s += str(n + y - len(set(l1 + l2))) + '\n'
print(s[:-1])


for _ in range(int(input())):
	print(sum(map(int, input().split())) - len(set(input().split() + input().split())))


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	n_arr = list(map(int, input().strip().split()))
	m_arr = list(map(int, input().strip().split()))
	size = len(n_arr)
	c = 0
	for i in range(size):
		if n_arr[i] in m_arr:
			c += 1
	print(c)


t = int(input())
results = []
for q in range(t):
	result = 0
	(n, m) = [int(i) for i in input().split()]
	bottom = [int(i) for i in input().split()]
	left = [int(i) for i in input().split()]
	for i in range(len(bottom)):
		for j in range(len(left)):
			if bottom[i] == left[j]:
				result += 1
	results.append(result)
for q in results:
	print(q)


for _ in range(int(input())):
	(n, m) = list(map(int, input().strip().split()))
	arr1 = list(map(int, input().strip().split()))
	arr2 = list(map(int, input().strip().split()))
	i = 0
	j = 0
	ans = 0
	while i < n and j < m:
		if arr1[i] == arr2[j]:
			ans += 1
			i += 1
			j += 1
			continue
		if arr1[i] < arr2[j]:
			i += 1
		else:
			j += 1
	print(ans)


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	st1 = set(map(int, input().split()))
	st2 = set(map(int, input().split()))
	ans = st1.intersection(st2)
	print(len(ans))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = len(set(a).intersection(set(b)))
	print(ans)


for test_var in range(int(input())):
	(a, b) = map(int, input().split())
	up = list(map(int, input().split()))
	side = list(map(int, input().split()))
	ans = 0
	for m in up:
		if m in side:
			ans += 1
	print(ans)


R = lambda : map(int, input().split())
(t,) = R()
exec(t * 'R();print(len({*R()}&{*R()}));')


print('\n'.join((str(sum(map(int, input().split())) - len(set(list(map(int, input().split())) + list(map(int, input().split()))))) for _ in range(int(input())))))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	n_str_list = str(input()).split(' ')
	m_str_list = str(input()).split(' ')
	n_set = set()
	m_set = set()
	for n_str in n_str_list:
		n_set.add(int(n_str))
	for m_str in m_str_list:
		m_set.add(int(m_str))
	min_canc = len(n_set.intersection(m_set))
	print(min_canc)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = {}
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	cnt = 0
	for i in b:
		if i in d:
			cnt += 1
	print(cnt)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	t = list(map(int, input().split()))
	f = list(map(int, input().split()))
	u = {}
	for j in t:
		u[j] = 1
	p = 0
	for k in f:
		if k in u:
			p += 1
	print(p)


a = ''
for _ in range(int(input())):
	trains = []
	(n, m) = map(int, input().split())
	k = list(map(int, input().split()))
	k1 = list(map(int, input().split()))
	a += str(len(k) + len(k1) - len(set(k + k1))) + '\n'
print(a)


for _ in range(int(input())):
	(n, m) = input().split()
	list1 = [int(x) for x in input().split()]
	list2 = [int(x) for x in input().split()]
	count = 0
	for i in list1:
		if i in list2:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	c = 0
	nl = list(map(int, input().split()))
	ml = list(map(int, input().split()))
	if len(nl) < len(ml):
		for i in range(len(nl)):
			if nl[i] in ml:
				c += 1
	else:
		for i in range(len(ml)):
			if ml[i] in nl:
				c += 1
	print(c)


t = int(input())
l = []
for i in range(t):
	s = 0
	a = list(map(int, input().split()))
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	if a[0] > a[1]:
		for y in n:
			if y in m:
				s += 1
	else:
		for y in m:
			if y in n:
				s += 1
	l.append(str(s))
print('\n'.join(l))


[print(len(set(input().split()) & set(input().split()))) for i in range(int(input())) if input()]


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_count = [b.count(a[i]) for i in range(n)]
	print(sum(a_count))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	x = set(map(int, input().split(' ')))
	y = set(map(int, input().split(' ')))
	z = x.intersection(y)
	print(len(z))


n = int(input())
for i in range(n):
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	d = dict(zip(l1 + l2, l1 + l2))
	print(len(l1 + l2) - len(d.keys()))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	botArray = list(map(int, input().split()))
	botSet = set(botArray)
	leftArr = list(map(int, input().split()))
	res = 0
	for i in leftArr:
		if i in botSet:
			res += 1
	print(res)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	bot = [int(x) for x in input().split()]
	left = [int(x) for x in input().split()]
	occ = [0 for x in range(101)]
	cancel = 0
	for x in bot:
		occ[x] = 1
	for x in left:
		if occ[x] == 1:
			cancel += 1
		occ[x] = 1
	print(cancel)
	t -= 1


a = int(input())
for x in range(a):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	e = list(map(int, input().split()))
	j = [0 for y in range(100)]
	h = [0 for y in range(100)]
	for y in d:
		j[y - 1] = 1
	for y in e:
		h[y - 1] = 1
	count = 0
	for y in range(100):
		if abs(j[y] - h[y]) == 0 and j[y] > 0 and (h[y] > 0):
			count += 1
	print(count)


from collections import defaultdict, deque, Counter, OrderedDict
import sys
from bisect import bisect_left

def main():
	t = int(input())
	while t:
		t -= 1
		(n, m) = [int(i) for i in input().split()]
		a = set([int(i) for i in input().split()])
		b = set([int(i) for i in input().split()])
		print(len(a.intersection(b)))
main()


import sys
from math import *
from collections import deque, Counter

def linp():
	return list(map(int, sys.stdin.readline().split()))

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

def sinp():
	return sys.stdin.readline().rstrip('\n')

def inp():
	return int(sys.stdin.readline())
for t in range(inp()):
	(n, m) = minp()
	l1 = linp()
	l2 = linp()
	ans = 0
	for i in range(n):
		for j in range(m):
			if l1[i] == l2[j]:
				ans += 1
	print(ans)


t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	k = list(set(l) & set(l1))
	print(len(k))
	t -= 1


import sys
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, sys.stdin.readline().strip().split()))
test_cases = 1
test_cases = int(input())
for _ in range(test_cases):
	(n, m) = inp()
	a = inp()
	b = inp()
	a = set(a)
	ans = 0
	for i in b:
		if i in a:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	d = dict()
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for i in b:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	r = 0
	for i in d:
		if d[i] >= 2:
			r += 1
	print(r)


n = int(input())
res = []
for i in range(n):
	t = list(map(int, input().split()))
	left = list(map(int, input().split()))
	bottom = list(map(int, input().split()))
	res.extend(left)
	res.extend(bottom)
	res = set(res)
	print(sum(t) - len(res))
	res.clear()
	res = []


t = int(input())
for i in range(t):
	ans = 0
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = set(list(map(int, input().split())))
	for i in a:
		if i in b:
			ans += 1
	print(ans)


def get_intersections(l1, l2):
	return len(set(l1).intersection(l2))

def solve():
	t = int(input())
	for _ in range(t):
		(n, m) = [int(x) for x in input().split()]
		bottom_train_numbers = [int(x) for x in input().split()]
		left_train_numbers = [int(x) for x in input().split()]
		print(get_intersections(left_train_numbers, bottom_train_numbers))
solve()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	l = set(map(int, input().split()))
	m = set(map(int, input().split()))
	print(len(l & m))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = set([int(i) for i in input().split()])
	brr = set([int(i) for i in input().split()])
	print(len(arr.intersection(brr)))


import math
import sys
from time import time
from collections import Counter, deque
import heapq
import bisect
input = sys.stdin.readline

def main():
	(n, m) = list(map(int, input().split()))
	A = set(list(map(int, input().split())))
	B = set(list(map(int, input().split())))
	print(len(A & B))
for i in range(int(input())):
	main()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	list_n = [int(x) for x in input().split()][:n]
	list_m = [int(x) for x in input().split()][:m]
	track = {}
	cancelTheTrains = 0
	for i in range(n):
		track[list_n[i]] = True
	for j in range(m):
		if list_m[j] in track:
			cancelTheTrains += 1
	print(cancelTheTrains)


for _ in range(int(input())):
	input()
	s1 = [int(i) for i in input().split()]
	s2 = [int(i) for i in input().split()]
	s = 0
	for i in s1:
		if i in s2:
			s += 1
	print(s)


ask = int(input())
for i in range(ask):
	list = []
	canceled = 0
	(a, b) = input().split()
	c = input().split()
	d = input().split()
	for k in c:
		list.append(k)
	for u in d:
		if u in list:
			canceled += 1
		else:
			list.append(u)
	print(canceled)


t = int(input())
for o in range(t):
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	c = 0
	if n > m:
		for i in l2:
			if i in l1:
				c += 1
	elif n < m:
		for i in l1:
			if i in l2:
				c += 1
	else:
		for i in l1:
			if i in l2:
				c += 1
	print(c)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s = set(map(int, input().split()))
	s1 = set(map(int, input().split()))
	print(len(s & s1))


tests = int(input())
for i in range(tests):
	(nrA, nrB) = input().split(' ')
	trainsA = []
	trainsB = []
	trainsA = input().split(' ')
	trainsB = input().split(' ')
	contor = 0
	for each1 in trainsA:
		for each2 in trainsB:
			if each1 == each2:
				contor += 1
	print(contor)


from collections import Counter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	bot = list(map(int, input().split()))
	left = list(map(int, input().split()))
	cb = Counter(bot)
	cl = Counter(left)
	c = cb + cl
	res = 0
	for x in c:
		if c[x] > 1:
			res += 1
	print(res)


import sys
import math, bisect, operator
(inf, m) = (float('inf'), 10 ** 9 + 7)
sys.setrecursionlimit(10 ** 5)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	(n, m) = neo()
	A = Neo()
	B = Neo()
	print(n + m - len(set(A + B)))


for _ in range(int(input())):
	nm = list(map(int, input().split()))
	n = nm[0]
	m = nm[1]
	c = 0
	h = list(map(int, input().split()))
	v = list(map(int, input().split()))
	if len(h) < len(v):
		for i in h:
			if i in v:
				c += 1
	else:
		for j in v:
			if j in h:
				c += 1
	print(c)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
mod = 998244353
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, m) = inp()
	a = set(inp())
	b = set(inp())
	c = a & b
	ans = len(c)
	out(ans)


import math
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	st = set()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		st.add(a[i])
	for i in range(m):
		st.add(b[i])
	print(n + m - len(st))


import sys
input = sys.stdin.readline
try:
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = {}
		arr = [int(i) for i in input().split()]
		arr2 = [int(i) for i in input().split()]
		for i in arr:
			a[i] = a.get(i, 0) + 1
		for i in arr2:
			a[i] = a.get(i, 0) + 1
		ans = 0
		for i in a:
			if a[i] > 1:
				ans += 1
		print(ans)
except EOFError as e:
	print(e)


def solve():
	input()
	a = set((int(x) for x in input().split()))
	print(len(a.intersection(set((int(x) for x in input().split())))))
for _ in range(int(input())):
	solve()


def solve():
	(n, m) = map(int, input().split())
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	ans = a.intersection(b)
	print(len(ans))
t = int(input())
for _ in range(t):
	solve()


t = int(input())
while t:
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	c = 0
	if len(l1) <= len(l2):
		for i in range(len(l2)):
			for j in range(len(l1)):
				if l2[i] == l1[j]:
					c += 1
				else:
					continue
	else:
		for i in range(len(l1)):
			for j in range(len(l2)):
				if l1[i] == l2[j]:
					c += 1
				else:
					continue
	print(c)
	t = t - 1


t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split())
	bottom = set(map(int, input().split()))
	left = list(map(int, input().split()))
	ans = 0
	for i in left:
		if i in bottom:
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	b = []
	for i in range(101):
		a.append(0)
		b.append(0)
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	for i in range(n):
		a[x[i]] += 1
	for i in range(m):
		b[y[i]] += 1
	c = 0
	for i in range(101):
		if a[i] == 1 and b[i] == 1:
			c += 1
	print(c)


from sys import stdin
from sys import stdout
from math import *
input = stdin.readline
for __ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = {}
	for i in range(n):
		d[a[i]] = 1
	ans = 0
	for i in range(m):
		if d.get(b[i]) != None:
			ans += 1
	print(ans)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	l = set(map(int, input().split()))
	b = set(map(int, input().split()))
	s = l.intersection(b)
	print(len(s))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	ans = 0
	for i in range(a):
		if l1[i] in l2:
			ans += 1
	print(ans)


import math
pi = math.acos(-1)
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = [0] * 101
	ans = 0
	for x in a:
		cnt[x] = cnt[x] + 1
	for x in b:
		if cnt[x]:
			ans = ans + 1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	s = list(map(int, input().split()))
	s1 = list(map(int, input().split()))
	count = 0
	for j in range(n):
		if s[j] in s1:
			count = count + 1
	print(count)


t = int(input())

def main(n, m, a, b):
	s = 0
	for i in a:
		s += i in b
	return s
for _ in range(t):
	(n, m) = map(int, input().split())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	print(main(n, m, a, b))


a = int(input())
for i in range(a):
	(num_bott, num_left) = map(int, input().split())
	bott = set(map(int, input().split()))
	left = set(map(int, input().split()))
	cra = bott.intersection(left)
	print(len(cra))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lst1 = [int(i) for i in input().split()]
	lst2 = [int(i) for i in input().split()]
	print(n + m - len(set(lst1 + lst2)))


r = lambda : map(int, input().split())
(t,) = r()
exec(t * 'r();print(len({*r()}&{*r()}));')


t = int(input())
for _ in range(t):
	(n, m) = input().split()
	nn = list(map(int, input().split()))
	mm = list(map(int, input().split()))
	for i in mm:
		nn.append(i)
	s = set(nn)
	print(int(n) + int(m) - len(s))


try:
	t = int(input())
	for i in range(0, t):
		(n, m) = list(map(int, input().split(' ')))
		x = list(map(int, input().split(' ')))
		y = list(map(int, input().split(' ')))
		for i in range(0, len(x)):
			x[i] += 1
		for i in range(0, len(y)):
			y[i] += 1
		c = 0
		for i in range(0, len(x)):
			for j in range(0, len(y)):
				if y[j] == x[i]:
					c += 1
		print(c)
except:
	pass