Problem: 2050E - Three Strings
Language: python

Solution 1 (runtime: 217 ms):
from __future__ import division, print_function
import heapq
import os,collections,math,random,heapq,bisect
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(10**5)
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
from collections import Counter as cnt
from bisect import bisect_left as fl
from bisect import bisect as fr
def inp():
    return int(input())
def ints():
    return list(map(int,input().split()))
def yes():
    o.append("YES")
def no():
    o.append("NO")
def go(x):
    return o.append(x)
def out():
    print(*o,sep = '\n')
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a



mod=10**9+7
#powers2 = [pow(2,i,mod) for i in range(100000)]


def main():
    a = input()
    b = input()
    c = input()
    n,m = len(a),len(b)
    dp = []
    for i in range(n+1):
        dp.append([-1]*(m+1))
    dp[0][0] = 0
    for i in range(n+1):
        for j in range(m+1):
            if i < n:
                dp[i+1][j] = max(dp[i+1][j],dp[i][j] + (a[i] == c[i+j]))
            if j < m:
                dp[i][j+1] = max(dp[i][j+1],dp[i][j] + (b[j] == c[i+j]))
    
    x = dp[n][m]
    print(n+m-x)
  
    

    



BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    o = []
    
    for i in range(inp()):
        #print(i,"###########")
        main()
    out()
    








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

using namespace std;

 

#define ll long long

#define ull unsigned long long 

#define int long long int

 

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

#define no cout << "NO\n"

#define yes cout << "YES\n"

#define mod 1000000007

#define endd cout << "\n"

#define endl "\n"

#define came cout<<"came\n";

 

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x <<" "; __print(x); cerr << endl;

#define start_T auto start = std::chrono::high_resolution_clock::now();

#define end_T auto end = std::chrono::high_resolution_clock::now(); \

chrono::duration<double> duration = end - start; \

cout << "Time taken: "<<duration.count()<<" seconds"<<endl;

#else 

#define debug(x)

#define start_T

#define end_T

#endif

//----------------------------------------------------------------------------------------------  

template<class T>

void __print(T t){cerr<<t<<" ";}

template<class T>

void in(T a[],int n){for(int i=0;i<n;i++) cin>>a[i];}

template<class T> 

void out(T a[], int x){for(int i = 0; i < x; i++){cout << a[i] << " "; } cout << endl;}

template<class T> 

void in(vector<T>& a, int n){for(int i = 0; i < n; i++){ T x; cin >> x; a.push_back(x);}}

template<class T>

void in(vector<vector<T>>& a,int n,int m){vector<T> tp;for(int i=0;i<n;i++){tp.clear();in(tp,m);a.push_back(tp);}}

template<class T>

void out(vector<T> a){for(auto i : a)cout << i << " ";cout << endl;}

struct pair_hash{

template <class T1, class T2>

std::size_t operator()(const pair<T1, T2>& pair) const {return std::hash<T1>()(pair.first) ^ (std::hash<T2>()(pair.second) << 1);}};

class DSU{

 public:

    vector<int> parent,rank,size;

    DSU(int n){

         // rank.resize(n+1,0);

         parent.resize(n+1);

         size.resize(n+1,1);

         iota(parent.begin(),parent.end(),0);

    }

    //finding ultimate parent()

    int fup(int node){

         if(node == parent[node]) return node;

         // path compression

         return parent[node] = fup(parent[node]);

    }

    // union by rank()

    void joinr(int u,int v){

         int p1 = fup(u), p2 = fup(v);

         if(p1==p2) return;

         else if(rank[p1]>rank[p2]){

             parent[p2]=p1;

         }

         else if(rank[p2]>rank[p1]){

             parent[p1]=p2;

         }

         else{

            parent[p1]=p2;

            //we ar attaching component p1 to p2

            rank[p2]++;

         }

    }

    // union by size()

    void joins(int u,int v){

        int p1 = fup(u);

        int p2 = fup(v);

        if(p1==p2) return;

        else if(size[p1]>size[p2]) size[p1]+=size[p2],parent[p2]=p1;

        else size[p2]+=size[p1],parent[p1]=p2;

}};

class SEG{

 public:

    vector<int> seg;

    vector<int> arr;

    vector<int> lazy;

    SEG(int n){

       this->seg = vector<int>(n*4+1,0);

       this->lazy = vector<int>(n*4+1,0);

       this->arr.clear();

    }

    void build(){

        if(this->arr.size()==0) return;

       this->build(0,0,this->arr.size()-1);

    }

    int query(int l,int r){

         return this->query(0,0,arr.size()-1,l,r);

    }

    // Builds a Seg Tree

    int build(int ind,int lo,int hi){

         if(lo==hi){

             return this->seg[ind] = this->arr[lo];

         }

         int mid = (lo+hi)/2;

         return this->seg[ind] = __gcd(build(2*ind+1,lo,mid),build(2*ind+2,mid+1,hi));

    }

    int query(int ind,int lo,int hi,int l,int r){

         //complete lying

         // l --- low -- high --- r

         if(lo>=l && hi<=r) return this->seg[ind];

         //Not overlap

         // lo -- hi -- l -- r [or] l -- r -- lo -- hi

         if(hi<l || lo>r) return 0;

         //Semi Overlap

         int mid = (lo+hi)/2;

         return __gcd(query(ind*2+1,lo,mid,l,r),query(ind*2+2,mid+1,hi,l,r));

    }

