ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <climits>

using namespace std;

#define pb push_back
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define LOG(n) 31 - __builtin_clz(n)
#define nl  "\n"
#define ok  cout<<"OK\n"
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define free freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define ff first
#define ss second
#define vi vector<int>
#define vvi vector<vector<int> >
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef pair<int,int> pii;
typedef long double ld;
const long long INF = 1ll << 32;
const long long MAX_N = 1e12 + 5;
const long long MOD = 1e9 + 7;
const long long N = 9999999;
long double pi = 3.1415926535;

void show(vector<int> a) {for(auto it : a) cout<<it<<","; cout<<nl;}
int gcd(int a, int b){if(a == 0) return b; if(b == 0) return a;int r = min(a, b);while(r>0){if(a%r==0 && b%r==0){break;}r--;}return r;}

int sq(int n){if(n==0)return 0LL;int l=1,r=n;while(l<=r){int m=l+(r-l)/2;int p=m*m;if(p==n)return m;if(p<n)l=m+1;else r=m-1;}return l;}
int I;

void solve() {
    int n;
    cin>>n;
    
    vector<vector<int> > adj(n + 1);
    vector<int> deg(n + 1, 0);
    int element = -1, mxDegree = 0;
    for (int i = 0 ; i < n - 1 ; i++) {
        int u, v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        deg[u]++;
        deg[v]++;
    }
    
    multiset<int> maxDegree;
    for (int i = 1 ; i <= n ; i++) {
        maxDegree.insert(deg[i]);
        if (mxDegree < deg[i]) {
            mxDegree = deg[i];
            element = i;
        }
    }
    
    maxDegree.erase(--maxDegree.end());
    
    for (int node : adj[element]) {
        maxDegree.erase(maxDegree.find(deg[node]));
        maxDegree.insert(deg[node] - 1);
    }
    
    cout<<mxDegree + *maxDegree.rbegin() - 1<<endl;
    
}

int32_t main(){
    ios;
//    freopen("visitfj.in","r",stdin);
//    freopen("visitfj.out","w",stdout);
    int Test = 1;
    cin>>Test;
    for(I = 1 ; I <= Test ; I++)
    {
        solve();
    }
 
 
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

#define Fast_IO                       \

    ios_base::sync_with_stdio(false); \

    cin.tie(NULL);                    \

    cout.tie(NULL);

#define int long long int

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)



/* ***********  My code start here *********** */



int32_t main()

{

    Fast_IO



#ifndef ONLINE_JUDGE

        freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

    clock_t danger_close = clock();



    int t;

    cin >> t;

    while (t--)

    {

        string a = "", b = "", c = "";

        cin >> a >> b >> c;

        c = " " + c;

        a = " " + a;

        b = " " + b;

        int x = a.size(), y = b.size();

        int dp[x+2][y+2];

        for(int i = 0; i <= x+1; i++)

            for(int j = 0; j <= y+1; j++)

                dp[i][j] = 0;

        for(int i = 1; i <= x; i++)

        {

            if(a[i] == c[i])

                dp[i][0] = dp[i-1][0];

            else

                dp[i][0] = dp[i-1][0] + 1;

        }

        for(int i = 1; i <= y; i++)

        {

            if(b[i] == c[i])

                dp[0][i] = dp[0][i-1];

            else

                dp[0][i] = dp[0][i-1] + 1;

        }

        for(int i = 1; i <= x; i++)

        {

            for(int j = 1; j <= y; j++)

            {

                int m1, m2;

                if(a[i] == c[i+j])

                    m1 = dp[i-1][j];

                else

                    m1 = dp[i-1][j] + 1;

                if(b[j] == c[i+j])

                    m2 = dp[i][j-1];

                else

                    m2 = dp[i][j-1] + 1;

                dp[i][j] = min(m1, m2);

            }

        }

        cout << dp[x][y] << endl;

    }

    debug("Total Time: %.3f\n", (double)(clock() - danger_close) / CLOCKS_PER_SEC);

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

#define int long long

#define loop(i, n, x) for (int i = 0; i < n; i += x)



int mex(vector<int> arr)

{

    int N = arr.size();

    sort(arr.begin(), arr.end());

    int mex = 0;

    for (int idx = 0; idx < N; idx++)

    {

        if (arr[idx] == mex)

        {

            mex += 1;

        }

    }

    return mex;

}

void solve()

{

    int n, x, y;

    cin >> n >> x >> y;

    int secondOccur = max(x, y) - 1;

    int firstOccur = min(x, y) - 1;

    vector<int> ans(n, -1);

    loop(i, n - 1, 1)

    {

        if (i == 0)

        {

            ans[i] = 0;

            continue;

        }

        if (i == secondOccur && i - 1 != firstOccur)

        {

            ans[i] = mex({ans[i - 1], ans[firstOccur]});

            continue;

        }

        if (ans[i - 1] == 0)

        {

            ans[i] = 1;

        }

        else if (ans[i - 1] == 2)

        {

            ans[i] = mex({ans[i - 1], ans[i - 2]});

        }

        else if (ans[i - 1] == 1)

        {

            ans[i] = 0;

        }

    }

    if (secondOccur == n - 1)

    {

        ans[n - 1] = mex({ans[0], ans[firstOccur], ans[n - 2]});

    }

    else

    {

        ans[n - 1] = mex({ans[0], ans[n - 2]});

    }

    loop(i, n, 1)

    {

        cout << ans[i] << " ";

    }

    cout << endl;

}



int32_t main()

{

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);



    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}



Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

