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

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

#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef unordered_map<ll, ll> umpl;
typedef unordered_map<int, int> umpi;
typedef map<ll, ll> mpl;
typedef map<int, int> mpi;
typedef priority_queue<ll> pql;
typedef priority_queue<int> pqi;
typedef priority_queue<ll, vector<ll>, greater<ll>> minpql;
typedef priority_queue<int, vector<int>, greater<int>> minpqi;
typedef stack<ll> stl;
typedef stack<int> sti;
const ll mod = 1'000'000'007;
const ll N = 3e5, M = N;
vpii dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
vpii dir1 = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};
//=======================

vi g[N];

// int f(string &a, string &b, string &c, int i, int j, int k, vector<vector<vector<int>>> &vec)
int f(string &a, string &b, string &c, int i, int j, int k, vector<vector<int>> &vec)
{
    if(k<0)
    {
        return 0;
    }
    if(i<0)
    {
        int ans=0;
        while(j>=0)
        {
            if(b[j]==c[k])
            {
                j--;
                k--;
            }
            else
            {
                j--;
                k--;
                ans++;
            }
        }
        return ans;
    }

    if(j<0)
    {
        int ans=0;
        while(i>=0)
        {
            if(a[i]==c[k])
            {
                i--;
                k--;
            }
            else
            {
                i--;
                k--;
                ans++;
            }
        }
        return ans;
    }
    if(vec[i][j]!=-1)
    {
        return vec[i][j];
    }
    int takinga=0;
    if(i>=0)
    {
        if(a[i]!=c[k]){
            takinga++;
        }
        takinga += f(a,b,c, i-1, j, k-1, vec);
    }
    else
    {
        takinga=INT_MAX;
    }
    
    int takingb=0;
    if(j>=0)
    {
        if(b[j]!=c[k]){
            takingb++;
        }
        takingb += f(a,b,c, i, j-1, k-1, vec);
    }
    else
    {
        takingb=INT_MAX;
    }
    
    return vec[i][j]=min(takinga, takingb);
}
void solve()
{
    ll n, i, k, m, j;
    string a,b,c;
    cin>>a>>b>>c;
    // vector<vector<vector<int>>> vec(a.length(), vector<vector<int>> (b.length(), vector<int> (c.length(), -1)));
    // cout<<f(a,b,c,a.length()-1, b.length()-1, c.length()-1, vec)<<endl;
    vector<vector<int>> vec(a.length()+1, (vector<int> (b.length()+1, -1) ) );
    cout<<f(a,b,c,a.length()-1, b.length()-1, c.length()-1, vec)<<endl;
    return;
}



int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Solution 2 (runtime: 702 ms):
#include <iostream>
#include <bits/stdc++.h>
// #include <sys/resource.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace chrono;
// using namespace __gnu_pbds;

// def

// Speed
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Asquare cout.tie(NULL);

// Aliases
using ll = long long;
using lld = long double;
using ull = unsigned long long;

// Constants
const lld pi = 3.141592653589793238;
const ll INF = LONG_LONG_MAX;
const ll mod = 1000000007;

// TypeDEf
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll, ll> umll;
typedef map<ll, ll> mll;
typedef vector<vector<ll>> vvll;

// Macros
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fl(i, n) for (int i = 0; i < n; i++)
#define rl(i, m, n) for (int i = n; i >= m; i--)
#define py cout << "YES\n";
#define pm cout << "-1\n";
#define pn cout << "NO\n";
#define pimp cout << "IMPOSSIBLE\n";
#define vr(v) v.begin(), v.end()
#define rv(v) v.end(), v.begin()

// Debug
#ifdef AbhinavAwasthi
#define debug(x)       \
    cerr << #x << " "; \
    cerr << x << " ";  \
    cerr << endl;
#else
#define debug(x) ;
#endif

// Operator overloads
template <typename T1, typename T2> // cin >> pair<T1, T2>
istream &operator>>(istream &istream, pair<T1, T2> &p)
{
    return (istream >> p.first >> p.second);
}
template <typename T> // cin >> vector<T>
istream &operator>>(istream &istream, vector<T> &v)
{
    for (auto &it : v)
        cin >> it;
    return istream;
}
template <typename T1, typename T2> // cout << pair<T1, T2>
ostream &operator<<(ostream &ostream, const pair<T1, T2> &p)
{
    return (ostream << p.first << " " << p.second);
}
template <typename T> // cout << vector<T>
ostream &operator<<(ostream &ostream, const vector<T> &c)
{
    for (auto &it : c)
        cout << it << " ";
    return ostream;
}

// Utility functions
template <typename T>
void print(T &&t) { cout << t << "\n"; }
void printarr(ll arr[], ll n)
{
    fl(i, n) cout << arr[i] << " ";
    cout << "\n";
}
template <typename T>
void printvec(vector<T> v)
{
    ll n = v.size();
    fl(i, n) cout << v[i] << " ";
    cout << "\n";
}
template <typename T>
ll sumvec(vector<T> v)
{
    ll n = v.size();
    ll s = 0;
    fl(i, n) s += v[i];
    return s;
}

// Mathematical functions
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
} //__gcd
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll moduloMultiplication(ll a, ll b, ll mod)
{
    ll res = 0;
    a %= mod;
    while (b)
    {
        if (b & 1)
            res = (res + a) % mod;
        b >>= 1;
    }
    return res;
}
ll powermod(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

// Graph-dfs
//  bool gone[MN];
//  vector<int> adj[MN];
//  void dfs(int loc){
//      gone[loc]=true;
//      for(auto x:adj[loc])if(!gone[x])dfs(x);
//  }

// Sorting
bool sorta(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
bool sortd(const pair<int, int> &a, const pair<int, int> &b) { return (a.second > b.second); }

// Bits
string decToBinary(int n)
{
    string s = "";
    int i = 0;
    while (n > 0)
    {
        s = to_string(n % 2) + s;
        n = n / 2;
        i++;
    }
    return s;
}
ll binaryToDecimal(string n)
{
    string num = n;
    ll dec_value = 0;
    int base = 1;
    int len = num.length();
    for (int i = len - 1; i >= 0; i--)
    {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }
    return dec_value;
}

// Check
bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
bool isPowerOfTwo(ll n)
{
    if (n == 0)
        return false;
    return (ceil(log2(n)) == floor(log2(n)));
}
bool isPerfectSquare(ll x)
{
    if (x >= 0)
    {
        ll sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}

ll dp[1005][1005];

ll findMin(int i, int j,string &a, string &b, string &c){
    if(i + j == c.size())   return 0;
    
    if(dp[i][j] != -1)  return dp[i][j];
    
    ll mn = LLONG_MAX;
    
    if(i < a.length()){
        if(a[i] == c[i + j]){
            mn = min(mn,findMin(i + 1,j,a,b,c));
        }
        else{
            mn = min(mn, findMin(i + 1,j,a,b,c) + 1);
        }
    }
    
    if(j < b.length()){
        if(b[j] == c[i + j]){
            mn = min(mn, findMin(i,j+1,a,b,c));
        }
        else{
            mn = min(mn, findMin(i,j+1,a,b,c) + 1);
        }
    }
    
    return dp[i][j] = mn;
}

void func()
{
    string a,b,c;
    cin>>a>>b>>c;
    
    memset(dp,-1,sizeof(dp));
    
    cout<<findMin(0,0,a,b,c)<<endl;
}


int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        func();
    }
}