#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        string ss = s + s;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, ss.size()) lets[ss[i] - 'a'].push_back(i);

        int ind = -2;
        int counter = 0;
        rep(i, 0, t.size()) {
            vector<int> cur = lets[t[i] - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }

            int tmp = *lower_bound(cur.begin(), cur.end(), ind + 1);
            if (tmp >= s.size()) {
                ind = -2;
                counter++;
                tmp -= s.size();
            }
            ind = tmp;

            // bool found = false;
            // rep(j, 0, cur.size()) {
            //     if (cur[j] > ind) {
            //         ind = cur[j];
            //         found = true;
            //         break;
            //     }
            // }
            // if (!found) {
            //     counter++;
            //     i--;
            //     ind = -1;
            // }
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


#pragma GCC optimize("unroll-loops,no-stack-protector")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        string ss = s + s;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, ss.size()) lets[ss[i] - 'a'].push_back(i);

        int ind = 0;
        int counter = 0;
        for (char c : t) {
            vector<int> cur = lets[c - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }

            int tmp = *lower_bound(cur.begin(), cur.end(), ind);
            if (tmp >= s.size()) {
                counter++;
                tmp -= s.size();
            }
            ind = tmp + 1;
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, s.size()) lets[s[i] - 'a'].push_back(i);

        int ind = -1;
        int counter = 0;
        rep(i, 0, t.size()) {
            vector<int> cur = lets[t[i] - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }
            bool found = false;
            rep(j, 0, cur.size()) {
                if (cur[j] > ind) {
                    ind = cur[j];
                    found = true;
                    break;
                }
            }
            if (!found) {
                counter++;
                i--;
                ind = -1;
            }
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


#pragma GCC optimize("unroll-loops,no-stack-protector")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        string ss = s + s;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, ss.size()) lets[ss[i] - 'a'].push_back(i);

        int ind = 0;
        int counter = 0;
        for (char c : t) {
            if (lets[c - 'a'].size() == 0) {
                counter = -1;
                break;
            }

            int tmp = *lower_bound(lets[c - 'a'].begin(), lets[c - 'a'].end(), ind);
            if (tmp >= s.size()) {
                counter++;
                tmp -= s.size();
            }
            ind = tmp + 1;
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


#pragma GCC optimize("unroll-loops,no-stack-protector")
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        string ss = s + s;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, ss.size()) lets[ss[i] - 'a'].push_back(i);

        int ind = 0;
        int counter = 0;
        for (char c : t) {
            vector<int> cur = lets[c - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }

            int tmp = *lower_bound(cur.begin(), cur.end(), ind);
            if (tmp >= s.size()) {
                counter++;
                tmp -= s.size();
            }
            ind = tmp + 1;
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
int T;
string s, t;
int main() {
	ios::sync_with_stdio(0);
	cin >> T;
	while (T--) {
		vector<int>v[27];//v[alpha-'a']对应s的下标
		int num[27] = { 0 };//num[alpha-'a']%(v[alpha-'a'].size())为每个字母在s中是第几个
		string z;
		int lens, lent, flg = 0, cnt = 1,pre=-1;
		cin >> s >> t;
		lens = s.length(), lent = t.length();
		for (int i = 0; i <= lens - 1; i++) v[s[i] - 'a'].push_back(i);
		for (int i = 0; i <= lent - 1; i++) {
			if (v[t[i] - 'a'].empty()) {
				flg = 1;
				break;
			}
			if (v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())] <= pre)cnt++;
			pre = v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())];
			num[t[i] - 'a']++;
		}
		if (flg)cout << "-1\n";
		else cout << cnt << '\n';
	}
	return 0;
}


#include<iostream>
#include<unordered_map>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
int t;
unordered_map<char, bool>m;
int main() {
	scanf("%d", &t);
	while (t--) {
		m.clear();
		int cnt = 0;//使用子串个数
		string s, ans;
		cin >> s >> ans;
		int lens = s.length(), len = ans.length();
		int cur = 0;
		for (int i = 0; i <= lens - 1; i++)m[s[i]] = 1;
		for (int i = 0; i <= len - 1; i++) {
			if (!m[ans[i]]) {
				cnt = -1;
				break;
			}
			while (ans[i] != s[cur%lens]) cur++;
			cur++;
		}
		printf("%d\n", (cur-1)/lens+1);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
int T, d[100000];
string s, t;
int bs(int l, int r, int num) {//找到第一个小于num的数的位置
	int i = l, j = r;
	while (i < j) {
		int mid = (i + j) >> 1;
		if (num > d[mid])j = mid;
		else i = mid + 1;
	}
	return i;
}
int main() {
	ios::sync_with_stdio(0);
	cin >> T;
	while (T--) {
		memset(d, 0, sizeof(d));
		vector<int>v[27];//v[alpha-'a']对应s的下标
		int num[27] = { 0 };//num[alpha-'a']%(v[alpha-'a'].size())为每个字母在s中是第几个
		string z;
		int lens, lent, flg = 0, cnt = 0;
		cin >> s >> t;
		lens = s.length(), lent = t.length();
		for (int i = 0; i <= lens - 1; i++) v[s[i] - 'a'].push_back(i);
		d[++cnt] = v[t[0] - 'a'][num[t[0] - 'a'] % (v[t[0] - 'a'].size())];
		num[t[0] - 'a']++;
		for (int i = 1; i <= lent - 1; i++) {
			if (v[t[i] - 'a'].empty()) {
				flg = 1;
				break;
			}
			if (v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[0] - 'a'].size())] <= d[cnt])d[++cnt] = v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[0] - 'a'].size())];
			else d[bs(1, cnt, v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[0] - 'a'].size())])] = v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[0] - 'a'].size())];
			num[t[i] - 'a']++;
		}
		if (flg)cout << "-1\n";
		else cout << cnt << '\n';
	}
	return 0;
}


