def findCommon(s1, s2):
    longest = ""
    for startIndex in range(len(s1)):
        endIndex = startIndex + 1
        while endIndex <= len(s1):
            if s1[startIndex:endIndex] in s2 and len(s1[startIndex:endIndex]) > len(longest):
                longest = s1[startIndex:endIndex]
            elif s1[startIndex:endIndex] in s2 and len(s1[startIndex:endIndex]) == len(longest) and s1[startIndex:endIndex] < longest:
                longest = s1[startIndex:endIndex]
            elif s1[startIndex:endIndex] not in s2:
                endIndex += 1
                continue
            endIndex += 1
    return longest, s1[:s1.find(longest)], s2[:s2.find(longest)], s1[s1.find(longest) + len(longest):], s2[s2.find(longest) + len(longest):]


def findADF(strings):
    ADF = 0

    for i in range(2):
        strings[i] = strings[i].upper()
        j = 0
        while j < len(strings[i]):
            if not strings[i][j].isalpha():
                strings[i] = strings[i][:j] + strings[i][j + 1:]
                j -= 1
            j += 1

    loop = True
    while loop:
        loop = False
        newStrings = []
        for i in range(0, len(strings), 2):
            longest, l1, l2, r1, r2 = findCommon(strings[i], strings[i + 1])
            if len(longest) > 0:
                loop = True
                newStrings += [l1, l2, r1, r2]
                ADF += len(longest)
        strings = newStrings
    return ADF


fileLines = open("inputSenior.txt", "r").read().split("\n")
ADFlist = []
index = 0
while index < len(fileLines):
    if fileLines[index] == "":
        index += 1
        continue
    else:
        ADFlist += [findADF([fileLines[index], fileLines[index + 1]])]
        index += 1
    index += 1

for i in ADFlist:
    print(i)