As we all know, Chef is cooking string for long days, his new discovery on string is the longest common pattern length. The longest common pattern length between two strings is the maximum number of characters that both strings have in common. Characters are case sensitive, that is, lower case and upper case characters are considered as different. Note that characters can repeat in a string and a character might have one or more occurrence in common between two strings. For example, if Chef has two strings A = "Codechef" and B = "elfedcc", then the longest common pattern length of A and B is 5 (common characters are c, d, e, e, f).
Chef wants to test you with the problem described above. He will give you two strings of Latin alphabets and digits, return him the longest common pattern length.

-----Input-----
The first line of the input contains an integer T, denoting the number of test cases. Then the description of T test cases follows.
The first line of each test case contains a string A. The next line contains another character string B.

-----Output-----
For each test case, output a single line containing a single integer, the longest common pattern length between A and B.

-----Constraints-----
- 1 ≤ T ≤ 100
- 1 ≤ |A|, |B| ≤ 10000 (104), where |S| denotes the length of the string S
- Both of A and B can contain only alphabet characters (both lower and upper case) and digits

-----Example-----
Input:
4
abcd
xyz
abcd
bcda
aabc
acaa
Codechef
elfedcc

Output:
0
4
3
5

-----Explanation-----
Example case 1. There is no common character.
Example case 2. All the characters are same.
Example case 3. Three characters (a, a and c) are same.
Example case 4. This sample is mentioned by the statement.

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	a = sorted(input())
	b = sorted(input())
	c = 0
	s = set(a)
	for i in s:
		c += min(a.count(i), b.count(i))
	print(c)


for _ in range(int(input())):
	a = input()
	b = input()
	(a, b) = (list(a), list(b))
	a.sort()
	b.sort()
	d1 = {}
	d2 = {}
	for i in a:
		if i in d1:
			d1[i] += 1
		else:
			d1[i] = 1
	for i in b:
		if i in d2:
			d2[i] += 1
		else:
			d2[i] = 1
	count = 0
	if len(d1) > len(d2):
		for (i, j) in d2.items():
			if i in d1.keys():
				count += min(j, d1[i])
	else:
		for (i, j) in d1.items():
			if i in d2.keys():
				count += min(j, d2[i])
	print(count)


r2 = lambda : range(1, n + 1)
alph = lambda : s.isalpha()
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
si = lambda : input()
ssi = lambda : list(input())
sepi = lambda : map(int, input().split())
seti = lambda : set(map(int, input().split()))
for i in range(int(input())):
	str1 = si()
	str2 = si()
	check = []
	ans = 0
	for i in str1:
		if i in str2 and i not in check:
			check.append(i)
			ans += min(str1.count(i), str2.count(i))
	print(ans)


for _ in range(int(input())):
	a = input()
	b = input()
	k = set(a)
	c = 0
	for i in k:
		c += min(a.count(i), b.count(i))
	print(c)


for i in range(int(input())):
	A = input()
	B = input()
	count = 0
	for x in A:
		if x in B:
			B = B.replace(x, '', 1)
			count += 1
	print(count)


t = int(input())
while t:
	count = 0
	a = input()
	b = input()
	if len(a) > len(b):
		(a, b) = (b, a)
	for i in a:
		if i in b:
			b = b.replace(i, '', 1)
			count += 1
	print(count)
	t -= 1


for _ in range(int(input())):
	x = input()
	y = input()
	c = 0
	l = []
	for i in range(len(x)):
		if x[i] not in l and x[i] in y:
			l.append(x[i])
			c += min(x.count(x[i]), y.count(x[i]))
	print(c)


from collections import Counter
t = int(input())
for ni in range(t):
	a = list(input())
	b = list(input())
	a1 = Counter(a)
	b1 = Counter(b)
	s = 0
	for i in a1.keys():
		if i in b1:
			s = s + min(a1[i], b1[i])
	print(s)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	r = []
	c = 0
	for i in a:
		if i in b and i not in r:
			r.append(i)
			c += min(a.count(i), b.count(i))
	print(c)


for i in range(int(input())):
	a = input()
	b = input()
	count = 0
	for i in a:
		if i in b:
			count += 1
			b = b.replace(i, '', 1)
	print(count)


from collections import Counter
for x in range(int(input())):
	a = input()
	b = input()
	x = dict(Counter(a))
	y = dict(Counter(b))
	final = 0
	for key in x:
		if key in y:
			if x[key] < y[key]:
				final += x[key]
			else:
				final += y[key]
	print(final)


