Problem: 2050E - Three Strings
Language: python

Solution 1 (runtime: 1702 ms):
def min_changes(t, cases):
    results = []
    
    for a, b, c in cases:
        len_a, len_b = len(a), len(b)
        
        # Создаем DP таблицу
        dp = [[float('inf')] * (len_b + 1) for _ in range(len_a + 1)]
        dp[0][0] = 0  # Базовый случай: ничего не нужно менять, если строка пустая
        
        for i in range(len_a + 1):
            for j in range(len_b + 1):
                if i < len_a:  # Если можно использовать следующий символ из a
                    change_cost = 0 if c[i + j] == a[i] else 1
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + change_cost)
                    
                if j < len_b:  # Если можно использовать следующий символ из b
                    change_cost = 0 if c[i + j] == b[j] else 1
                    dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + change_cost)
        
        results.append(dp[len_a][len_b])
    
    return results

# Чтение входных данных
t = int(input())
cases = [tuple(input().strip() for _ in range(3)) for _ in range(t)]

# Получение результатов
results = min_changes(t, cases)

# Печать результатов
for result in results:
    print(result)

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)])