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

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

int f(int i, int j ,int ind, int m ,int n,int p, string &a, string &b, string & c, vector<vector<int>>&dp){
    // if(i>=m){
    //     int count =0;
    //     while(j<n&&ind<p){
    //         if(c[ind]!=b[j]){
    //             count++;
    //         }
    //         ind++;
    //         j++;
    //     }
    //     return count;
    // }
    // if(j>=n){
    //     int count =0;
    //     while(i<m&&ind<p){
    //         if(c[ind]!=a[i]){
    //             count++;
    //         }
    //         ind++;
    //         i++;
    //     }
    //     return count;

    // }
    if(ind>=p){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }

    
    int val=INT_MAX;

    if(i<m&&a[i]==c[ind]){
        val=min(val,f(i+1,j,ind+1,m,n,p,a,b,c,dp));
    }
     if(j<n&&b[j]==c[ind]){
        val=min(val,f(i,j+1,ind+1,m,n,p,a,b,c,dp));
    }
    if(i<m&&a[i]!=c[ind]){
        val=min(val,1+f(i+1,j,ind+1,m,n,p,a,b,c,dp));

        
    }
    if(j<n&&b[j]!=c[ind]){
        val=min(val,1+f(i,j+1,ind+1,m,n,p,a,b,c,dp));
    }
    return dp[i][j]=val;
}

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

       cin>>a;
       cin>>b;
       cin>>c;

       int m=a.size();
       int n=b.size();
       int p=c.size();
       
       vector<vector<int>>dp(m+1,vector<int>(n+1,-1));
       int ans=f(0,0,0,m,n,p,a,b,c,dp);
       cout<<ans<<endl;


       
    }
    return 0;
}


Solution 2 (runtime: 2265 ms):
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
 
/*
------------------------------------------
Author       :- Shadan Hussain
Started      :- [04-01-24]
College      :- NIT Rourkela
------------------------------------------
*/
 
#define int long long int
#define el '\n'
#define take(x) int x; cin>>x;
#define getv(v, n)  vector<int> v;for (int i = 0; i < n; i++){ take(x) v.push_back(x);}
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define sortv(v) sort(all(v))
#define sortvr(v) sort(allr(v))
#define gcd(a,b)  __gcd(a,b)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define pb push_back
#define ppb pop_back
#define yes cout << "YES" << el
#define no cout << "NO" << el
#define ff first
#define ss second
#define MOD 1000000007
#define INF 1e18
#define ppc(x) __builtin_popcountll(x)
#define bitsparity(x) __builtin_parityll(x) //1/true for odd , 0/false for even
#define par(x) (x&1) //1/true for odd , 0/false for even
#define trail(x) __builtin_ctzll(x)
#define lead(x) __builtin_clzll(x)
#define vecmin(x) *min_element(all(x)) // store it in a variable, then use the value
#define vecmax(x) *max_element(all(x)) // store it in a variable, then use the value
#define vecsum(x) accumulate(all(x), 0ll);
#define vecpre(x) partial_sum(all(x), x.begin())
#define vecsuf(x) partial_sum(allr(x), x.rbegin())
#define bug(x) cout<<#x<<"->"<<x<<el;
 
typedef long long ll; //-1e18 -> 1e18
typedef unsigned long long ull;  //0 -> 1e19
typedef long double lld;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update > pbdsg; // find_by_order, order_of_key
//pbds for increasing order, pbdsg for descending order, change data types for other usage
 
void fastio()
{ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());}
 
 bool cmp(pair<int,int>a,pair<int,int>b){
    if(a.first!=b.first)
    return a.first<b.first;
    else
    return a.second>b.second;
 }
//  int reverse(int n){
//     int ans=0;
//     while(n>0){
//         int d=n%10;
//         ans=ans*10+d;

//         n/=10;
//     }
//     return ans;
//  }

int f(string &s1,string& s2,string &s3,int i,int j,int k,map<pair<pair<int,int>,int>,int>&dp){
  int n=s1.size();
  int m=s2.size();
  int len=s3.size();
  if(k==len)
  return 0;
  if(dp.find({{i,j},k})!=dp.end())
  return dp[{{i,j},k}];
  int ans=1e9;
  if(j<m)
   ans=min(ans,1+f(s1,s2,s3,i,j+1,k+1,dp));
   if(i<n)
    ans=min(ans,1+f(s1,s2,s3,i+1,j,k+1,dp));

    if((i<n && s1[i]==s3[k]))
      ans=min(ans,f(s1,s2,s3,i+1,j,k+1,dp));
    if(j<m && s2[j]==s3[k])
    ans=min(ans,f(s1,s2,s3,i,j+1,k+1,dp));

  return dp[{{i,j},k}]= ans;
}
void shadan()
{
  string a,b,c;
  cin>>a>>b>>c;
  int n=a.size();
  int m=b.size();
  int len=c.size();
  map<pair<pair<int,int>,int>,int>dp;
  cout<<f(a,b,c,0,0,0,dp)<<endl;
  
 
}
signed main()
{
//   #ifndef ONLINE_JUDGE
//     //for getting input from input.txt
//     freopen("input1.txt", "r", stdin);
//     //for writing output to output.txt
//     freopen("output1.txt", "w", stdout);
// #endif
  fastio();
  int T = 1;
  cin >> T;
  for (int tc = 1; tc <= T; tc++)
  {
    /*cout << "Case #" << tc << ": ";*/
      shadan();
  }
  return 0;
}
//Snippet path: C:\Users\USER\AppData\Roaming\Sublime Text 3\Packages\User