#define int long long

#define loop(i, n, x) for (int i = 0; i < n; i += x)



void solve()

{

    int n, x, y;

    cin >> n >> x >> y;

    x--;

    y--;

    vector<int> ans(n);

    loop(i, n, 1)

    {

        ans[(x + i) % n] = i % 2;

    }

    if (n & 1 || !(y - x) & 1)

    {

        ans[x] = 2;

    }

    loop(i, n, 1)

    {

        cout << ans[i] << " ";

    }

    cout << endl;

}



int32_t main()

{

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);



    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

#define int long long

#define loop(i, n, x) for (int i = 0; i < n; i += x)



int mex(vector<int> arr)

{

    int N = arr.size();

    sort(arr.begin(), arr.end());

    int mex = 0;

    for (int idx = 0; idx < N; idx++)

    {

        if (arr[idx] == mex)

        {

            mex += 1;

        }

    }

    return mex;

}

void solve()

{

    int n, x, y;

    cin >> n >> x >> y;

    int secondOccur = max(x, y)-1;

    int firstOccur = min(x, y)-1;

    vector<int> ans(n, -1);

    loop(i, n - 1, 1)

    {

        if (i == 0)

        {

            ans[i] = 0;

            continue;

        }

        if (i == secondOccur)

        {

            ans[i] = mex({ans[i - 1], ans[firstOccur]});

            continue;

        }

        if (ans[i - 1] == 0 || ans[i - 1] == 2)

        {

            ans[i] = 1;

        }

        else if (ans[i - 1] == 1)

        {

            ans[i] = 0;

        }

    }

    if (secondOccur == n - 1)

    {

        ans[n - 1] = mex({ans[0], ans[firstOccur], ans[n - 2]});

    }

    else

    {

        ans[n - 1] = mex({ans[0], ans[n - 2]});

    }

    loop(i, n, 1)

    {

        cout << ans[i] << " ";

    }

    cout << endl;

}



int32_t main()

{

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);



    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

#define int long long

#define loop(i, n, x) for (int i = 0; i < n; i += x)



void solve()

{

    int n, x, y;

    cin >> n >> x >> y;

    x--;

    y--;

    vector<int> ans(n);

    loop(i, n, 1)

    {

        ans[(x + i) % n] = i % 2;

    }

    if (n & 1 || !(y - x) & 1)

    {

        ans[x] = 2;

    }

    loop(i, n, 1)

    {

        cout << ans[i] << " ";

    }

    cout << endl;

}



int32_t main()

{

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);



    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

#define int long long

#define loop(i, n, x) for (int i = 0; i < n; i += x)



void solve()

{

    int n, x, y;

    cin >> n >> x >> y;

    x--;

    y--;

    vector<int> ans(n);

    loop(i, n, 1)

    {

        ans[(x + i) % n] = i % 2;

    }

    if (n & 1 || !((y - x) & 1))

    {

        ans[x] = 2;

    }

    loop(i, n, 1)

    {

        cout << ans[i] << " ";

    }

    cout << endl;

}



int32_t main()

