#include <bits/stdc++.h>
using namespace std;
#define int              long long int
#define double           long double
#define print(a)         for(auto x : a) cout << x << " "; cout << endl


const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;

inline int power(int a, int b, int mod=M) {
    int x = 1;
    a %= mod;
    while (b) {
        if (b & 1) x = (x * a) % mod; 
        a = (a * a) % mod;
        b >>= 1;
    }
    return x;
}


//_ ***************************** START Below *******************************




string a;
string b;

//* finding  whether b is present in a as subseq or not

bool isSubseq(string a, string b, int i, int j){
	int n = a.size();
	int m = b.size();
	
	while(i<n && j<m){
		while(i<n && a[i] != b[j]) i++;
		if(i==n) break;
		
		i++;
		j++;
	}
	
	return j==m;
}





int consistency(int n, int m){
		
	int k = 0;
	
	while(k<n && a[k] != b[0]) k++;
	if(k==n) return -1;
	
	for(int i=1; i<m; i++){
		for(char ch = 'a'; ch<='z'; ch++){
			string c = b;
			c[i] = ch;
			if(isSubseq(a, c, k+1, 1)) return k+1;
		}
	}
		
	return -1;
}















void solve() {
    
	cin >> a >> b;
	int n = a.size();
	int m = b.size();
    
    cout << consistency(n, m) << endl;


}





int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}