q = int(input())
while q > 0:
	a = input()
	b = input()
	c = list(set(a))
	k = 0
	for i in c:
		k = k + min(a.count(i), b.count(i))
	print(k)
	q = q - 1


for i in range(int(input())):
	u = input()
	n = input()
	c = 0
	for i in u:
		if i in n:
			n = n.replace(i, '', 1)
			c += 1
	print(c)


t = 0
try:
	t = int(input())
except:
	pass
for _ in range(t):
	a = input()
	b = input()
	a = ''.join(sorted(a))
	b = ''.join(sorted(b))
	count = 0
	for b_character in b:
		if b_character in a:
			i = a.find(b_character)
			a = a[:i] + a[i + 1:]
			count += 1
	print(count)


T = int(input())
ans = []
for _ in range(T):
	A = input()
	B = input()
	acount = {}
	bcount = {}
	for i in A:
		acount[i] = acount.get(i, 0) + 1
	for i in B:
		bcount[i] = bcount.get(i, 0) + 1
	count = 0
	for i in acount.keys():
		if i in bcount:
			count += min(acount[i], bcount[i])
	ans.append(count)
for i in ans:
	print(i)


for i in range(int(input())):
	a = input()
	b = input()
	c = 0
	for i in set(a):
		m = min(a.count(i), b.count(i))
		c = c + m
	print(c)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	if len(a) > len(b):
		A = set(b)
		B = set(a)
	else:
		A = set(a)
		B = set(b)
	r = 0
	for i in A:
		r = r + min(a.count(i), b.count(i))
	print(r)


t = int(input())
for t in range(t):
	s1 = input()
	s2 = input()
	c = 0
	for i in s1:
		if i in s2:
			c += 1
			s2 = s2.replace(i, '', 1)
	print(c)


for _ in range(int(input())):
	a = input()
	b = input()
	d = dict()
	ct = 0
	for i in a:
		if i in d.keys():
			d[i] += 1
		else:
			d[i] = 1
	for j in b:
		if j in d.keys():
			if d[j] != 0:
				d[j] -= 1
				ct += 1
	print(ct)


for _ in range(int(input())):
	a = input()
	b = input()
	l = []
	c = 0
	for i in a:
		if i in b and i not in l:
			l.append(i)
			c += min(a.count(i), b.count(i))
	print(c)


for i in range(int(input())):
	a = input()
	b = input()
	if len(a) > len(b):
		mi = set(b)
		ma = set(a)
	else:
		mi = set(a)
		ma = set(b)
	r = 0
	for i in mi:
		r = r + min(a.count(i), b.count(i))
	print(r)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	l = 0
	x = list(set(a))
	y = list(set(b))
	for ele in x:
		A = a.count(ele)
		B = b.count(ele)
		l = l + min(A, B)
	print(l)


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	d1 = {}
	d2 = {}
	for i in s1:
		if i in d1:
			d1[i] += 1
		else:
			d1[i] = 1
	for i in s2:
		if i in d2:
			d2[i] += 1
		else:
			d2[i] = 1
	sum = 0
	for i in d1:
		if i in d2:
			sum += min(d1[i], d2[i])
	print(sum)


from sys import stdin as sin

def aint():
	return int(input())

def amap():
	return map(int, sin.readline().split())

def alist():
	return list(map(int, sin.readline().split()))

def astr():
	return input()
from collections import Counter as cc
for _ in range(int(input())):
	a = input()
	b = input()
	d1 = cc(a)
	d2 = cc(b)
	m = 0
	for i in d1:
		m += min(d1[i], d2[i])
	print(m)


for i in range(int(input())):
	a = input()
	b = input()
	c = list(set(a))
	k = 0
	for i in c:
		if a.count(i) >= b.count(i):
			k += b.count(i)
		else:
			k += a.count(i)
	print(k)


for _ in range(int(input())):
	(a, b) = (input(), input())
	l = 0
	for x in set(a) & set(b):
		l += min(a.count(x), b.count(x))
	print(l)


for _ in range(int(input())):
	a = input()
	b = input()
	d = list(set(a))
	s = 0
	for i in d:
		if b.count(i) >= a.count(i):
			s += a.count(i)
		else:
			s += b.count(i)
	print(s)


for _ in range(int(input())):
	a = input()
	b = input()
	c = 0
	for i in a:
		if i in b:
			c += 1
			b = b.replace(i, '', 1)
	print(c)


