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

Solution 1 (runtime: 124 ms):
#include <bits/stdc++.h>
using namespace std;

int Sam(vector<vector<int>> &dp, int ind1, int ind2, string &a, string &b, string &c)
{
    if (ind1 == a.length() && ind2 == b.length())
    {
        return 0;
    }

    if (dp[ind1][ind2] != -1)
        return dp[ind1][ind2];

    int t1 = INT_MAX, t2 = INT_MAX;
    int ccl = ind1 + ind2;
    if (ind1 != a.length())
    {
        
        if (a[ind1] != c[ccl])
        {
            t1 = 1 + Sam(dp, ind1 + 1, ind2, a, b, c);
        }
        else
            t1 = Sam(dp, ind1 + 1, ind2, a, b, c);
        
    }
    if (ind2 != b.length())
    {
        
        if (b[ind2] != c[ccl])
        {
            t2 = 1 + Sam(dp, ind1, ind2 + 1, a, b, c);
        }
        else
            t2 = Sam(dp, ind1, ind2 + 1, a, b, c);
        
    }

    return dp[ind1][ind2] = min(t1, t2);
}
int main()
{

    int t;
    cin >> t;
    while (t--)
    {
        string a, b, c;

        cin >> a >> b >> c;
        int la = a.length(), lb = b.length(), lc = c.length();
        vector<vector<int>> dp(la + 1, vector<int>(lb + 1, -1));
        cout << Sam(dp, 0, 0, a, b, c) << endl;
    }
}

Solution 2 (runtime: 124 ms):
/* Vivek Dhir */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long int li;
typedef long long int ll;
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define FA(i, start, end) for (int i = start; i < end; i++)
#define setbits(x) __builtin_popcountll(x)// counts no. of 1s
#define zrobits(x) __builtin_ctzll(x)// counts no. of zeros on left
#define mod 1000000007
#define INF 322337200489576
#define VI vector<int>
#define VL vector<ll>
#define AI(arr, t) VL arr(t); FA(i, 0, t) cin>>arr[i];
#define print(arr) for(auto x: arr) cout<< x <<' '; cout<<'\n';
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second
#define MP make_pair
#define WINNING() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifndef ONLINE_JUDGE
#define debug(x) cerr << x<< endl;
#endif
ll expo(ll a, ll b, ll M) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % M; a = (a * a) % M; b = b >> 1;} return res;}
void fil(){ 
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);freopen("error.txt", "w", stderr); 
#endif
}
/*-------------------------------------------------------------------------------------------------------------------------------------*/

int ans(vector<vector<int> > &dp,string &a, string &b, string &c, int i, int j, int k){
    if(c.length()==k){
        return 0;
    }
    if(dp[i][j]!=-1) return dp[i][j];
    int fans = INT_MAX;
    if(i==a.length()){
        if(b[j]==c[k]){
            fans = min(fans, ans(dp, a, b, c, i, j+1, k+1));
        }
        else{
            fans = min(fans, ans(dp, a, b, c, i, j+1, k+1)+1);
        }
    }if(j==b.length()){
        if(a[i]==c[k]){
            fans = min(fans, ans(dp, a, b, c, i+1, j, k+1));
        }
        else{
            fans = min(fans, ans(dp, a, b, c, i+1, j, k+1)+1);
        }
    }
    if(j!=b.length() && i!=a.length()){
        if(a[i]==c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i+1, j, k+1), ans(dp, a, b, c, i, j+1, k+1)+1));
        }
        if(b[j]==c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i+1, j, k+1)+1, ans(dp, a, b, c, i, j+1, k+1)));
        }
        if(b[j]!=c[k] && a[i]!=c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i, j+1, k+1)+1,  ans(dp, a, b, c, i+1, j, k+1)+1));
        }
    }
    return dp[i][j] = fans;
}

void solve(){
    string a, b, c;
    cin>>a>>b>>c;
    // cout<< a<<" "<<b<<" "<<c<<" ";
    vector<vector<int> > dp(a.length()+1, vector<int>(b.length()+1, -1));
    cout<<ans(dp, a, b, c, 0, 0, 0)<<"\n";
}

int main(){
    WINNING(); fil(); 
    ll t = 1;
    cin>>t;
    FA(i, 1, t+1){
        // cout << "Case #"<< i <<": ";
        solve(); 
        //cout<<"\n";
    }
}