You are given the strings $a$ and $b$, consisting of lowercase Latin letters. You can do any number of the following operations in any order:

if $|a| > 0$ (the length of the string $a$ is greater than zero), delete the first character of the string $a$, that is, replace $a$ with $a_2 a_3 \ldots a_n$;

if $|a| > 0$, delete the last character of the string $a$, that is, replace $a$ with $a_1 a_2 \ldots a_{n-1}$;

if $|b| > 0$ (the length of the string $b$ is greater than zero), delete the first character of the string $b$, that is, replace $b$ with $b_2 b_3 \ldots b_n$;

if $|b| > 0$, delete the last character of the string $b$, that is, replace $b$ with $b_1 b_2 \ldots b_{n-1}$.

Note that after each of the operations, the string $a$ or $b$ may become empty.

For example, if $a=$"hello" and $b=$"icpc", then you can apply the following sequence of operations:

delete the first character of the string $a$ $\Rightarrow$ $a=$"ello" and $b=$"icpc";

delete the first character of the string $b$ $\Rightarrow$ $a=$"ello" and $b=$"cpc";

delete the first character of the string $b$ $\Rightarrow$ $a=$"ello" and $b=$"pc";

delete the last character of the string $a$ $\Rightarrow$ $a=$"ell" and $b=$"pc";

delete the last character of the string $b$ $\Rightarrow$ $a=$"ell" and $b=$"p".

For the given strings $a$ and $b$, find the minimum number of operations for which you can make the strings $a$ and $b$ equal. Note that empty strings are also equal.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 100$). Then $t$ test cases follow.

The first line of each test case contains the string $a$ ($1 \le |a| \le 20$), consisting of lowercase Latin letters.

The second line of each test case contains the string $b$ ($1 \le |b| \le 20$), consisting of lowercase Latin letters.


-----Output-----

For each test case, output the minimum number of operations that can make the strings $a$ and $b$ equal.


-----Examples-----

Input
5
a
a
abcd
bc
hello
codeforces
hello
helo
dhjakjsnasjhfksafasd
adjsnasjhfksvdafdser
Output
0
2
13
3
20


-----Note-----

None

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation

Complete search


Solutions:
for _ in range(int(input())):
	a = input()
	b = input()
	n = len(a)
	m = len(b)
	(d1, d2) = (dict(), dict())
	for i in range(n):
		for j in range(i + 1, n + 1):
			d1[a[i:j]] = n - j + i
	for i in range(m):
		for j in range(i + 1, m + 1):
			d2[b[i:j]] = m - j + i
	d1[''] = n
	d2[''] = m
	ans = 10 ** 18
	for item in d1.keys():
		for item1 in d2.keys():
			if item1 == item:
				ans = min(ans, d1[item] + d2[item1])
	print(ans)


t = int(input())
for i in range(t):
	s1 = input()
	s2 = input()
	l1 = []
	if len(s1) >= len(s2):
		i = 0
		j = 0
		count = 0
		while j < len(s2):
			if i == j:
				if s1.find(s2[i]) >= 0:
					count += 1
					j += 1
				else:
					l1.append(count)
					count = 0
					i += 1
					j += 1
			elif s1.find(s2[i:j + 1]) >= 0:
				count += 1
				j += 1
			else:
				l1.append(count)
				count = 0
				i = i + 1
				j = i
	else:
		i = 0
		j = 0
		count = 0
		while j < len(s1):
			if i == j:
				if s2.find(s1[i]) >= 0:
					count += 1
					j += 1
				else:
					l1.append(count)
					count = 0
					i += 1
					j += 1
			elif s2.find(s1[i:j + 1]) >= 0:
				count += 1
				j += 1
			else:
				l1.append(count)
				count = 0
				i = i + 1
				j = i
	if count != 0:
		l1.append(count)
	print(len(s1) + len(s2) - 2 * max(l1))


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	mi = 0
	for i in range(0, len(b)):
		for j in range(i + 1, len(b) + 1):
			if b[i:j] in a:
				mi = max(mi, j - i)
	print(abs(len(a) - mi) + abs(len(b) - mi))


for _ in range(int(input())):
	a = input()
	b = input()
	maxl = 0
	for i in range(1, len(b) + 1):
		for j in range(len(b) - i + 1):
			if b[j:j + i] in a:
				maxl = max(maxl, i)
	print(len(a) + len(b) - 2 * maxl)


t = int(input())
for y in range(t):
	a = input()
	n = len(a)
	b = input()
	m = len(b)
	minn = 0
	for i in range(n):
		for j in range(i, n + 1):
			if a[i:j] in b:
				minn = max(minn, j - i)
	print(n + m - 2 * minn)


def solve():
	(a, b) = (input(), input())
	i = len(a)
	while i >= 0:
		j = 0
		while j + i <= len(a):
			if a[j:j + i] in b:
				return len(a) + len(b) - 2 * i
			j += 1
		i -= 1
	return 0
for _ in range(int(input())):
	print(solve())


score = 400
tried_wrds = set()

def main():
	T = int(input())
	for i in range(T):
		a = input()
		b = input()
		global score
		score = 400
		global tried_wrds
		tried_wrds = set()
		solve(a, b, 0)
		print(score)

def solve(a, b, sc):
	global score
	global tried_wrds
	cnt = b.count(a)
	if a not in tried_wrds:
		tried_wrds.add(a)
	else:
		return
	if sc > score:
		return
	if cnt:
		sc += len(b) - len(a)
		if sc < score:
			score = sc
		return
	elif a != '':
		a1 = a[1:]
		a2 = a[:-1]
		solve(a1, b, sc + 1)
		solve(a2, b, sc + 1)
	else:
		sc += len(b) - len(a)
		if sc < score:
			score = sc
		return