n = int(input())
for _ in range(n):
	a = input()
	b = input()
	d = []
	c = 0
	for ele in a:
		if ele in b and ele not in d:
			d.append(ele)
			c += min(a.count(ele), b.count(ele))
	print(c)


def soln():
	a = input()
	b = input()
	a1 = set(a)
	c = 0
	for i in a1:
		if i in b:
			c += min(a.count(i), b.count(i))
	print(c)

def main():
	t = int(input())
	while t > 0:
		t = t - 1
		soln()

def __starting_point():
	main()
__starting_point()


for _ in range(int(input())):
	str1 = input()
	str2 = input()
	res = []
	cnt = 0
	for e in str1:
		if e in str2 and e not in res:
			res.append(e)
			cnt += min(str1.count(e), str2.count(e))
	print(cnt)


for _ in range(int(input())):
	(a, b) = (input(), input())
	done = []
	count = 0
	for ele in a:
		if ele in b and ele not in done:
			done.append(ele)
			count += min(a.count(ele), b.count(ele))
	print(count)


t = int(input())
final = []
for jk in range(0, t):
	a = str(input())
	b = str(input())
	th = [a, b]
	final.append(th)
for mm in final:
	ad = list(mm[0])
	pk = list(mm[1])
	c = 0
	ory = []
	for ml in ad:
		if ml not in ory:
			ynj = ad.count(ml)
			oopt = pk.count(ml)
			if ynj == oopt:
				c += ynj
			elif ynj > oopt:
				c += oopt
			else:
				c += ynj
			ory.append(ml)
	print(c)


T = int(input())
for i in range(T):
	A = input()
	B = input()
	P = set(B)
	c = 0
	for j in P:
		P1 = B.count(j)
		P2 = A.count(j)
		S = min(P1, P2)
		c += S
	print(c)


t = int(input())
for h in range(t):
	a = input()
	b = input()
	aset = set(a)
	c = 0
	for i in aset:
		if i in b:
			c = c + min(a.count(i), b.count(i))
	print(c)


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	cnt = 0
	for ch in s1:
		if ch in s2:
			s2 = s2.replace(ch, '', 1)
			cnt += 1
	print(cnt)


test = int(input())
for _ in range(test):
	string1 = input().strip()
	string2 = input().strip()
	hashMap1 = {}
	hashMap2 = {}
	for i in string1:
		if i in hashMap1:
			hashMap1[i] += 1
		else:
			hashMap1[i] = 1
	for i in string2:
		if i in hashMap2:
			hashMap2[i] += 1
		else:
			hashMap2[i] = 1
	total = 0
	for i in hashMap2:
		if i in hashMap1:
			total = total + min(hashMap1[i], hashMap2[i])
	print(total)


from sys import stdin, stdout
try:
	t = eval(stdin.readline())
	for _ in range(t):
		s1 = str(input())
		s2 = str(input())
		Dict1 = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0, 'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0, '0': 0}
		Dict2 = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0, 'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0, '0': 0}
		answer = 0
		for i in range(len(s1)):
			Dict1[s1[i]] += 1
		for i in range(len(s2)):
			Dict2[s2[i]] += 1
		freqA = list(Dict1.values())
		freqB = list(Dict2.values())
		for j in range(len(Dict1)):
			answer += min(freqA[j], freqB[j])
		stdout.write(str(answer) + '\n')
except:
	pass


for _ in range(int(input())):
	A = input()
	B = input()
	c = 0
	a = list(set(A))
	b = list(set(B))
	for ele in a:
		x = A.count(ele)
		y = B.count(ele)
		c += min(x, y)
	print(c)


t = int(input())
while t > 0:
	a = input()
	b = input()
	ans = 0
	for i in a:
		if i in b:
			ans += 1
			b = b.replace(i, '', 1)
	print(ans)
	t -= 1


a = int(input())
for _ in range(a):
	b = input()
	b1 = set(b)
	c = input()
	s = 0
	for i in b1:
		if i in c:
			s += min(b.count(i), c.count(i))
	print(s)


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	f1 = {}
	f2 = {}
	a = sorted(list(set(s1)))
	b = sorted(list(set(s2)))
	for i in a:
		n = s1.count(i)
		f1[i] = n
	for j in b:
		m = s2.count(j)
		f2[j] = m
	a1 = set(list(f1))
	b1 = set(list(f2))
	l = list(a1 & b1)
	c = 0
	for o in l:
		if f1[o] == f2[o]:
			c = c + f1[o]
		if f1[o] > f2[o]:
			c = c + f2[o]
		if f1[o] < f2[o]:
			c = c + f1[o]
	print(c)