{

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);



    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t; 

    cin >> t;

    while(t--){

        string s; cin>>s;

        int n = s.length();

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

            for(int j=n-1; j>=1; j--) {

                if((s[j]!='0') && (s[j]-'0'-1 > s[j-1]-'0')) {

                    s[j] = s[j]-1;

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

                }

            }

        }

        cout<<s<<endl;

    }

    

    return 0;

}



Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t; 

    cin >> t;

    while(t--){

        string s; cin>>s;

        int n = s.length();

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

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

                if((s[j]!='0') && (s[j]-'0'-1 > s[j-1]-'0')) {

                    s[j] = s[j]-1;

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

                }

            }

        }

        cout<<s<<endl;

    }

    

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t; 

    cin >> t;

    while(t--){

        string s; cin>>s;

        int n = s.length();

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

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

                if((s[i]!='0') && (s[i]-'0'-1 > s[i-1]-'0')) {

                    s[i] = s[i]-1;

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

                }

            }

        }

        cout<<s<<endl;

    }

    

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t; 

    cin >> t;

    while(t--){

        string s; cin>>s;

        int n = s.length();

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

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

                if((s[i]!='0') && (s[i]-'0'-1 > s[i-1]-'0')) {

                    s[i] = s[i]-1;

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

                }

            }

        }

        cout<<s<<endl;

    }

    

    return 0;

}



Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t; 

    cin >> t;

    while(t--){

        string s; cin>>s;

        int n = s.length();

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

            for(int j=n-1; j>=1; j--) {

                if((s[j]!='0') && (s[j]-'0'-1 > s[j-1]-'0')) {

                    s[j] = s[j]-1;

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

                }

            }

        }

        cout<<s<<endl;

    }

    

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t; 

    cin >> t;

    while(t--){

        string s; cin>>s;

        int n = s.length();

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

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

                if((s[j]!='0') && (s[j]-'0'-1 > s[j-1]-'0')) {

                    s[j] = s[j]-1;

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

                }

            }

        }

        cout<<s<<endl;

    }

    

    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t; 

    cin >> t;

    while(t--){

        string s; cin>>s;

        int n = s.length();

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

            int j = i-1, curr = i;

            while(j>=0 && s[curr]>'0' && s[curr]>s[j]+1) {

                s[curr]--;

                swap(s[curr], s[j]);

                curr--;

                j = curr-1;

            }

        }

        cout<<s<<endl;

    }

    

    return 0;

}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#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;

#define ll long long 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // *A.find_by_order(X), A.order_of_key(X)

string a,b,c;
ll n,m;
ll dp[1001][1001];

ll rec(ll level1,ll level2){
    if(level1==n && level2==m) return 0;
    if(dp[level1][level2]!=-1) return dp[level1][level2];

    ll ans = INT_MAX;

if (level1 < n && c[level1 + level2] == a[level1]) {
    ans = min(ans, rec(level1 + 1, level2));
}

if (level2 < m && c[level1 + level2] == b[level2]) {
    ans = min(ans, rec(level1, level2 + 1));
}
    ans=min(ans,1+min(rec(level1+1,level2),rec(level1,level2+1)));
    return dp[level1][level2]=ans;
}

void solve() {

cin>>a>>b>>c;
n=a.size();
m=b.size();
memset(dp,-1,sizeof(dp));
cout<<rec(0,0)<<endl;





}



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#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;

#define ll long long 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // *A.find_by_order(X), A.order_of_key(X)

string a,b,c;
ll n,m;
ll dp[1010][1010];

ll rec(ll level1,ll level2){
    if(level1==n && level2==m) return 0;
    if(level1+level1>=n+m) return 0;
    if(dp[level1][level2]!=-1) return dp[level1][level2];

    ll ans = INT_MAX;

if (level1 < n && c[level1 + level2] == a[level1]) {
    ans = min(ans, rec(level1 + 1, level2));
}

if (level2 < m && c[level1 + level2] == b[level2]) {
    ans = min(ans, rec(level1, level2 + 1));
}
    ans=min(ans,1+min(rec(level1+1,level2),rec(level1,level2+1)));
    return dp[level1][level2]=ans;
}

void solve() {

cin>>a>>b>>c;
n=a.size();
m=b.size();
for(int i=0;i<1010;i++){
    for(int j=0;j<1010;j++){
        dp[i][j]=-1;
    }
}
cout<<rec(0,0)<<endl;





}



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#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;

