ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 311 ms):
#include <bits/stdc++.h>
using namespace std;
// SAKIB-22201185; I include comments to make someone understand my code.
// HAPPY CODING 
#define endl "\n"
#define ull unsigned long long int
#define fastios                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);

int main() {
    fastios;

    int test_cases;
    cin >> test_cases;

    while (test_cases--) {
        int array_size_n, array_size_m;
        cin >> array_size_n >> array_size_m;

        vector<int> array_n(array_size_n), array_m(array_size_m);

        for (int i = 0; i < array_size_n; i++) 
            cin >> array_n[i];

        for (int i = 0; i < array_size_m; i++) 
            cin >> array_m[i];

        priority_queue<int> max_heap;

        for (int i = 0; i < array_size_m; i++) 
            max_heap.push(array_m[i]);

        map<int, int> frequency_map;

        for (int i = 0; i < array_size_n; i++) 
            frequency_map[array_n[i]]++;

        bool is_possible = true;

        for (int i = 0; i < array_size_n - array_size_m + array_size_n; i++) {
            if (max_heap.empty()) {
                is_possible = false;
                break;
            }

            int current_top = max_heap.top();
            max_heap.pop();

            if (frequency_map[current_top] == 0) {
                max_heap.push(current_top / 2);
                max_heap.push((current_top + 1) / 2);
            } else {
                frequency_map[current_top]--;
            }
        }

        if (is_possible && max_heap.empty()) {
// use ternary operator
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Solution 2 (runtime: 202 ms):
#include <bits/stdc++.h>

using namespace std;
const int N = 2e5;
const int M = N;

int n, m, a[N + 1], b[M + 1];
multiset<int> rb;

int main() {
	int test = 1;
	scanf("%d", &test);
	while (test--) {
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		rb.clear();
		for (int i = 1; i <= m; i++) {
			scanf("%d", &b[i]);
			rb.insert(-b[i]);
		}
		sort(a + 1, a + 1 + n);
		reverse(a + 1, a + 1 + n);
		bool flag = true;
		int sz = m;
		for (int i = 1; i <= n; i++) {
			while (-*rb.begin() > a[i]) {
				int now = -*rb.begin();
				rb.erase(rb.begin());
				rb.insert({-(now / 2)});
				rb.insert({-((now + 1) / 2)});
				sz++;
				if (sz > n)
					break;
			}
			if (-*rb.begin() != a[i] || sz > n) {
				flag = false;
				break;
			} else
				rb.erase(rb.begin());
		}
		if (flag)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 234 ms):
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    int c,tmp[n+1];
    for(int i=0;i<=n;i++)tmp[i]=i;
    vector<pair<int,int>> ans;
    for(int i=1;i<=n;i++){
        cin>>c;
        int l=i,r=n,m=(l+r)/2;
        while(l<r){
            if(tmp[m]<c)l=m+1;
            else r=m;
            m=(l+r)/2;
        }
        for(int j=m;j<n;j++){
            ans.push_back(make_pair(tmp[j+1],tmp[j]));
            swap(tmp[j],tmp[j+1]);
        }
        for(int j=n-1;j>=i;j--){
            ans.push_back(make_pair(tmp[j+1],tmp[j]));
            swap(tmp[j],tmp[j+1]);
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans)cout<<i.first<<' '<<i.second<<endl;
    return 0;
}

Solution 2 (runtime: 1327 ms):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    
    // ll cnt=0;
    vector<pair<int,int>> ans;

    set<int> s;
    for (int i = 0; i < n; i++)
    {
        for (int j = v[i]+1; j <= n; j++)
        {
            if(s.find(j)!=s.end()) continue;
            ans.push_back({j,v[i]});
        }
        for (int j = n; j >= 1; j--)
        {
            if(j==v[i]) continue;
            if(s.find(j)!=s.end()) continue;
            ans.push_back({v[i],j});
        }
        s.insert(v[i]);
    }
    

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

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

void print(priority_queue<long long >pq)
{
	while(!pq.empty())
	{
		cout<<pq.top()<<" ";pq.pop();
	}
	cout<<"\n";
}

int main()
{
	long long t;
	cin>>t;
	
	while(t--)
	{
		long long n,m;
		cin>>n>>m;
		
		vector<long long>a(n),b(m);
		priority_queue<long long  >pq;//, vector<long long>, greater<long long >
		
		for(long long i=0;i<n;i++)
		{
			cin>>a[i];
		}
		
		for(long long i=0;i<m;i++)
		{
			cin>>b[i];
			pq.push(b[i]);
		}
		
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		
		long long j=n-1;
		bool flag = true;
		while(!pq.empty())
		{
			long long val = pq.top();
		//	cout<<val<<" "<<a[j]<<"\n";
		//	print(pq);
			pq.pop();
			if(j<0 || j<pq.size())
			{
				flag = false;
				break;
			}
			else if(a[j]<val)
			{
				pq.push(val/2ll);
				pq.push((val+1ll)/2ll);
			}
			else if(a[j]>val)
			{
				flag = false;
				break;
			}
			else{
			    j--;
			}
		}
		
	//	cout<<flag<<" "<<j<<" "<<pq.empty()<<"\n";
		if(!flag || j>=0 || !pq.empty())
		{
			cout<<"NO";
		}
		else{
			cout<<"YES";
		}
		cout<<"\n";
	}
}


Solution 2 (runtime: 436 ms):
#include<bits/stdc++.h>
 
#define ll long long int
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
using namespace std;

void solve() {
    int n, m; cin >> n >> m;

    if(m > n) {
        cout << "NO" << endl;
        return;
    }

    vector<ll> a, b;
    map<ll, ll> freq_a, freq_b;

    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        freq_a[x]++;
    }

    for(int i=0;i<m;i++) {
        int x;
        cin >> x;
        freq_b[x]++;
    }
    stack<int> st;
    for(auto& [k, v]:freq_b) {
        while(v) {
            v--;
            st.push(k);
        }
    }
    
    bool ans = true;
    while(!st.empty()) {
        auto x = st.top();
        st.pop();

        if(freq_a.count(x)) {
            freq_a[x]--;
            if(freq_a[x] == 0)
                freq_a.erase(x);
        } else {
            if(x == 1) {
                ans = false;
                break;
            }
            
            st.push(x/2);
            st.push((x+1)/2);
        }
    }

    if(freq_a.size())
        ans = false;

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

    return;
}

int main()
{
    fast;
 
    ll t = 1;
    cin >> t;
    while(t--) {
        solve();
    }    
 
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 374 ms):
#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        long long int a[n];
        long long int s = 0;
        for (int i=0; i<n; i++){
            cin >> a[i];
            s += a[i];
        }
        if (s%n){
            cout << "NO" << endl;
            continue;
        }
        s /= n;
        string ans = "YES";
        for (int i=1; i<n-1; i+=2){
            int f = s-a[i-1];
            a[i-1] = s;
            a[i+1] -= f;
        }
        for (int i=2; i<n-1; i+=2){
            int f = s-a[i-1];
            a[i-1] = s;
            a[i+1] -= f;
        }
        for (int i=0; i<n; i++){
            if (a[i]!=s){
                ans = "NO";
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Solution 2 (runtime: 327 ms):
#include <bits/stdc++.h>

#define fast                     \

    ios::sync_with_stdio(false); \

    cin.tie(nullptr)

#define ll long long

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        ll k = 0, d, n, sum = 0;

        bool flag = true;

        cin >> n;

        vector<int> A(n);

        for (int i = 0; i < n; i++)

            cin >> A[i];

        for (int i = 0; i < n; i++)

            sum += A[i];



        if (sum % n != 0)

            flag = false;

        else

        {

            d = sum / n;

            for (int i = 1; i < n - 1; i++)

            {

                if (A[i - 1] < d && A[i - 1] > 0)

                {

                    k = d - A[i - 1];

                    A[i + 1] = A[i + 1] - k;

                    A[i - 1] = d;

                }

                else

                {

                    k = A[i - 1] - d;

                    A[i + 1] = A[i + 1] + k;

                    A[i - 1] = d;

                }

            }

        }

        for (int j = 0; j < n; j++)

            if (A[j] != d)

                flag = false;

        cout << (flag ? "YES" : "NO") << endl;

    }



    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 217 ms):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t; // number of test cases
    cin >> t;
    while (t--) {
        int n, k;
        cin>>n>>k;
        vector<int> a(n);
        
        for(int i = 0; i<n; i++){
            cin>>a[i];           
        }
        sort(a.begin(), a.end());
        vector<int> fq;
        fq.push_back(1);
        for(int i = 1; i<n; i++){
            if(a[i] == a[i-1]){
                fq.back()++;
            }
            else{
                fq.push_back(1);
            }
        }
        sort(fq.begin(), fq.end());
        int s = fq.size();
        bool done = false;
        int tk = k;
        for(int i = 0; i<s-1; i++){
            
            if(fq[i] > k){
                cout<<s-i<<endl;
                done = true;
                break;
            }
            k -= fq[i];
        }
        if(!done){
            cout<<1<<endl;
        }
        
        
        
        
    }
    return 0;
}

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

void solve() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        map<int, int> freq;
        
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            freq[a[i]]++;
        }
        
        if (n == k) {
            // If n == k, we can include all elements
            cout << 1 << endl;
            continue;
        }
        
        vector<int> counts;
        for (const auto& pair : freq) {
            counts.push_back(pair.second);
        }
        
        sort(counts.begin(), counts.end());
        
        int removable = 0;
        int total = 0;
        for (int count : counts) {
            if (total + count <= k) {
                total += count;
                removable++;
            } else {
                break;
            }
        }
        
        int result = freq.size() - removable;
        cout << result << endl;
    }
}