n = int(input())
b = 0
li = []
for i in range(n):
	g = input()
	h = input()
	for z in g:
		if z in li:
			continue
		li.append(z)
		if h.count(z) == 0:
			continue
		elif h.count(z) == g.count(z):
			b += h.count(z)
		elif h.count(z) != g.count(z):
			b += min(h.count(z), g.count(z))
	print(b)
	b = 0
	li.clear()


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	x = list(set(a))
	lis = []
	lis1 = []
	for i in range(len(x)):
		if x[i] in b:
			lis.append(x[i])
	lis1 = []
	for i in range(len(lis)):
		if a.count(lis[i]) > b.count(lis[i]):
			lis1.append(b.count(lis[i]))
		else:
			lis1.append(a.count(lis[i]))
	print(sum(lis1))


for i in range(int(input())):
	a = input()
	b = input()
	freq1 = {}
	freq2 = {}
	for i in range(len(a)):
		if a[i] in freq1:
			freq1[a[i]] += 1
		else:
			freq1[a[i]] = 1
	for i in range(len(b)):
		if b[i] in freq2:
			freq2[b[i]] += 1
		else:
			freq2[b[i]] = 1
	s = []
	for key in freq1.keys():
		if key in freq2.keys():
			s.append(min(freq1[key], freq2[key]))
	q = 0
	for i in range(len(s)):
		q = q + s[i]
	print(q)


for i in range(int(input())):
	a = input()
	b = input()
	ct = 0
	for j in a:
		if j in b:
			b = b.replace(j, '', 1)
			ct += 1
	print(ct)


testcases = int(input())
while testcases:
	A = input()
	B = input()
	char_dict = {}
	for val in A:
		if val not in char_dict:
			char_dict[val] = 1
		else:
			char_dict[val] += 1
	common = 0
	for val in B:
		if val in char_dict and char_dict[val] >= 1:
			common += 1
			char_dict[val] -= 1
			if char_dict[val] == 0:
				del char_dict[val]
	print(common)
	testcases -= 1


try:
	for _ in range(int(input())):
		A = input()
		B = input()
		d = 0
		for i in A:
			if i in B:
				d += 1
				B = B.replace(i, '', 1)
		print(d)
except:
	pass


for _ in range(int(input())):
	a = input()
	b = input()
	s = ''
	for i in a:
		if i in b and i not in s:
			s += min(a.count(i), b.count(i)) * i
	print(len(s))


for i in range(int(input())):
	s1 = input()
	s2 = input()
	s3 = []
	c = 0
	for j in s1:
		if j in s2 and j not in s3:
			s3.append(j)
			c += min(s1.count(j), s2.count(j))
	print(c)


t = int(input())
ans = []
while t > 0:
	dic_a = {}
	dic_b = {}
	a = input()
	b = input()
	common = 0
	for letter in a:
		if letter in dic_a:
			dic_a[letter] += 1
		else:
			dic_a[letter] = 1
	for letter in b:
		if letter in dic_b:
			dic_b[letter] += 1
		else:
			dic_b[letter] = 1
	if len(a) > len(b):
		for key in dic_a:
			if key in dic_b:
				common += min(dic_a[key], dic_b[key])
	else:
		for key in dic_b:
			if key in dic_a:
				common += min(dic_a[key], dic_b[key])
	ans.append(common)
	t -= 1
for an in ans:
	print(an)


from collections import Counter
for _ in range(int(input())):
	s1 = input()
	s2 = input()
	c1 = Counter(s1)
	c2 = Counter(s2)
	ans = 0
	se = set(s1).union(set(s2))
	for i in se:
		ans += min(c1[i], c2[i])
	print(ans)


from sys import stdin
from collections import defaultdict
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	a = input()
	b = input()
	dict1 = defaultdict(int)
	dict2 = defaultdict(int)
	for i in a:
		dict1[i] += 1
	for i in b:
		dict2[i] += 1
	sum1 = 0
	for i in dict1:
		min1 = min([dict1[i], dict2[i]])
		sum1 = sum1 + min1
	print(sum1)


for _ in range(int(input())):
	a = list(map(str, input()))
	b = list(map(str, input()))
	(s, k) = (set(a), 0)
	for i in s:
		k += min(a.count(i), b.count(i))
	print(k)


from collections import *
for _ in range(int(input())):
	str1 = input()
	str2 = input()
	x = Counter(str1)
	y = Counter(str2)
	count = 0
	for i in x:
		count += min(x[i], y[i])
	print(count)