#define ll long long 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // *A.find_by_order(X), A.order_of_key(X)

string a,b,c;
ll n,m;
ll dp[1010][1010];

ll rec(ll level1,ll level2){
    if(level1==n && level2==m) return 0;
    if(level1+level1>=n+m) return 0;
    if(dp[level1][level2]!=-1) return dp[level1][level2];

    ll ans = INT_MAX;

if (level1 < n && c[level1 + level2] == a[level1]) {
    ans = min(ans, rec(level1 + 1, level2));
}

if (level2 < m && c[level1 + level2] == b[level2]) {
    ans = min(ans, rec(level1, level2 + 1));
}
    ans=min(ans,1+min(rec(level1+1,level2),rec(level1,level2+1)));
    return dp[level1][level2]=ans;
}

void solve() {

cin>>a>>b>>c;
n=a.size();
m=b.size();
for(int i=0;i<1010;i++){
    for(int j=0;j<1010;j++){
        dp[i][j]=-1;
    }
}
cout<<rec(0,0)<<endl;





}



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#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;

#define ll long long 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // *A.find_by_order(X), A.order_of_key(X)

string a,b,c;
ll n,m;
ll dp[1010][1010];

ll rec(ll level1,ll level2){
    if(level1==n && level2==m) return 0;
    if(level1+level2>=n+m) return 0;
    if(dp[level1][level2]!=-1) return dp[level1][level2];

    ll ans = INT_MAX;

if (level1 < n && c[level1 + level2] == a[level1]) {
    ans = min(ans, rec(level1 + 1, level2));
}

if (level2 < m && c[level1 + level2] == b[level2]) {
    ans = min(ans, rec(level1, level2 + 1));
}
    ans=min(ans,1+min(rec(level1+1,level2),rec(level1,level2+1)));
    return dp[level1][level2]=ans;
}

void solve() {

cin>>a>>b>>c;
n=a.size();
m=b.size();
for(int i=0;i<1010;i++){
    for(int j=0;j<1010;j++){
        dp[i][j]=-1;
    }
}
cout<<rec(0,0)<<endl;





}



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#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;

#define ll long long 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // *A.find_by_order(X), A.order_of_key(X)

string a,b,c;
ll n,m;
ll dp[1010][1010];

ll rec(ll level1,ll level2){
    if(level1==n && level2==m) return 0;
    if(level1+level2>=n+m) return 0;
    if(dp[level1][level2]!=-1) return dp[level1][level2];

    ll ans = INT_MAX;

if (level1 < n && c[level1 + level2] == a[level1]) {
    ans = min(ans, rec(level1 + 1, level2));
}

if (level2 < m && c[level1 + level2] == b[level2]) {
    ans = min(ans, rec(level1, level2 + 1));
}
    ans=min(ans,1+min(rec(level1+1,level2),rec(level1,level2+1)));
    return dp[level1][level2]=ans;
}

void solve() {

cin>>a>>b>>c;
n=a.size();
m=b.size();
for(int i=0;i<1010;i++){
    for(int j=0;j<1010;j++){
        dp[i][j]=-1;
    }
}
cout<<rec(0,0)<<endl;





}



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Submission (verdict: Accepted):
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#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;

#define ll long long 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // *A.find_by_order(X), A.order_of_key(X)

string a,b,c;
ll n,m;
ll dp[1010][1010];

ll rec(ll level1,ll level2){
    if(level1==n && level2==m) return 0;
  
    if(dp[level1][level2]!=-1) return dp[level1][level2];

    ll ans = INT_MAX;

if (level1 < n && c[level1 + level2] == a[level1]) {
    ans = min(ans, rec(level1 + 1, level2));
}

if (level2 < m && c[level1 + level2] == b[level2]) {
    ans = min(ans, rec(level1, level2 + 1));
}
if(level1<n) ans=min(ans,1+rec(level1+1,level2));
if(level2<m)  ans=min(ans,1+rec(level1,level2+1));
    return dp[level1][level2]=ans;
}

void solve() {

cin>>a>>b>>c;
n=a.size();
m=b.size();
for(int i=0;i<1010;i++){
    for(int j=0;j<1010;j++){
        dp[i][j]=-1;
    }
}
cout<<rec(0,0)<<endl;





}



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}