#include <bits/stdc++.h>
using namespace std;
#define Samurai ios_base::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL);
string a,b,c; vector<vector<int>>dp;
int rec(int i=0, int j=0){
if(i==a.size() && j==b.size()) return 0;
int &ret = dp[i][j];
if(~ret) return ret;
ret = INT_MAX;
if(i<a.size()){
if(a[i] == c[i+j]) ret = rec(i+1,j);
else ret = 1 + rec(i+1,j);
}
if(j<b.size()){
if(b[j] == c[i+j]) ret = min(ret, rec(i,j+1));
else ret = min(ret, 1 + rec(i,j+1));
}
return ret;
}
int main(){ Samurai
int _t = 1;
cin >> _t;
for (int i = 1; i <= _t; i++){
cin >> a >> b >> c;
dp = vector<vector<int>>(a.size()+5,vector<int>(b.size()+5,-1));
cout << rec() << '\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgU2FtdXJhaSBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSwgY291dC50aWUoTlVMTCksIGNpbi50aWUoTlVMTCk7CnN0cmluZyBhLGIsYzsgdmVjdG9yPHZlY3RvcjxpbnQ+PmRwOwppbnQgcmVjKGludCBpPTAsIGludCBqPTApewogICAgaWYoaT09YS5zaXplKCkgJiYgaj09Yi5zaXplKCkpIHJldHVybiAwOwogICAgaW50ICZyZXQgPSBkcFtpXVtqXTsKICAgIGlmKH5yZXQpIHJldHVybiByZXQ7CiAgICByZXQgPSBJTlRfTUFYOwogICAgaWYoaTxhLnNpemUoKSl7CiAgICAgICAgaWYoYVtpXSA9PSBjW2kral0pIHJldCA9IHJlYyhpKzEsaik7CiAgICAgICAgZWxzZSByZXQgPSAxICsgcmVjKGkrMSxqKTsKICAgIH0KICAgIGlmKGo8Yi5zaXplKCkpewogICAgICAgIGlmKGJbal0gPT0gY1tpK2pdKSByZXQgPSBtaW4ocmV0LCByZWMoaSxqKzEpKTsKICAgICAgICBlbHNlIHJldCA9IG1pbihyZXQsIDEgKyByZWMoaSxqKzEpKTsKICAgIH0KICAgIHJldHVybiByZXQ7Cn0KaW50IG1haW4oKXsgU2FtdXJhaQogICAgaW50IF90ID0gMTsKICAgIGNpbiA+PiBfdDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IF90OyBpKyspewogICAgICAgIGNpbiA+PiBhID4+IGIgPj4gYzsKICAgICAgICBkcCA9IHZlY3Rvcjx2ZWN0b3I8aW50Pj4oYS5zaXplKCkrNSx2ZWN0b3I8aW50PihiLnNpemUoKSs1LC0xKSk7CiAgICAgICAgY291dCA8PCByZWMoKSA8PCAnXG4nOwogICAgfQogICAgcmV0dXJuIDA7Cn0KCg==