main()


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LI1():
	return list(map(int1, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10 ** 16
md = 10 ** 9 + 7

def solve():
	(m, n) = (len(a), len(b))
	for d in range(min(m, n), 0, -1):
		for i in range(m):
			if i + d > m:
				break
			p = a[i:i + d]
			j = b.find(p)
			if j != -1:
				return m + n - 2 * d
	return m + n
for _ in range(II()):
	a = SI()
	b = SI()
	print(solve())


for i in range(int(input())):
	(a, b) = (input(), input())
	ans = 0
	for i in range(0, len(a)):
		for j in range(i, len(a)):
			if a[i:j + 1] in b:
				ans = max(ans, j - i + 1)
	print(len(a) - ans + len(b) - ans)


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	ml = 0
	for i in range(len(a)):
		cur = 0
		while cur <= len(a) - i - 1 and a[i:i + cur + 1] in b:
			cur += 1
		ml = max(ml, cur)
	print(len(a) + len(b) - 2 * ml)


for _ in range(int(input())):
	a = input()
	b = input()
	s = set()
	if len(b) > len(a):
		(b, a) = (a, b)
	for i in range(len(b)):
		for j in range(i + 1, len(b) + 1):
			if b[i:j] in a:
				s.add(len(b[i:j]))
	print(len(a) - max(s) + (len(b) - max(s)) if len(s) > 0 else len(a) + len(b))


for _ in range(int(input())):
	a = input()
	b = input()
	c = min(len(a), len(b))
	if len(a) < len(b):
		s1 = b
		s2 = a
	else:
		s1 = a
		s2 = b
	max = 0
	if s2 in s1:
		max = len(s2)
	else:
		for i in range(c):
			max = max
			for j in range(i + 1, c + 1):
				if s2[i:j:1] in s1:
					if len(s2[i:j:1]) > max:
						max = len(s1[i:j:1])
					else:
						max = max
	print(len(a) + len(b) - 2 * max)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	a = input()[:-1]
	b = input()[:-1]
	x = len(a)
	y = len(b)
	c = 0
	for i in range(x):
		for j in range(i + 1, x + 1):
			if a[i:j] in b:
				if len(a[i:j]) > c:
					c = len(a[i:j])
	print(x + y - 2 * c)


def LCSubStr(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
t = int(input())
for _ in range(t):
	a = input()
	b = input()
	m = len(a)
	n = len(b)
	x = LCSubStr(a, b, m, n)
	print(m - x + (n - x))


T = int(input())
for _ in range(T):
	a = input()
	b = input()
	out = len(a) + len(b)
	for i in range(len(a)):
		for j in range(len(a), i, -1):
			if a[i:j] in b:
				out = min(out, len(a) + len(b) - 2 * (j - i))
	print(out)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		a = input()[:-1]
		b = input()[:-1]
		if len(a) > len(b):
			(a, b) = (b, a)
		n = len(a)
		p = False
		for i in range(n, -1, -1):
			if p:
				break
			for j in range(n + 1 - i):
				if a[j:j + i] in b:
					ans = len(b) + len(a) - i * 2
					p = True
					break
		print(ans)
main()


for i in range(0, int(input())):
	a = input()
	b = input()
	l = 0
	d = 0
	for i in range(len(a)):
		for j in range(len(b)):
			if a[i] == b[j]:
				d += 1
				k = 1
				c = ''
				while i + k < len(a) and j + k < len(b):
					if a[i + k] != b[j + k]:
						break
					else:
						c += a[i + k]
						k += 1
				if l < len(c):
					l = len(c)
	if d == 0:
		print(len(a) + len(b))
	else:
		print(len(a) + len(b) - 2 - 2 * l)


t = int(input())
for _ in range(t):
	a = str(input())
	b = str(input())
	x = len(a)
	y = len(b)
	if x > y:
		mini = 0
		for i in range(y):
			for j in range(i + 1, y + 1):
				s = b[i:j]
				l = j - i
				p = 0
				for k in range(l, x + 1):
					if a[p:k] == s:
						mini = max(mini, k - p)
					p += 1
		print(x + y - 2 * mini)
	else:
		mini = 0
		for i in range(x):
			for j in range(i + 1, x + 1):
				s = a[i:j]
				l = j - i
				p = 0
				for k in range(l, y + 1):
					if b[p:k] == s:
						mini = max(mini, k - p)
					p += 1
		print(x + y - 2 * mini)


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	c = 0
	f = ''
	s = ''
	for i in range(len(a)):
		s = a[i]
		if s in b:
			if len(s) > c:
				c = len(s)
				f = s
			for j in range(i + 1, len(a)):
				if s + a[j] in b:
					s += a[j]
					if len(s) > c:
						c = len(s)
						f = s
				else:
					if len(s) > c:
						c = len(s)
						f = s
					break
	if f == '':
		print(len(a) + len(b))
	else:
		print(len(a) + len(b) - 2 * c)


for tests in range(int(input())):
	a = input()
	b = input()
	m = 100
	la = len(a)
	x = 0
	for i in range(la):
		for j in range(i, la):
			if b.count(a[i:j + 1]) > 0:
				if i + la - j - 1 + (b.find(a[i:j + 1]) - 1 + len(b) - (b.find(a[i:j + 1]) - 1 + len(a[i:j + 1]))) < m:
					m = i + la - j - 1 + (b.find(a[i:j + 1]) - 1 + len(b) - (b.find(a[i:j + 1]) - 1 + len(a[i:j + 1])))
					x = 1
			else:
				break
	if x == 1:
		print(m)
	else:
		print(len(a) + len(b))


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	max_len = 0
	for i in range(len(a)):
		for j in range(i + 1, len(a) + 1):
			sub_len = b.find(a[i:j])
			if sub_len != -1:
				if j - i > max_len:
					max_len = j - i
	print(len(a) - max_len + (len(b) - max_len))


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline

def fun(A, B):
	n = len(A)
	m = len(B)
	if m == 0 or n == 0:
		return 0
	if n == 1 and m == 1:
		if A[0] == B[0]:
			return 1
		else:
			return 0
	dp = [[0 for x in range(m + 1)] for y in range(n + 1)]
	final = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if A[i - 1] == B[j - 1]:
				dp[i][j] = 1 + dp[i - 1][j - 1]
			else:
				dp[i][j] = 0
			final = max(final, dp[i][j])
	return final
t = int(input())
for _ in range(t):
	s = input().strip()
	s1 = input().strip()
	x = fun(s, s1)
	print(len(s) + len(s1) - 2 * x)


for x in range(int(input())):
	a = input()
	b = input()
	c = 0
	for i in range(len(a)):
		for j in range(i, len(a)):
			if a[i:j + 1] in b and j - i + 1 > c:
				c = j - i + 1
	print(len(a) + len(b) - 2 * c)


t = int(input())
for i in range(t):
	lol = []
	a = input()
	b = input()
	if len(a) >= len(b):
		big = a
		small = b
	else:
		big = b
		small = a
	for j in range(len(small)):
		size = len(small) - j
		for l in range(len(small) - size + 1):
			if small[l:l + size] in big:
				lol.append(len(small) + len(big) - size - size)
	if len(lol) == 0:
		lol = [len(small) + len(big)]
	print(min(lol))


class String:

	def __init__(self, string):
		self.string = string

	def changes(self, other):
		a = self.string
		b = other.string
		changes = 0
		for i in range(len(a)):
			for j in range(i, len(a) + 1):
				if a[i:j] in b and j - i > changes:
					changes = j - i
		return len(a) + len(b) - 2 * changes
testcase = int(input())
for t in range(testcase):
	a = String(input())
	b = String(input())
	print(a.changes(b))


t = input()
L = []
for i in range(int(t) * 2):
	L.append(input())

def mov(a, b):
	na = len(a)
	nb = len(b)
	m = 0
	for i in range(na):
		for j in range(nb):
			if a[i] == b[j]:
				i1 = i
				j1 = j
				m1 = 0
				while i1 < na and j1 < nb and (b[j1] == a[i1]):
					m1 += 1
					j1 += 1
					i1 += 1
				m = max(m, m1)
	return na + nb - 2 * m
i = 0
while i <= len(L) - 2:
	print(mov(L[i], L[i + 1]))
	i += 2


t = int(input())
for i in range(t):
	a = input()
	b = input()
	ans = 0
	mm = ''
	for level in range(1, len(a) + 1):
		for pos in range(len(a)):
			if a[pos:pos + level] in b and len(mm) < len(a[pos:pos + level]):
				mm = a[pos:pos + level]
	print(len(a) - len(mm) + len(b) - len(mm))


for iii in range(int(input())):
	a = input()
	b = input()
	n = len(a)
	m = len(b)
	ans = 0
	for l in range(1, min(n, m) + 1):
		for i in range(n - l + 1):
			for j in range(m - l + 1):
				if a[i:i + l] == b[j:j + l]:
					ans = max(ans, l)
	print(m + n - 2 * ans)


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	if len(a) >= len(b):
		(a, b) = (b, a)
	ans = 9999999999
	for i in range(0, len(a) + 1):
		for j in range(0, len(a) - i + 1):
			if a[i:i + j] in b:
				ans = min(ans, len(a) - len(a[i:i + j]) + len(b) - len(a[i:i + j]))
	print(ans)


def lcs(a, b):
	longest = 0
	for i in range(len(a)):
		for j in range(len(b)):
			bj = j
			ai = i
			length = 0
			while ai < len(a) and bj < len(b) and (a[ai] == b[bj]):
				length += 1
				bj += 1
				ai += 1
			if length > longest:
				longest = length
	return longest

def solve():
	a = input()
	b = input()
	common = lcs(a, b)
	return len(a) + len(b) - common * 2
times = int(input())
for i in range(times):
	print(solve())


def solve(X, Y, m, n):
	ss = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				ss[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				ss[i][j] = ss[i - 1][j - 1] + 1
				result = max(result, ss[i][j])
			else:
				ss[i][j] = 0
	return result
for __ in range(int(input())):
	a = input()
	b = input()
	m = len(a)
	n = len(b)
	j = solve(a, b, m, n)
	print(n + m - j - j)


x = int(input())
for z in range(x):
	i = 0
	combo = 0
	best_combo = 0
	a = input()
	b = input()
	string = a[0]
	while i < len(a):
		bj_string = string
		if bj_string in b:
			combo += 1
			if combo > best_combo:
				best_combo = combo
			if i + combo < len(a):
				string += a[i + combo]
			else:
				i += 1
				combo = 0
				if i < len(a):
					string = a[i]
		else:
			i += 1
			combo = 0
			if i < len(a):
				string = a[i]
	print(len(a) + len(b) - best_combo * 2)


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	if len(s2) > len(s1):
		(s1, s2) = (s2, s1)
	ans = 0
	for i in range(len(s2)):
		for j in range(i, len(s2)):
			if s2[i:j + 1] in s1:
				ans = max(ans, len(s2[i:j + 1]))
	print(len(s1) + len(s2) - 2 * ans)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	if len(a) < len(b):
		small = a
		big = b
	else:
		big = a
		small = b
	substrs = ['']
	for i in range(len(small)):
		for j in range(i + 1, len(small) + 1):
			substrs.append(small[i:j])
	substrs.sort(key=len, reverse=True)
	ans = len(small) + len(big)
	for s in substrs:
		if s in big:
			print(len(small) - len(s) + len(big) - len(s))
			break


def solve():
	a = input()
	b = input()
	sol = ''
	for i in range(len(a)):
		for j in range(i, len(a)):
			ss = a[i:j + 1]
			if ss in b and len(ss) > len(sol):
				sol = ss
	print(len(a) - len(sol) + (len(b) - len(sol)))

def main():
	t = int(input())
	for i in range(t):
		solve()
main()


def main(s1, s2):
	(n1, n2) = (len(s1), len(s2))
	dp = [[0 for i in range(n2 + 1)] for j in range(n1 + 1)]
	res = 0
	for i in range(1, n1 + 1):
		for j in range(1, n2 + 1):
			if s1[i - 1] == s2[j - 1]:
				dp[i][j] = 1 + dp[i - 1][j - 1]
				res = max(res, dp[i][j])
	return res
t = int(input())
for x in range(t):
	a = input()
	b = input()
	n = len(a)
	m = len(b)
	lcs = main(a, b)
	print(m + n - 2 * lcs)


for _ in range(int(input())):
	a = str(input())
	b = str(input())
	ans = 0
	for i in range(len(a)):
		for j in range(i + 1):
			if a[j:len(a) - (i - j)] in b:
				k = len(a[j:len(a) - (i - j)])
				print(len(a) + len(b) - 2 * k)
				ans += 1
				break
		if ans == 1:
			break
	if ans == 0:
		print(len(a) + len(b))


def LCSubStr(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
t = int(input())
for q in range(t):
	ch = input()
	sh = input()
	n = len(ch)
	m = len(sh)
	print(n + m - 2 * LCSubStr(ch, sh, n, m))


n = int(input())
for i in range(n):
	a = input()
	b = input()
	ans = 0
	for l in range(0, len(a)):
		for i in range(l, len(a) + 1):
			temp = a[l:i]
			for j in range(0, len(b) + 1):
				if i - l + j > len(b):
					break
				if temp == b[0 + j:i - l + j]:
					if len(temp) > ans:
						ans = len(temp)
	print(len(a) + len(b) - 2 * ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	a = list(data())
	b = list(data())
	(n, m) = (len(a), len(b))
	answer = n + m
	for i in range(n):
		for j in range(m):
			if a[i] == b[j]:
				cnt = 0
				while i + cnt < n and j + cnt < m:
					if a[i + cnt] == b[j + cnt]:
						cnt += 1
					else:
						break
				answer = min(answer, n + m - 2 * cnt)
	out(answer)


for i in range(int(input())):
	s1 = input()
	s2 = input()
	l = mx = c = 0
	temp = -1
	if len(s1) < len(s2):
		st1 = s1
		st2 = s2
		dp = [[0 for x in range(len(st2) + 1)] for y in range(len(st1) + 1)]
	else:
		st1 = s2
		st2 = s1
		dp = [[0 for x in range(len(st2) + 1)] for y in range(len(st1) + 1)]
	for i in range(1, len(st1) + 1):
		new = 0
		for j in range(1, len(st2) + 1):
			if st1[i - 1] == st2[j - 1]:
				dp[i][j] = dp[i - 1][j - 1] + 1
				new = 1
				if dp[i][j] > mx:
					mx = dp[i][j]
	print(len(st1) + len(st2) - mx * 2)


n = int(input())

def findSame(a, b):
	l = min(len(a), len(b))
	mn = 0
	for i in range(l + 1):
		for q in range(len(a) - i + 1):
			for w in range(len(b) - i + 1):
				if a[q:q + i] == b[w:w + i]:
					mn = max(mn, i)
	return len(a) + len(b) - 2 * mn
for i in range(n):
	a = input()
	b = input()
	if a == b:
		print(0)
	else:
		t = findSame(a, b)
		print(t)


def main():
	from sys import stdin, stdout
	rl = stdin.readline
	wl = stdout.write
	for _ in range(int(rl())):
		a = rl().strip()
		b = rl().strip()
		(n, m) = (len(a), len(b))
		dp = [[0] * (m + 1) for _ in range(n + 1)]
		r = 0
		for i in range(n):
			dp[i][0] = 0
		for j in range(m):
			dp[0][j] = 0
		for i in range(1, n + 1):
			for j in range(1, m + 1):
				if a[i - 1] == b[j - 1]:
					dp[i][j] = 1 + dp[i - 1][j - 1]
					r = max(r, dp[i][j])
		wl(str(n + m - 2 * r) + '\n')
main()


def ans(a, b):
	alen = len(a)
	blen = len(b)
	mini = min(alen, blen)
	if alen < blen:
		for i in range(mini, 0, -1):
			for j in range(alen - i + 1):
				if a[j:j + i] in b:
					return alen + blen - 2 * i
	else:
		for i in range(mini, 0, -1):
			for j in range(blen - i + 1):
				if b[j:j + i] in a:
					return alen + blen - 2 * i
	return alen + blen
T = int(input())
while T > 0:
	a = input()
	b = input()
	print(ans(a, b))
	T -= 1


def LCS(X, Y, m, n):
	maxLength = 0
	endingIndex = m
	lookup = [[0 for x in range(n + 1)] for y in range(m + 1)]
	for i in range(1, m + 1):
		for j in range(1, n + 1):
			if X[i - 1] == Y[j - 1]:
				lookup[i][j] = lookup[i - 1][j - 1] + 1
				if lookup[i][j] > maxLength:
					maxLength = lookup[i][j]
					endingIndex = i
	return X[endingIndex - maxLength:endingIndex]
for _ in range(int(input())):
	a = input()
	b = input()
	n = len(a)
	m = len(b)
	an = LCS(a, b, n, m)
	val = 0
	ans = len(an)
	val += n - ans
	val += m - ans
	print(val)


def double_ended(a, b):
	matrix = [[0 for i in range(len(a))] for i in range(len(b))]
	maximum = 0
	for i in range(len(b)):
		for j in range(len(a)):
			if a[j] == b[i]:
				if i - 1 >= 0 and j - 1 >= 0:
					matrix[i][j] = 1 + matrix[i - 1][j - 1]
				else:
					matrix[i][j] = 1
				if matrix[i][j] > maximum:
					maximum = matrix[i][j]
	count = len(b) + len(a) - 2 * maximum
	print(count)
tc = int(input().strip())
for t in range(tc):
	a = input()
	b = input()
	double_ended(a, b)


for i in range(int(input())):
	string1 = input()
	string2 = input()
	if string1 == string2:
		print(0)
	else:
		shorter = min([string1, string2], key=len)
		longer = [i for i in [string1, string2] if i != shorter][0]
		common_substrings = []
		for n in range(len(shorter) + 1):
			for x in range(len(shorter) + 1):
				if shorter[n:x] in longer and shorter[n:x] != '':
					common_substrings.append(shorter[n:x])
		if len(common_substrings) == 0:
			print(len(shorter) + len(longer))
		else:
			to_minus = len(max(common_substrings, key=len))
			print(len(shorter) - to_minus + (len(longer) - to_minus))


def solve():
	a = input()
	b = input()
	m = 0
	for i in range(len(a)):
		s = a[i:]
		for j in range(len(b)):
			if b[j] == s[0]:
				k = 0
				while k + j < len(b) and k < len(s) and (b[k + j] == s[k]):
					k += 1
				if k > m:
					m = k
	return len(a) + len(b) - 2 * m
t = int(input())
while t > 0:
	print(solve())
	t -= 1


def solve():
	a = input()
	b = input()
	ans = ''
	if len(a) <= len(b):
		temp = a
		a = b
		b = temp
	for i in range(len(b), 0, -1):
		for j in range(len(b)):
			if b[j:j + i] in a:
				ans = b[j:j + i]
				break
			if j + i >= len(b):
				break
		if ans != '':
			break
	print(len(a) - len(ans) + len(b) - len(ans))
for i in range(int(input())):
	solve()


def printLCSSubStr(X: str, Y: str, m: int, n: int):
	LCSuff = [[0 for i in range(n + 1)] for j in range(m + 1)]
	length = 0
	(row, col) = (0, 0)
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				if length < LCSuff[i][j]:
					length = LCSuff[i][j]
					row = i
					col = j
			else:
				LCSuff[i][j] = 0
	if length == 0:
		return ''
	resultStr = ['0'] * length
	while LCSuff[row][col] != 0:
		length -= 1
		resultStr[length] = X[row - 1]
		row -= 1
		col -= 1
	return ''.join(resultStr)
last = []
t = int(input())
for i in range(t):
	X = input()
	Y = input()
	m = len(X)
	n = len(Y)
	ans = printLCSSubStr(X, Y, m, n)
	l = len(ans)
	last.append(m - l + n - l)
for i in last:
	print(i)


import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
import math as mt
from types import GeneratorType
BUFSIZE = 8192

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
import sys
from math import ceil, log2
INT_MAX = sys.maxsize
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def minVal(x, y):
	return x if x < y else y

def getMid(s, e):
	return s + (e - s) // 2

def RMQUtil(st, ss, se, qs, qe, index):
	if qs <= ss and qe >= se:
		return st[index]
	if se < qs or ss > qe:
		return INT_MAX
	mid = getMid(ss, se)
	return minVal(RMQUtil(st, ss, mid, qs, qe, 2 * index + 1), RMQUtil(st, mid + 1, se, qs, qe, 2 * index + 2))

def RMQ(st, n, qs, qe):
	if qs < 0 or qe > n - 1 or qs > qe:
		print('Invalid Input')
		return -1
	return RMQUtil(st, 0, n - 1, qs, qe, 0)

def constructSTUtil(arr, ss, se, st, si):
	if ss == se:
		st[si] = arr[ss]
		return arr[ss]
	mid = getMid(ss, se)
	st[si] = minVal(constructSTUtil(arr, ss, mid, st, si * 2 + 1), constructSTUtil(arr, mid + 1, se, st, si * 2 + 2))
	return st[si]

def constructST(arr, n):
	x = int(ceil(log2(n)))
	max_size = 2 * int(2 ** x) - 1
	st = [0] * max_size
	constructSTUtil(arr, 0, n - 1, st, 0)
	return st
MOD = 10 ** 9 + 7
mod = 10 ** 9 + 7
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def z_array(s1):
	n = len(s1)
	z = [0] * n
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and s1[r - l] == s1[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and s1[r - l] == s1[r]:
					r += 1
				z[i] = r - l
				r -= 1
	return z

def fs(x):
	if x < 2:
		return 0
	return x * (x - 1) // 2
t = int(input())

def check(s1, s2):
	for i1 in range(len(s2)):
		for j1 in range(i1, len(s2) + 1):
			if s1 == s2[i1:j1]:
				return True
	return False

def solve():
	maxi = 0
	for i in range(len(a)):
		for j in range(i, len(a) + 1):
			if check(a[i:j], b):
				maxi = max(maxi, j - i)
	return len(a) + len(b) - 2 * maxi
for _ in range(t):
	a = input()
	b = input()
	print(solve())


for tt in range(int(input())):
	(s, t) = (input(), input())
	ans = len(s) + len(t)
	for i in range(len(s)):
		for j in range(i, len(s)):
			sb = s[i:j + 1]
			if sb in t:
				ans = min(ans, len(s) + len(t) - len(sb) * 2)
	print(ans)


def commonSubstring(s1, s2):
	numElementos = [[0] * (len(s2) + 1) for x in range(len(s1) + 1)]
	most = 0
	x = ''
	count = 0
	for i in range(0, len(s1)):
		for j in range(0, len(s2)):
			if s1[i] == s2[j]:
				count = numElementos[i][j] + 1
				numElementos[i + 1][j + 1] = count
				if count > most:
					most = count
					x = ''
				if len(s1[i - count + 1:i + 1]) >= most:
					x = ''.join(s1[i - count + 1:i + 1])
	return print(len(s1) + len(s2) - 2 * len(x))
t = int(input())
for i in range(0, t):
	s1 = input()
	s2 = input()
	commonSubstring(s1, s2)


for _ in range(0, int(input())):
	a = input()
	b = input()
	m = 0
	for i in range(0, len(a)):
		for j in range(0, len(b)):
			if a[i] == b[j]:
				c = 1
				x = i
				y = j
				while x < len(a) and y < len(b) and (a[x] == b[y]):
					m = max(c, m)
					x = i + c
					y = j + c
					c += 1
	print(len(a) + len(b) - 2 * m)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
sys.setrecursionlimit(10 ** 4)
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def bs(arr, n, x):
	i = 0
	j = n
	while i < j:
		mid = i + (j - i) // 2
		if arr[mid] >= x:
			j = mid
		else:
			i = mid + 1
	return j

def main():
	ans = ''
	for _ in range(ii()):
		a = I().strip()
		b = I().strip()
		dp = [[0 for j in range(len(a) + 1)] for i in range(len(b) + 1)]
		var = 0
		for i in range(1, len(b) + 1):
			for j in range(1, len(a) + 1):
				if a[j - 1] == b[i - 1]:
					dp[i][j] = dp[i - 1][j - 1] + 1
					var = max(var, dp[i][j])
		ans += str(len(a) - var + len(b) - var) + '\n'
	print(ans)
main()


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	a = input().rstrip()
	b = input().rstrip()
	aa = set()
	bb = set()
	for i in range(len(a)):
		c = []
		for j in range(i, len(a)):
			c.append(a[j])
			aa.add(tuple(c))
	for i in range(len(b)):
		c = []
		for j in range(i, len(b)):
			c.append(b[j])
			bb.add(tuple(c))
	z = aa.intersection(bb)
	max_len = 0
	for i in z:
		max_len = max(max_len, len(i))
	ans = len(a) + len(b) - (max_len + max_len)
	print(ans)


a = int(input())

def rik(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
for i in range(a):
	b = input()
	c = input()
	d = len(b)
	e = len(c)
	print(d + e - 2 * rik(b, c, d, e))


t = int(input())
while t > 0:
	a = input()
	b = input()
	m = 0
	for j in range(len(a)):
		for i in range(j, len(a)):
			if a[j:i + 1] in b:
				if i + 1 - j > m:
					m = i + 1 - j
			else:
				break
	print(len(a + b) - 2 * m)
	t -= 1


for tc in range(int(input())):
	(s1, s2) = (input(), input())
	if s1 == s2:
		print(0)
		continue
	opr = len(s1) + len(s2)
	for i in range(len(s1)):
		for j in range(i + 1, len(s1) + 1):
			if s1[i:j] in s2:
				opr = min(opr, len(s1) + len(s2) - 2 * len(s1[i:j]))
	print(opr)


def lc(X, Y, m, n):
	l = [[0 for k in range(n + 1)] for i in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				l[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				l[i][j] = l[i - 1][j - 1] + 1
				result = max(result, l[i][j])
			else:
				l[i][j] = 0
	return result
for _ in range(int(input())):
	x = input()
	y = input()
	a = lc(x, y, len(x), len(y))
	print(len(x) + len(y) - 2 * a)


def f(a, b):
	m = len(a)
	n = len(b)
	common = ''
	for i in range(0, m):
		for j in range(0, n):
			k = 0
			while i + k <= m and j + k <= n and (a[i:i + k] == b[j:j + k]):
				if len(a[i:i + k]) >= len(common):
					common = a[i:i + k]
				k += 1
	return m + n - 2 * len(common)
t = int(input())
for i in range(0, t):
	a = input()
	b = input()
	print(f(a, b))
	print()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def A(n):
	return [0] * n

def AI(n, x):
	return [x] * n

def A2(n, m):
	return [[0] * m for i in range(n)]

def G(n):
	return [[] for i in range(n)]

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class ST:

	def __init__(self, arr):
		n = len(arr)
		mx = n.bit_length()
		self.st = [[0] * mx for i in range(n)]
		for i in range(n):
			self.st[i][0] = arr[i]
		for j in range(1, mx):
			for i in range(n - (1 << j) + 1):
				self.st[i][j] = max(self.st[i][j - 1], self.st[i + (1 << j - 1)][j - 1])

	def query(self, l, r):
		if l > r:
			return -inf
		s = (r + 1 - l).bit_length() - 1
		return max(self.st[l][s], self.st[r - (1 << s) + 1][s])

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def bell(s, g):
	dis = AI(n, inf)
	dis[s] = 0
	for i in range(n - 1):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
	change = A(n)
	for i in range(n):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
				change[v] = 1
	return dis

def lcm(a, b):
	return a * b // gcd(a, b)

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

def RP(nums):
	n = len(nums)
	s = set(nums)
	d = {}
	for (i, k) in enumerate(sorted(s), 1):
		d[k] = i
	bi = BIT([0] * (len(s) + 1))
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += bi.query(d[nums[i]] - 1)
		bi.update(d[nums[i]], 1)
	return ans

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j, n, m):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None
t = N()
for i in range(t):
	a = input()
	b = input()
	(m, n) = (len(a), len(b))
	ma = min(m, n)
	dp = [[[0] * n for i in range(m)] for j in range(ma + 1)]
	ans = 0
	for i in range(m):
		for j in range(n):
			if a[i] == b[j]:
				dp[1][i][j] = 1
				ans = 1
	for l in range(2, ma + 1):
		for i in range(m - l + 1):
			for j in range(n - l + 1):
				if a[i] == b[j] and dp[l - 1][i + 1][j + 1]:
					dp[l][i][j] = 1
					ans = max(ans, l)
	ans = m + n - 2 * ans
	print(ans)


for _ in range(int(input())):
	a = input()
	b = input()
	mx = len(a) + len(b)
	for i in range(len(a)):
		for j in range(i, len(a)):
			temp = a[i:j + 1]
			if temp in b:
				if len(a) + len(b) - 2 * (j - i + 1) < mx:
					mx = len(a) + len(b) - 2 * (j - i + 1)
	print(mx)


def printLCSSubStr(X: str, Y: str, m: int, n: int):
	LCSuff = [[0 for i in range(n + 1)] for j in range(m + 1)]
	length = 0
	(row, col) = (0, 0)
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				if length < LCSuff[i][j]:
					length = LCSuff[i][j]
					row = i
					col = j
			else:
				LCSuff[i][j] = 0
	if length == 0:
		return 0
	resultStr = ['0'] * length
	while LCSuff[row][col] != 0:
		length -= 1
		resultStr[length] = X[row - 1]
		row -= 1
		col -= 1
	q = ''.join(resultStr)
	return len(q)
t = int(input())
for _ in range(t):
	a = input()
	b = input()
	m = len(a)
	n = len(b)
	q = printLCSSubStr(a, b, m, n)
	e = abs(m - q) + abs(q - n)
	print(e)


import math
cases = int(input())
for c in range(cases):
	string1 = input()
	string2 = input()
	max = 0
	for i in range(len(string1)):
		for j in range(i, len(string1)):
			temp = string1[i:j + 1]
			if temp in string2 and len(temp) > max:
				max = len(temp)
	answ = len(string2) - max + len(string1) - max
	print(answ)


I = input
exec(int(I()) * 'a=I();b=I();l=len(a);print(l+len(b)-2*max(j-i for j in range(l+1)for i in range(j+1)if a[i:j]in b));')


def getCharNGram(n, s):
	charGram = [''.join(s[i:i + n]) for i in range(len(s) - n + 1)]
	return charGram
t = int(input())
for _ in range(t):
	A = input()
	B = input()
	if len(A) < len(B):
		ans = len(B) + len(A)
		for i in range(1, len(A) + 1):
			check = getCharNGram(i, A)
			for c in check:
				if c in B:
					ans = min(ans, len(B) - i + len(A) - i)
	else:
		ans = len(A) + len(B)
		for i in range(1, len(B) + 1):
			check = getCharNGram(i, B)
			for c in check:
				if c in A:
					ans = min(ans, len(A) - len(c) + len(B) - i)
	print(ans)


test_n = int(input())
for _ in range(test_n):
	a = input()
	b = input()
	if a == b:
		print(0)
		continue
	longer = ''
	shorter = ''
	if len(a) >= len(b):
		longer = a
		shorter = b
	else:
		longer = b
		shorter = a
	len_s = len(shorter)
	len_l = len(longer)
	f = 0
	for i in range(len_s, 0, -1):
		for s in range(0, len_s - i + 1):
			if shorter[s:s + i] in longer:
				print(len_s - i + len_l - i)
				f = 1
				break
		if f == 1:
			break
	if f == 0:
		print(len_s + len_l)


def lcs(s1, s2):
	m = len(s1)
	n = len(s2)
	res = 0
	dp = [[None] * (n + 1) for i in range(m + 1)]
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				dp[i][j] = 0
			elif s1[i - 1] == s2[j - 1]:
				dp[i][j] = 1 + dp[i - 1][j - 1]
				res = max(res, dp[i][j])
			else:
				dp[i][j] = 0
	return res
n = int(input())
while n > 0:
	s1 = input()
	s2 = input()
	res = lcs(s1, s2)
	print(len(s1) - res + len(s2) - res)
	n -= 1


t = int(input())
for _ in range(t):
	ans = 0
	s = str(input())
	s1 = str(input())
	for i in range(0, len(s)):
		e = ''
		for j in range(i, len(s)):
			e = e + s[j]
			if e in s1 and len(e) > ans:
				ans = len(e)
			else:
				pass
	print(len(s) + len(s1) - 2 * ans)


t = int(input())
for now in range(t):
	a = input()
	b = input()
	words_a = []
	words_b = []
	for L in range(1, len(a) + 1):
		for i in range(len(a) - L + 1):
			word = ''
			for j in range(L):
				word += a[i + j]
			words_a.append(word)
	for L in range(1, len(b) + 1):
		for i in range(len(b) - L + 1):
			word = ''
			for j in range(L):
				word += b[i + j]
			words_b.append(word)
	words = list(set(words_a).intersection(set(words_b)))
	word = ''
	max = 0
	for w in words:
		if len(w) > max:
			max = len(w)
			word = w
	print(len(a) - max + len(b) - max)


import math
from collections import Counter
import bisect

def LCSubStr(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
for _ in range(int(input())):
	a = input()
	b = input()
	n = len(a)
	m = len(b)
	print(n + m - 2 * LCSubStr(a, b, n, m))


def lcs(s1, s2):
	if s1 == s2:
		return len(s1)
	longestSubstring = 0
	for i in range(len(s1)):
		for j in range(i + 1, len(s1) + 1):
			substring = s1[i:j]
			if substring in s2:
				if len(substring) > longestSubstring:
					longestSubstring = len(substring)
	return longestSubstring
size = int(input())
for i in range(size):
	s1 = input()
	s2 = input()
	x = lcs(s1, s2)
	print(len(s1) - x + len(s2) - x)


t = int(input())
for test in range(t):
	a1 = input()
	b1 = input()
	c1 = 0
	z = len(a1)
	x = len(b1)
	for i in range(z):
		for j in range(i, z):
			if a1[i:j + 1] in b1 and j - i + 1 > c1:
				c1 = j - i + 1
	print(z + x - c1 - c1)


def fun(b, s):
	ans = []
	for i in range(len(s)):
		for j in range(i, len(s)):
			ans.append(s[i:j + 1])
	m = 0
	for i in ans:
		l = len(i)
		if i in b:
			if m < l:
				m = l
	return len(s) + len(b) - m * 2
n = int(input())
for _ in range(n):
	x = input()
	y = input()
	if len(x) > len(y):
		bda = x
		chota = y
	else:
		bda = y
		chota = x
	print(fun(bda, chota))


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	if len(s1) > len(s2):
		(s1, s2) = (s2, s1)
	max = 0
	for j in range(len(s1)):
		for k in range(j, len(s1)):
			found = s2.find(s1[j:k + 1])
			if found != -1:
				if k - j + 1 > max:
					max = k - j + 1
			else:
				break
	print(len(s1) + len(s2) - 2 * max)


def LCSubStr(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
for _ in range(int(input())):
	X = input()
	Y = input()
	m = len(X)
	n = len(Y)
	op = LCSubStr(X, Y, m, n)
	print(abs(2 * op - m - n))


from os import path
import sys, time
mod = int(1000000000.0 + 7)
from math import ceil, floor, gcd, log, log2, factorial, sqrt
from collections import defaultdict, Counter, OrderedDict, deque
from itertools import combinations, permutations
from bisect import *
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
localsys = 0
start_time = time.time()
nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)

def ceill(n, x):
	return (n + x - 1) // x
T = 1

def solve():
	a = S()
	b = S()
	(n1, n2) = (len(a), len(b))
	a1 = []
	a2 = []
	for i in range(n1):
		for j in range(n1, -1, -1):
			x = a[i:j]
			a1.append(x)
	for i in range(n2):
		for j in range(n2, -1, -1):
			a2.append(b[i:j])
	ans = maxx
	for i in a1:
		for j in a2:
			if i == j:
				ans = min(ans, n1 - len(i) + n2 - len(j))
	print(ans)

def run():
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
run()
T = I() if T else 1
for _ in range(T):
	solve()
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


t = int(input())
maxx = 0
while t:
	t -= 1
	s = input()
	p = input()
	maxx = 0
	for i in range(len(s)):
		for j in range(i, len(s)):
			if s[i:j + 1] in p and maxx < j + 1 - i:
				maxx = j + 1 - i
	print(len(s) + len(p) - maxx - maxx)


for _ in range(int(input())):
	(a, b) = (input(), input())
	m = 0
	for i in range(len(a)):
		if a[i] in b:
			c = 1
			while i + c < len(a) and a[i:i + c + 1] in b:
				c += 1
			if c > m:
				m = c
	print(len(a) + len(b) - 2 * m)


import math
n = int(input())
for i in range(n):
	a = input()
	b = input()
	if len(set(a).intersection(set(b))) > 0:
		k = min(len(a), len(b))
		if len(a) >= 2 and len(b) >= 2:
			x = []
			t = []
			for i in range(len(b) - 1):
				l = b[i]
				if l in a:
					x.append(l)
					for j in range(i + 1, len(b)):
						l += b[j]
						if l in a:
							x.append(l)
						else:
							break
			for i in x:
				g = len(i)
				t.append(g)
			y = max(t)
			print(len(a) + len(b) - 2 * y)
		else:
			print(len(a) + len(b) - 2 * len(set(a).intersection(set(b))))
	else:
		print(len(a) + len(b))


def main():
	test_counter = int(input())
	for _ in range(test_counter):
		first_word = Word(input())
		second_word = Word(input())
		print(first_word.get_delete_count_for_longest_common_substring(second_word))

class Word:

	def __init__(self, string):
		self.string = string

	def __eq__(self, other):
		return self.string == other.string

	def __len__(self):
		return len(self.string)

	def substring(self, start, end):
		return self.string[start:end]

	def longest_common_substring(self, other):
		max_length = 0
		for start in range(len(self)):
			end = len(self)
			while end > start:
				my_substring = self.substring(start, end)
				if my_substring in other.string:
					max_length = max(max_length, len(my_substring))
				end -= 1
		return max_length

	def get_delete_count_for_longest_common_substring(self, other):
		length_of_lcs = self.longest_common_substring(other)
		total_letters = len(self) + len(other)
		delete_count = total_letters - length_of_lcs * 2
		return delete_count
main()


from collections import defaultdict as df
import heapq
import bisect
t = int(input())
for ii in range(t):
	s1 = input().rstrip()
	s2 = input().rstrip()
	m = len(s1)
	n = len(s2)
	ans = 0
	dp = [[0] * (n + 1) for i in range(m + 1)]
	for i in range(len(s1) + 1):
		for j in range(len(s2) + 1):
			if i == 0 or j == 0:
				dp[i][j] = 0
			elif s1[i - 1] == s2[j - 1]:
				dp[i][j] = dp[i - 1][j - 1] + 1
				ans = max(ans, dp[i][j])
			else:
				dp[i][j] = 0
	print(m - ans + n - ans)


for _ in range(int(input())):
	a = input()
	b = input()
	gmx = 0
	for i in range(len(a)):
		mx = 0
		for j in range(len(b)):
			if i + j >= len(a):
				break
			if a[i + j] == b[j]:
				mx += 1
			else:
				mx = 0
			gmx = max(mx, gmx)
	for j in range(len(b)):
		mx = 0
		for i in range(len(a)):
			if i + j >= len(b):
				break
			if a[i] == b[i + j]:
				mx += 1
			else:
				mx = 0
			gmx = max(mx, gmx)
	print(len(a) + len(b) - 2 * gmx)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	if len(a) < len(b):
		(a, b) = (b, a)
	l = [0]
	n = len(a)
	m = len(b)
	for j in range(n):
		for k in range(m):
			tmpj = j + 0
			tmpk = k + 0
			if a[tmpj] == b[tmpk]:
				while tmpj < n and tmpk < m and (a[tmpj] == b[tmpk]):
					tmpj += 1
					tmpk += 1
			l.append(tmpj - j)
	val = max(l)
	if val == 0:
		print(len(a) + len(b))
	else:
		print(len(a) + len(b) - 2 * val)


for test in range(int(input())):
	a = input()
	b = input()
	c = 0
	lna = len(a)
	lnb = len(b)
	for i in range(lna):
		for j in range(i, lna):
			if a[i:j + 1] in b and j - i + 1 > c:
				c = j - i + 1
	print(lna + lnb - 2 * c)


for _ in range(int(input())):
	a = input()
	b = input()
	if a == b:
		print(0)
		continue
	else:
		ans = int(1000000000)
		for i in range(len(a)):
			for j in range(i, len(a)):
				temp = a[i:j + 1]
				if temp in b:
					ind = b.index(temp)
					val = i + len(a) - j - 1 + ind + len(b) - (ind + j - i + 1)
					if val < ans:
						ans = val
		if ans != 1000000000:
			print(ans)
		else:
			print(len(a) + len(b))


__version__ = '3.2'
__date__ = '2021-03-25'
import sys

def longest_common_substring(r, s):
	dp = [[0 for j in range(len(s) + 1)] for i in range(2)]
	result = 0
	for i in range(len(r)):
		for j in range(len(s)):
			if r[i] == s[j]:
				dp[1][j + 1] = dp[0][j] + 1
				result = max(dp[1][j + 1], result)
			else:
				dp[1][j + 1] = 0
		dp = [dp[1], dp[0]]
	return result

def solve(a, b):
	if a == b:
		return 0
	s = longest_common_substring(a, b)
	return len(a + b) - s - s

def main(argv=None):
	t = int(input())
	for _ in range(t):
		a = input()
		b = input()
		print(solve(a, b))
	return 0
STATUS = main()
sys.exit(STATUS)


one = [*open(0)][0::1]
for i in range(int(one[0])):
	on = one[2 * i + 1][:-1]
	two = one[2 * i + 2][:-1]
	tem = len(on)
	tem2 = len(two)
	if tem > tem2:
		temp = tem2
		s = two
		s2 = on
	else:
		temp = tem
		s = on
		s2 = two
	flag = 0
	ss = temp
	while temp > 0:
		temp -= 1
		for j in range(ss - temp):
			sss = s[j:j + temp + 1]
			if sss in s2:
				flag = len(sss)
				break
		if flag:
			break
	print(tem + tem2 - 2 * flag)


def fib_bottom_up(a, b, n, m):
	bottom_up = [[0 for f in range(m + 1)] for g in range(n + 1)]
	result = 0
	for i in range(n + 1):
		for j in range(m + 1):
			if i == 0 or j == 0:
				bottom_up[i][j] = 0
			elif a[i - 1] == b[j - 1]:
				bottom_up[i][j] = bottom_up[i - 1][j - 1] + 1
				result = max(result, bottom_up[i][j])
			else:
				bottom_up[i][j] = 0
	return result
t = int(input())
for k in range(t):
	a = input()
	b = input()
	n = len(a)
	m = len(b)
	x = fib_bottom_up(a, b, n, m)
	z = n + m - 2 * x
	print(z)


def LCS(X, Y, m, n):
	maxLength = 0
	endingIndex = m
	lookup = [[0 for x in range(n + 1)] for y in range(m + 1)]
	for i in range(1, m + 1):
		for j in range(1, n + 1):
			if X[i - 1] == Y[j - 1]:
				lookup[i][j] = lookup[i - 1][j - 1] + 1
				if lookup[i][j] > maxLength:
					maxLength = lookup[i][j]
					endingIndex = i
	return m + n - maxLength * 2

def process():
	(a, b) = (input(), input())
	return LCS(a, b, len(a), len(b))
for _ in range(int(input())):
	print(process())


e = int(input())
t = []
for i in range(e):
	st1 = input()
	st2 = input()
	t.append([st1, st2])
for j in range(e):
	a = t[j][0]
	b = t[j][1]
	le = len(a) + len(b)
	v = 0
	mat = [[0 for i in range(len(a) + 1)] for j in range(len(b) + 1)]
	for i in range(1, len(b) + 1):
		for j in range(1, len(a) + 1):
			if a[j - 1] == b[i - 1]:
				mat[i][j] = mat[i - 1][j - 1] + 1
	for i in range(1, len(b) + 1):
		for j in range(1, len(a) + 1):
			if mat[i][j] > v:
				v = mat[i][j]
	print(le - 2 * v)


for _ in range(int(input())):
	a = input()
	b = input()
	(m, al, bl) = (0, len(a), len(b))
	for i in range(al):
		for j in range(bl):
			if a[i] == b[j]:
				k = 0
				while i + k < al and j + k < bl and (a[i + k] == b[j + k]):
					k += 1
				if k > m:
					m = k
	print(al + bl - 2 * m)


def fun(A, B, n, m):
	dp = [[0] * (n + 1) for i in range(m + 1)]
	ans = -1
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				dp[i][j] = 0
			elif A[i - 1] == B[j - 1]:
				dp[i][j] = 1 + dp[i - 1][j - 1]
			else:
				dp[i][j] = 0
			ans = max(ans, dp[i][j])
	return ans
for t in range(int(input())):
	s1 = input()
	s2 = input()
	m = len(s1)
	n = len(s2)
	r = fun(s1, s2, n, m)
	print(m - r + n - r)


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import *
from statistics import *
from math import *
import fractions
import copy
from copy import deepcopy
import sys
import io
sys.setrecursionlimit(10000)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7
import random
from random import *
from time import time

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def normalncr(n, r):
	r = min(r, n - r)
	count = 1
	for i in range(n - r, n + 1):
		count *= i
	for i in range(1, r + 1):
		count //= i
	return count
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def reverse_bisect_right(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x > a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x >= a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def get_list():
	return list(map(int, input().split()))

def get_str_list_in_int():
	return [int(i) for i in list(input())]

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def input_int():
	return int(input())

def matrix(a, b):
	return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
	return (b, a)

def find_gcd(l):
	a = l[0]
	for i in range(len(l)):
		a = gcd(a, l[i])
	return a

def is_prime(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return 0
	return 1

def prime_factors(n):
	while n % 2 == 0:
		return [2] + prime_factors(n // 2)
	sqrta = int(sqrt(n))
	for i in range(3, sqrta + 1, 2):
		if n % i == 0:
			return [i] + prime_factors(n // i)
	return [n]

def p(a):
	if type(a) == str:
		print(a + '\n')
	else:
		print(str(a) + '\n')

def ps(a):
	if type(a) == str:
		print(a)
	else:
		print(str(a))

def kth_no_not_div_by_n(n, k):
	return k + (k - 1) // (n - 1)

def forward_array(l):
	n = len(l)
	stack = []
	forward = [0] * n
	for i in range(len(l) - 1, -1, -1):
		while len(stack) and l[stack[-1]] < l[i]:
			stack.pop()
		if len(stack) == 0:
			forward[i] = len(l)
		else:
			forward[i] = stack[-1]
		stack.append(i)
	return forward

def backward_array(l):
	n = len(l)
	stack = []
	backward = [0] * n
	for i in range(len(l)):
		while len(stack) and l[stack[-1]] < l[i]:
			stack.pop()
		if len(stack) == 0:
			backward[i] = -1
		else:
			backward[i] = stack[-1]
		stack.append(i)
	return backward
nc = 'NO'
yc = 'YES'
ns = 'No'
ys = 'Yes'

def LCSubStr(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	answer = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				answer += 1
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				answer += 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
				answer += 1
	return result
for i in range(int(input())):
	a = input()
	b = input()
	alen = len(a)
	blen = len(b)
	lcs = LCSubStr(a, b, alen, blen)
	print(alen + blen - 2 * lcs)


import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
	a = list(stdin.readline()[:-1])
	b = list(stdin.readline()[:-1])
	ans = 0
	for i in range(len(a)):
		for j in range(len(b)):
			now = 0
			for k in range(min(len(a) - i, len(b) - j)):
				if a[i + k] == b[j + k]:
					now += 1
				else:
					break
			ans = max(ans, now)
	ANS.append(str(len(a) + len(b) - 2 * ans))
print('\n'.join(ANS))


def lcs(a, b, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif a[i - 1] == b[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
x = int(input())
z = [0 for k in range(x)]
for i in range(0, x):
	a = input()
	b = input()
	if a == b:
		z[i] = 0
	else:
		m = len(a)
		n = len(b)
		z[i] = m + n - 2 * lcs(a, b, m, n)
for i in z:
	print(i)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def helper(a, b, i, j, n, m):
	count = 0
	while i < n and j < m:
		if a[i] == b[j]:
			i += 1
			j += 1
			count += 1
		else:
			break
	return count

def solve():
	for _ in range(get_int()):
		a = get_string()
		b = get_string()
		(n, m) = (len(a), len(b))
		ans = n + m
		for i in range(n):
			for j in range(m):
				if a[i] == b[j]:
					x = helper(a, b, i, j, n, m)
					ans = min(ans, n + m - 2 * x)
		get_print_int(ans)
solve()


for i in range(int(input())):
	a = list(input())
	b = list(input())
	a1 = len(a)
	b1 = len(b)
	if a1 > b1:
		(a1, b1) = (b1, a1)
		(a, b) = (b, a)
	s = []
	for i in range(a1):
		for j in range(i + 1, a1 + 1):
			s.append(a[i:j])
	s1 = 0
	for i in range(b1):
		for j in range(i + 1, i + 1 + a1):
			t = b[i:j]
			if t in s:
				s1 = max(s1, len(t))
	s1 = a1 + b1 - s1 - s1
	print(s1)


from difflib import SequenceMatcher
t = int(input())
solutions = []
for i in range(t):
	a = input()
	b = input()
	match = SequenceMatcher(None, a, b).find_longest_match(0, len(a), 0, len(b))
	solutions.append(len(a) + len(b) - 2 * match.size)
for i in solutions:
	print(i)


for _ in range(int(input())):
	a = input()
	b = input()
	x = 0
	s = []
	for i in range(len(b)):
		k = []
		for j in range(len(a)):
			if b[i] == a[j]:
				if i > 0 and j > 0:
					if s[i - 1][j - 1]:
						k.append(1 + s[i - 1][j - 1])
					else:
						k.append(1)
				else:
					k.append(1)
			else:
				k.append(0)
		x = max(max(k), x)
		s.append(k)
	print(len(a) + len(b) - x * 2)


t = int(input())
for ti in range(t):
	x = input()
	y = input()
	(x_l, y_l) = (len(x), len(y))
	ans = x_l + y_l
	for i in range(x_l):
		for j in range(i + 1, x_l + 1):
			s = x[i:j]
			if s in y:
				ans = min([ans, x_l + y_l - 2 * len(s)])
	print(ans)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict, Counter

def ceil(a, b):
	return (a + b - 1) // b
for _ in range(ri()):
	a = rs()
	b = rs()
	d = defaultdict(int)
	for i in range(len(a)):
		for j in range(i + 1, len(a) + 1):
			d[a[i:j]] += 1
	d1 = defaultdict(int)
	for i in range(len(b)):
		for j in range(i + 1, len(b) + 1):
			d1[b[i:j]] += 1
	x = 0
	y = ''
	for i in d.keys():
		if d[i] > 0 and d1[i] > 0:
			if x < len(i):
				x = len(i)
				y = i
	print(len(a) - x + len(b) - x)


se = int(input())
for it in range(se):
	c = 0
	s = input()
	st = input()
	x = len(s)
	for i in range(x):
		for j in range(i + 1, x + 1):
			pp = s[i:j]
			if pp in st:
				w = j - i
				c = max(c, w)
	v = len(st)
	zx = 2 * c
	z = x + v
	yy = z - zx
	if yy > 0:
		print(yy)
	else:
		print(0)


for _ in range(int(input())):
	a = input()
	b = input()
	ans = 0
	for i in range(len(a)):
		l = a[i]
		for j in range(len(b)):
			if b[j] == l:
				for k in range(100):
					if i + k >= len(a) or j + k >= len(b) or a[i + k] != b[j + k]:
						break
				ans = max(k, ans)
	print(len(a) + len(b) - 2 * ans)


def make_substring(a):
	return [a[i:j] for i in range(len(a)) for j in range(i + 1, len(a) + 1)]
for _ in range(int(input())):
	a = input()
	b = input()
	mx = 0
	for i in make_substring(a):
		mx = max(mx, len(i)) if i in b else mx
	print(len(a) + len(b) - 2 * mx)


n = int(input())
for i in range(n):
	a = input()
	b = input()
	subs_a = [a[i:j] for i in range(len(a)) for j in range(i + 1, len(a) + 1)]
	subs_b = [b[i:j] for i in range(len(b)) for j in range(i + 1, len(b) + 1)]
	lista = list(set(subs_a).intersection(set(subs_b)))
	if lista == []:
		print(len(a) + len(b))
	else:
		fator_comum = max(list(set(subs_a).intersection(set(subs_b))), key=len)
		print(len(a) + len(b) - 2 * len(fator_comum))


def solve():
	a = input()
	b = input()
	e = 0
	k = 1
	(i, j) = (0, 0)
	while i <= len(a) - k:
		while j <= len(b) - k:
			tempa = a[i:i + k]
			tempb = b[j:j + k]
			if tempa == tempb:
				k += 1
				e = 1
				i = 0
				j = 0
				continue
			j += 1
		j = 0
		i += 1
	if e == 1:
		print(len(a) + len(b) - 2 * (k - 1))
	else:
		print(len(a) + len(b))
t = int(input())
for x in range(t):
	solve()


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))

def sortByFirstAndSecond(A):
	A = sorted(A, key=lambda x: x[0])
	A = sorted(A, key=lambda x: x[1])
	return list(A)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	a = list(si())
	b = list(si())
	ans = 0
	for i in range(len(a)):
		for j in range(i, len(a)):
			for k in range(len(b)):
				for l in range(k, len(b)):
					if a[i:j + 1] == b[k:l + 1]:
						ans = max(ans, j - i + 1)
	print(len(a) + len(b) - ans - ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	a = input()
	b = input()
	x = len(a + b)
	n = 0
	for r in range(len(b)):
		for m in range(len(b) - r):
			j = b[m:m + r + 1]
			try:
				z = a.find(j)
				n = r + 1 if z > -1 else n
			except:
				pass
	print(x - 2 * n)


def KMPSearch(pat, txt):
	M = len(pat)
	N = len(txt)
	lps = [0] * M
	L = []
	j = 0
	computeLPSArray(pat, M, lps)
	i = 0
	while i < N:
		if pat[j] == txt[i]:
			i += 1
			j += 1
		if j == M:
			L.append(i - j)
			j = lps[j - 1]
		elif i < N and pat[j] != txt[i]:
			if j != 0:
				j = lps[j - 1]
			else:
				i += 1
	return L

def computeLPSArray(pat, M, lps):
	len = 0
	lps[0]
	i = 1
	while i < M:
		if pat[i] == pat[len]:
			len += 1
			lps[i] = len
			i += 1
		elif len != 0:
			len = lps[len - 1]
		else:
			lps[i] = 0
			i += 1
for _ in range(int(input())):
	a = input()
	b = input()
	if len(a) <= len(b):
		short = a
		long = b
	else:
		short = b
		long = a
	slen = len(short)
	llen = len(long)
	patterns = []
	for n in range(1, slen + 1):
		for i in range(0, slen - n + 1):
			patterns.insert(0, short[i:i + n])
	i = 0
	arr = KMPSearch(patterns[i], long)
	while len(arr) == 0:
		i += 1
		if i >= len(patterns):
			print(llen + slen)
			break
		arr = KMPSearch(patterns[i], long)
	else:
		length = len(patterns[i])
		print(slen + llen - 2 * length)


import math
t = int(input())

def get_answer(a, b):
	c = [[0 for _ in range(len(b) + 1)] for _ in range(len(a) + 1)]
	maxlen = 0
	maxindex = 0
	for i in range(1, len(a) + 1):
		for j in range(1, len(b) + 1):
			if a[i - 1] == b[j - 1]:
				c[i][j] = c[i - 1][j - 1] + 1
				if c[i][j] > maxlen:
					maxlen = c[i][j]
					maxindex = i + 1 - maxlen
	return len(a) + len(b) - 2 * maxlen
for _ in range(t):
	a = input()
	b = input()
	print(get_answer(a, b))


for _ in range(int(input())):
	(a, b) = sorted([input(), input()])
	m = 0
	for l in range(len(a)):
		for r in range(len(a) - 1, l - 1, -1):
			if a[l:r + 1] in b:
				m = max(r - l + 1, m)
	print(len(a) + len(b) - 2 * m)


t = int(input())
for q in range(t):
	a = input()
	b = input()
	mx = 0
	for i in range(len(a)):
		for j in range(len(b)):
			ln = 0
			x = i
			y = j
			while x < len(a) and y < len(b) and (a[x] == b[y]):
				ln += 1
				x += 1
				y += 1
			mx = max(mx, ln)
	print(len(a) - mx + len(b) - mx)


t = int(input())
for l in range(t):
	a = input()
	b = input()
	if len(a) < len(b):
		c = a
		d = b
	else:
		c = b
		d = a
	ans = 0
	for i in range(len(c)):
		for j in range(i, len(c)):
			if d.find(c[i:j + 1]) > -1:
				if len(c[i:j + 1]) > ans:
					ans = len(c[i:j + 1])
	print(len(d) + len(c) - 2 * ans)


t = int(input())
for y in range(t):
	a = input()
	b = input()
	if len(b) > len(a):
		(a, b) = (b, a)
	ans = 0
	for x in range(len(a)):
		x1 = 0
		ans1 = 0
		if a[x] in b:
			x1 = x + 1
			while a[x:x1 + 1] in b and x1 < len(a):
				x1 += 1
			ans1 = x1 - x
		if ans1 > ans:
			ans = ans1
	print(len(a) + len(b) - 2 * ans)


T = int(input())
for t in range(T):
	m = input()
	n = input()
	a = []
	b = []
	if len(m) > len(n):
		for i in range(len(n)):
			a.append(n[i])
		for i in range(len(m)):
			b.append(m[i])
	else:
		for i in range(len(n)):
			b.append(n[i])
		for i in range(len(m)):
			a.append(m[i])
	ma = 0
	for i in range(len(a)):
		for j in range(len(b)):
			if a[i] == b[j]:
				count = 0
				for k in range(min(len(a) - i, len(b) - j)):
					if a[k + i] == b[k + j]:
						count += 1
					else:
						break
				if count >= ma:
					ma = count
	ans = len(a) - ma + len(b) - ma
	print(ans)


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	if len(a) >= len(b):
		s1 = a
		s2 = b
	else:
		s1 = b
		s2 = a
	m = len(s2)
	if s1 == s2:
		print(0)
	else:
		s = ''
		for i in range(m):
			for j in range(i, m):
				if s2[i:j + 1] in s1:
					if len(s2[i:j + 1]) > len(s):
						s = s2[i:j + 1]
		print(len(s1) + len(s2) - 2 * len(s))


from difflib import SequenceMatcher
t = int(input())
for i in range(t):
	a = input()
	b = input()
	match = SequenceMatcher(None, a, b).find_longest_match(0, len(a), 0, len(b))
	n = match.size
	print(len(a) - n + len(b) - n)


import math
t = int(input())
for z in range(t):
	s1 = input()
	s2 = input()
	a = len(s1)
	b = len(s2)
	m = 0
	if a <= b:
		for i in range(a):
			for j in range(i + 1, a + 1):
				if s1[i:j] in s2:
					m = max(m, len(s1[i:j]))
		print(a + b - 2 * m)
	else:
		for i in range(b):
			for j in range(i + 1, b + 1):
				if s2[i:j] in s1:
					m = max(m, len(s2[i:j]))
		print(a + b - 2 * m)


n = int(input())
for _ in range(n):
	a = input()
	b = input()
	y = ''
	for i in range(len(a)):
		for j in range(i, len(a)):
			if a[i:j + 1] in b and len(y) < len(a[i:j + 1]):
				y = a[i:j + 1]
	print(len(a) + len(b) - len(y) * 2)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	a = rs()
	b = rs()
	aset = set()
	aset.add('')
	for i in range(len(a)):
		for j in range(i, len(a) + 1):
			aset.add(a[i:j])
	ans = len(a) + len(b)
	for i in range(len(b)):
		for j in range(i, len(b) + 1):
			sub = b[i:j]
			if sub in aset:
				ans = min(ans, len(a) + len(b) - 2 * len(sub))
	print(ans)


import math

def get_inp():
	return list(map(int, input().split()))

def solve():
	sa = input()
	sb = input()
	ia = 0
	max_cnt = 0
	while ia < len(sa):
		ib = 0
		while ib < len(sb):
			if sa[ia] == sb[ib]:
				i = ia
				j = ib
				cnt = 0
				while i < len(sa) and j < len(sb):
					if sa[i] == sb[j]:
						cnt += 1
					else:
						break
					i += 1
					j += 1
				if cnt > max_cnt:
					max_cnt = cnt
			ib += 1
		ia += 1
	return len(sa) + len(sb) - 2 * max_cnt
tc = int(input())
for _ in range(tc):
	print(solve())


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj

def sieve():
	li = [True] * (10 ** 3 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	(prime, cur) = ([0] * 200, 0)
	for i in range(10 ** 3 + 5):
		if li[i] == True:
			prime[cur] = i
			cur += 1
	return prime

def SPF():
	mx = 10 ** 7 + 1
	spf = [mx] * mx
	spf[1] = 1
	for i in range(2, mx):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx, i):
				if i < spf[j]:
					spf[j] = i
	return spf

def prime(n, d):
	while n != 1:
		d[spf[n]] = d.get(spf[n], 0) + 1
		n = n // spf[n]
	return
mod = 998244353
inf = 10000000000000000

def solve():
	a = stdin.readline()
	b = stdin.readline()
	n1 = len(a) - 1
	n2 = len(b) - 1
	ans = n1 + n2
	for i in range(n1):
		for j in range(i, n1):
			for k in range(n2):
				for l in range(k, n2):
					s1 = a[i:j + 1]
					s2 = b[k:l + 1]
					if len(s1) != len(s2):
						continue
					else:
						for w in range(len(s1)):
							if s1[w] != s2[w]:
								break
						else:
							ans = min(ans, n1 + n2 - 2 * len(s1))
	print(ans)
	return
t = II()
for i in range(t):
	solve()


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	ans = []
	if len(s1) >= len(s2):
		(s1, s2) = (s2, s1)
	for i in range(len(s1)):
		for j in range(len(s1), i, -1):
			if s1[i:j] in s2:
				ans.append(s1[i:j])
	ans = sorted(ans, key=lambda x: len(x), reverse=True)
	if ans == []:
		print(len(s1) + len(s2))
	else:
		print(len(s1) + len(s2) - len(ans[0]) * 2)


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	la = len(a)
	lb = len(b)
	res = 0
	for i in range(min(la, lb)):
		d = i + 1
		st = set()
		for j in range(la - i):
			st.add(a[j:j + d])
		f = True
		for j in range(lb - i):
			if b[j:j + d] in st:
				res = d
				f = False
				break
		if f:
			break
	print(la + lb - 2 * res)


T = int(input())
for t in range(T):
	a = input()
	b = input()
	n = len(b)
	L = -1
	for l in range(n, 0, -1):
		for i in range(n - l + 1):
			if b[i:i + l] in a:
				L = l
				break
		else:
			continue
		break
	if L == -1:
		L = 0
	print(len(a) + n - (L << 1))


N = int(input())
for tc in range(N):
	a = input()
	b = input()
	if a == b:
		print(0)
		continue
	cols = len(a) + 1
	rows = len(b) + 1
	arr_2d = []
	for r in range(rows):
		arr_2d.append([0] * cols)
		for c in range(cols):
			if c == 0 or r == 0:
				continue
			if a[c - 1] == b[r - 1]:
				diagonal = arr_2d[r - 1][c - 1]
				arr_2d[r][c] = diagonal + 1
	max_len = 0
	for r in range(rows):
		l_max = max(arr_2d[r])
		max_len = max(l_max, max_len)
	if max_len == 0:
		print('{}'.format(cols + rows - 2))
	else:
		print('{}'.format(rows + cols - 2 - max_len * 2))


for _ in range(int(input())):
	a = input()
	b = input()
	la = len(a)
	lb = len(b)
	res = 10 ** 18
	for i in range(la):
		for j in range(i, la):
			ta = a[i:j + 1]
			for x in range(lb):
				for y in range(x, lb):
					tb = b[x:y + 1]
					if ta == tb:
						tmp = 0
						tmp += abs(len(ta) - la)
						tmp += abs(len(tb) - lb)
						res = min(res, tmp)
	if res == 10 ** 18:
		print(la + lb)
	else:
		print(res)


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt
import bisect
import sys
import copy

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	s1 = input()
	s2 = input()
	mini = inf
	n1 = len(s1)
	n2 = len(s2)
	for i in range(len(s1)):
		for j in range(i, len(s1)):
			temp = s1[i:j + 1]
			lent = j - i + 1
			for p in range(len(s2)):
				if p + lent - 1 <= len(s2) - 1:
					temp2 = s2[p:p + lent]
					if temp == temp2:
						mini = min(mini, n1 - lent + n2 - lent)
	if mini == inf:
		print(n1 + n2)
	else:
		print(mini)


testcases = int(input())
for t in range(testcases):
	a = input()
	b = input()
	changes = 0
	for i in range(len(a)):
		for j in range(i, len(a) + 1):
			if a[i:j] in b and j - i > changes:
				changes = j - i
	print(len(a) + len(b) - 2 * changes)


import sys
import math
import bisect
from math import sqrt

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	a = input()
	b = input()
	m = len(a)
	n = len(b)
	lcs = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				lcs[i][j] = 0
			elif a[i - 1] == b[j - 1]:
				lcs[i][j] = lcs[i - 1][j - 1] + 1
				result = max(result, lcs[i][j])
			else:
				lcs[i][j] = 0
	print(n + m - 2 * result)


def LCSubStr(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
n = int(input())
for i in range(n):
	str1 = input()
	str2 = input()
	result = LCSubStr(str1, str2, len(str1), len(str2))
	ans = len(str1) - result + len(str2) - result
	print(ans)


import math
import sys
inf = float('inf')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	a = input()
	b = input()
	n1 = len(a)
	n2 = len(b)
	ans = 10 ** 9
	for i in range(n1):
		for j in range(i - 1, n1):
			x = a[i:j + 1]
			if x in b:
				ans = min(ans, n1 - len(x) + n2 - len(x))
	print(ans)


def solve():
	s1 = input().rstrip()
	s2 = input().rstrip()
	common = 0
	for length in range(len(s1), 0, -1):
		for i in range(len(s1) - length + 1):
			if s1[i:i + length] in s2:
				common = max(common, length)
	for length in range(len(s2), common, -1):
		for i in range(len(s2) - length + 1):
			if s2[i:i + length] in s1:
				common = max(common, length)
	print(len(s1) + len(s2) - common * 2)
T = int(input())
for t in range(T):
	solve()


for t in range(int(input())):
	a = input()
	b = input()
	ops = len(a) + len(b)
	for l in range(1, min(len(a), len(b)) + 1):
		for i1 in range(len(a)):
			if i1 + l > len(a):
				break
			for i2 in range(len(b)):
				if i2 + l > len(b):
					break
				if a[i1:i1 + l] == b[i2:i2 + l]:
					ops = min(ops, len(a) - l + len(b) - l)
	print(ops)


for _ in range(int(input())):
	(a, b) = (input(), input())
	maxx = ''
	for i in range(0, len(a)):
		for j in range(i, len(a)):
			if a[i:j + 1] in b:
				if len(maxx) < len(a[i:j + 1]):
					maxx = a[i:j + 1]
	print(len(a) - len(maxx) + len(b) - len(maxx))


def SubStr(X, Y, m, n):
	uf = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				uf[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				uf[i][j] = uf[i - 1][j - 1] + 1
				result = max(result, uf[i][j])
			else:
				uf[i][j] = 0
	return result
for _ in range(int(input())):
	a = input()
	b = input()
	print(len(a) + len(b) - 2 * SubStr(a, b, len(a), len(b)))


def Solve():
	s = input()
	p = input()
	if len(s) > len(p):
		(s, p) = (p, s)
	for i in range(len(s)):
		k = len(s) - i
		for j in range(0, i + 1):
			t = s[j:j + k]
			if p.find(t) >= 0:
				print(len(p) - len(t) + len(s) - len(t))
				return
	print(len(s) + len(p))
q = int(input())
while q:
	Solve()
	q -= 1


import sys
import math
from math import factorial, inf, gcd
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
sys.setrecursionlimit(10 ** 5)
t = 1
t = int(input())
for ii in range(t):
	a = input()
	b = input()
	(m, n) = (len(a), len(b))
	ans = 0
	for g in range(1, min(m, n) + 1):
		for i in range(m - g + 1):
			for j in range(n - g + 1):
				if a[i:i + g] == b[j:j + g]:
					ans = max(ans, g)
	print(m + n - ans * 2)


import math

def solve():
	a = input()
	b = input()
	ara = []
	arb = []
	s = b
	if len(a) > len(b):
		b = a
		a = s
	for i in range(0, len(a) + 1):
		temp = set()
		ara.append(set())
		arb.append(temp)
	ara[0].add(' ')
	arb[0].add(' ')
	for i in range(0, len(a)):
		for leng in range(0, len(a) - i):
			temp3 = ''
			for ii in range(i, i + leng + 1):
				temp3 += a[ii]
			ara[leng + 1].add(temp3)
	for i in range(0, len(b)):
		for leng in range(0, len(b) - i):
			if leng >= len(a):
				continue
			temp2 = ''
			for ii in range(i, i + leng + 1):
				temp2 += b[ii]
			arb[leng + 1].add(temp2)
	i = len(a)
	while i >= 0:
		for j in ara[i]:
			if j in arb[i]:
				print(len(a) + len(b) - 2 * i)
				return
		i -= 1
t = int(input())
while t:
	solve()
	t -= 1


def getLCSSubStr(X, Y, m, n):
	LCSuff = [[0 for i in range(n + 1)] for j in range(m + 1)]
	length = 0
	(row, col) = (0, 0)
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				if length < LCSuff[i][j]:
					length = LCSuff[i][j]
					row = i
					col = j
			else:
				LCSuff[i][j] = 0
	if length == 0:
		return ''
	resultStr = ['0'] * length
	while LCSuff[row][col] != 0:
		length -= 1
		resultStr[length] = X[row - 1]
		row -= 1
		col -= 1
	return ''.join(resultStr)

def find_ans(X, Y):
	m = len(X)
	n = len(Y)
	common_string = getLCSSubStr(X, Y, m, n)
	a = m - len(common_string)
	b = n - len(common_string)
	return a + b
test_cases = int(input())
ans = []
for _ in range(test_cases):
	X = input()
	Y = input()
	ans.append(find_ans(X, Y))
for i in ans:
	print(i)


def find(a, i, j, b):
	n = len(a)
	a = a[i:j + 1]
	try:
		index = b.index(a)
	except:
		return float('inf')
	total = index + len(b) - index - len(a) + i + n - j - 1
	return total

def solve(a, b, ans):
	min_val = float('inf')
	for i in range(len(a)):
		for j in range(i, len(a)):
			min_val = min(min_val, find(a, i, j, b))
	if min_val == float('inf'):
		min_val = len(a) + len(b)
	ans.append(str(min_val))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		a = input()
		b = input()
		solve(a, b, ans)
	print('\n'.join(ans))
main()


for _ in range(int(input())):
	a = input()
	b = input()
	if a == b:
		print('0')
	else:
		max_ = 0
		i = 0
		while i <= len(a) - 1:
			for j in range(i + 1, len(a) + 1):
				if a[i:j] in b:
					k = j - i
					if k > max_:
						max_ = k
					if j == len(a):
						i += 1
				else:
					i += 1
					break
		print(len(a) + len(b) - 2 * max_)


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	if a == b:
		print(0)
		continue
	(sa, sb) = (set(), set())
	na = len(a)
	nb = len(b)
	for i in range(na):
		for j in range(i, na):
			sa.add(a[i:j + 1])
	for i in range(nb):
		for j in range(i, nb):
			sb.add(b[i:j + 1])
	bests = list(sa & sb)
	if len(bests) == 0:
		print(na + nb)
	else:
		inter = max(bests, key=len)
		print(na + nb - 2 * len(inter))


for _ in range(int(input())):
	a = input()
	b = input()
	d = set()
	e = []
	for i in range(len(a)):
		for j in range(len(a), -1, -1):
			e.append(a[i:j])
	for i in range(len(b)):
		for j in range(len(b), -1, -1):
			d.add(b[i:j])
	maxi = 0
	for i in e:
		if i in d:
			maxi = max(maxi, len(i))
	print(len(a) + len(b) - 2 * maxi)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	a = input().strip()
	b = input().strip()
	(n, m) = (len(a), len(b))
	if n > m:
		(a, b) = (b, a)
		(n, m) = (m, n)
	an = n + m
	a += '0'
	b += '0'
	for i in range(n, 0, -1):
		x = a[:i]
		for j in range(n - i + 1):
			if x in b:
				an -= 2 * len(x)
				break
			x = x[1:] + a[j + i]
		if an != n + m:
			break
	print(an)


from difflib import SequenceMatcher
T = int(input())
for i in range(T):
	a = input()
	b = input()
	m = len(a)
	n = len(b)
	match = SequenceMatcher(None, a, b).find_longest_match(0, m, 0, n)
	print(m + n - 2 * match.size)


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	l = list()
	n = len(b)
	m = len(a)
	for i in range(n):
		for j in range(i + 1, n + 1):
			l.append(b[i:j])
	x = 0
	for i in l:
		y = len(i)
		if i in a and y > x:
			x = len(i)
	print(n + m - 2 * x)


list_ans = []
for _ in range(int(input())):
	a = input()
	b = input()
	x = 0
	if len(b) < len(a):
		(a, b) = (b, a)
	n = len(a)
	for i in range(n):
		while i + x < n and a[i:i + x + 1] in b:
			x += 1
	list_ans.append(len(a) + len(b) - 2 * x)
for item in list_ans:
	print(item)


def LCS(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
for _ in range(int(input())):
	a = str(input())
	b = str(input())
	an = LCS(a, b, len(a), len(b))
	s = len(a) + len(b) - 2 * an
	print(s)


def func(x, m, y, n):
	z = [[0 for i in range(n + 1)] for j in range(m + 1)]
	ans = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				z[i][j] = 0
			elif x[i - 1] == y[j - 1]:
				z[i][j] = z[i - 1][j - 1] + 1
				ans = max(ans, z[i][j])
			else:
				z[i][j] = 0
	return ans
for u in range(int(input())):
	x = input()
	y = input()
	m = len(x)
	n = len(y)
	ans = func(x, m, y, n)
	ans = m + n - 2 * ans
	print(ans)


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		a = input()
		b = input()
		m = 0
		for i in range(len(a)):
			for j in range(i, len(a)):
				if a[i:j + 1] in b:
					m = max(m, j + 1 - i)
		print(len(a) + len(b) - 2 * m)
solve()


t = int(input())

def LCSubstr(S, T):
	L = [[0 for j in range(len(T))] for i in range(len(S))]
	z = 0
	ret = []
	for i in range(len(S)):
		for j in range(len(T)):
			if S[i] == T[j]:
				if i == 0 or j == 0:
					L[i][j] = 1
				else:
					L[i][j] = L[i - 1][j - 1] + 1
				if L[i][j] > z:
					z = L[i][j]
					ret = [S[i - z + 1:i + 1]]
				elif L[i][j] == z:
					ret += S[i - z + 1:i + 1]
			else:
				L[i][j] = 0
	return ret
for i in range(t):
	s1 = input()
	s2 = input()
	if s1 == s2:
		print(0)
	else:
		d = LCSubstr(s1, s2)
		if len(d) == 0:
			print(len(s1) + len(s2))
		else:
			d = len(max(d, key=len))
			print(len(s1) + len(s2) - 2 * d)


t = int(input())
while t > 0:
	t = t - 1
	a = input()
	b = input()
	x1 = len(a)
	x2 = len(b)
	cost = 10 ** 9
	for i in range(x1):
		for j in range(i - 1, x1):
			p = a[i:j + 1]
			if p in b:
				cost = min(x1 - len(p) + x2 - len(p), cost)
	print(cost)


def solve():
	a = input()
	b = input()
	lenA = len(a)
	lenB = len(b)
	for i in range(min(lenA, lenB), 0, -1):
		for j in range(lenB):
			if j + i <= lenB and b[j:j + i] in a:
				return lenA + lenB - 2 * i
	return lenA + lenB
for _ in range(int(input())):
	print(solve())


def helper(a, b):
	if a == b:
		return 0
	small = min(a, b, key=len)
	if a == small:
		big = b
	else:
		big = a
	maxlen = 0
	for i in range(len(small)):
		for j in range(i + 1, len(small) + 1):
			if small[i:j] in big:
				maxlen = max(maxlen, len(small[i:j]))
	return len(a) - maxlen + (len(b) - maxlen)
for i in range(int(input())):
	a = input()
	b = input()
	print(helper(a, b))


for _ in range(int(input())):
	a = input().strip()
	b = input().strip()
	t = 0
	n = 0
	for i in range(len(a), 0, -1):
		for j in range(len(a) - i + 1):
			if b.find(a[j:i + j]) > -1:
				t = i
				n = 1
				break
		if n:
			break
	print(len(a) + len(b) - t - t)


def generateSubstring(a):
	ret = []
	for i in range(len(a)):
		for j in range(i + 1, len(a) + 1):
			ret.append(a[i:j])
	return set(ret)

def solve(a, b):
	seta = generateSubstring(a)
	setb = generateSubstring(b)
	substr = ''
	for e in seta:
		if e in setb:
			if len(e) > len(substr):
				substr = e
	return len(a) + len(b) - 2 * len(substr)
t = int(input())
for i in range(t):
	a = input()
	b = input()
	print(solve(a, b))


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	s = [a[i:j + 1] for i in range(len(a)) for j in range(i, len(a)) if a[i:j + 1] in b]
	if s:
		print(len(a) + len(b) - len(max(s, key=len)) * 2)
	else:
		print(len(a) + len(b))


def lcs(X, Y, m, n):
	LCSuff = [[0 for k in range(n + 1)] for l in range(m + 1)]
	result = 0
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				LCSuff[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1
				result = max(result, LCSuff[i][j])
			else:
				LCSuff[i][j] = 0
	return result
n = int(input())
for __ in range(n):
	s1 = input()
	s2 = input()
	nn = len(s1)
	mm = len(s2)
	res = lcs(s1, s2, nn, mm)
	print(nn - res + mm - res)


def main():
	a = input()
	b = input()
	m = 0
	for i in range(0, len(a)):
		for j in range(len(a), i, -1):
			n = b.find(a[i:j])
			if n >= 0 and j - i > m:
				m = j - i
	print(len(a) + len(b) - 2 * m)
	return
t = int(input())
for i in range(0, t):
	main()


import sys

def I():
	return int(sys.stdin.readline().rstrip())

def MI():
	return map(int, sys.stdin.readline().rstrip().split())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def LI2():
	return list(map(int, sys.stdin.readline().rstrip()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def LS2():
	return list(sys.stdin.readline().rstrip())
t = I()
for _ in range(t):
	a = S()
	b = S()
	len_a = len(a)
	len_b = len(b)
	ans = len_a + len_b
	for i in range(1, min(len_a, len_b) + 1):
		for j in range(len_a - i + 1):
			for k in range(len_b - i + 1):
				if a[j:j + i] == b[k:k + i]:
					ans = min(ans, len_a + len_b - 2 * i)
	print(ans)


for _ in range(0, int(input())):
	a = input()
	b = input()
	lenA = len(a)
	lenB = len(b)
	resultMaximum = 0
	for i in range(lenA):
		for j in range(i, lenA):
			if a[i:j + 1] in b:
				resultMaximum = max(resultMaximum, j - i + 1)
	print(lenA + lenB - 2 * resultMaximum)


for _ in range(int(input())):
	a1 = input()
	b1 = input()
	a = {}
	for i in range(len(a1)):
		s = a1[i]
		a[s] = 0
		for j in range(i + 1, len(a1)):
			s += a1[j]
			a[s] = 0
	b = {}
	for i in range(len(b1)):
		s = b1[i]
		b[s] = 0
		for j in range(i + 1, len(b1)):
			s += b1[j]
			b[s] = 0
	d = 0
	for i in a.keys():
		if i in b:
			d = max(d, len(i))
	print(len(a1) + len(b1) - d - d)


def solve(a, b):
	n = len(a)
	m = len(b)
	ans = n + m
	for i in range(n):
		for j in range(m):
			if a[i] == b[j]:
				ai = i
				bj = j
				common = 0
				while ai < n and bj < m and (a[ai] == b[bj]):
					ai += 1
					bj += 1
					common += 2
				ans = min(ans, n + m - common)
	return ans
local_ans = []
local_mode = False
t = int(input())
for _ in range(t):
	a = input()
	b = input()
	if local_mode:
		local_ans.append(solve(a, b))
	else:
		print(solve(a, b))

def getArr():
	return list(map(int, input().split()))

def getNums():
	return map(int, input().split())
if local_mode:

	def printAll(sol):
		for val in sol:
			print(val)
	printAll(local_ans)


def lcs(str_1, str_2, n, m):
	dp = [[0 for i in range(m + 1)] for i in range(n + 1)]
	result = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if str_1[i - 1] == str_2[j - 1]:
				dp[i][j] = dp[i - 1][j - 1] + 1
				result = max(result, dp[i][j])
			else:
				dp[i][j] = 0
	return result
for _ in range(int(input())):
	a = list(input())
	b = list(input())
	n = lcs(a, b, len(a), len(b))
	print(len(a) + len(b) - 2 * n)


my_mass = list()
size_1 = 0
size_2 = 0
a = list()
b = list()

def recurs(i, j, mass):
	global my_mass
	if len(mass) > len(my_mass):
		my_mass = mass
	if i == size_1:
		1
	else:
		for l in range(j, size_2):
			for k in range(i, size_1):
				if a[k] == b[l]:
					mass.append(a[k])
					recurs(k + 1, l + 1, mass)
					mass = []
				else:
					break
for i in range(int(input())):
	a = list(input())
	b = list(input())
	size_1 = len(a)
	size_2 = len(b)
	max = 0
	i = 0
	size = 0
	for i in range(0, len(b)):
		for j in range(0, len(a)):
			k = j
			l = i
			size = 0
			while b[l] == a[k]:
				l += 1
				k += 1
				size += 1
				if size > max:
					max = size
				if l == len(b):
					break
				if k == len(a):
					break
	print(len(a) - max + len(b) - max)


def huh(s):
	a = list(s)
	if min(a) == max(a):
		return True
	return False

def main():
	for _ in range(int(input())):
		a = input()
		b = input()
		n = len(a)
		m = len(b)
		d = []
		s = 0
		if huh(a) and a[0] not in b:
			s = n + m
		elif huh(b) and b[0] not in a:
			s = n + m
		elif n > m:
			for i in range(m):
				for j in range(i, m + 1):
					if b[i:j] in a:
						d += [j - i]
						s = n + m - 2 * max(d)
		elif n <= m:
			for i in range(n):
				for j in range(i + 1, n + 1):
					if a[i:j] in b:
						d += [j - i]
						s = n + m - 2 * max(d)
		elif a == b:
			d += [n]
			s = n + m - 2 * max(d)
		elif n == m and m == 1 and (a != b):
			d += [n + m]
			s = n + m - 2 * max(d)
		print(s)
main()


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve(s, p):
	ans = 0
	dp = [[0 for i in range(len(p) + 1)] for j in range(len(s) + 1)]
	for i in range(len(s)):
		for j in range(len(p)):
			if s[i] == p[j]:
				dp[i + 1][j + 1] = dp[i][j] + 1
				ans = max(ans, dp[i + 1][j + 1])
	return len(s) + len(p) - 2 * ans
t = int(input())
for i in range(t):
	s = input()
	p = input()
	print(solve(s, p))