#include<iostream>
#include<unordered_map>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
int t;
unordered_map<char, bool>m;
int main() {
	scanf("%d", &t);
	while (t--) {
		m.clear();
		int flg = 0;
		string s, ans;
		cin >> s >> ans;
		int lens = s.length(), len = ans.length();
		int cur = 0;
		for (int i = 0; i <= lens - 1; i++)m[s[i]] = 1;
		for (int i = 0; i <= len - 1; i++) {
			if (!m[ans[i]]) {
				flg = 1;
				break;
			}
			while (ans[i] != s[cur%lens]) cur++;
			cur++;
		}
		if (flg)printf("-1\n");
		else printf("%d\n", (cur-1)/lens+1);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
int T;
string s, t;
int main() {
	ios::sync_with_stdio(0);
	cin >> T;
	while (T--) {
		vector<int>v[27];//v[alpha-'a']对应s的下标
		string z;
		int lens, lent, flg = 0, cnt = 1, pre = -1;
		cin >> s >> t;
		lens = s.length(), lent = t.length();
		for (int i = 0; i <= lens - 1; i++) v[s[i] - 'a'].push_back(i);
		for (int i = 0; i <= lent - 1; i++) {
			if (v[t[i] - 'a'].size() == 0) {
				flg = 1;
				break;
			}
			int pos;
			if (v[t[i] - 'a'][v[t[i] - 'a'].size() - 1] <= pre)pos = -1;
			else pos = upper_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), pre)-v[t[i]-'a'].begin();
			if (pos == -1) pre = v[t[i] - 'a'][0], cnt++;
			else pre = v[t[i] - 'a'][pos];
		}
		if (flg)cout << "-1\n";
		else cout << cnt << '\n';
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
int T, d[100000];
string s, t;
int bs(int l, int r, int num) {//找到第一个小于num的数的位置
	int i = l, j = r;
	while (i < j) {
		int mid = (i + j) >> 1;
		if (num > d[mid])j = mid;
		else i = mid + 1;
	}
	return i;
}
int main() {
	ios::sync_with_stdio(0);
	cin >> T;
	while (T--) {
		memset(d, 0, sizeof(d));
		vector<int>v[27];//v[alpha-'a']对应s的下标
		int num[27] = { 0 };//num[alpha-'a']%(v[alpha-'a'].size())为每个字母在s中是第几个
		string z;
		int lens, lent, flg = 0, cnt = 0;
		cin >> s >> t;
		lens = s.length(), lent = t.length();
		for (int i = 0; i <= lens - 1; i++) v[s[i] - 'a'].push_back(i);
		d[++cnt] = v[t[0] - 'a'][num[t[0] - 'a'] % (v[t[0] - 'a'].size())];
		num[t[0] - 'a']++;
		for (int i = 1; i <= lent - 1; i++) {
			if (v[t[i] - 'a'].empty()) {
				flg = 1;
				break;
			}
			if (v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())] <= d[cnt])d[++cnt] = v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())];
			else d[bs(1, cnt, v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())])] = v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())];
			num[t[i] - 'a']++;
		}
		if (flg)cout << "-1\n";
		else cout << cnt << '\n';
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
int T, d[100000];
string s, t;
int bs(int l, int r, int num) {//找到第一个小于num的数的位置
	int i = l, j = r;
	while (i < j) {
		int mid = (i + j) >> 1;
		if (num > d[mid])j = mid;
		else i = mid + 1;
	}
	return i;
}
int main() {
	ios::sync_with_stdio(0);
	cin >> T;
	while (T--) {
		memset(d, 0, sizeof(d));
		vector<int>v[27];//v[alpha-'a']对应s的下标
		int num[27] = { 0 };//num[alpha-'a']%(v[alpha-'a'].size())为每个字母在s中是第几个
		string z;
		int lens, lent, flg = 0, cnt = 0;
		cin >> s >> t;
		lens = s.length(), lent = t.length();
		for (int i = 0; i <= lens - 1; i++) v[s[i] - 'a'].push_back(i);
		if (v[t[0] - 'a'].empty()) {
			cout << "-1\n";
			continue;
		}
		d[++cnt] = v[t[0] - 'a'][num[t[0] - 'a'] % (v[t[0] - 'a'].size())];
		num[t[0] - 'a']++;
		for (int i = 1; i <= lent - 1; i++) {
			if (v[t[i] - 'a'].empty()) {
				flg = 1;
				break;
			}
			if (v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())] <= d[cnt])d[++cnt] = v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())];
			else d[bs(1, cnt, v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())])] = v[t[i] - 'a'][num[t[i] - 'a'] % (v[t[i] - 'a'].size())];
			num[t[i] - 'a']++;
		}
		if (flg)cout << "-1\n";
		else cout << cnt << '\n';
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
int T;
string s, t;
int main() {
	ios::sync_with_stdio(0);
	cin >> T;
	while (T--) {
		vector<int>v[27];//v[alpha-'a']对应s的下标
		string z;
		int lens, lent, flg = 0, cnt = 1, pre = -1;
		cin >> s >> t;
		lens = s.length(), lent = t.length();
		for (int i = 0; i <= lens - 1; i++) v[s[i] - 'a'].push_back(i);
		for (int i = 0; i <= lent - 1; i++) {
			if (v[t[i] - 'a'].size() == 0) {
				flg = 1;
				break;
			}
			int pos, l = 0, r = v[t[i] - 'a'].size() - 1;
			if (v[t[i] - 'a'][r] <= pre)pos = -1;
			else {
				while (l < r) {
					int mid = (l + r) >> 1;
					if (pre < v[t[i] - 'a'][mid])r = mid;
					else l = mid + 1;
				}
				pos = l;
			}
			if (pos == -1) pre = v[t[i] - 'a'][0], cnt++;
			else pre = v[t[i] - 'a'][pos];
		}
		if (flg)cout << "-1\n";
		else cout << cnt << '\n';
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
int T;
string s, t;
int bs(vector<int>v, int num) {
	int i = 0, j = v.size() - 1;
	if (num >= v[j])return -1;
	while (i < j) {
		int mid = (i + j) >> 1;
		if (num < v[mid])j = mid;
		else i = mid + 1;
	}
	return i;
}
int main() {
	ios::sync_with_stdio(0);
	cin >> T;
	while (T--) {
		vector<int>v[27];//v[alpha-'a']对应s的下标
		int num[27] = { 0 };//num[alpha-'a']%(v[alpha-'a'].size())为每个字母在v中是第几个
		string z;
		int lens, lent, flg = 0, cnt = 1, pre = -1;
		cin >> s >> t;
		lens = s.length(), lent = t.length();
		for (int i = 0; i <= lens - 1; i++) v[s[i] - 'a'].push_back(i);
		for (int i = 0; i <= lent - 1; i++) {
			if (v[t[i] - 'a'].empty()) {
				flg = 1;
				break;
			}
			int pos = bs(v[t[i] - 'a'], pre);
			if (pos == -1) pre = v[t[i] - 'a'][0], cnt++;
			else pre = v[t[i] - 'a'][pos];
		}
		if (flg)cout << "-1\n";
		else cout << cnt << '\n';
	}
	return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
char s[100005],t[100005];
int p[100005],f[100005],ls,lt;
int tot[26],g[100005][26];
void work()
{
	memset(tot,0,sizeof tot);
	memset(f,63,sizeof f);f[0]=0;
	cin>>(s+1)>>(t+1);
	ls=strlen(s+1),lt=strlen(t+1);
	For(i,1,lt)p[i]=i-1;
	For(i,1,lt){
		int now=t[i]-'a';
		g[++tot[now]][now]=i;
	}
	For(i,1,ls)
	{
		int c=s[i]-'a';
		int totot=tot[c];
		for(int j=1;j<=totot;++j){
			int u=g[j][c];
			p[u]++;
			if(p[u]!=lt){
				int nxt=t[p[u]+1]-'a';
				g[++tot[nxt]][nxt]=u;
			}
		}tot[c]=0;
	}
	For(i,1,lt)if(p[i]==i-1){
		puts("-1");
		return ;
	}//else cout<<p[i]<<endl;
	For(i,1,lt)f[p[i]]=min(f[p[i]],f[i-1]+1);
	cout<<f[lt]<<endl;
}
signed main()
{
	int T=read();
	while(T--)work();
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
char s[100005],t[100005];
int p[100005],f[100005],ls,lt;
int tot[26],g[100005][26];
void work()
{
	memset(tot,0,sizeof tot);
	memset(f,63,sizeof f);f[0]=0;
	cin>>(s+1)>>(t+1);
	ls=strlen(s+1),lt=strlen(t+1);
	For(i,1,lt)p[i]=i-1;
	For(i,1,lt){
		int now=t[i]-'a';
		g[++tot[now]][now]=i;
	}
	For(i,1,ls)
	{
		int c=s[i]-'a';
		int totot=tot[c];
		for(int j=1;j<=totot;++j){
			int u=g[j][c];
			p[u]++;
			if(p[u]!=lt){
				int nxt=t[p[u]+1]-'a';
				g[++tot[nxt]][nxt]=u;
			}
		}tot[c]=0;
	}
	For(i,1,lt)if(p[i]==i-1){
		puts("-1");
		return ;
	}//else cout<<p[i]<<endl;
	f[p[1]+1]=1;
	For(i,1,lt)f[p[i]+1]=min(f[p[i]+1],f[i]+1);
	cout<<f[lt+1]<<endl;
}
signed main()
{
	int T=read();
	while(T--)work();
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
char s[100005],t[100005];
int ls,lt;
vector<int>g[26];
void work()
{
	int res=1;
	cin>>(s+1)>>(t+1);
	ls=strlen(s+1),lt=strlen(t+1);
	For(i,0,25)g[i].clear();
	For(i,1,ls)g[s[i]-'a'].push_back(i);
	For(i,1,lt)if(g[t[i]-'a'].size()==0){
		puts("-1");
		return;
	}
	int p=0;
	For(i,1,lt)
	{
		int c=t[i]-'a';
		if(g[c][g[c].size()-1]<=p){
			res++;
			p=0;
		}
		int l=0,r=g[c].size()-1,ans=r;
		while(l<=r)
		{
			int mid=l+r>>1;
			if(g[c][mid]>p)r=mid-1,ans=mid;
			else l=mid+1;
		}p=g[c][ans];
	//	cout<<i<<' '<<p<<' '<<res<<endl;
	}cout<<res<<endl;
}
signed main()
{
	int T=read();
	while(T--)work();
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
char s[100005],t[100005];
int p[100005],f[100005],ls,lt;
int tot[26],g[100005][26];
void work()
{
	memset(tot,0,sizeof tot);
	memset(f,63,sizeof f);f[0]=0;
	cin>>(s+1)>>(t+1);
	ls=strlen(s+1),lt=strlen(t+1);
	For(i,1,lt)p[i]=i-1;
	For(i,1,lt){
		int now=t[i]-'a';
		g[++tot[now]][now]=i;
	}
	For(i,1,ls)
	{
		int c=s[i]-'a';
		int totot=tot[c];
		tot[c]=0;
		for(int j=1;j<=totot;++j){
			int u=g[j][c];
			p[u]++;
			if(p[u]!=lt){
				int nxt=t[p[u]+1]-'a';
				g[++tot[nxt]][nxt]=u;
			}
		}
	}
	For(i,1,lt)f[p[i]]=min(f[p[i]],f[i-1]+1);
	if(f[lt]<0x3f3f3f3f)cout<<f[lt]<<endl;
	else puts("-1");
}
signed main()
{
	int T=read();
	while(T--)work();
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
char s[100005],t[100005];
int p[100005],f[100005],ls,lt;
int tot[26],g[100005][26];
void work()
{
	memset(tot,0,sizeof tot);
	memset(f,63,sizeof f);f[0]=0;
	cin>>(s+1)>>(t+1);
	ls=strlen(s+1),lt=strlen(t+1);
	For(i,1,lt)p[i]=i-1;
	For(i,1,lt){
		int now=t[i]-'a';
		g[++tot[now]][now]=i;
	}
	For(i,1,ls)
	{
		int c=s[i]-'a';
		int totot=tot[c];
		for(int j=1;j<=totot;++j){
			int u=g[j][c];
			p[u]++;
			if(p[u]!=lt){
				int nxt=t[p[u]+1]-'a';
				g[++tot[nxt]][nxt]=u;
			}
		}tot[c]=0;
	}
	For(i,1,lt)f[p[i]]=min(f[p[i]],f[i-1]+1);
	if(f[lt]<0x3f3f3f3f)cout<<f[lt]<<endl;
	else puts("-1");
}
signed main()
{
	int T=read();
	while(T--)work();
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
char s[100005],t[100005];
int p[100005],f[100005],ls,lt;
int tot[26],g[100005][26];
void work()
{
	memset(tot,0,sizeof tot);
	memset(f,63,sizeof f);f[0]=0;
	cin>>(s+1)>>(t+1);
	ls=strlen(s+1),lt=strlen(t+1);
	For(i,1,lt)p[i]=i-1;
	For(i,1,lt){
		int now=t[i]-'a';
		g[++tot[now]][now]=i;
	}
	For(i,1,ls)
	{
		int c=s[i]-'a';
		int totot=tot[c];
		for(int j=1;j<=totot;++j){
			int u=g[j][c];
			p[u]++;
			if(p[u]!=lt){
				int nxt=t[p[u]+1]-'a';
				g[++tot[nxt]][nxt]=u;
			}
		}tot[c]-=totot;
	}
	For(i,1,lt)f[p[i]]=min(f[p[i]],f[i-1]+1);
	if(f[lt]<0x3f3f3f3f)cout<<f[lt]<<endl;
	else puts("-1");
}
signed main()
{
	int T=read();
	while(T--)work();
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <list>

using namespace std;

int main() {
    int t;
    string s1, s2;
    int i = 0;
    int j = 0;
    int res = 0;
    cin >> t;
    bool isIn;
    vector<list<int>> vctr('z' - 'a' + 1);
    vector<vector<int>> fastVctr;
    for (int k = 0; k < t; k++)
    {
        cin >> s1 >> s2;
        for (int i = 0; i < vctr.size(); i++)
            vctr[i].clear();
        fastVctr.clear();
        fastVctr.resize(s1.length());
        for (int i = 0; i < s1.length(); i++)
        {
            fastVctr[i].resize('z' - 'a' + 1);
            if (i != 0)
                vctr[s1[i] - 'a'].push_back(i);
        }
        for (int i = 0; i < 'z' - 'a' + 1; i++)
            vctr[i].push_back(-1);
        for (int i = 0; i < s1.length(); i++)
            for (int j = 0; j < ('z' - 'a' + 1); j++)
            {
                    fastVctr[i][j] = vctr[j].front();
                    if (i + 1 == vctr[j].front())
                        vctr[j].pop_front();
            }
        isIn = false;
        i = 0;
        j = 0;
        res = 0;
        while (i != s1.length() && j != s2.length())
        {
            if (i == 0 && s1[i] == s2[j])
            {
                isIn = true;
                j++;
                if (fastVctr[i][s2[j] - 'a'] == -1)
                {
                    res++;
                    isIn = false;
                }
                continue;
            }
            i = fastVctr[i][s2[j] - 'a'];
            if (i == -1)
            {
                if (isIn)
                    isIn = false;
                else
                    break;
                i = 0;
                res++;
            }
            else
            {
                isIn = true;
                j++;
            }
        }
        if (isIn)
            cout << res + 1 << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main() {
    int t;
    string s1, s2;
    int i = 0;
    int j = 0;
    int res = 0;
    cin >> t;
    bool isIn;
    string findIn;
    for (int k = 0; k < t; k++)
    {
        cin >> s1 >> s2;
        res = 0;
        j = 0;
        isIn = true;
        findIn.clear();
        for (int i = 0; i < s1.length(); i++)
            if (findIn.find(s1[i]) == string::npos)
                findIn.append(1, s1[i]);
        s1 = findIn;
        //cout << findIn << endl;
        while (j != s2.length() && isIn)
        {
            isIn = false;
            i = 0;
            while (i != s1.length() && j != s2.length())
            {
                if (s1[i] == s2[j])
                {
                    isIn = true;
                    //cout << "i = " << i << " j = " << j << endl;
                    j++;
                }
                i++;
            }
            res++;
        }
        if (isIn)
            cout << res << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <list>

using namespace std;

int main() {
    int t;
    string s1, s2;
    int i = 0;
    int j = 0;
    int res = 0;
    cin >> t;
    bool isIn;
    vector<list<int>> vctr('z' - 'a' + 1);
    vector<vector<int>> fastVctr;
    for (int k = 0; k < t; k++)
    {
        cin >> s1 >> s2;
        for (int i = 0; i < vctr.size(); i++)
            vctr[i].clear();
        fastVctr.clear();
        fastVctr.resize(s1.length());
        for (int i = 0; i < s1.length(); i++)
        {
            fastVctr[i].resize('z' - 'a' + 1);
            if (i != 0)
                vctr[s1[i] - 'a'].push_back(i);
        }
        for (int i = 0; i < 'z' - 'a' + 1; i++)
            vctr[i].push_back(-1);
        for (int i = 0; i < s1.length(); i++)
            for (int j = 0; j < ('z' - 'a' + 1); j++)
            {
                    fastVctr[i][j] = vctr[j].front();
                    if (i + 1 == vctr[j].front())
                        vctr[j].pop_front();
            }
        isIn = false;
        i = 0;
        j = 0;
        res = 0;
        while (i != s1.length() && j != s2.length())
        {
            if (i == 0 && s1[i] == s2[j])
            {
                isIn = true;
                j++;
                continue;
            }
            i = fastVctr[i][s2[j] - 'a'];
            if (i == -1)
            {
                if (isIn)
                    isIn = false;
                else
                    break;
                i = 0;
                res++;
            }
            else
            {
                isIn = true;
                j++;
            }
        }
        if (isIn)
            cout << res + 1 << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <list>

using namespace std;

int main() {
    int t;
    string s1, s2;
    int i = 0;
    int j = 0;
    int res = 0;
    cin >> t;
    bool isIn;
    vector<list<int>> vctr('z' - 'a' + 1);
    vector<vector<int>> fastVctr;
    for (int k = 0; k < t; k++)
    {
        cin >> s1 >> s2;
        for (int i = 0; i < vctr.size(); i++)
            vctr[i].clear();
        fastVctr.clear();
        fastVctr.resize(s1.length());
        for (int i = 0; i < s1.length(); i++)
        {
            fastVctr[i].resize('z' - 'a' + 1);
            if (i != 0)
                vctr[s1[i] - 'a'].push_back(i);
        }
        for (int i = 0; i < 'z' - 'a' + 1; i++)
            vctr[i].push_back(-1);
        for (int i = 0; i < s1.length(); i++)
            for (int j = 0; j < ('z' - 'a' + 1); j++)
            {
                    fastVctr[i][j] = vctr[j].front();
                    if (i + 1 == vctr[j].front())
                        vctr[j].pop_front();
            }
        isIn = false;
        i = 0;
        j = 0;
        res = 0;
        while (i != s1.length() && j != s2.length())
        {
            if (!isIn && i == 0 && s1[i] == s2[j])
            {
                isIn = true;
                j++;
                if (j == s2.length())
                    continue;
                if (s1.length() == 1)
                {
                    res++;
                    i = 0;
                    isIn = false;
                }
                continue;
            }
            i = fastVctr[i][s2[j] - 'a'];
            if (i == -1)
            {
                if (isIn)
                    isIn = false;
                else
                    break;
                i = 0;
                res++;
            }
            else
            {
                isIn = true;
                j++;
            }
        }
        if (isIn)
            cout << res + 1 << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <list>

using namespace std;

int main() {
    int t;
    string s1, s2;
    int i = 0;
    int j = 0;
    int res = 0;
    cin >> t;
    bool isIn;
    vector<list<int>> vctr('z' - 'a' + 1);
    vector<vector<int>> fastVctr;
    for (int k = 0; k < t; k++)
    {
        cin >> s1 >> s2;
        for (int i = 0; i < vctr.size(); i++)
            vctr[i].clear();
        fastVctr.clear();
        fastVctr.resize(s1.length());
        for (int i = 0; i < s1.length(); i++)
        {
            fastVctr[i].resize('z' - 'a' + 1);
            if (i != 0)
                vctr[s1[i] - 'a'].push_back(i);
        }
        for (int i = 0; i < 'z' - 'a' + 1; i++)
            vctr[i].push_back(-1);
        for (int i = 0; i < s1.length(); i++)
            for (int j = 0; j < ('z' - 'a' + 1); j++)
            {
                    fastVctr[i][j] = vctr[j].front();
                    if (i + 1 == vctr[j].front())
                        vctr[j].pop_front();
            }
        isIn = false;
        i = 0;
        j = 0;
        res = 0;
        while (i != s1.length() && j != s2.length())
        {
            if (!isIn && i == 0 && s1[i] == s2[j])
            {
                isIn = true;
                j++;
                if (s1.length() == 1)
                {
                    res++;
                    i = 0;
                    isIn = false;
                }
                continue;
            }
            i = fastVctr[i][s2[j] - 'a'];
            if (i == -1)
            {
                if (isIn)
                    isIn = false;
                else
                    break;
                i = 0;
                res++;
            }
            else
            {
                isIn = true;
                j++;
            }
        }
        if (isIn)
            cout << res + 1 << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main() {
    int t;
    string s1, s2;
    int i = 0;
    int j = 0;
    int res = 0;
    cin >> t;
    bool isIn;
    for (int k = 0; k < t; k++)
    {
        cin >> s1 >> s2;
        res = 0;
        j = 0;
        isIn = true;
        while (j != s2.length() && isIn)
        {
            isIn = false;
            i = 0;
            while (i != s1.length() && j != s2.length())
            {
                if (s1[i] == s2[j])
                {
                    isIn = true;
                    //cout << "i = " << i << " j = " << j << endl;
                    j++;
                }
                i++;
            }
            res++;
        }
        if (isIn)
            cout << res << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <list>

using namespace std;

int main() {
    int t;
    string s1, s2;
    int i = 0;
    int j = 0;
    int res = 0;
    cin >> t;
    bool isIn;
    vector<list<int>> vctr('z' - 'a' + 1);
    vector<vector<int>> fastVctr;
    for (int k = 0; k < t; k++)
    {
        cin >> s1 >> s2;
        res = 0;
        isIn = true;
        vctr.clear();
        fastVctr.clear();
        fastVctr.resize(s1.length());
        for (int i = 0; i < s1.length(); i++)
        {
            fastVctr[i].resize('z' - 'a' + 1);
            if (i != 0)
                vctr[s1[i] - 'a'].push_back(i);
        }
        for (int i = 0; i < 'z' - 'a' + 1; i++)
            vctr[i].push_back(-1);
        int pos = 0;
        for (int i = 0; i < s1.length(); i++)
            for (int j = 0; j < ('z' - 'a' + 1); j++)
            {
                    fastVctr[i][j] = vctr[j].front();
                    if (i + 1 == vctr[j].front())
                        vctr[j].pop_front();
            }
        isIn = false;
        i = 0;
        j = 0;
        while (i != s1.length() && j != s2.length())
        {
            if (i == 0 && s1[i] == s2[j])
            {
                isIn = true;
                j++;
                continue;
            }
            i = fastVctr[i][s2[j] - 'a'];
            if (i == -1)
            {
                if (isIn)
                    isIn = false;
                else
                    break;
                i = 0;
                res++;
            }
            else
            {
                isIn = true;
                j++;
            }
        }
        if (isIn)
            cout << res + 1 << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}


/*
 * @Author: sunlu
 * @Date: 2020-01-29 19:24:08
 * @LastEditors  : sunlu
 * @LastEditTime : 2020-01-30 14:24:12
 */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn=200000;
#define debug(x) cerr<<#x<<":="<<x<<endl
template<class T>inline void read(T &x){
    x=0;ll f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    x=x*f;
}
int T;
char s[maxn],t[maxn];
map<char,vector<int>> mp;
int main(){
    cin>>T;
    while(T--){
        scanf("%s",s);
        scanf("%s",t);
        mp.clear();
        for(int i=0;i<strlen(s);i++)
        mp[s[i]].push_back(i);
        int op=1;
        int sit=-1;
        for(int i=0;i<strlen(t);i++)
        {
            if(mp[t[i]].size()==0){puts("-1");goto ggg;}
            bool ok=false;
            for(auto p:mp[t[i]]){
                if(p>sit){
                    ok=true;
                    sit=p;
                    break;
                }
            }
            if(!ok){
                op++;
                sit=*(mp[t[i]].begin());
            }
        }
        printf("%d\n",op);
        ggg:;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn=200000;
#define debug(x) cerr<<#x<<":="<<x<<endl
template<class T>inline void read(T &x){
    x=0;ll f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    x=x*f;
}
int T;
char s[maxn],t[maxn];
map<char,vector<int>> mp;
int main(){
    cin>>T;
    while(T--){
        scanf("%s",s);
        scanf("%s",t);
        mp.clear();
        for(int i=0;i<strlen(s);i++)
        mp[s[i]].push_back(i);
        int op=1;
        int sit=-1;
        for(int i=0;i<strlen(t);i++)
        {
            if(mp[t[i]].size()==0){puts("-1");goto ggg;}
            bool ok=false;
            auto it=upper_bound(mp[t[i]].begin(),mp[t[i]].end(),sit);
            if(it!=mp[t[i]].end()) ok=true,sit=*it;
            if(!ok){
                op++;
                sit=*(mp[t[i]].begin());
            }
        }
        printf("%d\n",op);
        ggg:;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn=500000;
#define debug(x) cerr<<#x<<":="<<x<<endl
template<class T>inline void read(T &x){
    x=0;ll f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    x=x*f;
}
int T;
string s,t,z;
map<char,vector<int>> mp;
int main(){
    cin>>T;
    while(T--){
        cin>>s;
        cin>>t;
        mp.clear();
        for(int i=0;i<s.length();i++)
        mp[s[i]].push_back(i);
        int op=1;
        int sit=-1;
        for(int i=0;i<t.length();i++)
        {
            if(mp[t[i]].size()==0){puts("-1");goto ggg;}
            bool ok=false;
            auto it=upper_bound(mp[t[i]].begin(),mp[t[i]].end(),sit);
            if(it!=mp[t[i]].end()){ok=true;sit=*it;}
            if(!ok){
                op++;
                sit=*(mp[t[i]].begin());
            }
        }
        cout<<op<<'\n';
        ggg:;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn=500000;
#define debug(x) cerr<<#x<<":="<<x<<endl
template<class T>inline void read(T &x){
    x=0;ll f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    x=x*f;
}
int T;
string s,t,z;
map<char,vector<int>> mp;
int main(){
    cin>>T;
    while(T--){
        cin>>s;
        cin>>t;
        mp.clear();
        for(int i=0;i<s.length();i++)
        mp[s[i]].push_back(i);
        int op=1;
        int sit=-1;
        for(int i=0;i<t.length();i++)
        {
            if(mp[t[i]].size()==0){puts("-1");goto ggg;}
            bool ok=false;
            for(auto p:mp[t[i]]){
                if(p>sit){
                    ok=true;
                    sit=p;
                    break;
                }
            }
            if(!ok){
                op++;
                sit=*(mp[t[i]].begin());
            }
        }
        cout<<op<<'\n';
        ggg:;
    }
    return 0;
}


/*
 * @Author: sunlu
 * @Date: 2020-01-29 19:24:08
 * @LastEditors  : sunlu
 * @LastEditTime : 2020-01-30 14:29:07
 */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn=200000;
#define debug(x) cerr<<#x<<":="<<x<<endl
template<class T>inline void read(T &x){
    x=0;ll f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    x=x*f;
}
int T;
char s[maxn],t[maxn];
map<char,vector<int>> mp;
int main(){
    cin>>T;
    while(T--){
        scanf("%s",s);
        scanf("%s",t);
        mp.clear();
        for(int i=0;i<strlen(s);i++)
        mp[s[i]].push_back(i);
        int op=1;
        int sit=-1;
        for(int i=0;i<strlen(t);i++)
        {
            if(mp[t[i]].size()==0){puts("-1");goto ggg;}
            bool ok=false;
            for(auto p:mp[t[i]]){
                if(p>sit){
                    ok=true;
                    sit=p;
                    break;
                }
            }
            auto it=upper_bound(mp[t[i]].begin(),mp[t[i]].end(),sit);
            if(it!=mp[t[i]].end()) ok=true,sit=*it;
            if(!ok){
                op++;
                sit=*(mp[t[i]].begin());
            }
        }
        printf("%d\n",op);
        ggg:;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn=200000;
#define debug(x) cerr<<#x<<":="<<x<<endl
template<class T>inline void read(T &x){
    x=0;ll f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    x=x*f;
}
int T;
char s[maxn],t[maxn];
map<char,vector<int>> mp;
int main(){
    cin>>T;
    while(T--){
        scanf("%s",s);
        scanf("%s",t);
        mp.clear();
        for(int i=0;i<strlen(s);i++)
        mp[s[i]].push_back(i);
        int op=1;
        int sit=-1;
        for(int i=0;i<strlen(t);i++)
        {
            if(mp[t[i]].size()==0){puts("-1");goto ggg;}
            bool ok=false;
            for(auto p:mp[t[i]]){
                if(p>sit){
                    ok=true;
                    sit=p;
                    break;
                }
            }
            auto it=upper_bound(mp[t[i]].begin(),mp[t[i]].end(),sit);
            if(it!=mp[t[i]].end()) ok=true,sit=*it;
            if(!ok){
                op++;
                sit=*(mp[t[i]].begin());
            }
        }
        printf("%d\n",op);
        ggg:;
    }
    return 0;
}


/*
 * @Author: sunlu
 * @Date: 2020-01-29 19:24:08
 * @LastEditors  : sunlu
 * @LastEditTime : 2020-01-30 14:08:25
 */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn=500000;
#define debug(x) cerr<<#x<<":="<<x<<endl
template<class T>inline void read(T &x){
    x=0;ll f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    x=x*f;
}
int T;
string s,t,z;
map<char,vector<int>> mp;
int main(){
    cin>>T;
    while(T--){
        cin>>s;
        cin>>t;
        mp.clear();
        for(int i=0;i<s.length();i++)
        mp[s[i]].push_back(i);
        int op=1;
        int sit=0;
        for(int i=0;i<t.length();i++)
        {
            if(mp[t[i]].size()==0){puts("-1");goto ggg;}
            bool ok=false;
            for(auto p:mp[t[i]]){
                if(p>sit){
                    ok=true;
                    sit=p;
                    break;
                }
            }
            if(!ok){
                op++;
                sit=0;
            }
        }
        cout<<op<<'\n';
        ggg:;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30],numt[30];
const int INF=1e9;
char s[N],t[N];
int main()
{
    cin.sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
    {
        vector<int>v[30];
        memset(nums,0,sizeof(nums));
        //memset(numt,0,sizeof(numt));
        cin >> s;
        cin >> t;
        for(int i=0;i<strlen(s);i++)
        {
            int x=s[i]-'a';
            v[x].push_back(i);
            nums[x]++;
        }
        for(int i=0;i<=26;i++)
        {
            v[i].push_back(INF);
        }
        int flag=-1,ans=1;
        for(int i=0;i<strlen(t);i++)
        {
            int x=t[i]-'a',cnt;
            if(nums[x])
            {
                cnt=*upper_bound(v[x].begin(),v[x].end(),flag);
                if(cnt==INF)
                {
                    ans++;//cout<<" "<<i<<" "<<v[x][cnt]<<"\n";
                    flag=(*v[x].begin());
                    //flag=v[x][cnt];
                }
                else
                    flag=cnt;
            }
            else
            {
                ans=-1;
                break;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
char s[N],t[N];
void solve()
{
    vector<int>v[30];
    //memset(nums,0,sizeof(nums));
    cin >> s;
    cin >> t;
    for(int i=0;i<strlen(s);i++)
    {
        int x=s[i]-'a';
        v[x].push_back(i);
    }
    int ans=1,position=-1;
    for(int i=0;i<strlen(t);i++)
    {
        int x=t[i]-'a';
        if(v[x].empty())
        {
            cout<<"-1\n";
            return ;
        }
        auto it=upper_bound(v[x].begin(),v[x].end(),position);
        if(it==v[x].end())
        {
            ans++;
            it=v[x].begin();
        }
        position=*it;
    }
    cout<<ans<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define ll long long

void solve()
{
    vector<int>v[27];
    string s,t;
    cin >> s >> t;
    int N=s.size();
    for(int i=0;i<N;i++)
    {
        int x=s[i]-'a';
        v[x].push_back(i);
    }
    int ans=1,position=-1;
    N=t.size();
    for(int i=0;i<N;i++)
    {
        int x=t[i]-'a';
        if(v[x].empty())
        {
            cout<<"-1\n";
            return ;
        }
        auto it=upper_bound(v[x].begin(),v[x].end(),position);
        if(it==v[x].end())
        {
            ans++;
            it=v[x].begin();
        }
        position=*it;
    }
    cout<<ans<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30],numt[30];
const int INF=1e9;
char s[N],t[N];
int main()
{
    cin.sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
    {
        vector<int>v[27];
        memset(nums,0,sizeof(nums));
        //memset(numt,0,sizeof(numt));
        cin >> s;
        cin >> t;
        for(int i=0;i<strlen(s);i++)
        {
            int x=s[i]-'a';
            v[x].push_back(i);
            nums[x]++;
        }
        for(int i=0;i<26;i++)
        {
            v[i].push_back(INF);
        }
        int flag=-1,ans=0;
        for(int i=0;i<strlen(t);i++)
        {
            ans++;
            int x=t[i]-'a';
            if(nums[x])
                flag=*upper_bound(v[x].begin(),v[x].end(),-1);
            else
            {
                ans=-1;
                break;
            }
            if(i!=strlen(t)-1)
                i++;
            while(i<strlen(t))
            {
                int x=t[i]-'a',cnt;
                if(nums[x])
                {
                    cnt=*upper_bound(v[x].begin(),v[x].end(),flag);
                    if(cnt==INF)
                    {
                        i--;
                        break;
                    }
                    else
                        flag=cnt;
                }
                else
                {
                    ans=-1;
                    break;
                }
                i++;
            }
            if(ans==-1)
                break;
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30],numt[30];
const int INF=1e9;
int main()
{
    int T;
    cin >> T;
    while(T--)
    {   vector<int>v[27];
        memset(nums,0,sizeof(nums));
        memset(numt,0,sizeof(numt));
        string s,t;
        cin >> s;
        cin >> t;
        for(int i=0;i<s.size();i++)
        {
            int x=s[i]-'a';
            v[x].push_back(i);
            nums[x]++;
        }
        for(int i=0;i<26;i++)
        {
            v[i].push_back(INF);
        }
        int flag=-1,ans=1;
        for(int i=0;i<t.size();i++)
        {
            int x=t[i]-'a',cnt;
            if(nums[x])
            {
                cnt=upper_bound(v[x].begin(),v[x].end(),flag)-v[x].begin();
                if(v[x][cnt]==INF)
                {
                    ans++,flag=-1;//cout<<" "<<i<<" "<<v[x][cnt]<<"\n";
                    cnt=upper_bound(v[x].begin(),v[x].end(),flag)-v[x].begin();
                    flag=v[x][cnt];
                }
                else
                    flag=v[x][cnt];
            }
            else
            {
                ans=-1;
                break;
            }
        }
        cout<<ans<<"\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30],numt[30];
const int INF=1e9;
char s[N],t[N];
int main()
{
    cin.sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
    {
        vector<int>v[27];
        memset(nums,0,sizeof(nums));
        //memset(numt,0,sizeof(numt));
        cin >> s;
        cin >> t;
        for(int i=0;i<strlen(s);i++)
        {
            int x=s[i]-'a';
            v[x].push_back(i);
            nums[x]++;
        }
        for(int i=0;i<26;i++)
        {
            v[i].push_back(INF);
        }
        int flag=-1,ans=1;
        for(int i=0;i<strlen(t);i++)
        {
            int x=t[i]-'a',cnt;
            if(nums[x])
            {
                cnt=*upper_bound(v[x].begin(),v[x].end(),flag);
                if(cnt==INF)
                {
                    ans++;//cout<<" "<<i<<" "<<v[x][cnt]<<"\n";
                    flag=*v[x].begin();
                    //flag=v[x][cnt];
                }
                else
                    flag=cnt;
            }
            else
            {
                ans=-1;
                break;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define ll long long

void solve()
{
    vector<int>v[27];
    //memset(nums,0,sizeof(nums));
    string s,t;
    int N=s.size();
    for(int i=0;i<N;i++)
    {
        int x=s[i]-'a';
        v[x].push_back(i);
    }
    int ans=1,position=-1;
    N=t.size();
    for(int i=0;i<N;i++)
    {
        int x=t[i]-'a';
        if(v[x].empty())
        {
            cout<<"-1\n";
            return ;
        }
        auto it=upper_bound(v[x].begin(),v[x].end(),position);
        if(it==v[x].end())
        {
            ans++;
            it=v[x].begin();
        }
        position=*it;
    }
    cout<<ans<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30];
const int INF=1e9;
char s[N],t[N];
void solve()
{
    vector<int>v[30];
    memset(nums,0,sizeof(nums));
    cin >> s;
    cin >> t;
    for(int i=0;i<strlen(s);i++)
    {
        int x=s[i]-'a';
        v[x].push_back(i);
        nums[x]++;
    }
    int ans=1,position=-1;
    for(int i=0;i<strlen(t);i++)
    {
        int x=t[i]-'a';
        if(nums[x]==0)
        {
            cout<<"-1\n";
            return ;
        }
        auto it=upper_bound(v[x].begin(),v[x].end(),position);
        if(it==v[x].end())
        {
            ans++;
            it=v[x].begin();
        }
        position=*it;

    }
    cout<<ans<<"\n";
}

int main()
{
    cin.sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30],numt[30];
const int INF=1e9;
char s[N],t[N];
int get_len(char s[])
{
    int i=0;
    while(s[i]!='\0')
    {
        i++;
    }
    return i;
}
int main()
{
    cin.sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
    {   vector<int>v[27];
        memset(nums,0,sizeof(nums));
        memset(numt,0,sizeof(numt));
        cin >> s;
        cin >> t;
        int n = get_len(s)
        for(int i=0;i<n;i++)
        {
            int x=s[i]-'a';
            v[x].push_back(i);
            nums[x]++;
        }
        for(int i=0;i<26;i++)
        {
            v[i].push_back(INF);
        }
        int flag=-1,ans=1;
        n=get_len(t);
        for(int i=0;i<n;i++)
        {
            int x=t[i]-'a',cnt;
            if(nums[x])
            {
                cnt=upper_bound(v[x].begin(),v[x].end(),flag)-v[x].begin();
                if(v[x][cnt]==INF)
                {
                    ans++,flag=-1;//cout<<" "<<i<<" "<<v[x][cnt]<<"\n";
                    cnt=upper_bound(v[x].begin(),v[x].end(),flag)-v[x].begin();
                    flag=v[x][cnt];
                }
                else
                    flag=v[x][cnt];
            }
            else
            {
                ans=-1;
                break;
            }
        }
        cout<<ans<<"\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30],numt[30];
const int INF=1e9;
char s[N],t[N];
int main()
{
    cin.sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
    {
        vector<int>v[27];
        memset(nums,0,sizeof(nums));
        //memset(numt,0,sizeof(numt));
        cin >> s;
        cin >> t;
        for(int i=0;i<strlen(s);i++)
        {
            int x=s[i]-'a';
            v[x].push_back(i);
            nums[x]++;
        }
        for(int i=0;i<26;i++)
        {
            v[i].push_back(INF);
        }
        int flag=-1,ans=0;
        for(int i=0;i<strlen(t);i++)
        {
            ans++;
            int x=t[i]-'a';
            flag=*upper_bound(v[x].begin(),v[x].end(),-1);
            i++;
            while(i<strlen(t))
            {
                int x=t[i]-'a',cnt;
                if(nums[x])
                {
                    cnt=*upper_bound(v[x].begin(),v[x].end(),flag);
                    if(cnt==INF)
                    {
                        i--;
                        break;
                    }
                    else
                        flag=cnt;
                }
                else
                {
                    ans=-1;
                    break;
                }
                i++;
            }
            if(ans==-1)
                break;
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30];
const int INF=1e9;
char s[N],t[N];
void solve()
{
    vector<int>v[30];
    //memset(nums,0,sizeof(nums));
    cin >> s;
    cin >> t;
    for(int i=0;i<strlen(s);i++)
    {
        int x=s[i]-'a';
        v[x].push_back(i);
    }
    int ans=1,position=-1;
    for(int i=0;i<strlen(t);i++)
    {
        int x=t[i]-'a';
        if(v[x].empty())
        {
            cout<<"-1\n";
            return ;
        }
        auto it=upper_bound(v[x].begin(),v[x].end(),position);
        if(it==v[x].end())
        {
            ans++;
            it=v[x].begin();
        }
        position=*it;
    }
    cout<<ans<<"\n";
}

int main()
{
    cin.sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define P pair<int,int>
#define ll long long
int nums[30],numt[30];
const int INF=1e9;
char s[N],t[N];
int main()
{
    cin.sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
    {
        vector<int>v[30];
        memset(nums,0,sizeof(nums));
        //memset(numt,0,sizeof(numt));
        cin >> s;
        cin >> t;
        for(int i=0;i<strlen(s);i++)
        {
            int x=s[i]-'a';
            v[x].push_back(i);
            nums[x]++;
        }
        for(int i=0;i<=26;i++)
        {
            v[i].push_back(INF);
        }
        int flag=-1,ans=1;
        for(int i=0;i<strlen(t);i++)
        {
            int x=t[i]-'a',cnt;
            if(nums[x])
            {
                cnt=*upper_bound(v[x].begin(),v[x].end(),flag);
                if(cnt==INF)
                {
                    ans++;//cout<<" "<<i<<" "<<v[x][cnt]<<"\n";
                    flag=*v[x].begin();
                    //flag=v[x][cnt];
                }
                else
                    flag=cnt;
            }
            else
            {
                ans=-1;
                break;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define ll long long

void solve()
{
    vector<int>v[27];
    //memset(nums,0,sizeof(nums));
    string s,t;
    cin >> s >> t;
    int N=s.size();
    for(int i=0;i<N;i++)
    {
        int x=s[i]-'a';
        v[x].push_back(i);
    }
    int ans=1,position=-1;
    N=t.size();
    for(int i=0;i<N;i++)
    {
        int x=t[i]-'a';
        if(v[x].empty())
        {
            cout<<"-1\n";
            return ;
        }
        auto it=upper_bound(v[x].begin(),v[x].end(),position);
        if(it==v[x].end())
        {
            ans++;
            it=v[x].begin();
        }
        position=*it;
    }
    cout<<ans<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
string s,t;
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {

        cin>>s>>t;
        for(int i=0;i<26;i++)
            q[i].clear(),f[i]=0;
        for(int i=0;i<s.size();i++){
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0;i<t.size();i++)
        {
            if(f[t[i]-'a']==0) vis=1;
        }
        for(int i=0;i<26;i++)
        {
            q[i].pb(100000000);
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0;i<t.size();i++)
            {
                int x=t[i]-'a';
                int p=lower_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p]+1;
                if(now>=s.size()){
                    now=0;
                    ans++;
                }
            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
string s,t;
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {

        cin>>s>>t;
        for(int i=0; i<26; i++)
            q[i].clear(),f[i]=0;
        for(int i=0; i<s.size(); i++)
        {
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0; i<t.size(); i++)
        {
            if(f[t[i]-'a']==0)
                vis=1;
        }
        for(int i=0; i<26; i++)
        {
            q[i].pb(100000000);
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0; i<t.size(); i++)
            {

                int x=t[i]-'a';
                int p=lower_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p]+1;
//                cout<<now<<endl;
                if(now>s.size())
                {
                    now=0;
                    ans++;
                }

            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
string s,t;
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {

        cin>>s>>t;
        for(int i=0; i<26; i++)
            q[i].clear(),f[i]=0;
        for(int i=0; i<s.size(); i++)
        {
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0; i<t.size(); i++)
        {
            if(f[t[i]-'a']==0)
                vis=1;
        }
        for(int i=0; i<26; i++)
        {
            q[i].pb(100000000);
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0; i<t.size(); i++)
            {
                int x=t[i]-'a';
                int p=lower_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p]+1;
                if(now>s.size())
                {
                    now=q[x][0]+1;
                    ans++;
                }

            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
string s,t;
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {

        cin>>s>>t;
        for(int i=0; i<26; i++)
            q[i].clear(),f[i]=0;
        for(int i=0; i<s.size(); i++)
        {
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0; i<t.size(); i++)
        {
            if(f[t[i]-'a']==0)
                vis=1;
        }
        for(int i=0; i<26; i++)
        {
            q[i].pb(100000000);
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0; i<t.size(); i++)
            {

                int x=t[i]-'a';
                int p=lower_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p]+1;
//                cout<<now<<endl;
                if(now>s.size())
                {
                    now=q[x][0];
                    ans++;
                }

            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
string s,t;
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {

        cin>>s>>t;
        for(int i=0;i<26;i++)
            q[i].clear(),f[i]=0;
        for(int i=0;i<s.size();i++){
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0;i<t.size();i++)
        {
            if(f[t[i]-'a']==0) vis=1;
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0;i<t.size();i++)
            {
                int x=t[i]-'a';
                int p=upper_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p];
                if(now>=s.size()){
                    now=0;
                    ans++;
                }
            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
string s,t;
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {

        cin>>s>>t;
        for(int i=0; i<26; i++)
            q[i].clear(),f[i]=0;
        for(int i=0; i<s.size(); i++)
        {
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0; i<t.size(); i++)
        {
            if(f[t[i]-'a']==0)
                vis=1;
        }
        for(int i=0; i<26; i++)
        {
            q[i].pb(100000000);
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0; i<t.size(); i++)
            {
                if(now>=s.size())
                {
                    now=0;
                    ans++;
                }
                int x=t[i]-'a';
                int p=lower_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p]+1;

            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
string s,t;
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {

        cin>>s>>t;
        for(int i=0;i<26;i++)
            q[i].clear(),f[i]=0;
        for(int i=0;i<s.size();i++){
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0;i<t.size();i++)
        {
            if(f[t[i]-'a']==0) vis=1;
        }
        for(int i=0;i<26;i++)
        {
            q[i].pb(100000000);
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0;i<t.size();i++)
            {
                int x=t[i]-'a';
                int p=upper_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p];
                if(now>=s.size()){
                    now=0;
                    ans++;
                }
            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        string s,t;
        cin>>s>>t;
        for(int i=0;i<26;i++)
            q[i].clear(),f[i]=0;
        for(int i=0;i<s.size();i++){
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0;i<t.size();i++)
        {
            if(f[t[i]-'a']==0) vis=1;
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0;i<t.size();i++)
            {
                int x=t[i]-'a';
                int p=upper_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p];
                if(now>=s.size()){
                    now=0;
                    ans++;
                }
            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

vector<int>q[30];
string s,t;
int f[30];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {

        cin>>s>>t;
        for(int i=0; i<26; i++)
            q[i].clear(),f[i]=0;
        for(int i=0; i<s.size(); i++)
        {
            q[s[i]-'a'].pb(i);
            f[s[i]-'a']=1;
        }
        int vis=0;
        for(int i=0; i<t.size(); i++)
        {
            if(f[t[i]-'a']==0)
                vis=1;
        }
        for(int i=0; i<26; i++)
        {
            q[i].pb(100000000);
        }
        if(vis)
            cout<<-1<<endl;
        else
        {
            int ans=1;
            int now=0;
            for(int i=0; i<t.size(); i++)
            {

                int x=t[i]-'a';
                int p=lower_bound(q[x].begin(),q[x].end(),now)-q[x].begin();
                now=q[x][p]+1; if(now>=s.size())
                {
                    now=0;
                    ans++;
                }

            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    int t;
    cin >> t;
    while(t--){
        map<char, bool> exist;
        map<char, int> minInd;
        int cnt = 0;
        string s; cin >> s;
        string t; cin >> t;
        for(int i = 0; i < s.size(); i++){
            if(!exist[s[i]]){
                exist[s[i]] = true;
                minInd[s[i]] = i;
            }
        }
        for(int i = 0; i < t.size();){
            if(!exist[t[i]]){
                cnt = -1;
                break;
            }
            cnt++;
            int p = minInd[t[i]];
            while(i < t.size() && p < s.size()){
                if(exist[t[i]]){
                    if(s[p] == t[i]){
                        i++;
                    }
                }
                else{
                    cnt = -1;
                    i = t.size();
                    break;
                }
                p++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll 1000000007
vector<int> factors;
void fact(int n){
    for(int i = 0; i <= n/i; i++){
        while(n% i == 0){

        }
    }
}
int main()
{ FAST
    int t; cin >> t;
    while(t--){
        map<char, vector<int> > pos;
        string s, t; cin >> s >> t;
        for(int i = 0; i < s.size(); i++){
            pos[s[i]].pb(i);
        }
        int curr; bool ans = true; int cnt = 1;
        if(pos[t[0]].size() != 0){
            curr = pos[t[0]][0];
        }
        else{
            cnt = -1;
            ans = false;
        }
        for(int i = 0; i < t.length() - 1 && ans; i++){
            if(pos[t[i]].size() == 0 || pos[t[i + 1]].size() == 0){
                cnt = -1;
                break;
            }
            auto num = upper_bound(pos[t[i+1]].begin(), pos[t[i + 1]].end(), curr);
            if(num - pos[t[i + 1]].begin() != pos[t[i + 1]].end() - pos[t[i + 1]].begin()){
                curr = pos[t[i + 1]][num - pos[t[i + 1]].begin()];
            }
            else{
                cnt++;
                curr = pos[t[i + 1]][0];
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll 1000000007
vector<int> factors;
void fact(int n){
    for(int i = 0; i <= n/i; i++){
        while(n% i == 0){

        }
    }
}
int main()
{ FAST
    int t; cin >> t;
    while(t--){
        map<char, vector<int> > pos;
        string s, t; cin >> s >> t;
        for(int i = 0; i < s.size(); i++){
            pos[s[i]].pb(i);
        }
        int curr; bool ans = true; int cnt = 1;
        if(pos[t[0]].size() != 0){
            curr = pos[t[0]][0];
        }
        else{
            cnt = -1;
            ans = false;
        }
        for(int i = 0; i < t.length() - 1 && ans; i++){
            int lo = 0; int hi = pos[t[i + 1]].size() - 1; int mid = (lo + hi)/2; int best = -1;
            if(pos[t[i]].size() == 0 || pos[t[i + 1]].size() == 0){
                cnt = -1;
                break;
            }
            while(lo <= hi){
                mid = (lo + hi)/2;
                if(pos[t[i + 1]][mid] > curr){
                    best = pos[t[i + 1]][mid];
                    hi = mid - 1;
                }
                else{
                    lo = mid + 1;
                }
            }
            if(best != -1){
                curr = best;
            }
            else{
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    int t;
    cin >> t;
    while(t--){
        map<char, bool> exist;
        map<char, int> minInd;
        map<char, int> maxInd;
        int cnt = 0;
        string s; cin >> s;
        string t; cin >> t;
        for(int i = 0; i < s.size(); i++){
            if(!exist[s[i]]){
                exist[s[i]] = true;
                minInd[s[i]] = i;
            }
            maxInd[s[i]] = i;
        }
        bool have = false;
        for(int i = 0; i < t.size(); i++){
            if(!exist[t[i]]){
                cout << -1 << endl;
                have = true;
                i = t.size();
            }
            cnt++;
            if(i != t.size() - 1){
                while(minInd[t[i]] < maxInd[t[i+1]]){
                    i++;
                    if(i == t.size() - 1){
                        break;
                    }
                }
            }
        }
        if(!have){
            cout << cnt << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll 1000000007
vector<int> factors;
void fact(int n){
    for(int i = 0; i <= n/i; i++){
        while(n% i == 0){

        }
    }
}
int main()
{ FAST
    int t; cin >> t;
    while(t--){
        map<char, vector<int> > pos;
        string s, t; cin >> s >> t;
        for(int i = 0; i < s.size(); i++){
            pos[s[i]].pb(i);
        }
        int curr; bool ans = true; int cnt = 1;
        if(pos[t[0]].size() != 0){
            curr = pos[t[0]][0];
        }
        else{
            cnt = -1;
            ans = false;
        }
        for(int i = 0; i < t.length() - 1 && ans; i++){
            int lo = 0; int hi = pos[t[i + 1]].size() - 1; int mid = (lo + hi)/2; int best = -1;
            if(pos[t[i]].size() == 0 || pos[t[i + 1]].size() == 0){
                cnt = -1;
                break;
            }
            while(lo <= hi){
                mid = (lo + hi)/2;
                if(pos[t[i + 1]][mid] > curr){
                    best = pos[t[i + 1]][mid];
                    hi = mid - 1;
                }
                else{
                    lo = mid + 1;
                }
            }
            if(best != -1){
                curr = best;
            }
            else{
                cnt++;
                curr = pos[t[i + 1]][0];
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define o5 100020
using namespace std;

int P[o5][26];

int main(){
    int n;
    string s, t;
    cin >> n;
    while(n--){
        cin >> s >> t;
        int ls = s.length(), lt = t.length();
        for(int i=0; i<ls+10; i++){
            for(int j=0; j<26; j++){
                P[i][j] = -1;
            }
        }
        for(int i=ls-1; i>=0; i--){
            for(int j=0; j<26; j++){
                if(i!=ls-1) P[i][j]=P[i+1][j];
            }
            P[i][s[i]-'a']=i;
        }
        // for(int i=0; i<ls; i++){
        //     for(int j=0; j<26; j++){
        //         cout << P[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        int prev = -1, count = 0;
        bool f = true;
        for(int i=0; i<lt;){
            if(prev==-1 and P[0][t[i]-'a']==-1){
                f = false;
                break;
            }
            else if(prev==-1){
                count++;
                prev = P[0][t[i]-'a'];
                i++;
            }
            else{
                if(P[prev+1][t[i]-'a']==-1) prev=-1;
                else{
                    prev = P[prev+1][t[i]-'a'];
                    i++;
                }
            }
        }
        if(f) cout << count << endl;
        else cout << "-1" << endl;
    }
}


#include<bits/stdc++.h>
#define o5 100010
using namespace std;

int P[o5][26];

int main(){
    int n;
    string s, t;
    cin >> n;
    while(n--){
        cin >> s >> t;
        for(int i=s.length()-1; i>=0; i--){
            for(int j=0; j<26; j++){
                P[i][j] = 0;
            }
        }
        for(int i=s.length()-1; i>=0; i--){
            P[i][s[i]-'a']++;
            for(int j=0; j<26; j++){
                if(i<s.length()-1){
                    P[i][j]+=P[i+1][j];
                }
            }
        }
        // for(int i=0; i<s.length(); i++){
        //     for(int j=0; j<26; j++){
        //         cout << P[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        int prev = -1, count = 0;
        bool f = true;
        for(int i=0; i<t.length();){
            if(prev==-1 and P[0][t[i]-'a']==0){
                f = false;
                break;
            }
            else if(prev==-1){
                count++;
                for(int j=0; j<s.length(); j++){
                    if(j==s.length()-1 and P[j][t[i]-'a'] == 1) prev = j;
                    else if(P[j][t[i]-'a']-P[j+1][t[i]-'a']==1){
                        prev = j;
                        break;
                    }
                }
                i++;
            }
            else{
                bool fn = false;
                for(int j=prev+1; j<s.length(); j++){
                    if(j==s.length()-1 and P[j][t[i]-'a'] == 1){
                        prev = j;
                        fn = true;
                        i++;
                    }
                    else if(P[j][t[i]-'a']-P[j+1][t[i]-'a']==1){
                        prev = j;
                        fn = true;
                        i++;
                        break;
                    }
                }
                if(fn==false) prev=-1;
            }
        }
        if(f) cout << count << endl;
        else cout << "-1" << endl;
    }
}


#include<bits/stdc++.h>
#define o5 100010
using namespace std;

int P[o5][26];

int main(){
    int n;
    string s, t;
    cin >> n;
    while(n--){
        cin >> s >> t;
        for(int i=s.length()-1; i>=0; i--){
            for(int j=0; j<26; j++){
                P[i][j] = 0;
            }
        }
        for(int i=s.length()-1; i>=0; i--){
            P[i][s[i]-'a']++;
            for(int j=0; j<26; j++){
                if(i<s.length()-1){
                    P[i][j]+=P[i+1][j];
                }
            }
        }
        // for(int i=0; i<s.length(); i++){
        //     for(int j=0; j<26; j++){
        //         cout << P[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        int prev = -1, count = 0;
        bool f = true;
        for(int i=0; i<t.length();){
            if(prev==-1 and P[0][t[i]-'a']==0){
                f = false;
                break;
            }
            else if(prev==-1){
                count++;
                for(int j=0; j<s.length(); j++){
                    if(j==s.length()-1 and P[j][t[i]-'a'] == 1) prev = j;
                    else if(P[j][t[i]-'a']-P[j+1][t[i]-'a']==1){
                        prev = j;
                    }
                }
                i++;
            }
            else{
                bool fn = false;
                for(int j=prev+1; j<s.length(); j++){
                    if(j==s.length()-1 and P[j][t[i]-'a'] == 1){
                        prev = j;
                        fn = true;
                        i++;
                    }
                    else if(P[j][t[i]-'a']-P[j+1][t[i]-'a']==1){
                        prev = j;
                        fn = true;
                        i++;
                    }
                }
                if(fn==false) prev=-1;
            }
        }
        if(f) cout << count << endl;
        else cout << "-1" << endl;
    }
}


#include<bits/stdc++.h>
#define o5 100010
using namespace std;

int P[o5][26];

int main(){
    int n;
    string s, t;
    cin >> n;
    while(n--){
        cin >> s >> t;
        for(int i=s.length()-1; i>=0; i--){
            for(int j=0; j<26; j++){
                P[i][j] = 0;
            }
        }
        for(int i=s.length()-1; i>=0; i--){
            P[i][s[i]-'a']++;
            for(int j=0; j<26; j++){
                if(i<s.length()-1){
                    P[i][j]+=P[i+1][j];
                }
            }
        }
        // for(int i=0; i<s.length(); i++){
        //     for(int j=0; j<26; j++){
        //         cout << P[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        int prev = -1, count = 0;
        bool f = true;
        for(int i=0; i<t.length();){
            if(prev==-1 and P[0][t[i]-'a']==0){
                f = false;
                break;
            }
            else if(prev==-1){
                count++;
                for(int j=0; j<s.length(); j++){
                    if(j==s.length()-1 and P[j][t[i]-'a'] == 1) prev = j;
                    else if(P[j][t[i]-'a']-P[j+1][t[i]-'a']==1){
                        prev = j;
                        break;
                    }
                }
                i++;
            }
            else{
                bool fn = false;
                for(int j=prev+1; j<s.length(); j++){
                    if(j==s.length()-1 and P[j][t[i]-'a'] == 1){
                        prev = j;
                        fn = true;
                        i++;
                    }
                    else if(P[j][t[i]-'a']-P[j+1][t[i]-'a']==1){
                        prev = j;
                        fn = true;
                        i++;
                    }
                }
                if(fn==false) prev=-1;
            }
        }
        if(f) cout << count << endl;
        else cout << "-1" << endl;
    }
}


#include<bits/stdc++.h>
#define o5 100010
using namespace std;

int P[o5][26];

int main(){
    int n;
    string s, t;
    cin >> n;
    while(n--){
        cin >> s >> t;
        int ls = s.length(), lt = t.length();
        for(int i=ls-1; i>=0; i--){
            for(int j=0; j<26; j++){
                P[i][j] = 0;
            }
        }
        for(int i=ls-1; i>=0; i--){
            P[i][s[i]-'a']++;
            for(int j=0; j<26; j++){
                if(i<ls-1){
                    P[i][j]+=P[i+1][j];
                }
            }
        }
        // for(int i=0; i<ls; i++){
        //     for(int j=0; j<26; j++){
        //         cout << P[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        int prev = -1, count = 0;
        bool f = true;
        for(int i=0; i<lt;){
            if(prev==-1 and P[0][t[i]-'a']==0){
                f = false;
                break;
            }
            else if(prev==-1){
                count++;
                for(int j=0; j<ls; j++){
                    if(j==ls-1 and P[j][t[i]-'a'] == 1) prev = j;
                    else if(P[j][t[i]-'a']-P[j+1][t[i]-'a']==1){
                        prev = j;
                        break;
                    }
                }
                i++;
            }
            else{
                bool fn = false;
                for(int j=prev+1; j<ls; j++){
                    if(j==ls-1 and P[j][t[i]-'a'] == 1){
                        prev = j;
                        fn = true;
                        i++;
                    }
                    else if(P[j][t[i]-'a']-P[j+1][t[i]-'a']==1){
                        prev = j;
                        fn = true;
                        i++;
                        break;
                    }
                }
                if(fn==false) prev=-1;
            }
        }
        if(f) cout << count << endl;
        else cout << "-1" << endl;
    }
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;

const ld pi = acos(-1);

string s, t;

set < char > st;

ll i, j, ans, q, pos, minp[26][100501];

void solve(){
    cin >> s;

    cin >> t;

    st.clear();

    for (i = 0; i <= s.size(); i++){
        for (j = 0; j < 26; j++){
            minp[j][i] = MAXLL;
        }
    }

    for (i = 0; i < s.size(); i++){
        st.insert(s[i]);

        minp[s[i] - 'a'][i] = i;
    }

    for (i = 0; i < 26; i++){
        for (j = s.size() - 1; j >= 0; j--){
            minp[i][j] = min(minp[i][j], minp[i][j + 1]);
        }
    }

    for (i = 0; i < t.size(); i++){
        if (st.find(t[i]) == st.end()){
            cout << "-1" << endl;

            return;
        }
    }

    pos = 0;

    ans = 1;

    for (i = 0; i < t.size(); i++){
        if (minp[t[i] - 'a'][pos + 1] == MAXLL){
            ans++;

            pos = 0;
        }

        pos = minp[t[i] - 'a'][pos];
    }

    cout << ans << endl;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;

const ld pi = acos(-1);

set < pair < char, ll > > st1, st2;

set < pair < char, ll > > :: iterator iter;

string s, t;

ll i, ans, q, pos;

void solve(){
    cin >> s;

    cin >> t;

    st1.clear();
    st2.clear();

    for (i = 0; i < s.size(); i++){
        st1.insert({s[i], i});
    }

    for (i = 0; i < t.size(); i++){
        if (st1.lower_bound({t[i], 0}) == st1.end() || (*st1.lower_bound({t[i], 0})).fi != t[i]){
            cout << "-1" << endl;

            return;
        }
    }

    ans = 0;

    pos = -1;

    for (i = 0; i < t.size(); i++){
        iter = st2.upper_bound({t[i], pos});

        if (iter == st2.end() || (*iter).fi != t[i]){
            ans++;

            st2 = st1;

            pos = -1;

            iter = st2.upper_bound({t[i], pos});
        }

        pos = (*iter).se;

        st2.erase(iter);
    }

    cout << ans << endl;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;

const ld pi = acos(-1);

multiset < pair < char, ll > > st1, st2;

string s, t;

ll i, ans, q, pos;

void solve(){
    cin >> s;

    cin >> t;

    st1.clear();
    st2.clear();

    for (i = 0; i < s.size(); i++){
        st1.insert({s[i], i});
    }

    for (i = 0; i < t.size(); i++){
        if (st1.lower_bound({t[i], 0}) == st1.end()){
            cout << "-1" << endl;

            return;
        }
    }

    ans = 0;

    pos = 0;

    for (i = 0; i < t.size(); i++){
        if (st2.lower_bound({t[i], 0}) == st2.end() || (*st2.lower_bound({t[i], 0})).se < pos){
            ans++;

            st2 = st1;
        }

        pos = (*st2.lower_bound({t[i], 0})).se;

        st2.erase(st2.lower_bound({t[i], 0}));
    }

    cout << ans << endl;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;

const ld pi = acos(-1);

set < pair < char, ll > > st1, st2;

string s, t;

ll i, ans, q, pos;

void solve(){
    cin >> s;

    cin >> t;

    st1.clear();
    st2.clear();

    for (i = 0; i < s.size(); i++){
        st1.insert({s[i], i});
    }

    for (i = 0; i < t.size(); i++){
        if (st1.lower_bound({t[i], 0}) == st1.end()){
            cout << "-1" << endl;

            return;
        }
    }

    ans = 0;

    pos = -1;

    for (i = 0; i < t.size(); i++){
        if (st2.upper_bound({t[i], pos}) == st2.end() || (*st2.upper_bound({t[i], pos})).fi != t[i]){
            ans++;

            st2 = st1;

            pos = -1;
        }

        pos = (*st2.upper_bound({t[i], pos})).se;

        st2.erase(st2.lower_bound({t[i], pos}));
    }

    cout << ans << endl;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;

const ld pi = acos(-1);

set < pair < char, ll > > st1, st2;

string s, t;

ll i, ans, q, pos;

void solve(){
    cin >> s;

    cin >> t;

    st1.clear();
    st2.clear();

    for (i = 0; i < s.size(); i++){
        st1.insert({s[i], i});
    }

    for (i = 0; i < t.size(); i++){
        if (st1.lower_bound({t[i], 0}) == st1.end() || (*st1.lower_bound({t[i], 0})).fi != t[i]){
            cout << "-1" << endl;

            return;
        }
    }

    ans = 0;

    pos = -1;

    for (i = 0; i < t.size(); i++){
        if (st2.upper_bound({t[i], pos}) == st2.end() || (*st2.upper_bound({t[i], pos})).fi != t[i]){
            ans++;

            st2 = st1;

            pos = -1;
        }

        pos = (*st2.upper_bound({t[i], pos})).se;

        st2.erase(st2.lower_bound({t[i], pos}));
    }

    cout << ans << endl;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;

const ld pi = acos(-1);

string s, t;

set < char > st;

ll i, j, ans, q, pos, minp[26][100501];

void solve(){
    cin >> s;

    cin >> t;

    st.clear();

    for (i = 0; i <= s.size(); i++){
        for (j = 0; j < 26; j++){
            minp[j][i] = MAXLL;
        }
    }

    for (i = 0; i < s.size(); i++){
        st.insert(s[i]);

        minp[s[i] - 'a'][i] = i;
    }

    for (i = 0; i < 26; i++){
        for (j = s.size() - 1; j >= 0; j--){
            minp[i][j] = min(minp[i][j], minp[i][j + 1]);
        }
    }

    for (i = 0; i < t.size(); i++){
        if (st.find(t[i]) == st.end()){
            cout << "-1" << endl;

            return;
        }
    }

    pos = -1;

    ans = 1;

    for (i = 0; i < t.size(); i++){
        if (minp[t[i] - 'a'][pos + 1] == MAXLL){
            ans++;

            pos = -1;
        }

        pos = minp[t[i] - 'a'][pos + 1];
    }

    cout << ans << endl;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;

const ld pi = acos(-1);

set < pair < char, ll > > st1, st2;

string s, t;

ll i, ans, q, pos;

void solve(){
    cin >> s;

    cin >> t;

    st1.clear();
    st2.clear();

    for (i = 0; i < s.size(); i++){
        st1.insert({s[i], i});
    }

    for (i = 0; i < t.size(); i++){
        if (st1.lower_bound({t[i], 0}) == st1.end()){
            cout << "-1" << endl;

            return;
        }
    }

    ans = 0;

    pos = 0;

    for (i = 0; i < t.size(); i++){
        if (st2.lower_bound({t[i], 0}) == st2.end() || st2.lower_bound({t[i], pos}) == st2.end()){
            ans++;

            st2 = st1;
        }

        pos = (*st2.lower_bound({t[i], 0})).se;

        st2.erase(st2.lower_bound({t[i], 0}));
    }

    cout << ans << endl;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;

const ld pi = acos(-1);

set < pair < char, ll > > st1, st2;

string s, t;

ll i, ans, q, pos;

void solve(){
    cin >> s;

    cin >> t;

    st1.clear();
    st2.clear();

    for (i = 0; i < s.size(); i++){
        st1.insert({s[i], i});
    }

    for (i = 0; i < t.size(); i++){
        if (st1.lower_bound({t[i], 0}) == st1.end()){
            cout << "-1" << endl;

            return;
        }
    }

    ans = 0;

    pos = 0;

    for (i = 0; i < t.size(); i++){
        if (st2.lower_bound({t[i], 0}) == st2.end() || st2.lower_bound({t[i], pos}) == st2.end()){
            ans++;

            st2 = st1;
        }

        pos = (*st2.lower_bound({t[i], pos})).se;

        st2.erase(st2.lower_bound({t[i], pos}));
    }

    cout << ans << endl;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        solve();
    }

    return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<map>

#define ll long long
#define MAX 100005
using namespace std;

string s,t;
int next_jump[MAX][30];

int main( )
{
	ll T;
	cin >> T;
	while(T--){
		cin >> s >> t;
		int l1 = s.length(),l2 = t.length();
		memset(next_jump,-1,sizeof(next_jump));
		for(int i = 0; i < l1; i++){
			for(int j = i - 1; j >= 0; j--){
				if(s[i] == s[j]){
					break;
				}next_jump[j][s[i] - 'a'] = i;

			}
		}
		next_jump[0][s[0] - 'a'] = 0;
	//	cout << "1" << endl;
		int i = 0,j = 0;
		int dt = 1000;
		int ans = 0;
		int pre_i = -1;
		while(dt--&& i < l2){
			cout << "::" << endl;
			for(j = 0; j < l1; ){
				cout << i << "||" << endl;
				if(s[j] == t[i]){
					i++;
				}

				if(next_jump[j][t[i] - 'a'] == -1){
					j = l1;
				}else{
					j = next_jump[j][t[i] - 'a'];
				}
			}
			if(pre_i == i){
				break;
			}else{
				pre_i = i;
			}
			ans++;
		}
		if(i < l2){
			cout << "-1" << endl;
		}else
			cout << ans << endl;
	}
	return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cstring>
using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;

int main()
{
	string sa, sb;
	cin >> sa;
	cin >> sb;
	ll a[26], b[26];
	fill(a, a+26, 0);
	fill(b, b+26, 0);

	for(size_t i = 0; i < sb.size(); i++) {
		b[sb[i] - 'a']++;
		if(sa[i] != '?') {
			a[sa[i] - 'a']++;
		}
	}

	if(sa.size() < sb.size()) {
		cout << 0 << endl;
		return 0;
	}

	ll res = 0;
	ll cnt = 0;

	ll n = sb.size();

	for(int i = 0; i < 26; i++) {
		if(a[i] <= b[i]) {
			cnt++;
		}
	}

	if(cnt == 26) {
		res++;
	}

	for(size_t i = n; i < sa.size(); i++) {
		if(sa[i - n] != '?') {
			a[sa[i - n] - 'a']--;
		}

		if(sa[i] != '?') {
			a[sa[i] - 'a']++;
		}

		cnt = 0;
		for(int j = 0; j < 26; j++) {
			if(a[j] <= b[j]) {
				cnt++;
			}
		}

		if(cnt == 26) {
			res++;
		}
	}

	cout << res << endl;
	return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int comp(string a, string b)
{
  int res = 1;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  string ne;
  ne = a.substr(a.rfind("?") + 1, a.size());
  for(int i = 0; i < ne.size(); i++)
  {
    int pos = b.find(ne[i]);
    if (pos == -1) res = 0;
    else b[pos] = '*';
  }
  return res;
}

int main()
{
  string s, p;
  cin >> s;
  cin >> p;
  int ans = 0;
  int len = p.size();
  for(int i = len - 1; i < s.size(); i++)
  {
    if(p.find(s[i]) != -1 || s[i] == '?')
    {
      if (comp(s.substr(i - len + 1, len), p) == 1) ans++;
    }
    else
    {
      i = i + len - 1;
    }
  }
  cout << ans;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cstring>
using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;

int main()
{
	string sa, sb;
	cin >> sa;
	cin >> sb;
	int a[26], b[26];
	fill(a, a+26, 0);
	fill(b, b+26, 0);

	for(size_t i = 0; i < sb.size(); i++) {
		b[sb[i] - 'a']++;
		if(sa[i] != '?') {
			a[sa[i] - 'a']++;
		}
	}

	for(int i = 0; i < 26; i++) {

		cout << a[i] << " " << b[i] << endl;
	}
	ll res = 0;
	ll cnt = 0;

	ll n = sb.size();

	for(int i = 0; i < 26; i++) {
		if(a[i] <= b[i]) {
			cnt++;
		}
	}

	if(cnt == 26) {
		res++;
	}

	for(size_t i = n; i < sa.size(); i++) {
		if(sa[i - n] != '?') {
			a[sa[i - n] - 'a']--;
		}

		if(sa[i] != '?') {
			a[sa[i] - 'a']++;
		}
		cnt = 0;
		for(int j = 0; j < 26; j++) {
			if(a[j] <= b[j]) {
				cnt++;
			}
		}

		if(cnt == 26) {
			res++;
		}
	}

	cout << res << endl;
	return 0;
}