Problem: 2050E - Three Strings
Language: python

Solution 1 (runtime: 374 ms):
for _ in range(int(input())):
    a = input()
    b = input()
    c = input()

    m = len(a)
    n = len(b)
    
    a = '$' + a
    b = '$' + b
    c = '$' + c

    dp = [[None for j in range(n + 1)] for i in range(m + 1)]
    dp[0][0] = 0

    for i in range(1, m + 1):
        if a[i] == c[i]:
            dp[i][0] = dp[i - 1][0]
        else:
            dp[i][0] = 1 + dp[i - 1][0]

    for j in range(1, n + 1):
        if b[j] == c[j]:
            dp[0][j] = dp[0][j - 1]
        else:
            dp[0][j] = 1 + dp[0][j - 1]

    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if a[i] == c[i + j]:
                if b[j] == c[i + j]:
                    dp[i][j] = min(dp[i - 1][j], dp[i][j - 1])
                else:
                    dp[i][j] = min(dp[i - 1][j], 1 + dp[i][j - 1])
            else:
                if b[j] == c[i + j]:
                    dp[i][j] = min(1 + dp[i - 1][j], dp[i][j - 1])
                else:
                    dp[i][j] = min(1 + dp[i - 1][j], 1 + dp[i][j - 1])

    print(dp[m][n])

Solution 2 (runtime: 280 ms):
# import sys
# sys.setrecursionlimit(2*(10**3))
# for _ in range(int(input())):
#     a = input()
#     b = input()
#     c = input()
#     dic = {}

#     def calculate(i,j,k,dic):
#         if (i,j,k) in dic:
#             return dic[(i,j,k)]
#         if i == len(a):
#             count = 0
#             while k <len(c):
#                 if c[k] != b[j]:
#                     count+=1
#                 k+=1
#                 j+=1
#             dic[(i,j,k)] = count
#             return count
#         if j == len(b):
#             count = 0
#             while k < len(c):
#                 if c[k] != a[i]:
#                     count+=1
#                 i+=1
#                 k+=1
#             dic[(i,j,k)] = count
#             return count 

#         if c[k]!=a[i] and c[k]!=b[j]:
#             count = 1 + min(calculate(i+1,j,k+1,dic),calculate(i,j+1,k+1,dic))
#         elif c[k]!=a[i] and c[k] == b[j]:
#             count = min(calculate(i,j+1,k+1,dic),calculate(i+1,j,k+1,dic)+1)
#         elif c[k]==a[i] and c[k] != b[j]:
#             count = min(calculate(i,j+1,k+1,dic)+1,calculate(i+1,j,k+1,dic))
#         else:
#             count = min(calculate(i+1,j,k+1,dic),calculate(i,j+1,k+1,dic))

#         dic[(i,j,k)] = count
#         return count    
            
#     print(calculate(0,0,0,dic))

for _ in range(int(input())):
    a = input()
    b = input()
    c = input()

    dp = [[float('inf')] * (len(b) + 1) for _ in range(len(a) + 1)]

    for i in range(len(a) + 1):
        for j in range(len(b) + 1):
            k = i + j
            if k > len(c):
                continue

            if i == 0 and j == 0:
                dp[i][j] = 0
            else:
                if i > 0 and c[k - 1] == a[i - 1]:
                    dp[i][j] = min(dp[i][j], dp[i - 1][j])
                if j > 0 and c[k - 1] == b[j - 1]:
                    dp[i][j] = min(dp[i][j], dp[i][j - 1])
                if i > 0 and c[k - 1] != a[i - 1]:
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1)
                if j > 0 and c[k - 1] != b[j - 1]:
                    dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1)

    print(dp[len(a)][len(b)])