int main() {
    solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

#define fori(n) for(int i=0; i<int(n); i++)
#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) long long l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinvi(a, n) vector<int> a(n); fori(n) { cin>>a[i]; }
#define cinvll(a, n) vector<long long> a(n); fori(n) { cin>>a[i]; }
#define cinvs(s, n) vector<string> s(n); fori(n) { cin>>s[i]; }
#define cinvd(a, n) vector<double> a(n); fori(n) { cin>>a[i]; }

#define endl "\n"
#define ll long long
#define PB push_back
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<string> vs;
typedef vector<long long> vll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cini(t);
    while (t--) {
        cins(s);
        int n = s.size();
        for (int i = n - 1; i > 0; i--) {
            while (s[i] != '0' && s[i] > s[i - 1] + 1) {
                s[i]--;
                swap(s[i], s[i - 1]);
                i = min(n - 1, i + 1);
            } 
        }
        cout << s << endl;
    }
}


Solution 2 (runtime: 93 ms):
#include <iostream>

#include <vector>

#include <iomanip>

#include <cstring>

#include <string>

#include <array>

#include <sstream>

#include <algorithm>

#include <cmath>

#include <climits>

#include<bitset>

#include <tuple>

#include<unordered_set>

#include<map>

#include<set>

#include <stack>

