Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
//                                               <-------GAUTAM KUMAR SHAH------->          
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const long long mod=1e9+7;
#define loop(i,n)      for(int i=0;i<n;i++)
#define loopr(i,n)      for(int i=n;i>0;i--)
#define cin(arr,n)     for(int i=0;i<n;i++) cin>>arr[i];
#define loopv(i,k,n)   for(int i=k;i<n;i++)
#define vi vector<long long int>
#define mi map<long long int,long long int>
ll mod_expo(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} // (a^b)%mod
ll mminv(ll a) {return mod_expo(a, mod-2);}
ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;}
ll mod_div(ll a, ll b) {a = a % mod; b = b % mod; return (mod_mul(a, mminv(b)) + mod) % mod;}  //only for prime m
ll nCr(ll n,ll r) {if (r==0 || n==0) return 1; ll fac[n+1];fac[0]=1; for(int i = 1; i<n+1 ; i++)
fac[i]=(fac[i-1]*i)%mod;return(fac[n]*mminv(fac[r])%mod*mminv(fac[n-r])%mod)%mod;} 
 
int solve(string &a,string &b,string &c,int i,int j){
    int a1=a.size();
    int b1=b.size();
    int c1=c.size();
    int k=i+j;
    if(k==a1+b1){
        return 0;
    }
    int pick1=INT_MAX,npick1=INT_MAX,pick2=INT_MAX,npick2=INT_MAX;
    if(a[i]==c[k]){
        pick1=(solve(a,b,c,i+1,j));
    }
    if(b[j]==c[k]){
        pick2=(solve(a,b,c,i,j+1));
    }
    npick1=(1+solve(a,b,c,i+1,j));
    npick2=(1+solve(a,b,c,i,j+1));
    return min(min(pick1,pick2),min(npick1,npick2));


}
 
int main(){
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
   int t;
   cin>>t;
   while(t--)
   {
        string a,b,c;
        cin>>a>>b>>c;
        int ans=solve(a,b,c,0,0);
        cout<<ans<<endl;
 
   }
   return 0;
}

Submission (verdict: Time limit exceeded on test 6):
//                                               <-------GAUTAM KUMAR SHAH------->          
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const long long mod=1e9+7;
#define loop(i,n)      for(int i=0;i<n;i++)
#define loopr(i,n)      for(int i=n;i>0;i--)
#define cin(arr,n)     for(int i=0;i<n;i++) cin>>arr[i];
#define loopv(i,k,n)   for(int i=k;i<n;i++)
#define vi vector<long long int>
#define mi map<long long int,long long int>
ll mod_expo(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} // (a^b)%mod
ll mminv(ll a) {return mod_expo(a, mod-2);}
ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;}
ll mod_div(ll a, ll b) {a = a % mod; b = b % mod; return (mod_mul(a, mminv(b)) + mod) % mod;}  //only for prime m
ll nCr(ll n,ll r) {if (r==0 || n==0) return 1; ll fac[n+1];fac[0]=1; for(int i = 1; i<n+1 ; i++)
fac[i]=(fac[i-1]*i)%mod;return(fac[n]*mminv(fac[r])%mod*mminv(fac[n-r])%mod)%mod;} 
 
int solve(string &a,string &b,string &c,int i,int j){
    int a1=a.size();
    int b1=b.size();
    int c1=c.size();
    
    int k=i+j;
    if(k==a1+b1){
        return 0;
    }
    int pick1=INT_MAX,npick1=INT_MAX,pick2=INT_MAX,npick2=INT_MAX;
    if(a[i]==c[k] && i<a1){
        pick1=(solve(a,b,c,i+1,j));
    }
    if(b[j]==c[k] && j<b1){
        pick2=(solve(a,b,c,i,j+1));
    }
    if(i<a1)
    npick1=(1+solve(a,b,c,i+1,j));
    if(j<b1)
    npick2=(1+solve(a,b,c,i,j+1));
    return min(min(pick1,pick2),min(npick1,npick2));


}
 
int main(){
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
   int t;
   cin>>t;
   while(t--)
   {
        string a,b,c;
        cin>>a>>b>>c;
        int ans=solve(a,b,c,0,0);
        cout<<ans<<endl;
 
   }
   return 0;
}