#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;
}