#include <bits/stdc++.h>
using namespace std;
int p = -1;
bool isSubsequence(const string& A, const string& B) {
int n = A.size();
int m = B.size();
int i = 0, j = 0, count = 0;
while (i < m && j < n) {
if (A[j] == B[i]) {
if(count==0){
p = j;
}
i++;
j++;
count++;
} else {
j++;
}
}
return count == m;
}
int main() {
int t;
cin>>t;
while(t--){
string a,b;
cin>>a;
cin>>b;
int answer = -1;
for(int i=1;i<b.size();i++){
for(char c='a';c<='z';c++){
string r = b ;
r[i] = c;
p = -1;
if (isSubsequence(a, r)) {//p!=-1
answer = p+1;
}
}
}
cout<<answer;
cout<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBwID0gLTE7CmJvb2wgaXNTdWJzZXF1ZW5jZShjb25zdCBzdHJpbmcmIEEsIGNvbnN0IHN0cmluZyYgQikgewogICAgaW50IG4gPSBBLnNpemUoKTsKICAgIGludCBtID0gQi5zaXplKCk7CiAgICBpbnQgaSA9IDAsIGogPSAwLCBjb3VudCA9IDA7CiAgICAKICAgIHdoaWxlIChpIDwgbSAmJiBqIDwgbikgewogICAgICAgIGlmIChBW2pdID09IEJbaV0pIHsKICAgICAgICAgICAgaWYoY291bnQ9PTApewogICAgICAgICAgICAgICAgcCA9IGo7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgICAgIGkrKzsKICAgICAgICAgICAgaisrOwogICAgICAgICAgICBjb3VudCsrOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGorKzsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHJldHVybiBjb3VudCA9PSBtOwp9CgppbnQgbWFpbigpIHsKICAgIAogICAgaW50IHQ7CiAgICBjaW4+PnQ7CiAgICB3aGlsZSh0LS0pewogICAgc3RyaW5nIGEsYjsKICAgIGNpbj4+YTsKICAgIGNpbj4+YjsKICAgIGludCBhbnN3ZXIgPSAtMTsKICAgIGZvcihpbnQgaT0xO2k8Yi5zaXplKCk7aSsrKXsKICAgICAgICAKICAgICAgICBmb3IoY2hhciBjPSdhJztjPD0neic7YysrKXsKICAgICAgICAgICAgc3RyaW5nIHIgPSBiIDsKICAgICAgICAgICAgcltpXSA9IGM7IAogICAgIHAgPSAtMTsKICAgICBpZiAoaXNTdWJzZXF1ZW5jZShhLCByKSkgey8vcCE9LTEKICAgICAgICAgYW5zd2VyID0gcCsxOwogICAgIH0gCiAgICB9CiAgICAKICAgIH0KICAgIGNvdXQ8PGFuc3dlcjsKICAgIGNvdXQ8PCJcbiI7CiAgICAKICAgIH0KICAgIHJldHVybiAwOwp9