Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// template <typename Type, typename ComparatorFn = less<Type>>
// using ordered_set = tree<Type, null_type, ComparatorFn, rb_tree_tag, tree_order_statistics_node_update>;
// //ordered_set<int, greater_equal<int>> st
// template<typename Type, typename ComparatorFn>
// bool ordered_set_erase(ordered_set<Type, ComparatorFn> &st, Type val) {
// 	if (st.lower_bound(val) == st.upper_bound(val)) return false;
// 	st.erase(st.find_by_order(st.order_of_key(val)));
// 	return true;
// }

// methods -> *find_by_order, order_of_key
// comparators -> less, less_equal, greater, greater_equal

//random No
// mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); //use by rng()
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;++i)
#define REPI(i,a,b) for(ll i=a;i>=b;--i)
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define all(a) (a).begin(),(a).end()
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define yes {cout<<'Y'<<'E'<<'S'<<endl; return;}
#define no {cout << 'N' << 'O' << endl; return;}
#define endl "\n"
#define Ka_chow ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x)                cout<<#x<<": "<<x<<"\n"
#define db2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<"\n"
#define db3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"\n"
#define db4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<"\n"
#define db5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<"\n"
const int M = 1e9 + 7;
const int N = 1e6 + 7;
#define inf 1000000000000000000
vector<bool> sv(N + 1, true);
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int prod(const int& a, const int& b)
{
	return ((ll)(a)) * b % M;
}
int sum(const int& a, const int& b)
{
	int c = a + b;
	return c >= M ? c - M : c;
}
int power(int a, int b) {
	int ans = 1;
	a = a % M;
	while (b) {
		if (b & 1) ans = (ans * 1LL * a) % M;
		a = (a * 1LL * a) % M;
		b >>= 1;
	}
	return ans;
}

void seive() {
	sv[0] = false, sv[1] = false;

	for (int i = 2; i * i <= N; ++i) {
		if (sv[i]) {
			for (int j = i * i; j <= N; j += i) sv[j] = 0;
		}
	}
}
void _print(vector<int> v) {
	for (auto &e : v) cout << e << " ";
	cout << endl;
}
vi prefixSum(vi v, bool fl) {
	vi ans;
	int sum = 0;
	if (fl) {
		for (auto &e : v) {
			sum += e;
			ans.eb(sum);
		}
	} else {
		REPI(i, v.size() - 1, 0) {
			sum += v[i];
			ans.eb(sum);
		}
	}
	return ans;
}

//32 r loop logabi 10^9 le & 64 r logabi 10^18 le
map<int, map<int, int>> dp;

int f(int i, int j, int k, string a, string b, string c) {
	if (k >= c.size()) return 0;
	if (dp.count(i) && dp[i].count(j)) return dp[i][j];
	int ans = INT_MAX;
	if (i < a.size()) {
		if (a[i] == c[k]) ans = min(ans, f(i + 1, j, k + 1, a, b, c));
		else ans = min(ans, 1 + f(i + 1, j, k + 1, a, b, c));
	}
	if (j < b.size()) {
		if (b[j] == c[k]) ans = min(ans, f(i, j + 1, k + 1, a, b, c));
		else ans = min(ans, 1 + f(i, j + 1, k + 1, a, b, c));
	}
	return dp[i][j] = ans;
}

void Blue() {
	// Think Twice Code Once
	string a, b, c;
	cin >> a >> b >> c;
	dp.clear();
	cout << f(0, 0, 0, a, b, c) << endl;
}

signed main() {
	Ka_chow
	// seive();
	tc(t)
	Blue();
}

/*
ॐ নমঃ শিৱায়
 */