#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#include<string>
int p=-1;
int findOccurence(const string& a,const string& b)
{
int n=a.size();
int m=b.size();
int count=0;
int i=0,j=0;
while(i<n && j<m)
{
if(a[i]==b[j])
{
if(count==0)
{
p=i;
}
count++;
i++;
j++;
}
else
{
i++;
}
}
return count==m;
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
string a,b;
cin>>a;
cin>>b;
int n=a.size();
int m=b.size();
int answer=-1;
for(int i=1;i<m;i++)
{
for(char c='a';c<='z';c++)
{
string r=b;
r[i]=c;
//p=-1;
if(findOccurence(a,r))
{
answer=p+1;
}
}
}
cout<<answer<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8c3RyaW5nPgppbnQgcD0tMTsKaW50IGZpbmRPY2N1cmVuY2UoY29uc3Qgc3RyaW5nJiBhLGNvbnN0IHN0cmluZyYgYikKIHsKCWludCBuPWEuc2l6ZSgpOwoJaW50IG09Yi5zaXplKCk7CglpbnQgY291bnQ9MDsKCWludCBpPTAsaj0wOwoJCgkgIHdoaWxlKGk8biAmJiBqPG0pCgkgICB7CgkgICAJIGlmKGFbaV09PWJbal0pCgkgICAJICB7CgkgICAJICAJaWYoY291bnQ9PTApCgkgICAJICAJIHsKCSAgIAkgIAkgCXA9aTsKCSAgIAkgIAkgfQoJICAgCSAgCQoJICAgCSAgCWNvdW50Kys7CgkgICAJICAJaSsrOwoJICAgCSAgCWorKzsKCSAgIAkgIH0KCSAgIAkgIGVsc2UKCSAgIAkgICB7CgkgICAJICAgCWkrKzsKCSAgIAkgICB9CgkgICB9CgkgICAKCSAKCSAgcmV0dXJuIGNvdW50PT1tOwogfQoKCmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJaW50IHQ7CgljaW4+PnQ7Cgl3aGlsZSh0LS0pCg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