n=int(input())
for i in range(n):
jewel=input()
stone=input()
ans=0
if len(stone)>=len(jewel):
for j in jewel:
if j in stone:
ans+=1
stone.replace(j,’ ‘)
else:
for j in stone:
if j in jewel:
ans+=1
jewel.replace(j,’ ')
print(ans)
n=int(input())
for i in range(n):
jewel=input()
stone=input()
ans=0
if len(stone)>=len(jewel):
for j in jewel:
if j in stone:
ans+=1
stone.replace(j,’ ‘)
else:
for j in stone:
if j in jewel:
ans+=1
jewel.replace(j,’ ')
print(ans)