#include <queue>

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

FILE* stream;

#define ll long long



int d(char c)

{

	return (c - '0');

}



void solve()

{

	string s;

	cin >> s;



	int n = (int)s.size();



	for (int i = 0; i < n; ++i)

	{

		int best = d(s[i]);



		int pos = i;



		for (int j = i; j < min(i+10, n); ++j)

		{

			if( d(s[j])-(j-i)>best)

			{

				pos = j;

				best = d(s[j])-(j-i);







			}





		

		}

		while (pos > i)

		{

			swap(s[pos], s[pos - 1]);

			--pos;

		}



		s[i] = char(best + '0');

	}





	cout << s << endl;

}



signed main()

{

	FastIO

#ifndef ONLINE_JUDGE



		//For getting input from input.txt file

		freopen_s(&stream, "input.txt", "r", stdin);



	//Prlong longing the Output to output.txt file

	freopen_s(&stream, "output.txt", "w", stdout);



#endif



	ll tc = 1;

	cin >> tc;

	while (tc--) {

		solve();

	}



	return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define loop(i, x, y) for (int i = x; i < y; i++)
#define rloop(i, x, y) for (int i = x; i >= y; i--)
#define all(arr) arr.begin(),arr.end()
#define rt return
#define mpp map<int,int>
#define ff first
#define ss second
#define pb push_back
#define sortv(arr) sort(arr.begin(), arr.end())
#define rsortv(arr) sort(arr.begin(), arr.end(), greater<int>())
#define pii pair<int, int>
#define br cout << endl
#define dbg(a) cout<<a<<endl
#define ct continue
#define disp(a)                        \
  {                                    \
    for (int i = 0; i < a.size(); i++) \
      cout << a[i] << " ";             \
    cout << endl;                      \
  }
#define inp(a)                         \
  {                                    \
    for (int i = 0; i < a.size(); i++) \
      { cin >> a[i]; }                 \
  }
void Dinesh(){
  string s;
  cin>>s;
  string temp;
  int x=min((int)s.size(),10ll);
  loop(i,0,x){
    temp+=s[i];
  }
  // cout<<temp;
  string ans;
  loop(i,0,(int)s.size()){
     char c=temp[0];
     int pos=0;
    loop(j,1,(int)temp.size()){
      if((temp[j]-'0')-(j)>(c-'0')){
        c=temp[j]-(j);
        pos=j;
      }
    }
  ans+=c;
  string temp1 = (pos > 0 ? temp.substr(0, pos) : "") + temp.substr(pos + 1);
  if(x<(int)s.size())temp1+=s[x++];
  temp=temp1;
  }
  cout<<ans;br;


}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin >> t;
    while (t--) {
        Dinesh();
    }

    return 0;
}