    // Updates the I'th ind value 

    void update(int segind,int lo,int hi,int val,int ind){

         if(lo==hi && lo==ind){

             this->seg[segind] = val;

             return;

         }

         int mid = (lo+hi)/2;

         if(lo<=ind&&mid>=ind) update(2*segind+1,lo,mid,val,ind);

         else update(2*segind+2,mid+1,hi,val,ind);

         this->seg[segind] = max(this->seg[segind*2+1],this->seg[segind*2+2]);

    }

    //update Lazy

    void updatel(int ind,int lo,int hi,int l,int r,int val){

        // updating the pendings 

        if(this->lazy[ind]!=0){

             this->seg[ind] = (hi-lo+1)*this->lazy[ind];

             if(hi!=lo){

                this->lazy[2*ind+1]=this->lazy[2*ind+2]=this->lazy[ind];

             }

             this->lazy[ind]=0;

        }



        if(lo>r || hi<l || lo>hi) return;

        // l -- lo -- hi -- r

        if(lo>=l && hi<=r){

             this->seg[ind] += (hi-lo+1) * val;

             if(lo!=hi){

                 this->lazy[2*ind+1]+= val;

                 this->lazy[2*ind+2]+= val;

             }

        }

        

        int mid = (lo+hi)/2;

        updatel(ind*2+1,lo,mid,l,r,val);

        updatel(ind*2+2,mid+1,hi,l,r,val);

        this->seg[ind] = this->seg[ind*2+1] + this->seg[ind*2+2];

    }

    int queryl(int ind,int lo,int hi,int l,int r){

        // updating the pendings 

        if(this->lazy[ind]!=0){

             this->seg[ind] = (hi-lo+1)*this->lazy[ind];

             if(hi!=lo){

                this->lazy[2*ind+1]=this->lazy[2*ind+2]=this->lazy[ind];

             }

             this->lazy[ind]=0;

        }



        if(lo>r || hi<l || lo>hi) return 0;

        // l -- lo -- hi -- r

        if(lo>=l && hi<=r){

             return this->seg[ind];

        }

        int mid = (lo+hi)/2;

        return queryl(ind*2+1,lo,mid,l,r)+queryl(ind*2+2,mid+1,hi,l,r);

    }};

inline int fib(int n) {const double phi = (1 + sqrt(5)) / 2;const double psi = (1 - sqrt(5)) / 2;return round((pow(phi, n) - pow(psi, n)) / sqrt(5));}

inline int gcd(int A, int B){while(A>0&&B>0){if(A>B) A%=B;else B%=A;}return ((A==0)?B:A);}

inline int lcm(int A, int B) {return ((A * B) / (gcd(A, B)));}

inline bool isprime(int X) {if(X==1) return 0;if (X == 2) return true;for (int i = 2; i <= sqrt(X); i++) {if ((X % i) == 0)return false;}return true;}

// int Mod(string &a,int k){int rem=0;for(int i=0;i<a.size();i++){rem = (rem*10+(a[i]-'0'))%k;}return rem;}

class sieve{

  public:

  int n;

  vector<bool> is_prime;

  vector<int> primes;  

  sieve(int n){

     this->n=n;

     is_prime.resize(n+1,true);

     is_prime[0] = is_prime[1] = false;

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

     if(is_prime[i]){

        primes.push_back(i);

        for(int j=i*i;j<=n;j+=i)

            is_prime[j] = false;

    }

   }

  }

  bool fun(int ind){

     return is_prime[ind];

  } };

int pow(int a,int b){if(b==0) return 1;int res=pow(a,b/2);if(b%2) return ((((res*res)%mod)*a)%mod);else return ((res*res)%mod);}

int modInverse(int a,int p){int res=1,exp=p-2;while(exp){if(exp%2)res=(1LL*res*a)%p;a=(1LL*a*a)%p; exp/=2;}return res;}

//-------------------------------------------------UDF------------------------------------------------

map<tuple<int,int,int>,int> dp;

int fun(string &a,string &b,string &c,int i,int j,int k){

     if(i<0&&j<0&&k<0) return 0;

     if(i<0){

         while(j>=0&&k>=0){

            if(b[j]==c[k]) j--,k--;

            else break;

         }

         if(k<0) return 0;

         return (k+1);

     }

     if(j<0){

         while(i>=0&&k>=0){

            if(a[i]==c[k]) i--,k--;

            else break;

         }

         if(k<0) return 0;

         return (k+1);

     }

     if(dp.find({i,j,k})!=dp.end()) return dp[{i,j,k}];

     int res = INT_MAX;

     res = min({res,fun(a,b,c,i,j-1,k-1)+(b[j]!=c[k]),fun(a,b,c,i-1,j,k-1)+(a[i]!=c[k])});

     return dp[{i,j,k}] = res;

}

signed main(){  

  init;start_T;

  #ifndef ONLINE_JUDGE

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

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

  freopen("error.txt", "w", stderr);  

  #endif

  ll _=1;

  cin>>_;

  while(_--){

     string a,b,c;cin>>a>>b>>c;

     dp.clear();

     cout<<fun(a,b,c,a.size()-1,b.size()-1,c.size()-1)<<endl;

  }

  end_T;

}