T = int(input())

for i in range(T):
    str1 = input()
    str2 = input()

    str1 = set(str1)
    str1_dict = { s : 0 for s in str1}

    for s1 in str1:
        for s2 in str2:
            if s1 == s2:
                str1_dict[s1] += 1

    print("#%d %d" % (i+1, max(str1_dict.values())))

b9cea96bf789695b40d8114acd5b5ed372b6f733
<mask token>

<mask token>
for i in range(T):
    str1 = input()
    str2 = input()
    str1 = set(str1)
    str1_dict = {s: (0) for s in str1}
    for s1 in str1:
        for s2 in str2:
            if s1 == s2:
                str1_dict[s1] += 1
    print('#%d %d' % (i + 1, max(str1_dict.values())))

T = int(input())
for i in range(T):
    str1 = input()
    str2 = input()
    str1 = set(str1)
    str1_dict = {s: (0) for s in str1}
    for s1 in str1:
        for s2 in str2:
            if s1 == s2:
                str1_dict[s1] += 1
    print('#%d %d' % (i + 1, max(str1_dict.values())))

T = int(input())

for i in range(T):
    str1 = input()
    str2 = input()

    str1 = set(str1)
    str1_dict = { s : 0 for s in str1}

    for s1 in str1:
        for s2 in str2:
            if s1 == s2:
                str1_dict[s1] += 1

    print("#%d %d" % (i+1, max(str1_dict.values())))