Solution 2 (runtime: 108 ms):
#include <bits/stdc++.h>

using namespace std;



int main() 

{

    int t;

    cin>>t;

    while(t--){

      string s1;

      cin>>s1;

      vector<int>a;

      for(int i=0;i<s1.size();i++){

        a.push_back((int)(s1[i]-'0'));

      }

      int n=s1.size();

      for(int i=1;i<n;i++){

        int index=i;

        while(index>=1 &&  a[index]>0 &&a[index]-1>a[index-1])

        {

          swap(a[index],a[index-1]);

          a[index-1]--;

          if(index>1){

            index--;

          }

          else{

            break;

          }

        }

      }

      for(int i=0;i<n;i++)

      cout<<a[i];

      cout<<endl;

      

      

    }

}
Problem: 2049B - pspspsps
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int t;

    cin >> t;

    while(t--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        map<char,int> mp;

        for(auto& x : s)

        {

            mp[x]++;

        }

        if(mp['.']==n) cout << "yes\n";

        else if(mp['s']==n) cout << "yes\n";

        else if(mp['p']==n) cout << "yes\n";

        else if(mp['.']+mp['s']==n||mp['.']+mp['p']==n) cout << "yes\n";

        else

        {

            int xp = -1,xs = -1;

            for(int i=0;i<n;i++)

            {

                if(s[i]=='p')

                {

                    xp = i;

                    break;

                }

            }

            for(int i=n-1;i>=0;i--)

            {

                if(s[i]=='s')

                {

                    xs = i;

                    break;

                }

            }

            if(xp<xs) cout << "no\n";

            else

            {

                if(mp['s']==1&&mp['p']==1)

                {

                    if(s[0]=='.'&&s[n-1]=='.') cout << "no\n";

                    else cout << "yes\n";

                }

                else if(mp['s']>1&&mp['p']>1) cout << "no\n";

                else

                {

                    if(mp['s']>1)

                    {

                        if(s[n-1]=='.') cout << "no\n";

                        else cout << "yes\n";

                    }

                    else

                    {

                        if(s[0]=='.') cout << "no\n";

                        else cout << "yes\n";

                    }

                }

            }

        }

    }

    return 0;

}

Solution 2 (runtime: 62 ms):
#include <iostream>

#include <vector>

#include <algorithm>

#include <set>

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        

        string ss;

        cin >> ss;

        if(n == 1){

            cout<<"YES"<<endl;

            continue;

        }

        int p = -1, s = -1;

        for (int i = 0; i < n; i++) {

            if (ss[i] == 'p' && p == -1) p = i;

            if (ss[i] == 's') s = i;

        }

        

        if (s != -1 && p != -1 && p < s) {

            cout << "NO" << endl;

            continue;

        }



        set<char> cnt;

        for (int i = 1;i< n-1;i++ ) {

            if (ss[i] != '.') cnt.insert(ss[i]);

        }



        if (cnt.size() > 1) {

            cout << "NO" << endl;

            continue;

        }



        if (cnt.size() == 0) {

            cout << "YES" << endl;

            continue;

        }



        // char bet = *cnt.begin();

        // bool ans = (ss[0] == ss[n - 1] && ss[n - 1] == bet) || (ss[0] == 's' && ss[n - 1] == 'p');

         cout << "YES" << endl;



    }

    

    return 0;

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

