def longest_substring(x, y):
	try:
		x_substring = [x[i: j] for i in range(len(x)) for j in range(i + 1, len(x) + 1)]
		y_substring = [y[i: j] for i in range(len(y)) for j in range(i + 1, len(y) + 1)]
		substrings = []
		max_len = 0

		for i in range(len(x_substring)):
			for j in range(len(y_substring)):
				if x_substring[i] == y_substring[j] and len(x_substring[i]) >= max_len:
					max_len = len(x_substring[i])
					substrings.append(x_substring[i])

		substrings = sorted([i for i in substrings if len(i) >= max_len])
		return substrings[0]
	except IndexError:
		return 0


def solve(x, y):
	if longest_substring(x, y) == 0:
		return 0
	ls = longest_substring(x, y)
	x = x.replace(ls, "1234567890", 1)
	y = y.replace(ls, "1234567890", 1)
	x_left, x_right = x.split("1234567890")
	y_left, y_right = y.split("1234567890")
	x_left, x_right, y_left, y_right = x_left.strip(), x_right.strip(), y_left.strip(), y_right.strip()
	print(x_left, y_left, "|", x_right, y_right, len(ls.replace(" ", ""))) 
	return len(ls.replace(" ", "").strip()) + solve(x_left, y_left) + solve(x_right, y_right)


fIn = open("input.txt", "r")
for i in range(5):
	x, y = fIn.readline().strip().upper(), fIn.readline().strip().upper()
	x = ''.join([i for i in x if i.isalpha()])
	y = ''.join([i for i in y if i.isalpha()])
	print(solve(x, y))
fIn.close()