for i in range(int(input())):
	a = input()
	b = input()
	c = list(a)
	d = set(c)
	c = 0
	for e in d:
		x = a.count(e)
		y = b.count(e)
		c = c + min(x, y)
	print(c)


t = int(input())
for t in range(t):
	a = input()
	b = input()
	d1 = {}
	d2 = {}
	for i in a:
		if i in d1:
			d1[i] = d1[i] + 1
		else:
			d1[i] = 1
	for j in b:
		if j in d2:
			d2[j] = d2[j] + 1
		else:
			d2[j] = 1
	count = 0
	for key in d1:
		if key in d2:
			count += min(d1[key], d2[key])
	print(count)


from collections import Counter
for i in range(int(input())):
	R = input()
	K = input()
	x = dict(Counter(R))
	y = dict(Counter(K))
	res = 0
	for key in x:
		if key in y:
			if x[key] <= y[key]:
				res += x[key]
			else:
				res += y[key]
	print(res)


try:
	from collections import Counter
	testcases = int(input())
	while testcases:
		A = input()
		B = input()
		dictA = dict(Counter(A))
		dictB = dict(Counter(B))
		longestCommonPatter = 0
		for keys in dictA:
			if keys in B:
				longestCommonPatter += min(dictA[keys], dictB[keys])
		print(longestCommonPatter)
		testcases -= 1
except:
	pass


for _ in range(int(input())):
	A = sorted(input())
	B = sorted(input())
	a = b = 0
	cnt = 0
	while a < len(A) and b < len(B):
		if A[a] == B[b]:
			cnt += 1
			a += 1
			b += 1
		elif A[a] < B[b]:
			a += 1
		else:
			b += 1
	print(cnt)


for i in range(int(input())):
	str1 = input()
	str2 = input()
	cnt = 0
	for j in str1:
		if j in str2:
			str2 = str2.replace(j, '', 1)
			cnt += 1
	print(cnt)


from collections import Counter
t = int(input())
for i in range(t):
	a = input()
	b = input()
	print(len(a) - sum((Counter(a) - Counter(b)).values()))


from math import ceil
for _ in range(int(input())):
	a = list(input())
	b = list(input())
	n = len(a)
	m = len(b)
	a.sort()
	b.sort()
	i = j = c = 0
	while True:
		if ord(a[i]) < ord(b[j]):
			i += 1
		elif ord(a[i]) > ord(b[j]):
			j += 1
		else:
			c += 1
			i += 1
			j += 1
		if i == n or j == m:
			break
	print(c)


t = int(input())
for i in range(t):
	x = str(input())
	y = str(input())
	count = 0
	for i in x:
		if i in y:
			y = y.replace(i, '', 1)
			count += 1
	print(count)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	d = {}.fromkeys(a)
	c = 0
	for i in d:
		c += min(a.count(i), b.count(i))
	print(c)


for i in range(int(input())):
	a = input()
	b = input()
	s = sorted(a)
	k = sorted(b)
	p1 = 0
	p2 = 0
	c = 0
	while p1 < len(a) and p2 < len(b):
		if s[p1] == k[p2]:
			p1 += 1
			p2 += 1
			c += 1
		elif s[p1] > k[p2]:
			p2 += 1
		elif s[p1] < k[p2]:
			p1 += 1
	print(c)


from collections import Counter
for tc in range(int(input())):
	a = input().strip()
	b = input().strip()
	ac = Counter(a)
	bc = Counter(b)
	common = 0
	for i in ac:
		if i in bc:
			common += min(ac[i], bc[i])
	print(common)


from collections import Counter

def solve(A, B):
	a = Counter(A)
	b = Counter(B)
	ans = 0
	for i in a:
		if i in b:
			ans += min(a[i], b[i])
	return ans
t = int(input())
for _ in range(t):
	A = input()
	B = input()
	print(solve(A, B))


from collections import Counter
for _ in range(int(input())):
	a = input()
	b = input()
	a1 = Counter(a)
	b1 = Counter(b)
	c = a1 & b1
	if len(c) == 0:
		print(0)
	else:
		d = list(c.elements())
		print(len(d))


for _ in range(int(input())):
	a = input()
	b = input()
	a_set = list(set(a))
	l = 0
	for c in a_set:
		if c in b:
			l += min(a.count(c), b.count(c))
	print(l)


a = int(input())
for i in range(a):
	b = input()
	c = input()
	d = 0
	for char in b:
		if char in c:
			c = c.replace(char, '', 1)
			d += 1
	print(d)