#include<iostream>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int t;unsigned int m,n;
int **edit=new int*[2001]; bool flag;
for(unsigned int k=0;k<2001;k++){edit[k]=new int[2001];}
string::iterator i,j;
scanf("%d",&t);getchar();
while(t--)//test cases
{
string *a=new string;
string *b=new string;
getline(cin,*a);m=(*a).length()+1;//cout<<m;
getline(cin,*b);n=(*b).length()+1;//cout<<n;
for(unsigned int x=0;x<m;x++)
{
for(unsigned int y=0;y<n;y++)
{
if(x==0&&y==0){edit[x][y]=0;}
else if(x==0){edit[x][y]=edit[x][y-1]+1;}//insert operation
else if(y==0){edit[x][y]=edit[x-1][y]+1;}//delete operation
else
{ i=(*a).begin()+x-1;j=(*b).begin()+y-1;
if(*i==*j){ flag=0;}
else {flag=1;}
edit[x][y]=min(min(edit[x-1][y-1]+flag,edit[x-1][y]+1),edit[x][y-1]+1);
}
}
}
printf("%d\n",edit[m-1][n-1]);
delete a;
delete b;
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0cmluZz4KI2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpCnsKICAgIGludCB0O3Vuc2lnbmVkIGludCBtLG47CiAgICBpbnQgKiplZGl0PW5ldyBpbnQqWzIwMDFdOyBib29sIGZsYWc7CiAgICBmb3IodW5zaWduZWQgaW50IGs9MDtrPDIwMDE7aysrKXtlZGl0W2tdPW5ldyBpbnRbMjAwMV07fQoKICAgIHN0cmluZzo6aXRlcmF0b3IgaSxqOwogICAgc2NhbmYoIiVkIiwmdCk7Z2V0Y2hhcigpOwogICAgd2hpbGUodC0tKS8vdGVzdCBjYXNlcwogICAgewogICAgICAgIHN0cmluZyAqYT1uZXcgc3RyaW5nOwogICAgICAgIHN0cmluZyAqYj1uZXcgc3RyaW5nOwogICAgICAgIGdldGxpbmUoY2luLCphKTttPSgqYSkubGVuZ3RoKCkrMTsvL2NvdXQ8PG07CiAgICAgICAgZ2V0bGluZShjaW4sKmIpO249KCpiKS5sZW5ndGgoKSsxOy8vY291dDw8bjsKCiAgICAgICAgZm9yKHVuc2lnbmVkIGludCB4PTA7eDxtO3grKykKICAgICAgICB7CiAgICAgICAgICAgIGZvcih1bnNpZ25lZCBpbnQgeT0wO3k8bjt5KyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKHg9PTAmJnk9PTApe2VkaXRbeF1beV09MDt9CiAgICAgICAgICAgICAgICBlbHNlIGlmKHg9PTApe2VkaXRbeF1beV09ZWRpdFt4XVt5LTFdKzE7fS8vaW5zZXJ0IG9wZXJhdGlvbgogICAgICAgICAgICAgICAgZWxzZSBpZih5PT0wKXtlZGl0W3hdW3ldPWVkaXRbeC0xXVt5XSsxO30vL2RlbGV0ZSBvcGVyYXRpb24KICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHsgICBpPSgqYSkuYmVnaW4oKSt4LTE7aj0oKmIpLmJlZ2luKCkreS0xOwogICAgICAgICAgICAgICAgICAgIGlmKCppPT0qail7IGZsYWc9MDt9CiAgICAgICAgICAgICAgICAgICAgZWxzZSB7ZmxhZz0xO30KICAgICAgICAgICAgICAgICAgICAgICAgZWRpdFt4XVt5XT1taW4obWluKGVkaXRbeC0xXVt5LTFdK2ZsYWcsZWRpdFt4LTFdW3ldKzEpLGVkaXRbeF1beS0xXSsxKTsKICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KCnByaW50ZigiJWRcbiIsZWRpdFttLTFdW24tMV0pOwpkZWxldGUgYTsKZGVsZXRlIGI7Cn0KICAgIHJldHVybiAwOwp9Cgo=