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: interview

Starter code:

Solutions:
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))

# cook your dish here

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)
    

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)

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)

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)


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)
		


# cook your dish here
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

# cook your dish here
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)

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 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 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)) 

# cook your dish here
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)

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())
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)


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)


# cook your dish here
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)
    


# cook your dish here
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)
         

# cook your dish here
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

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)
    

a=int(input())
# list(map(int,input().split()))
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)

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()