Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
#define ll long long int
#define vl vector<long long>
#define all(x) x.begin(), x.end()
#define in cin >>
#define out cout <<
#define br cout << "\n";
#define sz(x) (ll)(x).size()
#define yes() out "YES";
#define no() out "NO";
#define vvl vector<vl>
#define pb push_back
#define fi first
#define se second
#define tc \
    ll t;  \
    in t;  \
    while (t--)
using namespace std;

ll lcs_tabular(string X, string Y, string Z)
{
    ll m = sz(X), n = sz(Y);

    // Create a 2D DP table to store results
    vector<vector<ll>> dp(m + 1, vector<ll>(n + 1, INT_MAX));

    // Base case: If Z is empty, no cost is required
    for (ll i = 0; i <= m; i++)
    {
        for (ll j = 0; j <= n; j++)
        {
            if (i + j == 0) // Z is empty
                dp[i][j] = 0;
        }
    }

    // Fill the DP table
    for (ll i = 0; i <= m; i++)
    {
        for (ll j = 0; j <= n; j++)
        {
            ll k = i + j; // Current index in Z
            if (k > sz(Z))
                continue;

            // If both X and Y contribute to Z[k-1]
            if (i > 0 && k > 0 && X[i - 1] == Z[k - 1])
            {
                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            }

            if (j > 0 && k > 0 && Y[j - 1] == Z[k - 1])
            {
                dp[i][j] = min(dp[i][j], dp[i][j - 1]);
            }

            // If X contributes but does not match Z[k-1]
            if (i > 0 && k > 0 && X[i - 1] != Z[k - 1])
            {
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
            }

            // If Y contributes but does not match Z[k-1]
            if (j > 0 && k > 0 && Y[j - 1] != Z[k - 1])
            {
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
            }
        }
    }

    return dp[m][n];
}

void solve()
{
    string a, b, c;
    in a >> b >> c;

    ll ans = lcs_tabular(a, b, c);
    out ans;
    br
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif
    tc { solve(); }
}


Solution 2 (runtime: 874 ms):
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)1e3 + 5
#define N (1ll<<10)

ll dp[MAXN][MAXN];
string a, b, c;

ll f(ll i1, ll i2) {
    ll n = a.length();
    ll m = b.length();
    if(i1 >= n && i2 >= m) return 0;
    if(dp[i1][i2] != -1) return dp[i1][i2];
    ll cid = i1 + i2;
    ll ans = inf;
    if(i1 < n) ans = (a[i1] != c[cid]) + f(i1 + 1, i2);
    if(i2 < m) ans = min(ans, (b[i2] != c[cid]) + f(i1, i2 + 1));

    return dp[i1][i2] = ans;

}

void solve(){
    cin >> a >> b >> c;
    loop(i, 0, MAXN) {
        loop(j, 0, MAXN) {
            dp[i][j] = -1;
        }
    }

    cout << f(0, 0) << endl;
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    ll t = 1;
    cin>>t;
    while(t--){
        solve();
    }
        
    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}