Solution 1 (runtime: 109 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string a,b,c;
vector<vector<int>> dp;
int fnc(int i, int j)
{
  if(i>=a.length() && j >= b.length())
  {
    return 0;
  }
  if(dp[i][j] != -1)
  {
    return dp[i][j];
  }
  int x1 = 1e9;
  int x2 = 1e9;
  if(i < a.length())
  {
  x1 = fnc(i+1,j) + (a[i] != c[i+j]);
  }
  if(j < b.length())
  {
  x2 = fnc(i,j+1) + (b[j] != c[i+j]);
  }
  return dp[i][j] =  min(x1,x2);
}
void solve()
{
  cin >> a >> b >> c;
vector<vector<int>> ddp(a.length()+1,vector<int> (b.length()+1,-1));
dp = ddp;
  cout << fnc(0,0) << endl;
}
int32_t main(){
    int tt;
   cin >> tt;
   while(tt>0){
   solve();
   --tt;
   }


  //solve();
}

Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
void test_case()
{
    string a,b,c;
    cin >> a >> b >> c;
    int n = (int)a.size(), m = (int)b.size();
    int dp[n + 1][m + 1];
    fill(&dp[0][0], &dp[0][0] + (n + 1) * (m + 1), inf);
    dp[0][0] = 0;

    for(int i = 0;i < n;i++)
        dp[i+1][0] = dp[i][0] + (a[i] != c[i]);

    for(int i = 0;i < m;i++)
        dp[0][i+1] = dp[0][i] + (b[i] != c[i]);

    for(int i = 1;i<=n;i++)
    {
        for(int j = 1;j<=m;j++)
        {
            dp[i][j] = min(dp[i-1][j] + (a[i-1] != c[i+j-1]),dp[i][j-1] + (b[j-1] != c[i+j-1]));
        }
    }
    cout << dp[n][m] << "\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        test_case();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

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

int solve(string &a,string &b,string &c, int i, int j, int k, vector<vector<int>>& dp) {
    //forgot to pass by reference
    if(k>=c.length()){return 0;}
    if(dp[i][j]!=-1){return dp[i][j];}
    int ans = INT_MAX;

    if (i < a.length()) {
        ans = min(ans, solve(a, b, c, i + 1, j, k + 1, dp) +!(a[i] == c[k]));
    }
    if (j < b.length()) {
        ans = min(ans,solve(a, b, c, i, j + 1, k + 1, dp) + !(b[j] == c[k]));
    }
    return dp[i][j]= ans;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        vector<vector<int>> dp(c.length()+1, vector<int>(c.length()+1, -1));
        cout << solve(a, b, c, 0, 0, 0, dp) << endl;
    }
    return 0;
}

Solution 2 (runtime: 78 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int rec(vector<char>& a,vector<char>& b,vector<char>&  c,int i,int j,int n1,int n2,vector<vector<int>> &dp){
   if(dp[i][j]!=-1)
       return dp[i][j];
    if(i==n1 && j==n2){
        return dp[i][j]=0;
    }
    if(i==n1){
        if(b[j]==c[i+j]){
            return dp[i][j]=rec(a,b,c,i,j+1,n1,n2,dp);
        }
        else 
        return dp[i][j]=1+rec(a,b,c,i,j+1,n1,n2,dp);
    }
    if(j==n2){
        if(a[i]==c[i+j]){
            return dp[i][j]=rec(a,b,c,i+1,j,n1,n2,dp);
        }
        else 
        return dp[i][j]=1+rec(a,b,c,i+1,j,n1,n2,dp);
    }
    if(a[i]==c[i+j] && b[j]==c[i+j]){
        return dp[i][j]=min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else if(a[i]==c[i+j]){
        return dp[i][j]=min(1+rec(a,b,c,i,j+1,n1,n2,dp),rec(a,b,c,i+1,j,n1,n2,dp));
    }
    else if(b[j]==c[i+j]){
        return dp[i][j]=min(1+rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else{
        return dp[i][j]=1+min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n1=a.size(),n2=b.size();
    vector<char>a1(n1),b1(n2),c1(n1+n2);
    for(int i=0;i<n1;i++){
        a1[i]=a[i];
    }
    for(int i=0;i<n2;i++){
        b1[i]=b[i];
    }
    for(int i=0;i<n1+n2;i++){
        c1[i]=c[i];
    }
    vector<vector<int>> dp(n1+1,vector<int>(n2+1,-1));
    cout<<rec(a1,b1,c1,0,0,n1,n2,dp)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}