You are given two strings $s$ and $t$ consisting of lowercase Latin letters. Also you have a string $z$ which is initially empty. You want string $z$ to be equal to string $t$. You can perform the following operation to achieve this: append any subsequence of $s$ at the end of string $z$. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. For example, if $z = ac$, $s = abcde$, you may turn $z$ into following strings in one operation:   $z = acace$ (if we choose subsequence $ace$);  $z = acbcd$ (if we choose subsequence $bcd$);  $z = acbce$ (if we choose subsequence $bce$). 

Note that after this operation string $s$ doesn't change.

Calculate the minimum number of such operations to turn string $z$ into string $t$. 


-----Input-----

The first line contains the integer $T$ ($1 \le T \le 100$) — the number of test cases.

The first line of each testcase contains one string $s$ ($1 \le |s| \le 10^5$) consisting of lowercase Latin letters.

The second line of each testcase contains one string $t$ ($1 \le |t| \le 10^5$) consisting of lowercase Latin letters.

It is guaranteed that the total length of all strings $s$ and $t$ in the input does not exceed $2 \cdot 10^5$.


-----Output-----

For each testcase, print one integer — the minimum number of operations to turn string $z$ into string $t$. If it's impossible print $-1$.


-----Example-----
Input
3
aabce
ace
abacaba
aax
ty
yyt

Output
1
-1
3

Difficulty: MEDIUM_HARD

Solutions:
from bisect import bisect_right as br
for t in range(int(input())):
	s = input()
	t = input()
	alp = 'abcdefghijklmnopqrstuvwxyz'
	dic = {}
	for i in alp:
		dic[i] = []
	for i in range(len(s)):
		dic[s[i]].append(i)
	prev = -1
	ans = 1
	for i in t:
		idx = br(dic[i], prev)
		if len(dic[i]) == 0:
			ans = -1
			break
		if idx == len(dic[i]):
			ans += 1
			prev = dic[i][0]
		else:
			prev = dic[i][idx]
	print(ans)


T = int(input())
for i in range(T):
	s = input()
	t = input()
	n = len(s)
	m = len(t)
	d = []
	for _ in range(26):
		d.append([])
	if set(s).intersection(set(t)) != set(t):
		print(-1)
	else:
		for j in range(n):
			while len(d[ord(s[j]) - 97]) < j + 1:
				d[ord(s[j]) - 97].append(j)
		for j in range(n):
			d[ord(s[j]) - 97] += [-1] * (n - len(d[ord(s[j]) - 97]))
		q = 0
		k = 1
		for j in range(m):
			if q == n:
				k += 1
				q = d[ord(t[j]) - 97][0] + 1
			elif d[ord(t[j]) - 97][q] == -1:
				k += 1
				q = d[ord(t[j]) - 97][0] + 1
			elif q > d[ord(t[j]) - 97][q]:
				k += 1
				q = d[ord(t[j]) - 97][0] + 1
			else:
				q = d[ord(t[j]) - 97][q] + 1
		print(k)


T = int(input())
for _ in range(T):
	s = input()
	t = input()
	n = len(s)
	pos = [[] for _ in range(26)]
	for i in range(n):
		pos[ord(s[i]) - 97].append(i)
	val = -1
	ans = 1
	for x in t:
		p = pos[ord(x) - 97]
		if not p:
			ans = -1
			break
		(l, r) = (0, len(p) - 1)
		while l <= r:
			mid = (l + r) // 2
			if p[mid] > val:
				r = mid - 1
			else:
				l = mid + 1
		if l < len(p):
			val = p[l]
		else:
			ans += 1
			val = p[0]
	print(ans)


from collections import defaultdict
import bisect
for _ in range(int(input())):
	(d, total, k, current) = (defaultdict(list), 1, 0, -1)
	s = input()
	t = input()
	for i in range(len(s)):
		d[s[i]].append(i)
	while k != len(t):
		if len(d[t[k]]) == 0:
			total = -1
			break
		current = bisect.bisect_right(d[t[k]], current)
		if current >= len(d[t[k]]):
			current = -1
			total += 1
		else:
			current = d[t[k]][current]
			k += 1
	print(total)


from collections import defaultdict
for _ in range(int(input())):
	a = input()
	b = input()
	f = 0
	cnt = 0
	x = -1
	d = defaultdict(list)
	for i in range(len(a)):
		d[a[i]].append(i)
	ma = -1
	for i in range(len(b)):
		l = d[b[i]]
		if len(l) == 0:
			cnt = -2
			break
		(beg, end) = (0, len(l) - 1)
		while beg <= end:
			mid = (beg + end) // 2
			if l[mid] > x:
				end = mid - 1
			else:
				beg = mid + 1
		if beg < len(l):
			x = l[beg]
		else:
			cnt += 1
			x = l[0]
	print(cnt + 1)


def upperBound(array, k):
	low = 0
	high = len(array)
	while low < high:
		mid = (low + high) // 2
		if array[mid] < k:
			low = mid + 1
		else:
			high = mid
	return low
for _ in range(int(input())):
	s = input().strip()
	t = input().strip()
	array = [[] for _ in range(26)]
	for i in range(len(s)):
		array[ord(s[i]) - ord('a')].append(i)
	temp = -1
	ops = 1
	flag = True
	for i in t:
		k = ord(i) - ord('a')
		if len(array[k]) == 0:
			flag = False
			break
		if temp == -1:
			temp = array[k][0]
			continue
		klag = False
		tt = upperBound(array[k], temp)
		if tt == len(array[k]):
			ops += 1
			temp = array[k][0]
			continue
		if array[k][tt] == temp:
			tt += 1
		if tt < len(array[k]):
			klag = True
			temp = array[k][tt]
		if not klag:
			ops += 1
			temp = array[k][0]
			continue
	if flag:
		print(ops)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	s = str(input())
	t = str(input())
	INF = 10 ** 18
	n = len(s)
	m = len(t)
	X = [[INF] * 26 for i in range(n + 5)]
	for i in reversed(range(n)):
		for j in range(26):
			X[i][j] = X[i + 1][j]
		X[i][ord(s[i]) - ord('a')] = i
	ans = 1
	pos = 0
	for i in range(m):
		if pos == n:
			pos = 0
			ans += 1
		if X[pos][ord(t[i]) - ord('a')] == INF:
			pos = 0
			ans += 1
			if X[pos][ord(t[i]) - ord('a')] == INF and pos == 0:
				ans = INF
				break
		pos = X[pos][ord(t[i]) - ord('a')] + 1
	if ans == INF:
		print(-1)
	else:
		print(ans)


from collections import defaultdict

def search(a, t):
	l = 0
	r = len(a) - 1
	ans = -1
	while r - l >= 0:
		mid = (l + r) // 2
		if a[mid] < t:
			l = mid + 1
		if a[mid] >= t:
			r = mid - 1
			ans = mid
	return ans
t = int(input())
for _ in range(t):
	s = input().strip()
	t = input().strip()
	ss = set(s)
	st = set(t)
	bad = False
	for i in st:
		if i not in ss:
			bad = True
	if bad:
		print(-1)
	else:
		d = defaultdict(list)
		for i in range(len(s)):
			d[s[i]].append(i)
		ct = 0
		ans = 1
		for i in range(len(t)):
			if ct > d[t[i]][-1]:
				ans += 1
				ct = d[t[i]][0] + 1
			else:
				q = search(d[t[i]], ct)
				ct = d[t[i]][q] + 1
		print(ans)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	s = S()
	n = len(s)
	a = [[-1 for i in range(n)] for i in range(26)]
	for i in range(n):
		a[ord(s[i]) - 97][i] = i
	for i in range(26):
		val = -1
		for j in range(n - 1, -1, -1):
			if a[i][j] != -1:
				val = a[i][j]
			else:
				a[i][j] = val
	ans = True
	flg = True
	stp = 0
	t = list(map(lambda x: ord(x) - 97, S()))
	ln = len(t)
	for i in range(ln):
		if flg:
			stp += 1
			if a[t[i]][0] != -1:
				ind = a[t[i]][0] + 1
			else:
				ans = False
				break
		if i + 1 < ln and ind < n and (a[t[i + 1]][ind] != -1):
			ind = a[t[i + 1]][ind] + 1
			flg = False
		else:
			flg = True
	print(stp if ans else -1)


from bisect import bisect_right
from collections import defaultdict

def solve():
	s = input()
	t = input()
	heads = defaultdict(int)
	occurrences = defaultdict(list)
	for (i, ch) in enumerate(s):
		occurrences[ch].append(i)
	ops = 1
	last = -1
	for ch in t:
		if len(occurrences[ch]) == 0:
			print('-1')
			return
		p = bisect_right(occurrences[ch], last, heads[ch])
		if p == len(occurrences[ch]) or last > occurrences[ch][p]:
			last = -1
			ops += 1
			heads = defaultdict(int)
		else:
			heads[ch] = p
		last = occurrences[ch][heads[ch]]
	print(ops)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	s = list(data())
	t = list(data())
	d = dd(list)
	for i in range(len(s)):
		d[s[i]].append(i)
	r = True
	i = 0
	index = []
	answer = 0
	while i < len(t):
		if t[i] not in d.keys():
			r = False
			break
		if not index:
			answer += 1
			index.append(d[t[i]][0])
		else:
			temp = br(d[t[i]], index[-1])
			if temp == len(d[t[i]]):
				temp -= 1
			if d[t[i]][temp] <= index[-1]:
				i -= 1
				index = []
			else:
				index.append(d[t[i]][temp])
		i += 1
	if r:
		out(str(answer) + '\n')
		continue
	out('-1\n')


for _ in range(int(input())):
	s = list(map(lambda c: ord(c) - 97, input()))
	n = len(s)
	t = list(map(lambda c: ord(c) - 97, input()))
	if len(set(t) - set(s)) > 0:
		print(-1)
		continue
	next_c = [-1] * 26
	dp = [[-1] * 26 for _ in range(n)]
	for i in range(n - 1, -1, -1):
		next_c[s[i]] = i
	for i in range(n - 1, -1, -1):
		for j in range(26):
			dp[i][j] = next_c[j]
		next_c[s[i]] = i
	pos = -1
	ans = 1
	for c in t:
		if pos >= dp[pos][c]:
			ans += 1
		pos = dp[pos][c]
	print(ans)


import bisect
from collections import defaultdict

def solve():
	s = input()
	t = input()
	pos = defaultdict(list)
	for (i, ch) in enumerate(s):
		pos[ch].append(i)
	prev = -1
	ans = 1
	for ch in t:
		if ch not in pos:
			print('-1')
			return
		cur_idx = bisect.bisect_left(pos[ch], prev + 1)
		if cur_idx >= len(pos[ch]):
			cur = pos[ch][0]
			ans += 1
		else:
			cur = pos[ch][cur_idx]
		prev = cur
	print(ans)
for _ in range(int(input())):
	solve()


import bisect
T = int(input())
for tt in range(T):
	s = input()
	t = input()
	len_s = len(s)
	len_t = len(t)
	ans = 0
	record = [[] for i in range(26)]
	for i in range(len_s):
		record[ord(s[i]) - ord('a')].append(i)
	len_record = [0 for i in range(26)]
	for i in range(26):
		len_record[i] = len(record[i])
	tj = 0
	while tj < len_t:
		si = 0
		while si < len_s:
			if tj >= len_t:
				break
			now = ord(t[tj]) - ord('a')
			if not record[now]:
				ans = -1
				break
			left = bisect.bisect_left(record[now], si, 0, len_record[now])
			if left == len_record[now]:
				break
			else:
				tj += 1
				si = record[now][left] + 1
		if ans == -1:
			break
		else:
			ans += 1
	print(ans)


tests = int(input())
while tests > 0:
	s = input()
	t = input()
	dpList = []
	i = len(s) - 1
	cd = {}
	while i >= 0:
		cd[s[i]] = i
		dpList.append(cd.copy())
		i -= 1
	dpList = dpList[::-1]
	dpList.append({})
	ans = 1
	i = 0
	ci = 0
	while i < len(t):
		val = t[i]
		nextIndex = len(s) + 1
		if val in dpList[ci]:
			ci = dpList[ci][val] + 1
			i += 1
		else:
			if ci == 0:
				ans = -1
				break
			ans += 1
			ci = 0
	print(ans)
	tests -= 1


import sys
from bisect import bisect_left
from collections import defaultdict
for _ in range(int(input())):
	s = input()
	t = input()
	inds = defaultdict(list)
	for i in range(len(s)):
		inds[s[i]].append(i)
	cnt = 1
	ti = 0
	si = 0
	for ti in range(len(t)):
		if t[ti] not in inds:
			print(-1)
			break
		ci = bisect_left(inds[t[ti]], si)
		if ci != len(inds[t[ti]]):
			si = inds[t[ti]][ci] + 1
		else:
			si = inds[t[ti]][0] + 1
			cnt += 1
	else:
		print(cnt)


for t in range(int(input())):
	s = input()
	z = input()
	c = []
	a = []
	plus = 0
	for i in z:
		c.append(i)
		plus += 1
	count = 0
	for i in s:
		a.append(i)
		count += 1
	b = [[0 for i in range(26)] for j in range(count + 1)]
	alpha = [9999999 for i in range(26)]
	for i in range(count):
		alpha[ord(a[i]) - 97] = min(alpha[ord(a[i]) - 97], i)
	i = count - 1
	while i >= 1:
		b[i][ord(a[i]) - 97] = i
		b[i - 1] = b[i][:]
		i -= 1
	add = 1
	one = alpha[ord(c[0]) - 97]
	if one == 9999999:
		print(-1)
		continue
	i = 0
	while True:
		i += 1
		if i == plus:
			flag = 1
			break
		two = ord(c[i]) - 97
		if b[one + 1][two] == 0:
			add += 1
			one = alpha[ord(c[i]) - 97]
			if one == 9999999:
				flag = -1
				break
		else:
			one = b[one + 1][two]
	if flag == -1:
		print(-1)
	else:
		print(add)


from collections import defaultdict, deque
import bisect

def case():
	s = input()
	t = input()
	d = defaultdict(list)
	for i in range(len(s)):
		d[s[i]].append(i)
	for i in t:
		if not len(d[i]):
			print(-1)
			return
	count = 0
	i = 0
	prev = -1
	while i < len(t):
		if bisect.bisect_right(d[t[i]], prev) < len(d[t[i]]):
			prev = d[t[i]][bisect.bisect_right(d[t[i]], prev)]
			i += 1
		else:
			prev = -1
			count += 1
	print(count + 1)
for _ in range(int(input())):
	case()


import string
import bisect

def getNextLarger(arr, val):
	index = bisect.bisect_right(arr, val)
	if index == len(arr):
		return None
	return arr[index]

def isImpossible(s, t):
	s = set(s)
	for letter in t:
		if letter not in s:
			return True
	return False

def solve(s, t):
	if isImpossible(s, t):
		return -1
	letterOccurrences = {letter: [] for letter in string.ascii_lowercase}
	for (index, letter) in enumerate(s):
		letterOccurrences[letter].append(index)
	t = list(t)
	t.reverse()
	numOperations = 0
	while t:
		lastUsedIndexInS = -1
		numOperations += 1
		while t:
			nextLetter = t[-1]
			nextAppearanceOfLetter = getNextLarger(letterOccurrences[nextLetter], lastUsedIndexInS)
			if nextAppearanceOfLetter is None:
				break
			t.pop()
			lastUsedIndexInS = nextAppearanceOfLetter
	return numOperations
n = int(input())
for _ in range(n):
	s = input()
	t = input()
	print(solve(s, t))


import sys
import bisect
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	s1 = input().strip()
	s2 = input().strip()
	locations = {}
	for i in range(len(s1)):
		if s1[i] in locations:
			locations[s1[i]].append(i)
		else:
			locations[s1[i]] = [i]
	(a, b) = (len(s1), len(s2) - 1)
	(i, j) = (a, b)
	g = 0
	ans = 1
	out = 0
	while j >= 0:
		if s2[j] not in locations:
			ans = -1
			break
		i = bisect.bisect_right(locations[s2[j]], i) - 1
		if i < 0:
			i = a
			ans += 1
		else:
			i = locations[s2[j]][i] - 1
			j -= 1
	print(ans)


from bisect import bisect_right
for t in range(int(input())):
	s = input()
	t = input()
	sd = {i: [] for i in range(26)}
	for i in range(len(s)):
		sd[ord(s[i]) - ord('a')].append(i)
	res = 1
	last = -1
	for i in t:
		a = ord(i) - ord('a')
		if sd[a] == []:
			res = -1
			break
		temp = bisect_right(sd[a], last)
		if temp >= len(sd[a]):
			res += 1
			last = sd[a][0]
		else:
			last = sd[a][temp]
	print(res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import bisect
testcases = int(input())
for j in range(testcases):
	strings = input()
	stringt = input()
	dict1 = {}
	moves = 1
	for s in range(len(strings)):
		if not strings[s] in dict1:
			dict1[strings[s]] = [s]
		else:
			dict1[strings[s]].append(s)
	broke = False
	cv = -1
	chain = 0
	outy = ''
	for s in range(len(stringt)):
		if stringt[s] in dict1:
			ind = min(bisect.bisect_left(dict1[stringt[s]], cv + 1), len(dict1[stringt[s]]) - 1)
			if dict1[stringt[s]][ind] <= cv:
				moves += 1
				cv = dict1[stringt[s]][0]
			else:
				cv = dict1[stringt[s]][ind]
		else:
			broke = True
			break
	if broke == True:
		print(-1)
	else:
		print(moves)


from bisect import bisect_right

def solve(s, t):
	pos = [[] for _ in range(26)]
	for (i, c) in enumerate(s):
		x = ord(c) - ord('a')
		pos[x].append(i)
	cur = -1
	ans = 1
	for (i, c) in enumerate(t):
		x = ord(c) - ord('a')
		if pos[x] == []:
			print(-1)
			return
		it = bisect_right(pos[x], cur)
		if it == len(pos[x]):
			it = 0
			ans += 1
		cur = pos[x][it]
	print(ans)

def main():
	tc = int(input())
	for _ in range(tc):
		s = input()
		t = input()
		solve(s, t)
main()


T = int(input())
for _ in range(T):
	s = input()
	t = input()
	order = {}
	for (i, char) in enumerate(s):
		if char in order:
			order[char].append(i)
		else:
			order[char] = [i]
	answer = 1
	prev = -1
	for char in t:
		if char not in order:
			answer = -1
			break
		a = 0
		b = len(order[char]) - 1
		if order[char][b] <= prev:
			answer += 1
			prev = -1
		if order[char][a] > prev:
			prev = order[char][a]
		else:
			while b - a > 1:
				m = (a + b) // 2
				if order[char][m] <= prev:
					a = m
				else:
					b = m
			prev = order[char][b]
	print(answer)


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	n = len(s)
	pos = [[-1 for i in range(26)] for i in range(n)]
	for i in range(n - 1, -1, -1):
		if i + 1 < n:
			pos[i] = pos[i + 1].copy()
		pos[i][ord(s[i]) - ord('a')] = i
	ans = 1
	prev = 0
	n1 = len(t)
	for i in range(n1):
		ch = ord(t[i]) - ord('a')
		if pos[0][ch] == -1:
			ans = -1
			break
		if prev >= n:
			ans += 1
			prev = pos[0][ch] + 1
		elif pos[prev][ch] == -1:
			ans += 1
			prev = pos[0][ch] + 1
		else:
			prev = pos[prev][ch] + 1
	print(ans)


import bisect
t = int(input())
while t:
	s = input()
	x = input()
	apr = [[] for _ in range(26)]
	for i in range(len(s)):
		apr[ord(s[i]) - ord('a')].append(i)
	ans = 0
	px = 0
	ps = 0
	inv = False
	while px < len(x):
		moved = False
		while px < len(x) and ps < len(s):
			apr_pos = ord(x[px]) - ord('a')
			pos_found = bisect.bisect_left(apr[apr_pos], ps)
			if pos_found == len(apr[apr_pos]):
				break
			else:
				moved = True
				ps = apr[apr_pos][pos_found] + 1
				px += 1
		if not moved:
			inv = True
			break
		else:
			ans += 1
			ps = 0
	if inv:
		print(-1)
	else:
		print(ans)
	t -= 1


import sys
import math as mt
import bisect as bi
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	f = cc.defaultdict(list)
	s = input().strip()
	t = input().strip()
	if set(t) - set(s):
		print(-1)
		continue
	for i in range(len(s)):
		f[s[i]].append(i)
	mx = f[t[0]][0]
	ans = 1
	for i in range(1, len(t)):
		temp = bi.bisect_right(f[t[i]], mx)
		if temp == len(f[t[i]]):
			ans += 1
			mx = f[t[i]][0]
		else:
			mx = f[t[i]][temp]
	print(ans)


import bisect
t = int(input())
for i in range(t):
	s = input()
	t = input()
	dic = {}
	for j in range(len(s)):
		if s[j] in dic:
			dic[s[j]].append(j)
		else:
			dic[s[j]] = [j]
	count = 0
	prev = -1
	flag = False
	for j in range(len(t)):
		char = t[j]
		if char not in dic:
			flag = True
			break
		index = bisect.bisect_right(dic[char], prev, 0, len(dic[char]))
		if index >= len(dic[char]):
			index = bisect.bisect_right(dic[char], -1, 0, len(dic[char]))
			count += 1
		prev = dic[char][index]
	if flag:
		print(-1)
	else:
		print(count + 1)


for h in range(int(input())):
	s = input()
	t = input()
	dp = [[float('inf') for i in range(26)] for i in range(len(s) + 1)]
	dp[-2][ord(s[-1]) - ord('a')] = len(s) - 1
	for i in range(len(s) - 2, -1, -1):
		for j in range(26):
			dp[i][j] = dp[i + 1][j]
		dp[i][ord(s[i]) - ord('a')] = i
	ans = 1
	l1 = -1
	l2 = 0
	while l2 < len(t):
		if l1 == -1 and dp[l1 + 1][ord(t[l2]) - ord('a')] == float('inf'):
			print(-1)
			break
		elif dp[l1 + 1][ord(t[l2]) - ord('a')] != float('inf'):
			l1 = dp[l1 + 1][ord(t[l2]) - ord('a')]
			l2 += 1
		else:
			l1 = -1
			ans += 1
	else:
		print(ans)


import random
for _ in range(int(input())):
	s = input()
	t = input()
	pos = {}
	for i in range(len(s)):
		if s[i] in pos:
			pos[s[i]].append(i)
		else:
			pos[s[i]] = [i]

	def find(arr, target):
		l = 0
		r = len(arr) - 1
		while l < r:
			mid = l + r >> 1
			if arr[mid] <= target:
				l = mid + 1
			else:
				r = mid
		return l
	ans = 1
	last = -1
	for (i, let) in enumerate(t):
		if let in pos:
			ind = find(pos[let], last)
			if pos[let][ind] <= last:
				ans += 1
				last = pos[let][0]
			else:
				last = pos[let][ind]
		else:
			print(-1)
			break
	else:
		print(ans)


LETTERS = set(list('abcdefghijklmnopqrstuvwxyz'))

def PrepareLettersIndices(s):
	s_letters = dict()
	for letters in LETTERS:
		s_letters[letters] = []
	for i in range(len(s)):
		s_letters[s[i]].append(i)
	return s_letters

def BinSearch(num, numbers):
	if num >= numbers[-1]:
		return -1
	if num < numbers[0]:
		return numbers[0]
	left = 0
	right = len(numbers) - 1
	mid = (left + right) // 2
	while not numbers[mid] <= num < numbers[mid + 1]:
		if numbers[mid] <= num:
			left = mid
		else:
			right = mid
		mid = (left + right) // 2
	return numbers[mid + 1]

def main():
	T = int(input())
	for i in range(T):
		s = list(input())
		t = list(input())
		s_set = set(s)
		t_set = set(t)
		if not t_set.issubset(s_set):
			print(-1)
			continue
		letters_dict = PrepareLettersIndices(s)
		result = 1
		current = -1
		j = 0
		while j < len(t):
			new = BinSearch(current, letters_dict[t[j]])
			if new == -1:
				result += 1
				current = -1
			else:
				current = new
				j += 1
		print(result)
	return 0
main()


from bisect import bisect_left
import collections

def main():
	times = int(input().strip())
	for _ in range(times):
		s = input().strip()
		t = input().strip()
		if not set(s).issuperset(set(t)):
			print('-1')
			continue
		d = collections.defaultdict(list)
		for i in range(len(s)):
			d[s[i]].append(i)
		(idx, res) = (-1, 1)
		for c in t:
			newIdx = bisect_left(d[c], idx + 1)
			if newIdx == len(d[c]):
				idx = d[c][bisect_left(d[c], -1)]
				res += 1
			else:
				idx = d[c][newIdx]
		print(res)
main()


import math
import functools

@functools.lru_cache(maxsize=8128)
def quick_find(s, letter, start_index):
	return s.find(letter, start_index)

def convert(s, t):
	start_index = 0
	steps = 1
	i = 0
	while i < len(t):
		letter = t[i]
		index = quick_find(s, letter, start_index)
		if index == -1 and start_index == 0:
			return -1
		if index == -1:
			start_index = 0
			steps += 1
			i -= 1
		start_index = index + 1
		i += 1
	return steps
T = int(input())
for i in range(T):
	s = input()
	t = input()
	steps = convert(s, t)
	print(steps)


import sys
import bisect
t = int(input())
for test in range(t):
	s = list(input())
	t = list(input())
	cc = {}
	oo = {}
	for i in range(len(s)):
		if s[i] not in cc:
			cc[s[i]] = []
			cc[s[i]].append(i)
			oo[s[i]] = 1
		else:
			cc[s[i]].append(i)
			oo[s[i]] += 1
	op = 0
	flag = 0
	prev = -1
	for i in range(len(t)):
		if t[i] not in cc:
			flag = 1
			break
		x = cc[t[i]]
		pp = bisect.bisect(x, prev)
		if pp < oo[t[i]] and prev >= cc[t[i]][pp] or prev == -1 or pp >= oo[t[i]]:
			op += 1
			prev = cc[t[i]][0]
		else:
			prev = cc[t[i]][pp]
	if flag == 1:
		print(-1)
	else:
		print(op)


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	if not set(s2).issubset(set(s1)):
		print(-1)
		continue
	n = len(s1)
	l = [[10 ** 9 + 7] * 26 for _ in range(n)]
	for i in range(n - 1, 0, -1):
		for j in range(26):
			l[i - 1][j] = l[i][j]
		l[i - 1][ord(s1[i]) - 97] = i
	ans = 0
	curr = 0
	i = 0
	while i < len(s2):
		if curr == 10 ** 9 + 7:
			ans += 1
			curr = 0
		if s2[i] == s1[curr]:
			i += 1
			if i == len(s2):
				ans += 1
				break
			curr = l[curr][ord(s2[i]) - 97]
		else:
			curr = l[curr][ord(s2[i]) - 97]
	print(ans)


def Input():
	ans = []
	tem = input().split()
	for it in tem:
		ans.append(int(it))
	return ans
from collections import Counter
T = Input()[0]
for tt in range(T):
	s = input()
	t = input()
	s_map = Counter(s)
	t_map = Counter(t)
	flag = False
	for it in t_map.keys():
		if it not in s_map.keys():
			flag = True
			print(-1)
			break
	if flag:
		continue
	n = len(s)
	m = len(t)
	ma = {}
	for i in range(n):
		if s[i] not in ma.keys():
			ma[s[i]] = [i]
		else:
			ma[s[i]].append(i)
	ans = 0
	i = 0
	p = -1
	while i < m:
		if p == -1:
			ans += 1
			lis = ma[t[i]]
			p = lis[0]
			i += 1
		else:
			lis = ma[t[i]]
			(l, r) = (0, len(lis) - 1)
			while l < r:
				mid = (l + r) // 2
				if lis[mid] <= p:
					l = mid + 1
				else:
					r = mid
			if lis[l] > p:
				p = lis[l]
				i += 1
			else:
				p = -1
	print(ans)


import os, sys, math, random
T = int(input())
(s, t) = ('', '')
(ls, lt) = (0, 0)
mp = [[]]

def binserach(lst, t):
	(l, r) = (0, len(lst))
	if lst[r - 1] <= t:
		return lst[r - 1]
	while l <= r:
		m = l + int((r - l) / 2)
		if lst[m] > t:
			r = m - 1
		elif lst[m] == t:
			return lst[m]
		else:
			l = m + 1
	return lst[r]

def solve():
	(ls, lt) = (len(s), len(t))
	mp = [[] for _ in range(26)]
	for i in range(ls):
		c = s[i]
		ci = ord(c) - ord('a')
		mp[ci].append(i)
	(i, j) = (lt - 1, ls - 1)
	res = 0
	while i >= 0:
		ci = ord(t[i]) - ord('a')
		if len(mp[ci]) <= 0:
			return -1
		if mp[ci][0] > j:
			res += 1
			j = ls - 1
			continue
		jj = binserach(mp[ci], j)
		j = jj - 1
		i = i - 1
		if i < 0:
			res += 1
	return res
for _ in range(T):
	s = input()
	t = input()
	print(solve())


import sys
input = sys.stdin.readline

def bnsearch(L, x):
	start = 0
	end = len(L) - 1
	while start <= end:
		mid = (start + end) // 2
		if L[mid] == x:
			return mid
		if L[mid] > x:
			end = mid - 1
		else:
			start = mid + 1
	return start
for i in ' ' * int(input()):
	s = input()
	t = input()
	s = s[:len(s) - 1]
	t = t[:len(t) - 1]
	cond = True
	d = [[] for i in range(26)]
	checks = ''
	for i in s:
		if i not in checks:
			checks += i
	checkt = ''
	for i in t:
		if i not in checkt:
			checkt += i
	for i in checkt:
		if i not in checks:
			cond = False
			print(-1)
			break
	if not cond:
		continue
	for i in range(len(s)):
		d[ord(s[i]) - 97].append(i)
	counter = 1
	pt = 0
	for i in t:
		iL = d[ord(i) - 97]
		k = bnsearch(iL, pt)
		if k == len(iL):
			pt = iL[0] + 1
			counter += 1
			continue
		else:
			pt = iL[k] + 1
	print(counter)


from bisect import *

def read_ints():
	return map(int, input().split())

def read_int():
	return int(input())
T = read_int()
for _ in range(T):
	s = str(input())
	t = str(input())
	occ = dict()
	for (ii, cc) in enumerate(s):
		if cc not in occ:
			occ[cc] = [ii]
		else:
			occ[cc].append(ii)
	s_ind = 0
	ans = 1
	for (i, c) in enumerate(t):
		if c not in occ:
			ans = -1
			break
		else:
			k = bisect_left(occ[c], s_ind)
			if k == len(occ[c]):
				ans += 1
				s_ind = occ[c][0] + 1
			else:
				s_ind = occ[c][k] + 1
	print(ans)


n = int(input())
for i in range(0, n):
	s = input().rstrip()
	t = input().rstrip()
	L = []
	x = list(s)
	y = list(t)
	for j in range(0, 26):
		D = []
		L.append(D)
	for j in range(0, len(x)):
		L[ord(x[j]) - 97].append(j)
	M = list(L)
	j = 0
	tot = 0
	G = 0
	while j < len(y):
		A = ord(y[j]) - 97
		if len(L[A]) == 0:
			G = 1
			break
		else:
			M = list(L)
			O = 0
			while j < len(y):
				A = ord(y[j]) - 97
				if O == 0:
					if len(M[A]) != 0:
						O += 1
						j += 1
						V = M[A][0]
					else:
						break
				else:
					B = M[A]
					if len(B) != 0:
						I = 0
						J = len(B) - 1
						N = -1
						while I <= J:
							m = (I + J) // 2
							if B[m] <= V:
								I = m + 1
							else:
								N = B[m]
								J = m - 1
						if N != -1:
							V = N
							j += 1
						else:
							break
					else:
						break
			M = list(L)
			tot += 1
	if G == 1:
		print(-1)
	else:
		print(tot)


from bisect import bisect_left as br
from collections import defaultdict as dd
for _ in range(int(input())):
	(s, t) = (input(), input())
	(n1, n2) = (len(s), len(t))
	dic = dd(list)
	for (i, el) in enumerate(s):
		dic[el].append(i)
	(i, j, op, cur, cor, ans) = (0, 0, False, 0, True, 0)
	while j < n2:
		te = dic[t[j]]
		if not te:
			cor = False
			break
		else:
			k = br(te, i)
			if k >= len(te) and cur == 0:
				cor = False
				break
			elif k >= len(te):
				i = 0
				cur = 0
				ans += 1
				op = True
			else:
				i = te[k]
				cur += 1
				op = False
				j += 1
				i += 1
	if cor:
		print(ans if op else ans + 1)
	else:
		print(-1)


import string
n = int(input())
for i in range(n):
	s = input()
	t = input()
	ls = len(s)
	lt = len(t)
	A = [[-1] * 26 for i in range(ls)]
	B = [-1] * 26
	D = {}
	for i in range(26):
		D[chr(ord('a') + i)] = i
	L = [0] * 26
	for i in range(ls):
		for j in range(L[D[s[i]]], i):
			if A[j][D[s[i]]] == -1:
				A[j][D[s[i]]] = i
		if B[D[s[i]]] == -1:
			B[D[s[i]]] = i
		L[D[s[i]]] = i
	ans = 0
	tt = 0
	ne = 0
	while tt < lt:
		if tt == 0 or A[ne][D[t[tt]]] == -1:
			ans += 1
			ne = B[D[t[tt]]]
			if ne == -1:
				ans = -1
				break
		else:
			ne = A[ne][D[t[tt]]]
		tt += 1
	print(ans)


from bisect import bisect
for _ in range(int(input())):
	s = input()
	t = input()
	(d, di) = ({}, {})
	for (i, x) in enumerate(s):
		if d.get(x) == None:
			d[x] = []
			di[x] = 0
		d[x].append(i)
		di[x] += 1
	(last, res, k) = (100005, 0, 0)
	for (i, x) in enumerate(t):
		if d.get(x) == None:
			k = 1
			break
		a = bisect(d[x], last)
		if a == di[x]:
			res += 1
			last = d[x][0]
		else:
			last = d[x][a]
	if k == 1:
		print(-1)
	else:
		print(res)


import sys
inp = sys.stdin.readline
input = lambda : inp().strip()
flush = sys.stdout.flush

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	from bisect import bisect_right
	q = iin()
	while q:
		q -= 1
		(s, t) = (input(), input())
		ds = {}
		for (j, i) in enumerate(s):
			try:
				ds[i].append(j)
			except:
				ds[i] = [j]
		br = 0
		for i in t:
			if i not in ds:
				br = 1
				break
		if br:
			print(-1)
			continue
		l = {i: len(ds[i]) for i in ds}
		ans = 0
		ch = [ds[t[0]][0]]
		for i in t[1:]:
			pos = ch[-1]
			x = bisect_right(ds[i], pos)
			if x < l[i] and pos < ds[i][x]:
				y = ds[i][x]
				ch.append(y)
			else:
				ch = [ds[i][0]]
				ans += 1
		else:
			if ch:
				ans += 1
		print(ans)
main()


import bisect
from collections import defaultdict, Counter
import string

def bseach(arr, target, lo, hi):
	if hi < lo:
		return len(arr)

def solve():
	s = input()
	t = input()
	pos = defaultdict(lambda : [])
	for (i, ch) in enumerate(s):
		pos[ch].append(i)
	start = 0
	ans = 1
	for ch in t:
		if ch not in pos:
			print('-1')
			return
		cur_idx = bisect.bisect_left(pos[ch], start)
		if cur_idx >= len(pos[ch]):
			cur = pos[ch][0]
			ans += 1
		else:
			cur = pos[ch][cur_idx]
		start = cur + 1
	print(ans)
for _ in range(int(input())):
	solve()


from bisect import bisect_right
for _ in range(int(input())):
	s = input()
	t = input()
	pre = {i: [] for i in range(26)}
	a = ord('a')
	for i in range(len(s)):
		pre[ord(s[i]) - a].append(i)
	ans = 1
	last = -1
	for i in t:
		aim = ord(i) - a
		if pre[aim] == []:
			ans = -1
			break
		p = bisect_right(pre[aim], last)
		if p >= len(pre[aim]):
			ans += 1
			last = pre[aim][0]
		else:
			last = pre[aim][p]
	print(ans)


for _ in range(int(input())):
	s = input()
	t = input()
	nxt = [[-1] * 26 for _ in range(len(s))]
	exist = [False] * 26
	get_code = lambda c: ord(c) - ord('a')
	last = [-1] * 26
	first = [-1] * 26
	for i in range(len(s)):
		c = s[i]
		code = get_code(c)
		exist[code] = True
		if first[code] == -1:
			first[code] = i
		for j in range(i - 1, max(last[code] - 1, -1), -1):
			nxt[j][code] = i
		last[code] = i
	if exist[get_code(t[0])]:
		cur = len(s) - 1
		loop = 0
		for c in t:
			code = get_code(c)
			if not exist[code]:
				loop = -1
				break
			if nxt[cur][code] == -1:
				loop += 1
				cur = -1
			else:
				cur = nxt[cur][code]
			if cur == -1:
				cur = first[code]
		print(loop)
	else:
		print(-1)


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key
import bisect

def pi():
	return int(input())

def pl():
	return int(input(), 16)

def ti():
	return list(map(int, input().split()))

def ts():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
f = []

def factMod(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fact(n):
	global f
	f = [1 for i in range(n)]
	for i in range(1, n):
		f[i] = f[i - 1] * i

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncrMod(n, r, m):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def ncr(n, r):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] / (f[r] * f[n - r])

def nc2(n):
	return n * (n - 1) / 2

def main():
	C()
a = [[-1 for j in range(26)] for i in range(100005)]

def C():
	T = int(input())
	while T > 0:
		T -= 1
		s = ts()
		t = ts()
		p = [[] for i in range(26)]
		ans = 1
		curr = 0
		for i in range(len(s)):
			p[ord(s[i]) - ord('a')].append(i)
		for i in range(len(t)):
			j = ord(t[i]) - ord('a')
			if len(p[j]) == 0:
				ans = -1
				break
			index = bisect.bisect_left(p[j], curr, 0, len(p[j]))
			if index >= len(p[j]):
				while index >= len(p[j]):
					curr = 0
					ans += 1
					index = bisect.bisect_left(p[j], curr, 0, len(p[j]))
				curr = p[j][index] + 1
			else:
				curr = p[j][index] + 1
		print(ans)
main()


from collections import defaultdict
from bisect import bisect_right
import sys

def solution(s, t):
	if len(set(s).intersection(set(t))) < len(set(t)):
		print(-1)
	else:
		freq = defaultdict(list)
		(ns, nt) = (len(s), len(t))
		for i in range(ns):
			freq[s[i]].append(i)
		(res, i) = (0, 0)
		prev = -1
		while i < nt:
			idx = bisect_right(freq[t[i]], prev)
			if idx < len(freq[t[i]]):
				prev = freq[t[i]][idx]
				i += 1
			else:
				prev = -1
				res += 1
		print(res + 1)
for line in sys.stdin:
	t = int(line)
	break
p = 1
for line in sys.stdin:
	if p == 1:
		p *= -1
		s = line[:-1]
	else:
		p *= -1
		t = line[:-1]
		solution(s, t)


import bisect
for _ in range(int(input())):
	s = input()
	s = [ord(i) - 97 for i in s]
	t = input()
	t = [ord(i) - 97 for i in t]
	ind = [[] for i in range(26)]
	for i in range(len(s)):
		ind[s[i]].append(i)
	flag = 0
	for i in t:
		if len(ind[i]) == 0:
			flag = 1
			print(-1)
			break
	iii = 0
	cnt = 0
	if flag != 1:
		while iii < len(t):
			curr = -1
			cnt += 1
			while iii < len(t):
				ele = t[iii]
				pos = bisect.bisect_right(ind[ele], curr)
				if pos == len(ind[ele]):
					break
				else:
					curr = ind[ele][pos]
				iii += 1
			if curr == -1 and iii != len(t):
				cnt = -1
				break
		print(cnt)


from collections import defaultdict
from bisect import bisect_left
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	length_s = len(s)
	s_dic = defaultdict(list)
	for (i, x) in enumerate(s):
		s_dic[x] += [i]
	now = -1
	ans = 1
	for x in t:
		if len(s_dic[x]) == 0:
			ans = -1
			break
		next_pos = bisect_left(s_dic[x], now + 1)
		if next_pos == len(s_dic[x]):
			ans += 1
			now = s_dic[x][0]
		else:
			now = s_dic[x][next_pos]
	print(ans)


import bisect

def mini_idex(d, ele, prev):
	t = bisect.bisect_right(d[ele], prev)
	if t >= len(d[ele]):
		return -1
	else:
		return d[ele][t]
tt = int(input())
while tt != 0:
	s = input()
	t = input()
	d = {}
	for i in range(26):
		d[chr(ord('a') + i)] = []
	for i in range(len(s)):
		d[s[i]].append(i)
	f = 0
	i = 0
	count = 0
	prev = -1
	while i < len(t):
		if len(d[t[i]]) == 0:
			f = 1
			break
		else:
			temp = mini_idex(d, t[i], prev)
			if temp == -1:
				count += 1
				prev = -1
			else:
				prev = temp
				i += 1
	if f == 1:
		print(-1)
	else:
		count += 1
		print(count)
	tt -= 1


import string
t = int(input())
for ti in range(t):
	a = input()
	b = input()
	c = {key: list() for key in string.ascii_lowercase}
	for i in range(len(a)):
		c[a[i]].append(i)
	ans = 1
	pos = -1
	for j in b:
		cur = c[j]
		if len(cur) == 0:
			print(-1)
			break
		(li, ri) = (-1, len(cur))
		while ri - li > 1:
			mi = (ri + li) // 2
			if cur[mi] > pos:
				ri = mi
			else:
				li = mi
		if ri == len(cur):
			ans += 1
			pos = cur[0]
		else:
			pos = cur[ri]
	else:
		print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
from collections import Counter
from bisect import bisect_right
for _ in range(int(input())):
	s = input()
	t = input()
	z = ''
	a = [[] for i in range(26)]
	cnt = 0
	for i in s:
		a[ord(i) - ord('a')].append(cnt)
		cnt += 1
	pos = -1
	ans = 1
	f = 0
	for i in t:
		lss = a[ord(i) - ord('a')]
		if lss == []:
			f = 1
			break
		val = bisect_right(lss, pos)
		if val == len(lss):
			pos = lss[0]
			ans += 1
		else:
			pos = lss[val]
	print(ans if f == 0 else -1)


import math

def main():
	s1 = str(input())
	s2 = str(input())
	n = len(s1)
	dp = [[math.inf for _ in range(26)] for _ in range(n + 1)]
	for i in range(n - 1, -1, -1):
		for j in range(26):
			dp[i][j] = dp[i + 1][j]
		dp[i][ord(s1[i]) - ord('a')] = i
	res = 1
	pos = 0
	for i in range(len(s2)):
		if pos == n:
			pos = 0
			res += 1
		if dp[pos][ord(s2[i]) - ord('a')] == math.inf:
			pos = 0
			res += 1
			if dp[pos][ord(s2[i]) - ord('a')] == math.inf and pos == 0:
				print(-1)
				return
		pos = dp[pos][ord(s2[i]) - ord('a')] + 1
	print(res)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy
cases = int(input().strip())
for case in range(cases):
	s = list(input().strip())
	t = list(input().strip())
	ss = set(s)
	tt = list(set(t))
	can = True
	for i in range(len(tt)):
		if not tt[i] in ss:
			can = False
	if not can:
		print(-1)
	else:
		n = len(s)
		nxt = [{} for i in range(n)]
		for i in range(n - 1, -1, -1):
			if i + 1 < n:
				for (k, v) in nxt[i + 1].items():
					nxt[i][k] = v
			nxt[i][s[i]] = i
		ans = 1
		pos = 0
		for i in range(len(t)):
			if pos >= n or not t[i] in nxt[pos]:
				pos = 0
				ans += 1
			pos = nxt[pos][t[i]] + 1
		print(ans)


from collections import defaultdict
import bisect
t = int(input().strip())
for _ in range(t):
	s = input().strip()
	s_dict = defaultdict(list)
	for (index, l) in enumerate(s):
		s_dict[l].append(index)
	t = input().strip()
	ans = 0
	has = True
	cur_index = 0
	while cur_index < len(t):
		s_index = -1
		fin = True
		for i in range(cur_index, len(t)):
			if t[i] not in s_dict:
				has = False
				break
			else:
				s_result = bisect.bisect_right(s_dict[t[i]], s_index)
				if s_result == len(s_dict[t[i]]) or s_dict[t[i]][s_result] <= s_index:
					fin = False
					break
				s_index = s_dict[t[i]][s_result]
		cur_index = i
		ans += 1
		if not has or fin:
			break
	if not has:
		print(-1)
	else:
		print(ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint

def main():
	s = input()
	n = len(s)
	t = input()
	m = len(t)
	nxp = [[n] * 26 for i in range(n)]
	nxp[n - 1][ord(s[n - 1]) - ord('a')] = n - 1
	for i in range(n - 2, -1, -1):
		for j in range(26):
			nxp[i][j] = nxp[i + 1][j]
		nxp[i][ord(s[i]) - ord('a')] = i
	pt2 = 0
	cnt = 0
	while pt2 < m:
		c = pt2
		pt1 = 0
		cnt += 1
		while pt2 < m and pt1 < n:
			pt1 = nxp[pt1][ord(t[pt2]) - ord('a')]
			if pt1 < n:
				pt2 += 1
			pt1 += 1
		if c == pt2:
			print(-1)
			return
	print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


from collections import defaultdict
from bisect import bisect_left
from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	s = input().strip()
	t = input().strip()
	ans = 1
	d = defaultdict(list)
	for (i, si) in enumerate(s):
		d[si].append(i)
	ci = 0
	for ti in t:
		if ti not in d:
			ans = -1
			break
		ni = bisect_left(d[ti], ci)
		if ni >= len(d[ti]):
			ni = 0
			ans += 1
		ci = d[ti][ni] + 1
	print(ans)


import bisect
for _ in range(int(input())):
	s = str(input())
	t = str(input())
	(dictt, ans) = ({}, 1)
	for i in range(len(s)):
		dictt[s[i]] = []
	for i in range(len(s)):
		dictt[s[i]].append(i)
	try:
		index = dictt[t[0]][0]
		for i in t[1:]:
			if i in dictt:
				index = bisect.bisect(dictt[i], index)
				if len(dictt[i]) != index:
					index = dictt[i][index]
					continue
				else:
					index = dictt[i][0]
					ans += 1
			else:
				print(-1)
				break
		else:
			print(ans)
	except KeyError:
		print(-1)


tt = int(input())

def find(c, i):
	l = 0
	r = len(mp[c]) - 1
	ret = -1
	while l <= r:
		m = (l + r) // 2
		if mp[c][m] > i:
			ret = mp[c][m]
			r = m - 1
		else:
			l = m + 1
	return ret
for _ in range(tt):
	s = input()
	t = input()
	mp = [[] for i in range(26)]
	for i in range(len(s)):
		mp[ord(s[i]) - 97].append(i)
	prev = -1
	ans = 1
	for i in range(len(t)):
		g = find(ord(t[i]) - 97, prev)
		if len(mp[ord(t[i]) - 97]) == 0:
			ans = float('-inf')
		elif g != -1:
			prev = g
		else:
			ans += 1
			prev = mp[ord(t[i]) - 97][0]
	print(-1 if ans <= float('-inf') else ans)


from collections import defaultdict
from bisect import bisect_left

def HalfDead(s, t):
	indices = defaultdict(list)
	for (i, c) in enumerate(s):
		indices[c].append(i)
	turn = 1
	cur_idx = 0
	for c in t:
		if c not in indices:
			return -1
		if cur_idx > indices[c][-1]:
			turn += 1
			cur_idx = 0
		pos = bisect_left(indices[c], cur_idx)
		cur_idx = indices[c][pos] + 1
	return turn
for _ in range(int(input())):
	s = input()
	t = input()
	print(HalfDead(s, t))


import sys, os, io
from math import log, gcd, ceil
from collections import defaultdict as dd, deque, Counter
from heapq import heappush, heappop
from sys import stdin
from bisect import bisect_left, bisect_right
import math

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
mod = 998244353
tt = 1
tt = ii()
for _ in range(tt):
	s = si()
	t = si()
	d = dd(lambda : -1)
	n = len(s)
	l = [[-1 for i in range(26)] for j in range(n)]
	for i in range(n):
		l[i][ord(s[i]) - 97] = i
		if i < n - 1:
			for j in range(26):
				l[i + 1][j] = l[i][j]
	ptr = len(s) - 1
	i = len(t) - 1
	c = 0
	f = 0
	while i >= 0:
		if ptr == -1:
			ptr = l[-1][ord(t[i]) - 97]
			c += 1
		else:
			ptr = l[ptr][ord(t[i]) - 97]
		if ptr == -1:
			ptr = l[-1][ord(t[i]) - 97]
			if ptr == -1:
				f = 1
				break
			c += 1
		if t[i] == t[i - 1]:
			ptr -= 1
		i -= 1
	if f == 1:
		c = -2
	print(c + 1)


import sys
input = sys.stdin.readline
t = int(input())

def binary(ar, l, r, pos, n):
	m = (l + r) // 2
	if m == 0 and ar[m] > pos:
		return ar[m]
	elif m > 0 and ar[m] > pos and (ar[m - 1] <= pos):
		return ar[m]
	if l < r:
		if m > 0 and ar[m - 1] > pos:
			return binary(ar, l, m, pos, n)
		elif ar[m] <= pos:
			return binary(ar, m + 1, r, pos, n)
	return -2
for i in range(t):
	b = False
	ct = 1
	t = input()
	s = input()
	dic = {}
	fr = {}
	for j in range(len(t)):
		if t[j] not in dic:
			dic[t[j]] = [j]
			fr[t[j]] = 1
		else:
			dic[t[j]].append(j)
			fr[t[j]] += 1
	pos = -1
	for j in s:
		if j not in dic:
			print('-1')
			b = True
			break
		else:
			l = fr[j]
			val = binary(dic[j], 0, l - 1, pos, l)
			if val > pos:
				pos = val
			elif val == -2 and pos != -1:
				ct += 1
				pos = -1
				val = binary(dic[j], 0, l - 1, pos, l)
				if val > pos:
					pos = val
			elif val == -2 and pos == -1:
				print('-1')
				b = True
				break
	if b == False:
		print(ct)


import math
import bisect
T = int(input())
for t in range(T):
	Ss = input()
	St = input()
	D = dict()
	for s in range(len(Ss)):
		if Ss[s] not in D:
			D[Ss[s]] = [s]
		else:
			D[Ss[s]].append(s)
	ans = 1
	prev = -1
	fl = 0
	for i in range(len(St)):
		if St[i] in D:
			ind = bisect.bisect_right(D[St[i]], prev)
			if ind == len(D[St[i]]):
				curr = D[St[i]][0]
				ans += 1
			else:
				curr = D[St[i]][ind]
			prev = curr
		else:
			fl = 1
			break
	if fl == 1:
		print(-1)
	else:
		print(ans)


for _ in range(int(input())):
	s = input()
	t = input()
	if set(t).difference(set(s)):
		print(-1)
	else:
		nxt_s = [{'a': 0} for _ in range(-1, len(s))]
		cur = {}
		for i in range(len(s) - 1, -2, -1):
			nxt_s[i] = cur.copy()
			cur[s[i]] = i
		ans = 1
		i = -1
		for c in t:
			if c in nxt_s[i]:
				i = nxt_s[i][c]
			else:
				ans += 1
				i = nxt_s[-1][c]
		print(ans)


import sys
input = sys.stdin.readline

def search(arr, x):
	if arr[0] >= x:
		return arr[0]
	if arr[-1] < x:
		return -1
	lo = 0
	hi = len(arr) - 1
	ans = hi
	while lo <= hi:
		m = (lo + hi) // 2
		if arr[m] >= x:
			hi = m - 1
			ans = m
		else:
			lo = m + 1
	return arr[ans]
t = int(input())
for i in range(t):
	s = input().strip()
	t = input().strip()
	ans = 1
	a = [[] for i in range(26)]
	for j in range(len(s)):
		a[ord(s[j]) - ord('a')].append(j)
	s_idx = 0
	for char in t:
		c_idx = ord(char) - ord('a')
		if len(a[c_idx]) == 0:
			print(-1)
			break
		tmp = search(a[c_idx], s_idx)
		if tmp == -1:
			ans += 1
			s_idx = search(a[c_idx], 0) + 1
		else:
			s_idx = tmp + 1
	else:
		print(ans)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 5)
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
t = int(input())
for _ in range(t):
	s = input()
	t = input()
	hash = defaultdict(list)
	for i in range(len(s)):
		hash[s[i]].append(i)
	cnt = 1
	si = 0
	for i in range(len(t)):
		if t[i] not in hash:
			print(-1)
			break
		idx = bisect_left(hash[t[i]], si)
		if idx != len(hash[t[i]]):
			si = hash[t[i]][idx] + 1
		else:
			si = hash[t[i]][0] + 1
			cnt += 1
	else:
		print(cnt)


from collections import OrderedDict

def z_function(s):
	mas = [0] * len(s)
	(left, right) = (0, 0)
	mx = 0
	for i in range(1, len(s)):
		if i <= right:
			mas[i] = min(mas[i - left], right - i + 1)
		while i + mas[i] < len(s) and s[mas[i]] == s[mas[i] + i]:
			mas[i] += 1
		if i + mas[i] - 1 > right:
			right = i + mas[i] - 1
			left = i
		mx = max(mx, mas[i])
	return mx
test = int(input())
while test:
	test -= 1
	s = input()
	t = input()
	count = 0
	mas_s = [list() for i in range(27)]
	mas_t = [list() for i in range(27)]
	for i in enumerate(s):
		mas_s[ord(i[1]) - ord('a')].append(i[0])
	for i in enumerate(t):
		mas_t[ord(i[1]) - ord('a')].append(i[0])
	flag = 0
	for i in range(len(mas_t)):
		if len(mas_t[i]):
			if not len(mas_s[i]):
				flag = 1
				break
	if flag:
		print(-1)
		continue
	mas_ind = 27 * [0]
	ind = -1
	count = 1
	for i in t:
		while mas_s[ord(i) - ord('a')][mas_ind[ord(i) - ord('a')]] <= ind:
			left = mas_ind[ord(i) - ord('a')]
			right = len(mas_s[ord(i) - ord('a')])
			mid = left + 1
			while right - left > 1:
				mid = (right + left) // 2
				if mas_s[ord(i) - ord('a')][mid] > ind:
					right = mid
				else:
					left = mid
			mas_ind[ord(i) - ord('a')] = mid
			if mas_ind[ord(i) - ord('a')] == len(mas_s[ord(i) - ord('a')]):
				ind = -1
				count += 1
				mas_ind = 27 * [0]
		ind = mas_s[ord(i) - ord('a')][mas_ind[ord(i) - ord('a')]]
	print(count)


def solve(s: str, t: str):
	import collections, bisect
	d = collections.defaultdict(list)
	for (i, ch) in enumerate(s):
		d[ch].append(i)
	ptr = [-1] * len(t)
	for (i, ch) in enumerate(t):
		if not ch in d:
			return -1
		if i == 0:
			ptr[i] = d[ch][0]
		else:
			x = bisect.bisect_left(d[ch], ptr[i - 1] + 1)
			if x == len(d[ch]):
				ptr[i] = d[ch][0]
			else:
				ptr[i] = d[ch][x]
	ans = 1
	for i in range(len(ptr) - 1):
		if ptr[i] >= ptr[i + 1]:
			ans += 1
	return ans
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	print(solve(s, t))


T = int(input())

def solve():
	S = input()
	T = input()
	char_to_index = {}
	for (i, t) in enumerate(S):
		if t not in char_to_index:
			char_to_index[t] = []
		char_to_index[t].append(i)
	ans = (0, len(S) + 1)
	for t in T:
		if t not in char_to_index:
			return -1
		indices = char_to_index[t]
		nextIndex = len(indices)
		jump = len(indices)
		while jump != 0:
			while 0 <= nextIndex - jump and indices[nextIndex - jump] > ans[1]:
				nextIndex -= jump
			jump //= 2
		if nextIndex == len(indices):
			ans = (ans[0] + 1, indices[0])
		else:
			ans = (ans[0], indices[nextIndex])
	return ans[0]
for _ in range(T):
	print(solve())


from bisect import bisect_left
t = int(input())
for _ in range(t):
	s = input()
	t = input()
	d = {}
	for i in range(len(s)):
		if s[i] not in d:
			d[s[i]] = []
		d[s[i]].append(i)
	ans = 1
	j = 0
	for i in range(len(t)):
		if t[i] not in d:
			print(-1)
			break
		nxt = bisect_left(d[t[i]], j)
		if nxt != len(d[t[i]]):
			j = d[t[i]][nxt] + 1
		else:
			j = d[t[i]][0] + 1
			ans += 1
	else:
		print(ans)


for _ in range(int(input())):
	s = [ord(c) - 97 for c in list(input())]
	t = [ord(c) - 97 for c in list(input())]
	pl = [[] for i in range(26)]
	for i in range(len(s)):
		pl[s[i]].append(i)
	pos = -1
	j = 0
	ans = 1
	while j < len(t):
		i = t[j]
		if pl[i] == []:
			ans = -1
			break
		else:
			l = 0
			r = len(pl[i]) - 1
			while l <= r:
				mid = l + (r - l) // 2
				if pl[i][mid] > pos:
					r = mid - 1
				else:
					l = mid + 1
			if l >= len(pl[i]):
				ans += 1
				pos = -1
			else:
				pos = pl[i][l]
				j += 1
	print(ans)


from collections import defaultdict
from bisect import bisect_left

def biniz(a, x):
	i = bisect_left(a, x)
	return i
import math
a = int(input())
for i in range(a):
	al = defaultdict(list)
	ans = [0 for i in range(26)]
	ans1 = [0 for i in range(26)]
	x = input()
	y = input()
	flag = 0
	for i in range(len(x)):
		ans[ord(x[i]) - 97] += 1
		al[ord(x[i]) - 97].append(i)
	for i in range(len(y)):
		ans1[ord(y[i]) - 97] += 1
	for i in range(len(ans1)):
		if ans[i] == 0 and ans1[i] > 0:
			flag = 1
			break
	if flag == 1:
		print(-1)
		continue
	i = 0
	index = 0
	count = 1
	while i < len(y):
		t = biniz(al[ord(y[i]) - 97], index)
		if t == len(al[ord(y[i]) - 97]):
			index = 0
			count = count + 1
			continue
		else:
			index = al[ord(y[i]) - 97][t] + 1
			i = i + 1
	print(count)


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		S = input().rstrip('\n')
		T = input().rstrip('\n')
		N = len(S)
		nxt = [[N + 1] * 26 for _ in range(N + 1)]
		for i in range(N, 0, -1):
			s = S[i - 1]
			for j in range(26):
				c = chr(j + 97)
				if c == s:
					nxt[i - 1][j] = i
				else:
					nxt[i - 1][j] = nxt[i][j]
		seen = {}
		for s in S:
			seen[s] = 1
		ans = 1
		i = 0
		for t in T:
			t_ = ord(t) - 97
			if t not in seen:
				ans = -1
				break
			i = nxt[i][t_]
			if i == N + 1:
				ans += 1
				i = nxt[0][t_]
		print(ans)
main()


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	s = minp()
	t = minp()
	n = len(s)
	m = len(t)
	h = [None] * n
	hh = [None] * 26
	hh[ord(s[-1]) - ord('a')] = n - 1
	h[-1] = hh
	for i in range(n - 2, -1, -1):
		hh = hh.copy()
		hh[ord(s[i]) - ord('a')] = i
		h[i] = hh
	hh = [None] * 26
	z = None
	res = 0
	for i in range(len(t)):
		c = ord(t[i]) - ord('a')
		if z == None:
			z = 0
			res += 1
		ok = False
		if h[z][c] != None:
			z = h[z][c] + 1
			ok = True
			if z == n:
				z = None
		if not ok:
			if h[0][c] == None:
				print(-1)
				return
			res += 1
			z = h[0][c] + 1
	print(res)
for i in range(mint()):
	solve()


import sys

def input():
	return sys.stdin.readline()[:-1]
from bisect import bisect

def ctoi(c):
	return ord(c) - ord('a')
	print(ans)
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	if not set(s) >= set(t):
		print(-1)
	else:
		alph = [[] for _ in range(26)]
		for i in range(len(s)):
			alph[ctoi(s[i])].append(i)
		for a in alph:
			if a:
				a.append(a[0] + len(s))
		cur = len(s) - 1
		ans = 0
		for i in range(len(t)):
			ind = bisect(alph[ctoi(t[i])], cur)
			ans += alph[ctoi(t[i])][ind] - cur
			cur = alph[ctoi(t[i])][ind] % len(s)
		print(-(-ans // len(s)))


import sys
input = sys.stdin.readline

def solve():
	s = [ord(i) - 97 for i in input().strip()]
	t = [ord(i) - 97 for i in input().strip()]
	ss = set(s)
	tt = set(t)
	for i in tt:
		if i not in ss:
			print(-1)
			return
	nxt = [[-1 for _ in range(26)] for _ in range(len(s) + 1)]
	for i in range(len(s) - 1, -1, -1):
		for j in range(26):
			nxt[i][j] = nxt[i + 1][j]
		nxt[i][s[i]] = i
	count = 1
	pos = 0
	for i in range(len(t)):
		if pos == len(s) or nxt[pos][t[i]] == -1:
			pos = 0
			count += 1
		pos = nxt[pos][t[i]] + 1
	print(count)
for _ in range(int(input())):
	solve()


from bisect import bisect_right
for _ in range(int(input())):
	s = list(input())
	t = list(input())
	flag = 1
	d = {}
	for i in range(len(s)):
		if s[i] in d:
			d[s[i]].append(i)
		else:
			d[s[i]] = [i]
	z = [-1]
	count = 1
	x = 0
	for i in range(len(t)):
		if t[i] not in d:
			flag = 0
			break
		else:
			x = bisect_right(d[t[i]], z[-1])
			if x == len(d[t[i]]):
				x = 0
			z.append(d[t[i]][x])
	if flag == 1:
		i = 1
		t = len(z)
		while i < t - 1:
			if z[i] < z[i + 1]:
				i += 1
			elif z[i] > z[i + 1]:
				count += 1
				i += 1
			else:
				count += 1
				i += 1
	if flag == 0:
		print(-1)
	else:
		print(count)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d

def printTable(u):
	for _ in u:
		print(*_)

def getAns(s, t):
	l = len(s)
	l2 = len(t)
	(rows, cols) = (l, 26)
	u = [[-1 for i in range(cols)] for j in range(rows)]
	currLetterIndices = [-1] * 26
	for j in range(26):
		if j in s:
			ind = s.index(j)
			currLetterIndices[j] = 0
			for i in range(l):
				u[i][j] = ind
	for i in range(l):
		currLetter = s[i]
		for k in range(currLetterIndices[currLetter], i):
			u[k][currLetter] = i
		currLetterIndices[currLetter] = i
	currIndex = -1
	cycles = 1
	for letter in t:
		newIndex = u[currIndex][letter]
		if newIndex <= currIndex:
			cycles += 1
			if newIndex == -1:
				return -1
		currIndex = newIndex
	return cycles
for _ in range(int(input())):
	s = inputstringnum()
	t = inputstringnum()
	print(getAns(s, t))


import sys
from bisect import bisect_left
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	pos = {}
	for (i, c) in enumerate(s):
		if c not in pos:
			pos[c] = []
		pos[c].append(i)
	i = 0
	ctr = 1
	for c in t:
		if c not in pos:
			ctr = -1
			break
		p = bisect_left(pos[c], i)
		if p == len(pos[c]):
			i = 0
			ctr += 1
			p = bisect_left(pos[c], i)
		i = pos[c][p] + 1
	print(ctr)


INF = 1000000.0

def main():

	def solve():
		ss = input()
		tt = input()
		ls = len(ss)
		nxt = [[INF] * 26]
		for (i, s) in enumerate(ss[::-1]):
			nxt.append(nxt[-1].copy())
			nxt[-1][ord(s) - ord('a')] = ls - i - 1
		nxt.reverse()
		ans = 1
		pos = 0
		for t in tt:
			ordt = ord(t) - ord('a')
			nxtt = nxt[pos][ordt]
			if nxtt == INF:
				if nxt[0][ordt] == INF:
					print(-1)
					return
				ans += 1
				pos = nxt[0][ordt] + 1
			else:
				pos = nxtt + 1
		print(ans)
	q = int(input())
	for _ in range(q):
		solve()
main()


import bisect
from collections import *
n = int(input())
while n != 0:
	s = input()
	t = input()
	f = 9
	dic = defaultdict(list)
	for i in range(len(s)):
		dic[s[i]].append(i)
	i = 0
	pos = -1
	ans = 1
	while i < len(t):
		if len(dic[t[i]]) == 0:
			ans = -1
			break
		x = bisect.bisect_right(dic[t[i]], pos)
		if x >= len(dic[t[i]]):
			ans += 1
			pos = -1
		else:
			pos = dic[t[i]][x]
			i += 1
	print(ans)
	n -= 1


from collections import Counter
from itertools import accumulate
from bisect import bisect_right

def go():
	s = input()
	t = input()
	ind = {}
	for (i, a) in enumerate(s):
		if a not in ind:
			ind[a] = []
		ind[a].append(i)
	pos = -1
	result = 1
	for (i, b) in enumerate(t):
		if b not in ind:
			return -1
		v = bisect_right(ind[b], pos)
		if v < len(ind[b]):
			pos = ind[b][v]
		else:
			pos = ind[b][0]
			result += 1
	return result
T = int(input())
for _ in range(T):
	print(go())


import bisect, sys
input = sys.stdin.readline
t = int(input())
for testcase in range(t):
	s = list(input())
	t = list(input())
	idx = [[] for i in range(30)]
	for i in range(len(s) - 1):
		s[i] = ord(s[i])
		idx[s[i] - 97].append(i)
	now = -1
	res = 1
	for i in range(len(t) - 1):
		p = ord(t[i]) - 97
		if len(idx[p]) == 0:
			res = -1
			break
		k = bisect.bisect_right(idx[p], now)
		if k == len(idx[p]):
			res += 1
			now = idx[p][0]
		else:
			now = idx[p][k]
	print(res)


import sys
import math
from bisect import bisect_right as br
from collections import deque
from itertools import combinations as cb

def int_arr():
	return list(map(int, sys.stdin.readline().strip().split()))

def str_arr():
	return list(map(str, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	st = input()
	made = input()
	ind = [[-1 for i in range(26)]]
	prev = st[0]
	for i in range(1, len(st) + 1):
		x = ind[-1].copy()
		x[ord(prev) - 97] = i - 1
		ind.append(x)
		if i < len(st):
			prev = st[i]
	i = len(made) - 1
	j = len(st)
	ans = 0
	flag = 1
	while i >= 0 and flag == 1:
		j = len(st)
		ans += 1
		while j > 0 and i >= 0:
			val = made[i]
			f = ord(val) - 97
			z = ind[j][f]
			if z == -1:
				if j == len(st):
					print(-1)
					flag = 0
					break
				else:
					j = len(st)
					break
			else:
				j = z
				i -= 1
	if flag:
		print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
Q = int(input())
for _ in range(Q):
	S = [ord(a) - 97 for a in input()]
	T = [ord(a) - 97 for a in input()]
	N = len(S)
	S += S
	X = [[-1] * 26 for _ in range(N)]
	Y = [-1] * 26
	for _ in range(2):
		for i in range(N)[::-1]:
			a = S[i]
			X[i][a] = Y[a]
			for j in range(26):
				if X[i][j] == -1:
					X[i][j] = X[i + 1 - N][j]
			Y[a] = i
			X[i - 1][a] = i
	i = N - 1
	ans = 0
	for t in T:
		ni = X[i][t]
		if ni < 0:
			print(-1)
			break
		if ni <= i:
			ans += 1
		i = ni
	else:
		print(ans)


def s_map(s):
	m = [[None] * 26] + [[None] * 26 for _ in s]
	for (prev_i, (prev_x, prev_col, cur_col)) in reversed(list(enumerate(zip(s, m[1:], m), 1))):
		cur_col[:] = prev_col
		cur_col[prev_x] = prev_i
	return m

def solve(s, t):
	if not set(t).issubset(set(s)):
		return -1
	s = [ord(c) - ord('a') for c in s]
	t = [ord(c) - ord('a') for c in reversed(t)]
	m = s_map(s)
	n = 0
	while t:
		i = 0
		while t and m[i][t[-1]]:
			i = m[i][t[-1]]
			t.pop()
		n += 1
	return n
T = int(input())
for _ in range(T):
	s = input().strip()
	t = input().strip()
	print(solve(s, t))


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	t1 = input()
	p1 = defaultdict(list)
	p1[n - 1] = [n] * 26
	p2 = [n] * 26
	p2[ord(s[-1]) - 97] = n - 1
	for j in range(n - 2, -1, -1):
		ind = ord(s[j + 1]) - 97
		ind1 = ord(s[j]) - 97
		p1[j] = p1[j + 1][:]
		p1[j][ind] = j + 1
		p2[ind1] = min(p2[ind1], j)
	ans = 1
	ind = ord(t1[0]) - 97
	if p2[ind] == n:
		print(-1)
		continue
	l2 = p2[ind]
	for j in range(1, len(t1)):
		ind = ord(t1[j]) - 97
		if p2[ind] == n:
			print(-1)
			break
		if p1[l2][ind] == n:
			ans += 1
			l2 = p2[ind]
		else:
			l2 = p1[l2][ind]
	else:
		print(ans)


def f(s, t):
	dp = [[float('inf')] * 26 for i in range(len(s) + 10)]
	for i in reversed(range(len(s))):
		dp[i] = dp[i + 1].copy()
		dp[i][ord(s[i]) - 97] = i
	res = 1
	pos = 0
	for i in range(len(t)):
		if pos == len(s):
			pos = 0
			res += 1
		if dp[pos][ord(t[i]) - 97] == float('inf'):
			pos = 0
			res += 1
			if dp[pos][ord(t[i]) - 97] == float('inf'):
				res = float('inf')
				break
		pos = dp[pos][ord(t[i]) - 97] + 1
	return [res, -1][res == float('inf')]
for i in range(int(input())):
	s = input()
	t = input()
	print(f(s, t))


for _ in range(int(input())):
	s = list(map(lambda x: ord(x) - 97, input()))
	t = list(map(lambda x: ord(x) - 97, input()))
	if len(set(t) - set(s)) > 0:
		print(-1)
		continue
	dp = [[-1] * 26 for i in range(len(s))]
	nextt = [-1] * 26
	for i in range(len(s) - 1, -1, -1):
		nextt[s[i]] = i
	for i in range(len(s) - 1, -1, -1):
		dp[i] = nextt[:]
		nextt[s[i]] = i
	(pos, ans) = (-1, 1)
	for i in t:
		if pos >= dp[pos][i]:
			ans += 1
		pos = dp[pos][i]
	print(ans)


import sys
q = int(sys.stdin.readline())
for _ in range(q):
	s = sys.stdin.readline()[:-1]
	t = sys.stdin.readline()[:-1]
	if set(t).difference(set(s)):
		print(-1)
	else:
		arr = [{} for _ in range(len(s) + 1)]
		cur = {}
		for i in range(len(s) - 1, -2, -1):
			arr[i] = cur.copy()
			cur[s[i]] = i
		ans = 1
		i = -1
		for c in t:
			if c in arr[i]:
				i = arr[i][c]
			else:
				ans += 1
				i = arr[-1][c]
		print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		s = rs()
		t = rs()
		z = ''
		op = 0
		pos = {}
		for i in range(len(s)):
			if s[i] in pos:
				pos[s[i]].append(i)
			else:
				pos[s[i]] = [i]
		st = 0
		while st < len(t):
			if t[st] not in pos:
				op = -1
				break
			lp = -1
			f = 0
			while st < len(t):
				f = 1
				if t[st] not in pos:
					op = -1
					break
				positions = pos[t[st]]
				mark = bisect.bisect_left(positions, lp + 1)
				if mark == len(positions):
					break
				else:
					lp = positions[mark]
					st += 1
			if f:
				op += 1
		wi(op)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


for T in range(int(input())):
	s = input()
	t = input()
	if s == t:
		print(1)
		continue
	hsh1 = [0 for i in range(30)]
	hsh2 = hsh1[:]
	for i in s:
		hsh1[ord(i) - 97] += 1
	for i in t:
		hsh2[ord(i) - 97] += 1
	bad = 0
	for (i, j) in zip(hsh1, hsh2):
		if j > 0 and i == 0:
			print(-1)
			bad = 1
			break
	if bad:
		continue
	from collections import defaultdict as dd
	d = dd(list)
	for i in range(len(s)):
		d[s[i]].append(i)
	from bisect import bisect_right as br
	move = 1
	idx = -1
	k = 0
	while k != len(t):
		need = t[k]
		idx = br(d[need], idx)
		if idx >= len(d[need]):
			idx = -1
			move += 1
		else:
			idx = d[need][idx]
			k += 1
	print(move)


for _ in range(int(input())):
	s = input()
	t = input()
	d = {}
	for x in s:
		d[x] = 1
	for x in t:
		if d.get(x, 0) == 0:
			print(-1)
			break
	else:
		dp = [[-1] * 26 for i in range(len(s))]
		p = [-1] * 26
		for i in range(len(s) - 1, -1, -1):
			p[ord(s[i]) - 97] = i
		for i in range(len(s) - 1, -1, -1):
			dp[i] = p[:]
			p[ord(s[i]) - 97] = i
		ans = 1
		pos = -1
		for x in t:
			if pos >= dp[pos][ord(x) - 97]:
				ans += 1
			pos = dp[pos][ord(x) - 97]
		print(ans)


import sys, math

def bs(a, last):
	l = 0
	h = len(a) - 1
	ans = -1
	while l <= h:
		mid = (l + h) / 2
		mid = int(mid)
		if a[mid] > last:
			ans = mid
			h = mid - 1
		else:
			l = mid + 1
	return ans
for _ in range(int(input())):
	a = str(input())
	b = str(input())
	foo = []
	n = len(a)
	for i in range(26):
		tmp = []
		for j in range(n):
			if ord(a[j]) - ord('a') == i:
				tmp.append(j)
		foo.append(tmp)
	ans = -1
	last = -1
	for i in range(len(b)):
		if last == -1:
			ans = 1
			if len(foo[ord(b[i]) - ord('a')]) == 0:
				ans = -1
				break
			last = foo[ord(b[i]) - ord('a')][0]
		else:
			if len(foo[ord(b[i]) - ord('a')]) == 0:
				ans = -1
				break
			ind = bs(foo[ord(b[i]) - ord('a')], last)
			if ind == -1:
				last = foo[ord(b[i]) - ord('a')][0]
				ans += 1
			else:
				last = foo[ord(b[i]) - ord('a')][ind]
	print(ans)


def bin_poisk(q, arr):
	l = 0
	r = len(arr)
	while r - l > 1:
		x = (l + r) // 2
		if arr[x] <= q:
			l = x
		else:
			r = x
	if arr[-1] <= q:
		return -1
	if arr[l] <= q:
		if r == len(arr):
			return arr[-1]
		return arr[r]
	return arr[l]
n = int(input())
for i in range(n):
	d = dict()
	nabor = input()
	t = input()
	e = len(t)
	answer = 0
	for j in range(len(nabor)):
		if nabor[j] not in d:
			d[nabor[j]] = []
		d[nabor[j]].append(j)
	o = -1
	while o < e - 1:
		answer += 1
		w = -1
		while o < e - 1:
			if t[o + 1] not in d:
				answer = -1
				break
			q = bin_poisk(w, d[t[o + 1]])
			if q == -1:
				break
			w = q
			o += 1
		if answer == -1:
			break
	print(answer)


t = int(input())
for i in range(t):
	s = input()
	k = input()
	b = []
	a = []
	for j in s:
		b.append(j)
	for j in k:
		a.append(j)
	b1 = [[] for j in range(26)]
	for j in range(len(b)):
		b1[ord(b[j]) - 97].append(j)
	dp = [[-1] * 26 for j in range(len(b) + 1)]
	for j in range(26):
		k = b1[j]
		p = 0
		curr = 0
		while p < len(b):
			if curr < len(k):
				if k[curr] >= p:
					dp[p][j] = k[curr]
				else:
					curr += 1
					if curr < len(k):
						dp[p][j] = k[curr]
			else:
				break
			p += 1
	j = 0
	curr = 0
	ans = 1
	f = 0
	while j < len(a):
		p = ord(a[j]) - 97
		k = dp[curr][p]
		if k == -1:
			curr = 0
			k = dp[curr][p]
			if k == -1:
				f = -1
				break
			ans += 1
			curr = k + 1
		else:
			curr = k + 1
		j += 1
	if f == -1:
		print(-1)
	else:
		print(ans)


import sys
import io
from collections import defaultdict, Counter
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		s = input().strip()
		t = input().strip()
		N = len(s)
		arr = [[N + 1] * 26 for i in range(N + 2)]
		aa = ord('a')
		for i in range(N, 0, -1):
			cchar = ord(s[i - 1]) - aa
			for j in range(26):
				if cchar == j:
					arr[i - 1][j] = i
				else:
					arr[i - 1][j] = arr[i][j]
		st = set(t)
		t = [ord(i) - aa for i in t]
		ans = 0
		ss = set(s)
		if st - ss:
			print(-1)
		else:
			i = 0
			j = 0
			while j < len(t):
				if arr[i][t[j]] != N + 1:
					i = arr[i][t[j]]
					j += 1
				else:
					ans += 1
					i = 0
			print(ans + 1)
main()


import sys
import bisect
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		S = input().strip()
		A = [[] for _ in range(27)]
		for (i, s) in enumerate(S):
			A[ord(s) - ord('a')].append(i)
		T = input().strip()
		prev = -1
		ans = 1
		for t in T:
			if len(A[ord(t) - ord('a')]) == 0:
				print(-1)
				break
			else:
				next = bisect.bisect_right(A[ord(t) - ord('a')], prev)
				if next > len(A[ord(t) - ord('a')]) - 1:
					ans += 1
					prev = A[ord(t) - ord('a')][0]
				else:
					prev = A[ord(t) - ord('a')][next]
		else:
			print(ans)
main()


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	S = [ord(c) - 97 for c in input()]
	T = [ord(c) - 97 for c in input()]
	N = len(S)
	M = len(T)
	C1 = Counter(S)
	C2 = Counter(T)
	for (k, v) in C2.items():
		if C1[k] == 0:
			print(-1)
			break
	else:
		acc = list2d(26, N + 1, INF)
		for (i, c) in enumerate(S):
			acc[c][i] = i + 1
		for c in range(26):
			for i in range(N - 1, -1, -1):
				acc[c][i] = min(acc[c][i], acc[c][i + 1])
		cnt = 1
		i = 0
		for c in T:
			if acc[c][i] == INF:
				cnt += 1
				i = 0
			i = acc[c][i]
		print(cnt)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nex(arr, target):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans
n = int(input())
for i in range(n):
	s = input()
	t = input()
	d = dict()
	for j in range(len(s)):
		if s[j] not in d:
			d.update({s[j]: [j]})
		else:
			d[s[j]].append(j)
	f = 0
	m = -1
	ans = 1
	for j in range(len(t)):
		if t[j] not in d:
			f = 1
			break
		sm = nex(d[t[j]], m)
		if sm == -1:
			ans += 1
			sm = 0
		m = d[t[j]][sm]
	if f == 1:
		ans = -1
	print(ans)


def find(x, a):
	b = 0
	e = len(a) - 1
	while b <= e:
		m = (b + e) // 2
		if 0 < m < n - 1 and a[m] < x < a[m + 1]:
			return a[m + 1]
		elif a[m] > x:
			e = m - 1
		else:
			b = m + 1
	if 0 <= b <= len(a) - 1:
		return a[b]
	elif 0 <= e <= len(a) - 1:
		return a[e]
test = int(input())
for q in range(test):
	s = input()
	t = input()
	n = len(s)
	d = {}
	for i in range(n):
		if s[i] in d:
			d[s[i]] += [i]
		else:
			d[s[i]] = [i]
	x = len(t)
	l = []
	ans = 0
	for i in range(x):
		if t[i] in d:
			if i == 0:
				ans += 1
				l.append(d[t[i]][0])
			elif l[-1] >= d[t[i]][-1]:
				ans += 1
				l.append(d[t[i]][0])
			else:
				l.append(find(l[-1], d[t[i]]))
		else:
			ans = -1
			break
	print(ans)


from bisect import bisect_left
from collections import Counter, defaultdict
for _ in range(int(input())):
	s = input()
	t = input()
	sym_of_s_and_their_frequency = Counter(s)
	sym_of_t_and_their_frequency = Counter(t)
	flag = 1
	for sym in t:
		if sym not in sym_of_s_and_their_frequency:
			flag = 0
	if flag:
		sym_of_s_and_their_positions = defaultdict(list)
		for (ind, sym) in enumerate(s):
			sym_of_s_and_their_positions[sym].append(ind)
		num_of_sequences = 1
		where_ind_is = 0
		for sym in t:
			if where_ind_is > sym_of_s_and_their_positions[sym][-1]:
				num_of_sequences += 1
				where_ind_is = 0
			position = bisect_left(sym_of_s_and_their_positions[sym], where_ind_is)
			where_ind_is = sym_of_s_and_their_positions[sym][position] + 1
		print(num_of_sequences)
	else:
		print(-1)


from collections import Counter
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	s = g()
	z = g()
	n = len(s)
	h = {}
	for i in range(n):
		if s[i] not in h:
			h[s[i]] = []
		h[s[i]].append(i)
	(cnt, idx) = (0, -1)
	flag = True
	for ch in z:
		if ch in h:
			i = bisect_right(h[ch], idx)
			if i == len(h[ch]):
				cnt += 1
				idx = h[ch][0]
			else:
				idx = h[ch][i]
		else:
			flag = False
			break
	if flag:
		print(cnt + 1)
	else:
		print(-1)


def binarySearch(arr, x):
	l = 0
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
from math import *
for __ in range(int(input())):
	a = input()
	b = input()
	n = len(a)
	h = []
	for i in range(n):
		h.append([0] * 26)
	i = n - 1
	h[i][ord(a[i]) - 97] = i
	i -= 1
	while i >= 0:
		for ii in range(26):
			h[i][ii] = h[i + 1][ii]
		h[i][ord(a[i]) - 97] = i
		i -= 1
	ans = True
	c1 = [0] * 26
	c2 = [0] * 26
	for i in range(n):
		c1[ord(a[i]) - 97] = 1
	for i in range(len(b)):
		if c1[ord(b[i]) - 97] == 0:
			ans = False
			break
	if ans == False:
		print(-1)
	else:
		i = 0
		count = 1
		for j in range(len(b)):
			if i >= n or (h[i][ord(b[j]) - 97] == 0 and j != 0):
				i = 0
				count += 1
			i = h[i][ord(b[j]) - 97] + 1
		print(count)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect
for _ in range(int(input())):
	s = [ord(c) - 97 for c in list(input())]
	t = [ord(c) - 97 for c in list(input())]
	pl = [[] for i in range(26)]
	for i in range(len(s)):
		pl[s[i]].append(i)
	p = -1
	m = 1
	imp = False
	for c in t:
		if pl[c] == []:
			imp = True
			break
		j = bisect(pl[c], p)
		if j == len(pl[c]):
			p = pl[c][0]
			m += 1
		else:
			p = pl[c][j]
	print(-1 if imp else m)


import sys, heapq as h
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math
import string

def solve():
	S = listStr()
	N = len(S)
	T = listStr()
	NT = len(T)
	if set(T) - set(T).intersection(set(S)):
		return -1
	pre_calc = [[-1 for j in range(26)] for i in range(N)]
	letters = string.ascii_lowercase
	curr_arr = col.defaultdict(int)
	for letter in letters:
		curr_arr[letter] = -1
	for i in range(N - 1, -1, -1):
		curr_arr[S[i]] = i
		for j in range(26):
			pre_calc[i][j] = curr_arr[letters[j]]
	index = 0
	move = 0
	while index < NT:
		move += 1
		S_ind = 0
		x = ord(T[index]) - ord('a')
		while index < NT and S_ind < N and (pre_calc[S_ind][x] != -1):
			index += 1
			S_ind = pre_calc[S_ind][x] + 1
			if index < NT:
				x = ord(T[index]) - ord('a')
	return move
for _ in range(getInt()):
	print(solve())


def search_just_greater(arr, target):
	if target >= arr[-1]:
		return -1
	low = 0
	high = len(arr) - 1
	while low < high:
		mid = low + (high - low) // 2
		if arr[mid] <= target:
			low = mid + 1
		else:
			high = mid
	return low
for _ in range(int(input())):
	s = list(input())
	t = list(input())
	positions = []
	for i in range(26):
		positions.append([])
	for i in range(len(s)):
		positions[ord(s[i]) - 97].append(i)
	pointer = -1
	bufferEmpty = True
	ans = 0
	for i in range(len(t)):
		cur = ord(t[i]) - 97
		if len(positions[cur]) == 0:
			ans = -1
			break
		newptr = search_just_greater(positions[cur], pointer)
		if newptr == -1:
			ans += 1
			newptr = search_just_greater(positions[cur], -1)
		if i == len(t) - 1:
			ans += 1
		pointer = positions[cur][newptr]
	print(ans)


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())

def search(a, x):
	if a[-1] <= x:
		return -1
	l = 0
	r = len(a) - 1
	while r - l > 0:
		mid = l + r >> 1
		if a[mid] <= x:
			l = mid + 1
		else:
			r = mid
	return a[l]
for _ in range(int(input())):
	s = input().strip()
	t = input().strip()
	pos = defaultdict(list)
	for (i, v) in enumerate(s):
		pos[v].append(i)
	cur = -1
	res = 1
	flag = False
	for (i, v) in enumerate(t):
		if len(pos[v]) == 0:
			flag = True
			break
		nxt = search(pos[v], cur)
		if nxt == -1:
			nxt = pos[v][0]
			res += 1
		cur = nxt
	if flag:
		print(-1)
		continue
	print(res)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	s1 = st()
	s2 = st()
	if len(set(s2) - set(s1)):
		print(-1)
		continue
	l = [[] for i in range(26)]
	for (ind, i) in enumerate(s1):
		l[ord(i) - ord('a')].append(ind)
	currmaxright = len(s1)
	ans = 1
	i = len(s2) - 1
	while i >= 0:
		currind = ord(s2[i]) - ord('a')
		last = currmaxright
		toind = bl(l[currind], currmaxright)
		if toind:
			currmaxright = l[currind][toind - 1]
		else:
			i += 1
		if currmaxright == 0 or not toind:
			currmaxright = len(s1)
			if i:
				ans += 1
		i -= 1
	print(ans)


def main():
	from bisect import bisect_left
	from collections import defaultdict
	N = int(input())
	for i in range(N):
		d = defaultdict(list)
		S = input()
		S_len = len(S)
		S_set = set(S)
		for (i, s) in enumerate(S):
			d[s].append(i)
		T = input()
		if not all((t in S_set for t in T)):
			print(-1)
			continue
		cur = 0
		ans = 1
		for t in T:
			if d[t][-1] < cur or S_len <= cur:
				cur = 0
				ans += 1
			cur = bisect_left(d[t], cur)
			if S_len <= cur:
				cur = 0
				cur = bisect_left(d[t], cur)
				ans += 1
			cur = d[t][cur] + 1
		print(ans)
main()


for _ in range(int(input())):
	s = input()
	t = input()
	d = {}
	for i in range(len(s)):
		d[s[i]] = 1
	flag = True
	for i in range(len(t)):
		if d.get(t[i]) == None:
			flag = False
			break
	if not flag:
		print(-1)
		continue
	dp = []
	ll = [float('inf')] * 26
	for _ in range(len(s)):
		dp.append(list(ll))
	for i in range(len(s) - 1, -1, -1):
		dp[i][ord(s[i]) - ord('a')] = i
		for j in range(26):
			if j != ord(s[i]) - ord('a') and i + 1 < len(s):
				dp[i][j] = dp[i + 1][j]
	ct = 1
	i = 0
	j = 0
	while i < len(t):
		if j == len(s):
			j = 0
			ct += 1
		if dp[j][ord(t[i]) - ord('a')] >= float('inf'):
			ct += 1
			j = 0
		j = dp[j][ord(t[i]) - ord('a')] + 1
		i += 1
	print(ct)


n = int(input())
for _ in range(n):
	str1 = input()
	str2 = input()
	n = len(str1)
	m = len(str2)
	next_char = [[-1] * n for _ in range(26)]
	for i in range(n - 1, -1, -1):
		c = ord(str1[i]) - ord('a')
		if i < n - 1:
			for j in range(26):
				next_char[j][i] = next_char[j][i + 1]
		next_char[c][i] = i
	count = 1
	at = 0
	f = True
	for i in range(m):
		if at == n:
			at = 0
			count += 1
		c = ord(str2[i]) - ord('a')
		if next_char[c][at] == -1:
			if at == 0 or next_char[c][0] == -1:
				f = False
				break
			else:
				at = next_char[c][0] + 1
				count += 1
		else:
			at = next_char[c][at] + 1
	if f:
		print(count)
	else:
		print(-1)


def binarySearch(seq, a):
	if not seq:
		return -2
	n = len(seq)
	l = 0
	r = len(seq)
	while l < r:
		m = (l + r) // 2
		if seq[m] > a:
			r = m
		if seq[m] < a:
			l = m + 1
		if seq[m] == a:
			if m == n - 1:
				return -1
			return seq[m + 1]
	if l == n:
		return -1
	return seq[l]

def minOp(S, T):
	letters = [[] for _ in range(26)]
	for (i, c) in enumerate(S):
		letters[ord(c) - ord('a')].append(i)
	op = 1
	pre = -1
	for (i, t) in enumerate(T):
		t_pos = letters[ord(t) - ord('a')]
		t_index = binarySearch(t_pos, pre)
		if t_index == -1:
			op += 1
			pre = t_pos[0]
		elif t_index == -2:
			return -1
		else:
			pre = t_index
	return op
t = int(input())
for _ in range(t):
	S = input()
	T = input()
	print(minOp(S, T))


from sys import stdin, stdout

def bs(nums, target):
	low = 0
	high = len(nums) - 1
	while low < high:
		m = (high + low) // 2
		if nums[m] <= target:
			low = m + 1
		else:
			high = m
	if low == len(nums):
		return -1
	if nums[low] <= target:
		return -1
	return nums[low]

def main():
	casos = int(input())
	for c in range(casos):
		s = input()
		t = input()
		A = set(s)
		B = set(t)
		sw = 1
		Graf = []
		for i in range(30):
			Graf.append([])
		for x in B:
			if x == '\n':
				continue
			if x not in A:
				sw = 0
				break
		if sw:
			for j in range(len(s)):
				if s[j] == '\n':
					continue
				pos = ord(s[j]) - ord('a')
				Graf[pos].append(j + 1)
			ans = 0
			i = 0
			n = len(t)
			while i < n:
				ans += 1
				pos = 0
				while i < n:
					tmp = ord(t[i]) - ord('a')
					tmp = bs(Graf[tmp], pos)
					if i == n or tmp == -1:
						break
					pos = tmp
					i += 1
			print(ans)
		else:
			print(-1)
main()


import sys
input = sys.stdin.readline

def main():
	d = {}
	for i in range(26):
		d[chr(i + ord('a'))] = i
	for _ in range(int(input())):
		s = input().strip()
		t = input().strip()
		s1 = set(s)
		s2 = set(t)
		if not s2.issubset(s1):
			print(-1)
			continue
		n = len(s)
		l = [[10 ** 9 + 7 for i in range(26)] for j in range(n)]
		for i in range(n - 1, 0, -1):
			for j in range(26):
				l[i - 1][j] = l[i][j]
			l[i - 1][d[s[i]]] = i
		ans = 0
		curr = 0
		i = 0
		while i < len(t):
			if curr == 10 ** 9 + 7:
				ans += 1
				curr = 0
			if t[i] == s[curr]:
				i += 1
				if i == len(t):
					ans += 1
					break
				curr = l[curr][d[t[i]]]
			else:
				curr = l[curr][d[t[i]]]
		print(ans)
main()


def bsearch(a, x):
	l = 0
	r = len(a)
	while l < r:
		mid = (l + r) // 2
		if a[mid] > x:
			r = mid
		else:
			l = mid + 1
	return l
for _ in range(int(input())):
	s = input()
	t = input()
	Map = {}
	for i in range(len(s)):
		if s[i] not in Map:
			Map[s[i]] = []
		Map[s[i]].append(i)
	flag = 0
	c = 1
	n = len(t)
	i = 0
	maxInd = -1
	while i < n:
		if t[i] not in Map:
			flag = 1
			print('-1')
			break
		if Map[t[i]][0] > maxInd:
			maxInd = Map[t[i]][0]
			i += 1
		else:
			find = bsearch(Map[t[i]], maxInd)
			if find < len(Map[t[i]]):
				maxInd = Map[t[i]][find]
				i += 1
			else:
				c += 1
				maxInd = -1
	if flag == 0:
		print(c)


from sys import stdin
from bisect import bisect
t = int(stdin.readline())
for i in range(t):
	s = stdin.readline().strip()
	t = stdin.readline().strip()
	if not set(t) <= set(s):
		print(-1)
		continue
	p = [[] for i in range(26)]
	for (i, c) in enumerate(s):
		j = ord(c) - ord('a')
		p[j].append(i)
	x = 0
	ops = 0
	while x < len(t):
		k = -1
		while x < len(t):
			c = ord(t[x]) - ord('a')
			idx = bisect(p[c], k)
			if idx == len(p[c]):
				break
			k = p[c][idx]
			x += 1
		ops += 1
	print(ops)


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf

def atoi(s):
	return ord(s) - ord('a')

def inc(s, n=1):
	return chr((ord(s) - ord('a') + n) % 26 + ord('a'))

class XY:

	def __init__(self, x, y):
		self.x = x
		self.y = y

def rotate(a, b, c):
	ang = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)
	if ang == 0:
		return 0
	else:
		return ang / abs(ang)

def phi(n):
	(res, p) = (n, 2)
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			res -= res // p
		p += 1
	if n > 1:
		res -= res // n
	return res
for _ in range(iinp()):
	s = inp()
	t = inp()
	n = len(s)
	f = l2d(n + 1, 26, -1)
	for i in range(26):
		x = inc('a', i)
		for j in range(n - 1, -1, -1):
			if s[j] == x:
				f[j][i] = j
			else:
				f[j][i] = f[j + 1][i]
	cnt = 1
	flg = True
	for i in t:
		if f[0][atoi(i)] == -1:
			flg = False
			break
	if not flg:
		print(-1)
	else:
		(i, j) = (0, 0)
		while i < len(t):
			if f[j][atoi(t[i])] == -1:
				j = 0
				cnt += 1
			else:
				j = f[j][atoi(t[i])] + 1
				i += 1
		print(cnt)


from bisect import *
t = int(input())
for _ in range(t):
	s = input()
	t = input()
	char = [[] for i in range(26)]
	for i in range(len(s)):
		char[ord(s[i]) - 97].append(i)
	ans = 1
	index = 0
	for i in range(len(t)):
		if len(char[ord(t[i]) - 97]) == 0:
			ans = -1
			break
		if bisect_left(char[ord(t[i]) - 97], index) == len(char[ord(t[i]) - 97]):
			ans += 1
			index = 0
			if len(char[ord(t[i]) - 97]) == 0:
				ans = -1
				break
			index = char[ord(t[i]) - 97][bisect_left(char[ord(t[i]) - 97], index)] + 1
		else:
			index = char[ord(t[i]) - 97][bisect_left(char[ord(t[i]) - 97], index)] + 1
	print(ans)


from math import *
from bisect import *
test = int(input())
for i in range(test):
	s = input()
	t = input()
	char_s = {}
	l = len(s)
	for j in range(l):
		if s[j] not in char_s:
			char_s[s[j]] = [j]
		else:
			char_s[s[j]].append(j)
	for j in char_s:
		char_s[j].sort()
	ind = 0
	length = len(t)
	flag = True
	count = 0
	while ind < length:
		if t[ind] not in char_s:
			flag = False
			break
		k = 0
		while ind < length:
			if t[ind] not in char_s:
				flag = False
				break
			if k > char_s[t[ind]][-1]:
				count += 1
				break
			temp = bisect_left(char_s[t[ind]], k)
			k = char_s[t[ind]][temp] + 1
			ind += 1
		if flag == False:
			break
	if flag == False:
		print(-1)
	else:
		print(count + 1)


def main():
	T = int(input().strip())
	for _ in range(T):
		s = input().strip()
		t = input().strip()
		charset = set(s)
		if any((c not in charset for c in t)):
			print(-1)
			continue
		d = {c: len(s) for c in charset}
		jump = [0] * len(s)
		for i in range(len(s) - 1, -1, -1):
			jump[i] = dict(d)
			d[s[i]] = i
		i = -1
		result = 1
		for c in t:
			i += 1
			if i == len(s):
				i = 0
				result += 1
			while s[i] != c:
				i = jump[i][c]
				if i == len(s):
					i = 0
					result += 1
		print(result)
main()


for i in range(int(input())):
	s = input()
	inf = 10 ** 12
	x = input()
	dp = [[inf for i in range(26)] for j in range(len(s))]
	d = {}
	n = len(s)
	for i in range(n - 1, -1, -1):
		for j in range(26):
			if j == ord(s[i]) - ord('a'):
				dp[i][j] = i
			elif i + 1 < n:
				dp[i][j] = dp[i + 1][j]
	ind = 0
	c = 0
	i = 0
	while i < len(x):
		if dp[0][ord(x[i]) - ord('a')] == inf:
			print(-1)
			break
		else:
			ind = dp[ind][ord(x[i]) - ord('a')] + 1
			if ind > n:
				c += 1
				ind = 0
				i -= 1
			elif ind == n:
				c += 1
				ind = 0
			i += 1
	else:
		if ind != 0:
			c += 1
		print(c)


import sys
sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def SI():
	return sys.stdin.readline()[:-1]

def MI():
	return map(int, sys.stdin.readline().split())

def MI1():
	return map(int1, sys.stdin.readline().split())

def MF():
	return map(float, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LF():
	return list(map(float, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
	t = II()
	for _ in range(t):
		s = SI()
		t = SI()
		sn = len(s)
		nxt = [[0] * 26 for _ in range(sn + 1)]
		imp = [True] * 26
		for (i, c) in enumerate(s[::-1]):
			nxt[sn - i - 1] = nxt[sn - i][:]
			nxt[sn - i - 1][ord(c) - 97] = sn - i
			imp[ord(c) - 97] = False
		i = 0
		ans = 1
		flag = False
		for c in t:
			if imp[ord(c) - 97]:
				print(-1)
				flag = True
				break
			i = nxt[i][ord(c) - 97]
			if i == 0:
				ans += 1
				i = nxt[i][ord(c) - 97]
		if flag:
			continue
		print(ans)
main()


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from collections import defaultdict as dd, deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())
mod = 998244353
for _ in range(int(data())):
	s = data()
	t = data()
	l = [0] * len(s)
	d = dd(int)
	for i in range(len(s) - 1, -1, -1):
		l[i] = d.copy()
		d[s[i]] = i + 1
	ans = 1
	ind = 0
	i = 0
	flag = True
	while i < len(t):
		if ind == 0:
			if d[t[i]] == 0:
				print(-1)
				flag = False
				break
			else:
				ind = d[t[i]]
				if ind == 0:
					print(-1)
					flag = False
					break
		elif l[ind - 1][t[i]] == 0:
			ind = 0
			ans += 1
			i -= 1
		else:
			ind = l[ind - 1][t[i]]
			if ind == 0:
				print(-1)
				flag = False
				break
		i += 1
	if flag == True:
		print(ans)


import bisect
t = int(input())
while t:
	t -= 1
	s = input()
	target = input()
	j = 0
	d = {}
	for i in s:
		if i in d:
			d[i].append(j)
		else:
			d[i] = [j]
		j += 1
	count = 0
	if target[0] in d:
		last = d[target[0]][0]
	else:
		print(-1)
		continue
	flag = False
	for i in target[1:]:
		if i in d:
			g = bisect.bisect(d[i], last)
			if g >= len(d[i]):
				count += 1
				last = d[i][0]
			else:
				last = d[i][g]
		else:
			flag = True
			break
	if flag:
		print(-1)
	else:
		print(count + 1)


import sys
from math import log2, floor, ceil, sqrt
import bisect
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(int(ri())):
	s = ri()
	s = [ord(s[i]) - ord('a') for i in range(len(s))]
	t = ri()
	t = [ord(t[i]) - ord('a') for i in range(len(t))]
	dic = {}
	for i in range(len(s)):
		if s[i] in dic:
			dic[s[i]].append(i)
		else:
			dic[s[i]] = [i]
	j = 0
	flag = True
	ans = 0
	flag = True
	while j < len(t):
		ite = -1
		theflag = True
		while j < len(t):
			num = t[j]
			if num not in dic:
				theflag = False
				break
			ite = bisect.bisect_right(dic[num], ite)
			if ite < len(dic[num]):
				ite = dic[num][ite]
				j += 1
			else:
				break
		if not theflag:
			flag = False
			break
		ans += 1
	if not flag:
		print(-1)
	else:
		print(ans)


from sys import *
input = stdin.readline
from bisect import *
import math
from collections import *
import operator
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7
for _ in range(int(input())):
	s = input()[:-1]
	t = input()[:-1]
	if len(set(t) - set(s)):
		print(-1)
		continue
	arr = []
	for i in range(26):
		ch = chr(i + 97)
		temp = []
		for j in range(len(s)):
			if s[j] == ch:
				temp.append(j)
		arr.append(temp)
	prev = -1
	ans = 1
	for i in t:
		ch = ord(i) - 97
		ind = bisect_left(arr[ch], prev)
		if ind >= 0 and ind < len(arr[ch]) and (arr[ch][ind] >= prev):
			prev = arr[ch][ind] + 1
		else:
			ans += 1
			ind = bisect_left(arr[ch], -1)
			prev = arr[ch][ind] + 1
	print(ans)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	s = input()
	t = input()
	hash = defaultdict(list)
	for i in range(len(s)):
		hash[s[i]].append(i)
	i = 0
	k = len(t)
	n = len(s)
	prev = i
	ans = 0
	flag = 0
	while i < k:
		if hash[t[i]] == []:
			flag = 1
			break
		z = bisect_left(hash[t[i]], prev)
		if z != len(hash[t[i]]):
			prev = hash[t[i]][z]
			prev += 1
		else:
			ans += 1
			prev = hash[t[i]][0] + 1
		i += 1
	if flag:
		print(-1)
	else:
		print(ans + 1)


t = int(input())
for i in range(t):
	s = str(input())
	t = str(input())
	x = len(s)
	y = len(t)
	count1 = [0] * 26
	count2 = [0] * 26
	z = 0
	matrix1 = [[] for j in range(26)]
	for j in range(x):
		count1[ord(s[j]) - 97] += 1
		matrix1[ord(s[j]) - 97].append(j + 1)
	for j in range(y):
		count2[ord(t[j]) - 97] += 1
	for j in range(26):
		if count2[j] != 0 and count1[j] == 0:
			z += 1
			break
	if z == 1:
		print(-1)
	else:
		matrix = [[0] * 26 for j in range(x)]
		for j in range(26):
			h = 0
			l = len(matrix1[j])
			for k in range(x):
				if h == l:
					break
				elif h < l and matrix1[j][h] > k + 1:
					matrix[k][j] = matrix1[j][h]
				else:
					while h < l:
						if matrix1[j][h] > k + 1:
							matrix[k][j] = matrix1[j][h]
							break
						h += 1
		ans = 1
		j = 0
		lis = [0]
		g = 0
		while j < y:
			if g == 0:
				if t[j] == s[0]:
					lis.append(0)
					j += 1
					g += 1
				else:
					temp = matrix[lis[-1]][ord(t[j]) - 97]
					if temp != 0:
						lis.append(temp - 1)
						j += 1
						g += 1
					else:
						g = 0
						lis = [0]
						ans += 1
			else:
				temp = matrix[lis[-1]][ord(t[j]) - 97]
				if temp != 0:
					lis.append(temp - 1)
					j += 1
					g += 1
				else:
					g = 0
					lis = [0]
					ans += 1
		print(ans)


from bisect import bisect_left as lower
t = int(input())
for _ in range(t):
	s = input()
	z = input()
	ind = [[] for i in range(26)]
	for i in range(len(s)):
		ind[ord(s[i]) - ord('a')].append(i)
	ans = 1
	prev = -1
	for c in list(z):
		i = ord(c) - ord('a')
		if not ind[i]:
			ans = -1
			break
		j = lower(ind[i], prev + 1)
		if j == len(ind[i]):
			prev = ind[i][0]
			ans += 1
		else:
			prev = ind[i][j]
	print(ans)


import bisect
t = int(input())
for i in range(t):
	s = input()
	t = input()
	letters = {}
	for j in range(len(s)):
		ch = s[j]
		if ch not in letters.keys():
			letters[ch] = [j]
		else:
			letters[ch].append(j)
	count = 1
	failed = False
	cur = -1
	for ch in t:
		if ch not in letters.keys():
			failed = True
			break
		else:
			ind = bisect.bisect_right(letters[ch], cur)
			if ind < len(letters[ch]):
				cur = letters[ch][ind]
			else:
				cur = letters[ch][0]
				count += 1
	if failed:
		print(-1)
	else:
		print(count)


def binary(alpha, k):
	global dic, dicle
	n = dicle[alpha]
	ar = dic[alpha]
	if k >= ar[-1]:
		ans = n
	elif k < ar[0]:
		ans = 0
	else:
		l = 0
		r = n - 1
		while not (k >= ar[l] and k < ar[l + 1]):
			mid = (l + r) // 2
			if ar[mid] <= k:
				l = mid
			elif ar[mid] > k:
				r = mid
		ans = l + 1
	if ans == n:
		return ar[0]
	else:
		return ar[ans]
for _ in range(int(input())):
	st = input()
	le = len(st)
	dic = {}
	dicle = {}
	for i in range(le):
		if st[i] in dic:
			dic[st[i]].append(i)
			dicle[st[i]] += 1
		else:
			dic[st[i]] = [i]
			dicle[st[i]] = 1
	flag = True
	ts = input()
	count = 1
	cur = -1
	lets = len(ts)
	for j in range(lets):
		if ts[j] in dic:
			pos = binary(ts[j], cur)
			if pos <= cur:
				count += 1
				cur = pos
			else:
				cur = pos
		else:
			flag = False
	if flag:
		print(count)
	else:
		print(-1)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def upperbound(a, ele):
	l = 0
	r = len(a) - 1
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if a[mid] <= ele:
			l = mid + 1
		else:
			ans = a[mid]
			r = mid - 1
	return ans
for _ in range(iinput()):
	s = input()
	t = input()
	(n, m) = (len(s), len(t))
	ds = defaultdict(list)
	for i in range(n):
		ds[s[i]].append(i)
	ans = 0
	i = 0
	while i < m:
		j = i
		curr_idx = -1
		found = False
		while j < m and t[j] in ds:
			got = False
			nxt = upperbound(ds[t[j]], curr_idx)
			if nxt != -1:
				curr_idx = nxt
				got = True
			if not got:
				found = True
				break
			j += 1
		if not found and j < m:
			ans = -1
			break
		ans += 1
		i = j
	print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	a = ips()
	b = ips()
	a_set = set(a)
	b_set = set(b)
	flag = True
	for i in b_set:
		if i not in a_set:
			flag = False
			break
	if flag:
		a_dic = dd(list)
		for i in range(len(a)):
			a_dic[a[i]].append(i)
		pt = 0
		pos = -1
		ans = 0
		n = len(b)
		while pt < n:
			ele = b[pt]
			pos = br(a_dic[ele], pos)
			if pos == len(a_dic[ele]):
				pos = -1
				ans += 1
			else:
				pos = a_dic[ele][pos]
				pt += 1
		if pos != -1:
			ans += 1
		out(ans)
	else:
		out(-1)


for _ in range(int(input())):
	(s, t) = (input(), input())
	ss = set(list(s))
	flag = False
	for i in t:
		if i not in ss:
			flag = True
			break
	if flag:
		print(-1)
		continue
	n = len(s)
	dp = [list([float('inf')] * 26) for _ in range(n)]
	for i in range(n - 1, -1, -1):
		vl = ord(s[i]) - ord('a')
		dp[i][vl] = i
		for j in range(26):
			if j != vl and i < n - 1:
				dp[i][j] = dp[i + 1][j]
	ans = 1
	j = 0
	for i in range(len(t)):
		val = ord(t[i]) - ord('a')
		if j == n:
			(j, ans) = (0, ans + 1)
		if dp[j][val] == float('inf'):
			(ans, j) = (ans + 1, 0)
		j = dp[j][val] + 1
	print(ans)


def solve_simple(source, target):
	if not set(source) >= set(target):
		return -1
	operations = 0
	target_index = 0
	while target_index < len(target):
		operations += 1
		source_index = 0
		while source_index < len(source) and target_index < len(target):
			if source[source_index] == target[target_index]:
				target_index += 1
			source_index += 1
	return operations

def solve_optimal(source, target):
	if not set(source) >= set(target):
		return -1
	positions = {}
	next_positions = {}
	i = len(source) - 1
	while i >= 0:
		positions[source[i]] = i
		for (char, position) in positions.items():
			next_positions[i, char] = position
		i -= 1
	operations = 0
	target_index = 0
	while target_index < len(target):
		operations += 1
		position = 0
		while target_index < len(target):
			position = next_positions.get((position, target[target_index]))
			if position is None:
				break
			position += 1
			target_index += 1
	return operations
solve = solve_optimal
for T in range(int(input())):
	print(solve(input(), input()))


import bisect
t = int(input())
for _ in range(t):
	s = input()
	x = input()
	dic = {}
	i = 0
	for e in s:
		if e not in dic:
			dic[e] = [[], 0]
		dic[e][0].append(i)
		i += 1
	res = 1
	gi = 0
	for char in x:
		if char not in dic:
			res = -1
			break
		ind = dic[char][1]
		li = bisect.bisect_left(dic[char][0], gi)
		if li < len(dic[char][0]):
			dic[char][1] = li + 1
			gi = dic[char][0][li] + 1
		else:
			dic[char][1] = 1
			gi = dic[char][0][0] + 1
			res += 1
	print(res)


def countGreater(arr, k):
	l = 0
	r = len(arr) - 1
	n = len(arr)
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) // 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
T = int(input())
while T:
	s = input()
	t = input()
	ls = [[] for i in range(26)]
	for i in range(len(s)):
		ls[ord(s[i]) - 97].append(i)
	flag = True
	for i in range(len(t)):
		if len(ls[ord(t[i]) - 97]) == 0:
			flag = False
			break
	if flag:
		ans = 0
		x = -1
		i = 0
		while i < len(t):
			arr = ls[ord(t[i]) - 97]
			if countGreater(arr, x) == 0:
				ans += 1
				x = -1
				i -= 1
			else:
				x = arr[len(arr) - countGreater(arr, x)]
			i += 1
		print(ans + 1)
	else:
		print(-1)
	T -= 1


import bisect

def readInt():
	x = int(input())
	return x

def readList():
	x = map(int, input().split(' '))
	return list(x)
tx = readInt()
for _ in range(tx):
	s = input()
	t = input()
	pos = {chr(c): [] for c in range(ord('a'), ord('z') + 1)}
	index = 0
	for c in s:
		pos[c].append(index)
		index += 1
	(curr, ans) = (-1, 1)
	moveOn = False
	i = 0
	while i < len(t):
		c = t[i]
		if len(pos[c]) == 0:
			print('-1')
			moveOn = True
			break
		curr = bisect.bisect_right(pos[c], curr)
		if curr >= len(pos[c]):
			ans += 1
			curr = -1
		else:
			curr = pos[c][curr]
			i += 1
	if moveOn:
		continue
	print(ans)


from collections import *
from bisect import *
for i in range(int(input())):
	(s, t, mem, ans, last) = (input(), input(), defaultdict(list), 0, -1)
	for j in range(len(s)):
		mem[s[j]].append(j)
	for j in range(len(t)):
		if mem[t[j]]:
			ix = bisect_right(mem[t[j]], last)
			if ix >= len(mem[t[j]]):
				last = -1
				ix = bisect_right(mem[t[j]], last)
			if last == -1:
				ans += 1
			elif mem[t[j]][ix] < last:
				ans += 1
			last = mem[t[j]][ix]
		else:
			ans = -1
			break
	print(ans)


import bisect
t = int(input())
for _ in range(t):
	s = input()
	t = input()
	f = [list() for _ in range(26)]
	orda = ord('a')
	for i in range(len(s)):
		f[ord(s[i]) - orda].append(i)
	ans = 0
	idx = 10 ** 9
	for i in range(len(t)):
		search = ord(t[i]) - orda
		if f[search] == list():
			ans = -1
			break
		nidx = bisect.bisect_right(f[search], idx)
		if nidx < len(f[search]):
			idx = f[search][nidx]
		else:
			ans += 1
			idx = f[search][0]
	print(ans)


import sys
from collections import defaultdict
import bisect

def f(s, t):
	A = defaultdict(list)
	S = set(s)
	T = set(t)
	for i in T:
		if i not in S:
			return -1
	n = len(s)
	for i in range(n):
		A[s[i]].append(i)
	i = 0
	j = 0
	U = len(t)
	ans = 1
	while j < U:
		c = t[j]
		k = bisect.bisect_left(A[c], i)
		if k >= len(A[c]):
			i = 0
			ans += 1
		else:
			j += 1
			i = A[c][k] + 1
	return ans
n = int(input())
for i in range(n):
	s = input()
	t = input()
	print(f(s, t))


from collections import defaultdict
import bisect

def list_difference(list1, list2):
	result = list1.copy()
	for value in list2:
		if value in result:
			result.remove(value)
	return result
N = int(input())
for i in range(N):
	s = input()
	t = input()
	if set(list(t)) - set(list(s)):
		print(-1)
	elif len(t) == 1:
		print(1)
	else:
		count = 1
		sc = defaultdict(list)
		for (i, v) in enumerate(list(s)):
			sc[v].append(i)
		now = sc[t[0]][0]
		t = t[1:]
		for i in t:
			if now >= sc[i][-1]:
				count += 1
				now = sc[i][0]
			else:
				now = sc[i][bisect.bisect_right(sc[i], now)]
		print(count)


test = int(input())
for _ in range(test):
	s = input()
	t = input()
	(i1, i2) = (0, 0)
	(s1, s2) = (set(s), set(t))
	if len(s2 - s1) > 0:
		print(-1)
		continue
	dics = [0 for i in range(len(s))]
	sst = sorted(list(s))
	main = {i: 0 for i in sst}
	for i in range(len(s) - 1, -1, -1):
		dics[i] = main.copy()
		main[s[i]] = i

	def nex(i, x):
		val = dics[i][x]
		if val == 0 and s[0] != x:
			return (dics[0][x], True)
		elif val == 0:
			return (0, True)
		return (val, False)
	(i1, i2, ans) = (0, 0, 1)
	while i1 < len(t):
		if i2 >= len(s):
			i2 = 0
			ans += 1
		if s[i2] != t[i1]:
			(i2, f) = nex(i2, t[i1])
			if f:
				ans += 1
		i2 += 1
		i1 += 1
	print(ans)


ALPHA = 26

def offset(c):
	return ord(c) - ord('a')
T = int(input())
for cs in range(T):
	s = list(map(offset, list(input())))
	t = list(map(offset, list(input())))
	ls = len(s)
	nxt = [[-1 for j in range(ALPHA)] for i in range(ls)]
	nxt[ls - 1][s[ls - 1]] = ls - 1
	for i in range(ls - 2, -1, -1):
		for j in range(ALPHA):
			nxt[i][j] = nxt[i + 1][j]
		nxt[i][s[i]] = i
	cnt = 1
	cur = 0
	for c in t:
		if cur >= ls:
			cur = 0
			cnt += 1
		if nxt[cur][c] == -1:
			cur = 0
			cnt += 1
		if nxt[cur][c] == -1:
			cnt = -1
			break
		cur = nxt[cur][c] + 1
	print(cnt)


import bisect
import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		s1 = input()
		s2 = input()
		n = len(s1)
		d = {}
		le = {}
		for i in range(n):
			if ord(s1[i]) - 96 in d:
				d[ord(s1[i]) - 96].append(i)
			else:
				d[ord(s1[i]) - 96] = [i]
		for i in d:
			le[i] = len(d[i])
			d[i] = sorted(d[i])
		if not set(s2).issubset(set(s1)):
			print(-1)
		else:
			c = 1
			ind = 0
			m1 = len(s2)
			k = 0
			for i in s2:
				k += 1
				l1 = d[ord(i) - 96]
				ans = bisect.bisect_left(l1, ind)
				if ans == le[ord(i) - 96]:
					c += 1
					ind = (d[ord(i) - 96][0] + 1) % n
				else:
					ind = (l1[ans] + 1) % n
					if ind == 0 and k < m1:
						c += 1
			print(c)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def cc(chr):
	return ord(chr) - ord('a')
mod = 1000000007
INF = float('inf')
from bisect import bisect_left

def main():
	for _ in range(N()):
		s = input()
		z = input()
		(ls, lz) = (len(s), len(z))
		dic = defaultdict(list)
		for (i, v) in enumerate(s):
			dic[v].append(i)
		p = -1
		res = 1
		for i in range(lz):
			lis = dic[z[i]]
			if len(lis) == 0:
				print(-1)
				break
			np = bisect_left(lis, p)
			if np == len(lis):
				res += 1
				p = dic[z[i]][0]
				np = 0
			p = lis[np] + 1
		else:
			print(res)
main()


from collections import defaultdict

def solve():
	s = input()
	t = input()
	nxt = [defaultdict(lambda : float('inf')) for _ in range(len(s))]
	nxt[len(s) - 1][s[-1]] = len(s) - 1
	for i in reversed(range(len(s) - 1)):
		nxt[i] = nxt[i + 1].copy()
		nxt[i][s[i]] = i
	start = 0
	ans = 1
	for ch in t:
		if nxt[0][ch] == float('inf'):
			print('-1')
			return
		if start == len(s):
			start = 0
			ans += 1
		cur = nxt[start][ch]
		if cur == float('inf'):
			cur = nxt[0][ch]
			ans += 1
		start = cur + 1
	print(ans)
for _ in range(int(input())):
	solve()


from sys import stdin, stdout
from collections import defaultdict
for _ in range(int(stdin.readline())):
	s = stdin.readline().rstrip()
	t = stdin.readline().rstrip()
	d = defaultdict(list)
	for (i, c) in enumerate(s):
		d[c].append(i)
	ret = 1
	prev = -1
	for (i, c) in enumerate(t):
		a = d[c]
		if not a:
			stdout.write('-1\n')
			break
		(left, right) = (-1, len(a))
		while left + 1 < right:
			mid = left + right >> 1
			if a[mid] <= prev:
				left = mid
			else:
				right = mid
		if right == len(a) or a[right] <= prev:
			prev = a[0]
			ret += 1
		else:
			prev = a[right]
	else:
		stdout.write('%d\n' % ret)


import math
t = int(input())

def search(a, b):
	down = 0
	up = len(v[a]) - 1
	while 1:
		i = math.floor((down + up) / 2)
		if v[a][i] > b and i > 0 and (v[a][i - 1] > b):
			up = math.floor((up + down) / 2)
		elif v[a][i] < b:
			down = math.ceil((up + down) / 2)
		elif v[a][i] == b:
			i += 1
			break
		else:
			break
	return v[a][i]
for i2 in range(t):
	s = str(input())
	h = str(input())
	(v, count, ans) = ([[] for i in range(26)], -1, 1)
	for i in range(len(s)):
		v[ord(s[i]) - 97].append(i)
	for i in range(len(h)):
		if len(v[ord(h[i]) - 97]) == 0:
			ans = -1
			break
		if v[ord(h[i]) - 97][len(v[ord(h[i]) - 97]) - 1] <= count:
			ans += 1
			count = -1
		count = search(ord(h[i]) - 97, count)
	print(ans)


from bisect import bisect
for k in range(int(input())):
	d = {}
	for i in range(97, 123):
		d[chr(i)] = []
	s = input()
	for j in range(len(s)):
		d[s[j]].append(j)
	t = input()
	(cou, st, p, r) = (1, -1, 0, 0)
	while r < len(t):
		q = bisect(d[t[r]], st)
		if d[t[r]] == []:
			p = 1
			break
		try:
			if d[t[r]][q] == st:
				q += 1
			st = d[t[r]][q]
			r += 1
		except:
			cou += 1
			st = -1
	if p == 1:
		print(-1)
	else:
		print(cou)


import math
from collections import Counter, deque
from sys import stdout
import time
from math import factorial, log, gcd
import sys
from decimal import Decimal
import heapq

def S():
	return sys.stdin.readline().split()

def I():
	return [int(i) for i in sys.stdin.readline().split()]

def II():
	return int(sys.stdin.readline())

def IS():
	return sys.stdin.readline().replace('\n', '')

def main():
	s = IS()
	n = len(s)
	t = IS()
	alphabet = set(s)
	if alphabet | set(t) != alphabet:
		print(-1)
		return
	suf_m = dict([(i, [-1] * n) for i in alphabet])
	suf_m[s[-1]][-1] = n - 1
	for i in range(n - 2, -1, -1):
		el = s[i]
		for a in alphabet:
			if a != el:
				suf_m[a][i] = suf_m[a][i + 1]
			else:
				suf_m[el][i] = i
	idx = -1
	op = 0
	for i in range(len(t)):
		el = t[i]
		idx = suf_m[el][idx + 1]
		if idx == n - 1:
			op += 1
			idx = -1
		elif idx == -1:
			op += 1
			idx = suf_m[el][0]
	if idx != -1:
		op += 1
	print(op)
for _ in range(II()):
	main()


from sys import stdin
from bisect import bisect_left

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
debugging = False

def dprint(*args):
	if debugging:
		print(*args)
	else:
		pass

def iden(x):
	return ord(x) - ord('a')
t = intput()
for _ in range(t):
	source = input()
	target = input()
	sc = [0] * 26
	for alpha in source:
		sc[iden(alpha)] += 1
	failed = False
	for x in target:
		if sc[iden(x)] == 0:
			print(-1)
			failed = True
			break
	if failed:
		continue
	indexes = {}
	for i in range(len(source)):
		if source[i] not in indexes:
			indexes[source[i]] = []
		indexes[source[i]].append(i)
	head = 0
	source_head = 0
	cnt = 1
	used = False
	while head != len(target):
		used = True
		nxt_alpha = target[head]
		fnd = bisect_left(indexes[nxt_alpha], source_head)
		if fnd == len(indexes[nxt_alpha]):
			cnt += 1
			used = False
			source_head = 0
		else:
			source_head = indexes[nxt_alpha][fnd] + 1
			if source_head == len(source):
				source_head = 0
				cnt += 1
				used = False
			head += 1
	if not used:
		cnt -= 1
	print(cnt)


from bisect import bisect_left as bl, bisect_right as br
for _ in range(int(input())):
	s = list(map(lambda x: ord(x) - 97, input()))
	t = list(map(lambda x: ord(x) - 97, input()))
	if len(set(t) - set(s)) > 0:
		print(-1)
		continue
	a = [[] for i in range(26)]
	for i in range(len(s)):
		a[s[i]].append(i)
	(ind, ans) = (-1, 1)
	for i in t:
		k = br(a[i], ind)
		if k == len(a[i]):
			ans += 1
			ind = a[i][0]
		else:
			ind = a[i][k]
	print(ans)


from collections import defaultdict
from bisect import bisect_right

def main():
	S = input()
	ts = input()
	d = defaultdict(list)
	for (i, s) in enumerate(S):
		d[s].append(i)
	now = len(S)
	cnt = 0
	for t in ts:
		if len(d[t]) == 0:
			return -1
		l = d[t]
		ind = bisect_right(l, now)
		if len(l) == ind:
			cnt += 1
			now = l[0]
		else:
			now = l[ind]
	return cnt
T = int(input())
for _ in range(T):
	ans = main()
	print(ans)


import math
import bisect
from collections import defaultdict
for _ in range(int(input())):
	s = input()
	t = input()
	n = len(s)
	d = defaultdict(list)
	ans = 1
	for i in range(n):
		d[s[i]].append(i)
	k = 0
	curr = -1
	while k != len(t):
		if len(d[t[k]]) == 0:
			ans = -1
			break
		curr = bisect.bisect(d[t[k]], curr)
		if curr >= len(d[t[k]]):
			curr = -1
			ans += 1
		else:
			curr = d[t[k]][curr]
			k += 1
	print(ans)


for nt in range(int(input())):
	s = input()
	t = input()
	n = len(s)
	d = set(s)
	flag = 0
	for i in t:
		if i not in d:
			print(-1)
			flag = 1
			break
	if flag:
		continue
	dp = [[-1 for i in range(n)] for j in range(26)]
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			dp[ord(s[i]) - 97][-1] = i
			continue
		for j in range(26):
			if ord(s[i]) - 97 == j:
				dp[j][i] = i
			else:
				dp[j][i] = dp[j][i + 1]
	ans = 1
	k = 0
	for i in range(len(t)):
		if k >= n or dp[ord(t[i]) - 97][k] == -1:
			k = dp[ord(t[i]) - 97][0] + 1
			ans += 1
		else:
			k = dp[ord(t[i]) - 97][k] + 1
	print(ans)


from collections import defaultdict

def str2dict(s):
	dict_s = defaultdict(list)
	for i in range(len(s)):
		ch = s[i]
		dict_s[ch].append(i)
	return dict_s

def searchsorted(arr, x):
	l = 0
	r = len(arr) - 1
	while r - l > 1:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid
		else:
			r = mid
	if arr[l] >= x:
		return l
	return r

def find_oper(dict_s, t):
	i_t = 0
	n_oper = 0
	while i_t < len(t):
		i_s = -1
		n_oper += 1
		while i_t < len(t):
			ch = t[i_t]
			if ch not in dict_s:
				return -1
			if dict_s[ch][-1] <= i_s:
				break
			i_s = dict_s[ch][searchsorted(dict_s[ch], i_s + 1)]
			i_t += 1
	return n_oper
T = int(input())
out = [0] * T
for i in range(T):
	s = input()
	t = input()
	out[i] = str(find_oper(str2dict(s), t))
s = print('\n'.join(out))


INF = 10 ** 10

def main():
	print = out.append
	s = list(input())
	t = input()
	st = set(s)
	next = [[len(s)] * 26 for _ in range(len(s))]
	for (i, ele) in reversed(list(enumerate(s))):
		if i == 0:
			continue
		for j in range(26):
			next[i - 1][j] = next[i][j]
		next[i - 1][ord(ele) - ord('a')] = i
	ptr = 0
	res = 1
	for i in t:
		if ptr >= len(s):
			ptr = 0
			res += 1
		if i not in st:
			print(-1)
			return
		if s[ptr] == i:
			ptr += 1
		else:
			ptr = next[ptr][ord(i) - ord('a')] + 1
			if ptr > len(s):
				res += 1
				ptr = 0
				if s[ptr] == i:
					ptr += 1
				else:
					ptr = next[ptr][ord(i) - ord('a')] + 1
	print(res)
import sys
import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


T = int(input())
while T:
	T -= 1
	s = input()
	n = len(s)
	t = input()
	f = [[n] * 26] * n
	for i in range(n - 1, -1, -1):
		if i < n - 1:
			f[i] = f[i + 1].copy()
		f[i][ord(s[i]) - ord('a')] = i
	i = 0
	res = 1
	ok = True
	for c in t:
		j = ord(c) - ord('a')
		if i == n or f[i][j] == n:
			res += 1
			i = 0
			if f[i][j] == n:
				print(-1)
				ok = False
				break
		i = f[i][j] + 1
	if ok:
		print(res)


import bisect

def solve_slow():
	s = input()
	t = input()
	t_i = 0
	last_add = -1
	add = 0
	while add != last_add and t_i < len(t):
		last_add = add
		addition = False
		for s_i in s:
			if s_i == t[t_i]:
				addition = True
				t_i += 1
				if t_i >= len(t):
					break
		if addition:
			add += 1
	if add == last_add:
		print(-1)
	else:
		print(add)

def to_n(c):
	return ord(c) - ord('a')

def solve():
	s = input()
	t = input()
	idx = []
	for i in range(26):
		idx.append([])
	for (i, s_v) in enumerate(s):
		idx[to_n(s_v)].append(i)
	operations = 1
	cur = 0
	for t_i in t:
		l = idx[to_n(t_i)]
		if len(l) == 0:
			operations = -1
			break
		b = bisect.bisect_left(l, cur)
		if b == len(l) and l[b - 1] < cur:
			operations += 1
			cur = l[0]
		elif b == len(l):
			cur = l[b - 1]
		else:
			cur = l[b]
		cur += 1
	print(operations)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
for __ in range(int(input())):
	s = input()
	t = input()
	h = []
	g = [0] * 26
	for i in range(len(s)):
		g[ord(s[i]) - 97] = 1
	for i in range(len(s)):
		h.append([-1] * 26)
	s = s[::-1]
	h[0][ord(s[0]) - 97] = len(s) - 0 - 1
	for i in range(1, len(s)):
		for j in range(26):
			h[i][j] = h[i - 1][j]
		h[i][ord(s[i]) - 97] = len(s) - 1 - i
	h = h[::-1]
	count = 0
	x = 0
	ans = 0
	for i in range(len(t)):
		if g[ord(t[i]) - 97] == 0:
			ans = 1
			break
	if ans == 1:
		print(-1)
	else:
		for i in range(len(t)):
			if h[x][ord(t[i]) - 97] == -1:
				x = h[0][ord(t[i]) - 97] + 1
				count += 1
			else:
				x = h[x][ord(t[i]) - 97] + 1
				if x > len(s) - 1 and i < len(t) - 1:
					x = 0
					count += 1
		print(count + 1)


import sys, bisect
input = sys.stdin.readline
alphabetlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
alp = {i: e for (e, i) in enumerate(alphabetlist)}
for _ in range(int(input())):
	s = input().rstrip()
	t = input().rstrip()
	(n, m) = (len(s), len(t))
	data = [[] for i in range(26)]
	for i in range(n):
		data[alp[s[i]]].append(i)
	res = 1
	pos = -1
	for i in range(m):
		find = alp[t[i]]
		if not data[find]:
			res = -1
			break
		elif pos >= data[find][-1]:
			res += 1
			pos = data[find][0]
		else:
			id = bisect.bisect_right(data[find], pos)
			pos = data[find][id]
	print(res)


import math
import array
tc = int(input())
while tc:
	s = input()
	t = input()
	ns = len(s)
	nt = len(t)
	current = 0
	ans = 1
	dp = [[math.inf for _ in range(26)] for _ in range(ns + 1)]
	for i in range(ns - 1, -1, -1):
		for j in range(26):
			dp[i][j] = dp[i + 1][j]
		dp[i][ord(s[i]) - ord('a')] = i
	for i in range(nt):
		if current == ns:
			ans += 1
			current = 0
		if dp[current][ord(t[i]) - ord('a')] == math.inf:
			ans += 1
			current = 0
		if current == 0 and dp[current][ord(t[i]) - ord('a')] == math.inf:
			ans = -1
			break
		current = int(dp[current][ord(t[i]) - ord('a')] + 1)
	print(ans)
	tc -= 1


import bisect
from collections import defaultdict

def solve(s, t):
	if set(t) - set(s):
		return -1
	pos = defaultdict(list)
	for i in range(len(s)):
		pos[s[i]].append(i)
	c = 1
	j = pos[t[0]][0]
	for e in t[1:]:
		k = bisect.bisect(pos[e], j)
		if k < len(pos[e]):
			j = pos[e][k]
		else:
			c += 1
			j = pos[e][0]
	return c
for _ in range(int(input())):
	(s, t) = (input(), input())
	print(solve(s, t))


from math import *

def check(si, ti):
	lb = 0
	ub = len(ti)
	while lb + 1 < ub:
		tx = (lb + ub) // 2
		tc = (ub - lb) // 2
		if tx >= len(ti):
			return [False, -1]
		if ti[tx] > ci:
			ub -= tc
		else:
			lb += tc
	tx = (lb + ub) // 2
	for i in range(3):
		if tx >= len(ti):
			return [False, -1]
		if ti[tx] <= ci:
			tx += 1
		elif tx > 0 and ti[tx - 1] > ci:
			tx -= 1
	return [True, ti[tx]]
zzz = int(input())
for zz in range(zzz):
	s = input()
	t = input()
	d1 = set()
	d2 = set()
	for i in s:
		d1.add(i)
	for i in t:
		d2.add(i)
	if len(d2 - d1) > 0:
		print(-1)
	else:
		ind = {}
		for x in d1:
			ind[x] = []
		for i in range(len(s)):
			ind[s[i]].append(i)
		i = 1
		ans = 1
		ci = ind[t[0]][0]
		while i < len(t):
			c = check(ci, ind[t[i]])
			if c[0]:
				ci = c[1]
			else:
				ans += 1
				ci = ind[t[i]][0]
			i += 1
		print(ans)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(s, t) = (input()[:-1], input()[:-1])
	(n, m) = (len(s), len(t))
	nxt = [[0 for j in range(26)] for i in range(n + 1)]
	nxt[-1] = [-1] * 26
	for i in range(n - 1, -1, -1):
		for j in range(26):
			if s[i] == chr(ord('a') + j):
				nxt[i][j] = i
			else:
				nxt[i][j] = nxt[i + 1][j]
	a = ans = 0
	for i in t:
		if nxt[a][ord(i) - ord('a')] == -1:
			a = 0
			ans += 1
		a = nxt[a][ord(i) - ord('a')] + 1
		if not a:
			print(-1)
			break
	else:
		print(ans + 1)


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	for _ in range(int(input())):
		s = input()
		t = input()
		if len(set(t) - set(s)) != 0:
			print(-1)
		else:
			G = defaultdict(list)
			for (ii, i) in enumerate(s):
				G[i].append(ii)
			count = 1
			i = 0
			loc = -1
			for i in t:
				v = G[i]
				pos = bisect.bisect_left(v, loc + 1)
				if pos == len(v):
					count += 1
					loc = v[0]
				else:
					loc = v[pos]
			print(count)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import os
import sys
from atexit import register
from io import StringIO
sys.stdout = StringIO()
register(lambda : os.write(1, sys.stdout.getvalue().encode()))
alphabet = 'abcdefghijklmnopqrstuvwxyz'
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	seen_up_to = {}
	first_letter = {}
	next_letter = [{} for _ in range(len(s))]
	for i in range(len(s)):
		c = s[i]
		if c not in first_letter:
			first_letter[c] = i
		up_to = 0 if c not in seen_up_to else seen_up_to[c]
		for j in range(up_to, i):
			next_letter[j][c] = i
		seen_up_to[c] = i
	ret = 0
	t_i = 0
	while t_i < len(t):
		if t[t_i] not in first_letter:
			break
		s_i = first_letter[t[t_i]]
		t_i += 1
		while t_i < len(t) and t[t_i] in next_letter[s_i]:
			s_i = next_letter[s_i][t[t_i]]
			t_i += 1
		ret += 1
	if t_i != len(t):
		print(-1)
	else:
		print(ret)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(Q,) = I()
while Q:
	Q -= 1
	s = input()
	t = input()
	(n, m) = (len(s), len(t))
	s_set = set(s)
	t_set = set(t)
	for i in t_set:
		if i not in s_set:
			print(-1)
			break
	else:
		ans = 0
		idx = [[] for i in range(26)]
		for i in range(n):
			idx[ord(s[i]) - 97].append(i)
		cur = -1
		ok = 0
		for i in range(m):
			x = ord(t[i]) - 97
			k = br(idx[x], cur)
			if k == len(idx[x]):
				ans += 1
				cur = idx[x][0]
			else:
				cur = idx[x][k]
		ans += 1
		print(ans)


from bisect import bisect
T = int(input())
for i in range(T):
	s = [ord(c) - 97 for c in list(input())]
	t = [ord(c) - 97 for c in list(input())]
	pl = [[] for i in range(26)]
	for i in range(len(s)):
		pl[s[i]].append(i)
	p = -1
	m = 1
	imp = False
	for c in t:
		if pl[c] == []:
			imp = True
			break
		j = bisect(pl[c], p)
		if j == len(pl[c]):
			p = pl[c][0]
			m += 1
		else:
			p = pl[c][j]
	print(-1 if imp else m)


def partial_match_table(word):
	table = [0] * (len(word) + 1)
	table[0] = -1
	(i, j) = (0, 1)
	while j < len(word):
		matched = word[i] == word[j]
		if not matched and i > 0:
			i = table[i]
		else:
			if matched:
				i += 1
			j += 1
			table[j] = i
	return table

def kmp_search(text, word):
	table = partial_match_table(word)
	(i, p) = (0, 0)
	results = []
	while i < len(text) and p < len(word):
		if text[i] == word[p]:
			i += 1
			p += 1
			if p == len(word):
				p = table[p]
				results.append((i - len(word), i))
		elif p == 0:
			i += 1
		else:
			p = table[p]
	return results

def find(i, l):
	(mx, mn) = (len(l), -1)
	if l[-1] <= i:
		return l[0]
	idx = mx // 2
	while mx - mn > 1:
		if l[idx] > i:
			(mx, idx) = (idx, (idx + mn) // 2)
			continue
		(mn, idx) = (idx, (idx + mx) // 2)
	return l[idx + 1]
from collections import defaultdict
q = int(input())
for _ in range(q):
	s = input().strip()[::-1]
	t = input().strip()[::-1]
	d = defaultdict(list)
	for (i, c) in enumerate(s):
		d[c].append(i)
	f = 0
	for c in t:
		if c not in d:
			f = True
			break
	if f:
		print(-1)
		continue
	i = -1
	r = 1
	for c in t:
		j = find(i, d[c])
		if i >= j:
			r += 1
		i = j
	print(r)


t = int(input())

def ceil(a, b):
	return a // b + (a % b > 0)
for _ in range(t):
	sl = list(input())
	tl = list(input())
	from collections import defaultdict
	dic = defaultdict(list)
	n = len(sl)
	for (idx, s) in enumerate(sl):
		dic[s].append(idx + 1)
		dic[s].append(idx + n + 1)
	for s in dic:
		dic[s] = sorted(dic[s])
	import bisect
	ans = -1
	now = 0
	for t in tl:
		if t not in dic:
			print(-1)
			break
		idx = bisect.bisect_right(dic[t], now)
		ans += dic[t][idx] - now
		now = dic[t][idx] % n
	else:
		print(ans // n + 1)


from collections import defaultdict
from bisect import bisect_left

def solve(s, t):
	indices = defaultdict(list)
	for (i, c) in enumerate(s):
		indices[c].append(i)
	turn = 1
	currIndex = 0
	for c in t:
		if c not in indices:
			return -1
		if currIndex > indices[c][-1]:
			turn += 1
			currIndex = 0
		pos = bisect_left(indices[c], currIndex)
		currIndex = indices[c][pos] + 1
	return turn
T = int(input())
for t in range(T):
	s = input()
	t = input()
	print(solve(s, t))


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf
from itertools import permutations
from copy import deepcopy
from heapq import *
from sys import setrecursionlimit

def main():
	for _ in range(int(input())):
		s = input().rstrip()
		t = input().rstrip()
		(n, m) = (len(s), len(t))
		a = defaultdict(list)
		for (i, v) in enumerate(s):
			a[v].append(i)
		(ans, val) = (1, -1)
		for (j, i) in enumerate(t):
			if a[i] == []:
				val = -1
				break
			z = bisect_left(a[i], val)
			if z == len(a[i]):
				ans += 1
				z = 0
			val = a[i][z] + (0 if j == m - 1 else 0 if t[j] != t[j + 1] else 1)
		print(-1 if val == -1 else ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import defaultdict
import bisect
x = int(input())
for _ in range(x):
	a = input()
	b = input()
	m = len(a)
	n = len(b)
	d = defaultdict(list)
	for i in range(m):
		d[a[i]].append(i + 1)
	f = 0
	s = 1
	p = -1
	for i in b:
		if len(d[i]) == 0:
			f = 1
			break
		lol = bisect.bisect(d[i], p)
		if lol == len(d[i]):
			s += 1
			p = d[i][0]
		else:
			p = d[i][lol]
	if f:
		s = -1
	print(s)


from bisect import *
tt = int(input())
for _ in range(tt):
	s = list(input())
	t = list(input())
	s = [ord(i) - 97 for i in s]
	t = [ord(i) - 97 for i in t]
	freq = [[] for i in range(26)]
	j = 0
	for i in s:
		freq[i].append(j)
		j += 1
	freq2 = [[] for i in range(26)]
	j = 0
	for i in t:
		freq2[i].append(j)
		j += 1
	st = 0
	for i in range(26):
		if freq[i] == [] and len(freq2[i]) > 0:
			st = 1
			break
	if st:
		print(-1)
	else:
		ind = 0
		ind2 = 0
		co = 0
		while ind2 < len(t):
			co += 1
			while ind2 < len(t):
				x = bisect_left(freq[t[ind2]], ind)
				if x == len(freq[t[ind2]]):
					ind = 0
					break
				ind2 += 1
				ind = freq[t[ind2 - 1]][x] + 1
		print(co)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	s = input()
	t = input()
	n = len(s)
	ind = defaultdict(list)
	for i in range(n):
		ind[s[i]].append(i)
	last = -1
	ans = 1
	for i in t:
		if len(ind[i]) == 0:
			ans = -1
			break
		cur = bisect_left(ind[i], last)
		if cur == len(ind[i]):
			ans += 1
			cur = 0
		last = ind[i][cur] + 1
	print(ans)


import bisect
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 5)

def cal(i):
	global dic, dp, s
	pos = -1
	ans = 0
	for j in range(i, len(s)):
		pos = bisect.bisect_right(dic[s[j]], pos)
		if pos < len(dic[s[j]]):
			pos = dic[s[j]][pos]
		else:
			ans += 1
			pos = bisect.bisect_right(dic[s[j]], -1)
			pos = dic[s[j]][pos]
	return ans + 1
for _ in range(int(input())):
	t = input()
	s = input()
	dic = defaultdict(lambda : [])
	for i in range(len(t)):
		dic[t[i]].append(i)
	for i in s:
		if i not in dic:
			print(-1)
			break
	else:
		ans = cal(0)
		print(ans)


t = int(input())

def find(letter, after):
	global pos
	if letter not in pos.keys():
		return -2
	if pos[letter][0] > after:
		return pos[letter][0]
	elif pos[letter][-1] <= after:
		return -1
	lower = 0
	upper = len(pos[letter]) - 1
	while upper - lower > 1:
		mid = (lower + upper) // 2
		if pos[letter][mid] > after:
			upper = mid
		else:
			lower = mid
	return pos[letter][upper]
for number in range(t):
	s = input()
	t = input()
	pos = {}
	for (i, let) in enumerate(s):
		if let not in pos.keys():
			pos[let] = []
		pos[let].append(i)
	counter = 0
	i = -1
	found = False
	for l in t:
		c = find(l, i)
		if c == -2:
			print(-1)
			found = True
			break
		elif c == -1:
			counter += 1
			i = -1
			i = find(l, i)
		else:
			i = c
	if found:
		continue
	if i == -1:
		print(counter)
	else:
		print(counter + 1)


from collections import defaultdict
import bisect

def main():
	T = int(input())
	for p in range(T):
		s = input()
		t = input()
		dic = defaultdict(list)
		for (i, ch) in enumerate(s):
			dic[ch].append(i)
		ans = 1
		(i, j) = (0, 0)
		while i < len(t):
			ch = t[i]
			if ch not in dic:
				print(-1)
				break
			if j > dic[ch][-1]:
				ans += 1
				j = 0
			else:
				pos = bisect.bisect_left(dic[ch], j)
				j = dic[ch][pos] + 1
				i += 1
		if i == len(t):
			print(ans)
main()


from collections import defaultdict
from bisect import bisect_left
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	dict = defaultdict(list)
	for i in range(len(s)):
		dict[s[i]].append(i)
	ans = 1
	left = 0
	flag = False
	for c in t:
		if len(dict[c]) == 0:
			flag = True
			break
		i = bisect_left(dict[c], left)
		if i == len(dict[c]):
			ans += 1
			left = dict[c][0] + 1
		else:
			left = dict[c][i] + 1
	if flag:
		ans = -1
	print(ans)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	s = inp()
	t = inp()
	md = {}
	S = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(26):
		md[S[i]] = i
	nt = len(t)
	ns = len(s)
	ans = 1
	flg = True
	ind = 0
	cnt = l2d(26, ns + 1, -1)
	for i in range(ns - 1, -1, -1):
		for j in range(26):
			if j == md[s[i]]:
				cnt[j][i] = i
			else:
				cnt[j][i] = cnt[j][i + 1]
	i = 0
	while i < nt:
		if cnt[md[t[i]]][0] == -1:
			flg = False
			break
		if cnt[md[t[i]]][ind] == -1:
			ind = 0
			ans += 1
		else:
			ind = cnt[md[t[i]]][ind] + 1
			i += 1
	print(ans if flg else -1)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	s = list(sys.stdin.readline())
	s = s[:len(s) - 1]
	t = list(sys.stdin.readline())
	t = t[:len(t) - 1]
	d = [[] for _ in range(26)]
	for (i, x) in enumerate(s):
		s[i] = ord(x) - 97
		d[ord(x) - 97].append(i)
	for (i, x) in enumerate(t):
		t[i] = ord(x) - 97
	res = 1
	bad = False
	ind = 0
	for (i, x) in enumerate(t):
		if not d[x]:
			bad = True
			break
		if d[x][-1] < ind:
			res += 1
			ind = 0
		c = bisect_left(d[x], ind)
		ind = d[x][c] + 1
	print(res if not bad else -1)


import sys
input = sys.stdin.readline

def binSearch(arr, x, low, high):
	if len(arr) == 0:
		return -1
	if low > high or low >= len(arr):
		if low < len(arr) and arr[low] > x:
			return arr[low]
		return -1
	mid = (low + high) // 2
	if arr[mid] == x:
		return x
	elif arr[mid] < x:
		return binSearch(arr, x, mid + 1, high)
	return binSearch(arr, x, low, mid - 1)
from collections import defaultdict
for _ in range(int(input())):
	alphabets = defaultdict(list)
	(s, t, ans, pos) = (input(), input(), 1, 0)
	for i in range(len(s)):
		alphabets[s[i]].append(i)
	i = 0
	while i < len(t):
		k = t[i]
		temp = binSearch(alphabets[k], pos, 0, len(alphabets[k])) + 1
		if pos == 0 and temp == 0:
			ans = -1
			break
		pos = temp
		if pos == 0:
			i -= 1
			ans += 1
		i += 1
	print(ans)


from collections import defaultdict
import bisect
import sys

def load_sys():
	return sys.stdin.readlines()

def load_local():
	with open('input.txt', 'r') as f:
		input = f.readlines()
	return input

def f(s, t):
	(S, T) = (set(s), set(t))
	for c in T:
		if c not in S:
			return -1
	nxt = defaultdict(list)
	for i in range(len(s)):
		nxt[s[i]].append(i)
	i = j = ans = 0
	ans += 1
	while j < len(t):
		c = t[j]
		k = bisect.bisect_left(nxt[c], i)
		if k == len(nxt[c]):
			i = 0
			ans += 1
		else:
			j += 1
			i = nxt[c][k] + 1
	return ans
data = load_sys()
for i in range(1, len(data), 2):
	s = data[i].strip()
	t = data[i + 1].strip()
	print(f(s, t))


import math
import collections

def solve():
	s = input()
	t = input()
	dic = collections.defaultdict(list)
	for i in range(len(s)):
		dic[s[i]].append(i)
	cnt = 1
	idx = -1
	for i in range(len(t)):
		if t[i] not in dic:
			print(-1)
			return
		(l, r) = (0, len(dic[t[i]]))
		while l < r:
			m = (l + r) // 2
			if dic[t[i]][m] > idx:
				r = m
			else:
				l = m + 1
		if l == len(dic[t[i]]):
			cnt += 1
			idx = dic[t[i]][0]
		else:
			idx = dic[t[i]][l]
	print(cnt)

def main():
	T = 1
	T = int(input())
	while T:
		solve()
		T -= 1
main()


from bisect import bisect_right
for t in range(int(input())):
	s = input()
	t = input()
	sd = {i: [] for i in range(26)}
	for i in range(len(s)):
		sd[ord(s[i]) - ord('a')].append(i)
	res = 1
	lst = -1
	for j in range(len(t)):
		a = ord(t[j]) - 97
		if len(sd[a]) == 0:
			res = -1
			break
		tt = bisect_right(sd[a], lst)
		if tt == len(sd[a]):
			res += 1
			lst = sd[a][0]
		else:
			lst = sd[a][tt]
	print(res)


from collections import defaultdict
import bisect
T = int(input())
for i in range(T):
	s = input()
	t = input()
	dict1 = defaultdict(list)
	for i in range(len(s)):
		dict1[s[i]].append(i)
	ok = False
	try:
		index = dict1[t[0]][0]
	except:
		ok = True
	count = 1
	for j in range(1, len(t)):
		try:
			if dict1[t[j]][-1] > index:
				index = dict1[t[j]][bisect.bisect(dict1[t[j]], index)]
			else:
				index = dict1[t[j]][0]
				count += 1
		except:
			ok = True
	print(count if ok == False else -1)


import sys

def input():
	return sys.stdin.readline().rstrip()
DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)]

def slv():
	s = input()
	n = len(s)
	s *= 2
	t = input()
	m = len(t)
	dp = []
	for char in range(26):
		a = [2 * n] * (2 * n)
		for i in range(2 * n):
			if s[i] == chr(char + ord('a')):
				a[i] = i
		for i in reversed(range(2 * n - 1)):
			a[i] = min(a[i], a[i + 1])
		dp.append(a)
	(ans, pos) = (1, 0)
	for i in range(m):
		char = ord(t[i]) - ord('a')
		if dp[char][pos] == 2 * n:
			print(-1)
			return 0
		elif dp[char][pos] < n:
			pos = dp[char][pos] + 1
		else:
			pos = dp[char][pos] - n + 1
			ans += 1
	print(ans)
	return 0

def main():
	t = int(input())
	for i in range(t):
		slv()
	return 0
main()


import bisect
from collections import defaultdict
for _ in range(int(input())):
	s = str(input())
	t = str(input())
	l = defaultdict(list)
	j = 0
	for i in s:
		j += 1
		l[i].append(j)
	g = -1
	ans = 0
	h = 0
	for i in t:
		if len(l[i]) != 0:
			x = bisect.bisect_right(l[i], g)
			if x >= len(l[i]):
				g = l[i][0]
				ans += 1
			else:
				g = l[i][x]
		else:
			h = 1
			break
	if h == 1:
		print(-1)
	else:
		print(ans + 1)


from collections import defaultdict

def binSearch(arrBin, num):
	l = -1
	r = len(arrBin) - 1
	while l + 1 < r:
		m = (l + r) // 2
		if arrBin[m] <= num:
			l = m
		else:
			r = m
	if arrBin[r] <= num:
		return -1
	return arrBin[r]

def run(s, t):
	d = defaultdict(list)
	for i in range(len(s)):
		d[s[i]].append(i)
	ind = -1
	ans = 1
	for i in range(len(t)):
		if len(d[t[i]]) == 0:
			return -1
		pos = binSearch(d[t[i]], ind)
		ind = pos
		if pos == -1:
			ans += 1
			ind = -1
			pos = binSearch(d[t[i]], ind)
			ind = pos
			if pos == -1:
				return -1
	return ans
test = int(input())
for _ in range(test):
	s = input()
	t = input()
	print(run(s, t))


from sys import *
from bisect import *
q = int(stdin.readline())
for _ in range(q):
	s = input()
	t = input()
	m = []
	for i in range(26):
		m.append([])
	for i in range(len(s)):
		m[ord(s[i]) - 97].append(i)
	cnt = 1
	f = 0
	k = -1
	for i in range(len(t)):
		ls = m[ord(t[i]) - 97]
		if len(ls) == 0:
			f = 1
			break
		pos = bisect_right(ls, k)
		if pos == len(ls):
			k = ls[0]
			cnt += 1
		else:
			k = ls[pos]
	if f == 1:
		print(-1)
	else:
		print(cnt)


def solve(s, t):
	dp = [[float('inf') for i in range(26)] for j in range(len(s))]
	for i in range(len(s) - 1, -1, -1):
		dp[i][ord(s[i]) - ord('a')] = i
		if i + 1 < len(s):
			for j in range(26):
				dp[i][j] = min(dp[i][j], dp[i + 1][j])
	moves = 0
	i = 0
	j = 0
	while True:
		index = dp[i][ord(t[j]) - ord('a')]
		if index == float('inf') and i == 0:
			print(-1)
			return
		found = False
		if index == float('inf'):
			i = 0
			moves += 1
			found = True
		else:
			j += 1
			i = index + 1
			if i == len(s):
				i = 0
				moves += 1
				found = True
		if j == len(t):
			if not found:
				moves += 1
			break
	print(moves)

def main():
	T = int(input())
	for i in range(T):
		s = input()
		t = input()
		solve(s, t)
main()


def alpha(x):
	return ord(x) - 97
for _ in range(int(input())):
	s = input()
	t = input()
	curi = 0
	iters = 1
	nexts = [[-1 for _ in range(len(s) + 1)] for _ in range(26)]
	for i in range(26):
		for j in range(len(s) - 1, -1, -1):
			if alpha(s[j]) == i:
				nexts[i][j] = j
			else:
				nexts[i][j] = nexts[i][j + 1]
	for i in range(26):
		for j in range(len(s) - 1, -1, -1):
			if nexts[i][j] == -1:
				nexts[i][j] = nexts[i][0]
	for ch in t:
		if curi == len(s):
			curi = 0
			iters += 1
		nexti = nexts[alpha(ch)][curi]
		if nexti == -1:
			print(-1)
			break
		if nexti < curi:
			iters += 1
		curi = nexti + 1
	else:
		print(iters)


import sys
input = sys.stdin.readline
t = int(input())
for test in range(t):
	s = input().strip()
	t = input().strip()
	LEN = len(s)
	NEXT = [[-1] * 26 for i in range(LEN + 1)]
	for i in range(LEN - 1, -1, -1):
		for j in range(26):
			NEXT[i][j] = NEXT[i + 1][j]
		NEXT[i][ord(s[i]) - 97] = i
	ANS = 0
	ind = 0
	indt = 0
	LENT = len(t)
	while indt < LENT:
		k = t[indt]
		if ind == 0 and NEXT[ind][ord(k) - 97] == -1:
			print(-1)
			break
		elif NEXT[ind][ord(k) - 97] == -1:
			ANS += 1
			ind = 0
		else:
			ind = NEXT[ind][ord(k) - 97] + 1
			indt += 1
	else:
		print(ANS + 1)


import sys, bisect as bi
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	s = input().strip()
	t = input().strip()
	an = 1
	if set(t) - set(s):
		print(-1)
	else:
		al = [[] for i in range(26)]
		for i in range(len(s)):
			al[ord(s[i]) - 97].append(i)
		p = al[ord(t[0]) - 97][0]
		for i in range(1, len(t)):
			cr = ord(t[i]) - 97
			ix = bi.bisect(al[cr], p)
			if ix == len(al[cr]):
				an += 1
				p = al[cr][0]
			else:
				p = al[cr][ix]
		print(an)


from sys import stdin
input = stdin.readline

def printTable(u):
	for _ in u:
		print(*_)

def getAns(s, t):
	l = len(s)
	l2 = len(t)
	(rows, cols) = (l, 26)
	u = [[-1 for i in range(cols)] for j in range(rows)]
	currLetterIndices = [-1] * 26
	for j in range(26):
		if j in s:
			ind = s.index(j)
			currLetterIndices[j] = 0
			for i in range(l):
				u[i][j] = ind
	for i in range(l):
		currLetter = s[i]
		for k in range(currLetterIndices[currLetter], i):
			u[k][currLetter] = i
		currLetterIndices[currLetter] = i
	currIndex = -1
	cycles = 1
	for letter in t:
		newIndex = u[currIndex][letter]
		if newIndex <= currIndex:
			cycles += 1
			if newIndex == -1:
				return -1
		currIndex = newIndex
	return cycles
for _ in range(int(input())):
	s = [ord(x) - 97 for x in input().rstrip()]
	t = [ord(x) - 97 for x in input().rstrip()]
	print(getAns(s, t))


from sys import stdin
input = lambda : stdin.readline().strip()
from array import array
for _ in range(int(input())):
	s = input()
	t = input()
	n = len(s)
	dp = [[-1 for i in range(26)] for i in range(n + 1)]
	for i in range(n - 1, -1, -1):
		dp[i] = dp[i + 1].copy()
		dp[i][ord(s[i]) - 97] = i
	op = 0
	base = 0
	for i in t:
		base = dp[base][ord(i) - 97] + 1
		if base == 0:
			op += 1
			base = dp[base][ord(i) - 97] + 1
			if base == 0:
				base = 0
				op = -1
				break
	if base != 0:
		op += 1
	print(op)


import bisect
from sys import stdin
input = stdin.readline
for xoxo in range(1):
	for _ in range(int(input())):
		a = []
		for i in range(26):
			a.append([])
		s = input()
		t = input()
		for i in range(len(s) - 1):
			a[ord(s[i]) - 97].append(i)
		i = 0
		kk = 1
		ans = 0
		lt = len(t) - 1
		for i in range(lt):
			if len(a[ord(t[i]) - 97]) == 0:
				print('-1')
				kk = 0
				break
		if kk == 0:
			continue
		i = 0
		while i < lt:
			k = 0
			while i < lt:
				j = bisect.bisect_left(a[ord(t[i]) - 97], k)
				if j == len(a[ord(t[i]) - 97]):
					ans += 1
					break
				i += 1
				if i >= lt:
					ans += 1
					break
				k = a[ord(t[i - 1]) - 97][j] + 1
		print(ans)


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

def In():
	return map(int, input().split())

def ln():
	return list(map(int, input().split()))

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	a = Sn()
	n = len(a)
	dp = [[float('inf')] * 26 for i in range(n + 1)]
	b = Sn()
	pre = set()
	d = [float('inf')] * 26
	for i in range(n - 1, -1, -1):
		pre.add(a[i])
		d[ord(a[i]) - ord('a')] = i
		for j in range(26):
			dp[i][j] = d[j]
	ans = 1
	pos = 0
	for x in b:
		if x not in pre:
			print(-1)
			return
		if pos == len(a):
			pos = 0
			ans += 1
		if dp[pos][ord(x) - ord('a')] == Inf:
			pos = 0
			ans += 1
		pos = dp[pos][ord(x) - ord('a')] + 1
	print(ans)
	pass

def main():
	T = I()
	for i in range(T):
		solve()
M = 998244353
P = 1000000007
Inf = float('inf')

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import bisect
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	sts = set(s)
	stt = set(t)
	if stt.issubset(sts):
		dt2 = [-1] * 26
		for i in range(len(s)):
			if dt2[ord(s[i]) - 97] == -1:
				dt2[ord(s[i]) - 97] = [i]
			else:
				dt2[ord(s[i]) - 97].append(i)
		ind1 = -1
		cnt = 1
		for ch in t:
			ind = bisect.bisect_right(dt2[ord(ch) - 97], ind1)
			if ind == len(dt2[ord(ch) - 97]) or ind1 >= dt2[ord(ch) - 97][ind]:
				cnt += 1
				ind1 = dt2[ord(ch) - 97][0]
			else:
				ind1 = dt2[ord(ch) - 97][ind]
		print(cnt)
	else:
		print(-1)


inf = float('inf')
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	n = len(s)
	loc = [[inf for __ in range(26)] for _ in range(n + 1)]
	s2 = []
	t2 = []
	for c in s:
		s2.append(ord(c) - ord('a'))
	for c in t:
		t2.append(ord(c) - ord('a'))
	s = s2
	t = t2
	for j in range(n - 1, -1, -1):
		for i in range(26):
			loc[j][i] = loc[j + 1][i]
		loc[j][s[j]] = j
	possible = True
	tptr = 0
	nMoves = 0
	while True:
		nMoves += 1
		sptr = 0
		c = t[tptr]
		if loc[sptr][c] == inf:
			possible = False
			break
		while tptr < len(t) and loc[sptr][c] != inf:
			sptr = loc[sptr][c] + 1
			tptr += 1
			if tptr == len(t):
				break
			c = t[tptr]
		if tptr == len(t):
			break
	if possible:
		print(nMoves)
	else:
		print(-1)


from bisect import *
from collections import defaultdict
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	d = defaultdict(list)
	for i in range(len(s)):
		d[s[i]].append(i)
	ans = 1
	prev_idx = -1
	flag = True
	for i in range(len(t)):
		if len(d[t[i]]) == 0:
			flag = False
			break
		idx = bisect_right(d[t[i]], prev_idx)
		if idx == len(d[t[i]]):
			ans += 1
			prev_idx = d[t[i]][0]
		else:
			prev_idx = d[t[i]][idx]
	if flag:
		print(ans)
	else:
		print(-1)


import sys
from string import ascii_lowercase as lows
t = int(sys.stdin.readline())

def firstGreaterThan(nums, n):
	if nums[-1] <= n:
		return nums[0]
	low = 0
	high = len(nums) - 1
	mid = low
	while low != high:
		mid = (low + high) // 2
		if nums[mid] > n:
			high = mid
		else:
			low = mid + 1
	return nums[low]
for _ in range(t):
	s = sys.stdin.readline().strip()
	t = sys.stdin.readline().strip()
	s = list(zip(s, range(1, len(s) + 1)))
	proc = {}
	for c in lows:
		at = list(filter(lambda x: x[0] == c, s))
		at = [tup[1] for tup in at]
		proc[c] = at
	at = 0
	revs = 1
	for c in t:
		if len(proc[c]) == 0:
			revs = -1
			break
		nex = firstGreaterThan(proc[c], at)
		if nex <= at:
			revs += 1
		at = nex
	print(revs)


import sys
import bisect
q = int(input())
while q:
	s = input()
	t = input()
	l = -1
	ch = 0
	cnt = 1
	d = {i: [] for i in range(26)}
	ind = 0
	for i in s:
		d[ord(i) - 97].append(ind)
		ind += 1
	for i in t:
		if d[ord(i) - 97] == []:
			print(-1)
			ch = 1
			break
		else:
			p = bisect.bisect_right(d[ord(i) - 97], l)
			if p >= len(d[ord(i) - 97]):
				cnt += 1
				l = d[ord(i) - 97][0]
			else:
				l = d[ord(i) - 97][p]
	if ch == 0:
		print(cnt)
	q -= 1


from collections import defaultdict
from bisect import bisect
n = int(input())

def solve():
	curr_s = -1
	curr_j = 0
	k = 1
	while curr_j < len(t):
		curr_t = t[curr_j]
		if not idx[curr_t]:
			k = -1
			break
		else:
			res = bisect(idx[curr_t], curr_s)
			if res == len(idx[curr_t]):
				k += 1
				curr_s = -1
			else:
				curr_s = idx[curr_t][res]
				curr_j += 1
	print(k)
for _ in range(n):
	s = input()
	t = input()
	idx = defaultdict(list)
	for (i, c) in enumerate(s):
		idx[c].append(i)
	solve()


from bisect import bisect_right as br
for _ in range(int(input())):
	a = list(input())
	t = list(input())
	l = list(set(t))
	flag = 0
	for x in l:
		if x not in a:
			flag = 1
			break
	if flag == 1:
		print(-1)
		continue
	d = {}
	for i in range(len(a)):
		if a[i] not in d:
			d[a[i]] = [i]
		else:
			d[a[i]].append(i)
	ans = len(t)
	b = t
	choose = [0] * len(t)
	choose[0] = d[b[0]][0]
	for i in range(1, len(b)):
		p = br(d[b[i]], choose[i - 1])
		if p >= len(d[b[i]]):
			choose[i] = d[b[i]][0]
		else:
			ans -= 1
			choose[i] = d[b[i]][p]
	print(ans)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	s = input().rstrip()
	t = input().rstrip()
	L = len(s)
	dp = []
	cur_min = [-1] * 26
	for i in range(L):
		x = s[L - 1 - i]
		xx = ord(x) - 97
		cur_min[xx] = L - 1 - i
		dp.append(cur_min[:])
	dp.reverse()
	ans = 1
	ALL = set(s)
	for x in t:
		if x not in ALL:
			ans = -1
	if ans < 0:
		print(ans)
		continue
	cur = 0
	for x in t:
		xx = ord(x) - 97
		if cur == L or dp[cur][xx] < 0:
			cur = 0
			ans += 1
		cur = dp[cur][xx] + 1
	print(ans)


import bisect
import sys
a = [1, 2, 3]
t = int(input())
g = sys.stdin.readlines()
for i in range(t):
	answer = 1
	s = g[2 * i].replace('\n', '')
	t = g[2 * i + 1].replace('\n', '')
	d = dict()
	for i in range(len(s)):
		try:
			d[s[i]].append(i)
		except KeyError:
			d[s[i]] = [i]
	j = -1
	for i in range(len(t)):
		if t[i] not in d.keys():
			answer = -1
			break
		y = bisect.bisect_right(d[t[i]], j)
		if y < len(d[t[i]]):
			j = d[t[i]][y]
		else:
			answer += 1
			j = -1
			y = bisect.bisect_right(d[t[i]], j)
			j = d[t[i]][y]
	print(answer)


def bi_search(a, x):
	(l, r) = (0, len(a) - 1)
	if a[r] <= x:
		return -1
	while l < r:
		m = (l + r) // 2
		if a[m] <= x:
			l = m + 1
		else:
			r = m
	return a[r]

def solve(s, t):
	pos = [[] for _ in range(26)]
	for (i, c) in enumerate(s):
		x = ord(c) - ord('a')
		pos[x].append(i)
	cur = -1
	ans = 1
	for (i, c) in enumerate(t):
		x = ord(c) - ord('a')
		if pos[x] == []:
			print(-1)
			return
		it = bi_search(pos[x], cur)
		if it == -1:
			it = pos[x][0]
			ans += 1
		cur = it
	print(ans)

def main():
	tc = int(input())
	for _ in range(tc):
		s = input()
		t = input()
		solve(s, t)
main()


import sys
readline = sys.stdin.readline
Qu = int(readline())
Ans = [None] * Qu
for qu in range(Qu):
	T = list(map(lambda x: ord(x) - 97, readline().strip()))
	S = list(map(lambda x: ord(x) - 97, readline().strip()))
	N = len(S)
	M = len(T)
	inf = 10 ** 9 + 7
	table = [[inf] * 26 for _ in range(M + 1)]
	for i in range(M - 1, -1, -1):
		t = T[i]
		for j in range(26):
			table[i][j] = table[i + 1][j]
		table[i][t] = i
	cnt = 0
	j = -1
	ans = 1
	while cnt < N:
		s = S[cnt]
		if j == M or table[j + 1][s] == inf:
			ans += 1
			j = -1
		j = table[j + 1][s]
		cnt += 1
		if j == inf:
			ans = -1
			break
	Ans[qu] = ans
print('\n'.join(map(str, Ans)))


tt = int(input())
for i in range(tt):
	s = input()
	t = input()
	sm = [[] for i in range(len(s))]
	sa = [-1 for i in range(26)]
	cind = 0
	start = 0
	cnt = 1
	s0 = s[0]
	for i in range(len(s) - 1, -1, -1):
		sm[i] = sa.copy()
		sa[int(s[i], base=36) - 10] = i
	sa = sm[0].copy()
	for i in range(26):
		if sa[i] == -1:
			sa[i] = -2
	if sa[int(s[0], base=36) - 10] == -2:
		sa[int(s[0], base=36) - 10] = -3
	sm[0] = sa.copy()
	if s0 == t[0]:
		start = 1
	for i in range(start, len(t)):
		l = int(t[i], base=36) - 10
		nind = sm[cind][l]
		if nind == -1:
			cnt += 1
			if int(s0, base=36) - 10 == l:
				cind = 0
				continue
			else:
				if sm[0][l] == -2:
					print(-1)
					break
				cind = sm[0][l]
				continue
		if nind == -2:
			print(-1)
			break
		if nind == -3:
			cind = 0
			cnt += 1
		else:
			cind = nind
	else:
		print(cnt)


def next(arr, target):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans

def sol():
	s = list(input())
	t = list(input())
	f = []
	for i in range(26):
		f.append([])
	for i in range(len(s)):
		f[ord(s[i]) - 97].append(i)
	for i in range(len(t)):
		t[i] = ord(t[i]) - 97
	ind = 0
	c = 1
	inds = [0] * 26
	l = -1
	while ind < len(t):
		if inds[t[ind]] >= len(f[t[ind]]):
			if len(f[t[ind]]) == 0:
				c = -1
				break
			inds = [0] * 26
			l = -1
			c += 1
			continue
		fl = False
		ne = next(f[t[ind]], l)
		if ne == -1:
			inds = [0] * 26
			l = -1
			c += 1
			continue
		inds[t[ind]] = ne
		if f[t[ind]][inds[t[ind]]] <= l:
			inds = [0] * 26
			l = -1
			c += 1
			continue
		l = f[t[ind]][inds[t[ind]]]
		inds[t[ind]] += 1
		ind += 1
	print(c)
for _ in range(int(input())):
	sol()


def getRow(c):
	return ord(c) - 97
for t in range(int(input())):
	s = input()
	t = input()
	inf = len(s)
	grid = [[inf] * len(s) for _ in range(26)]
	grid[getRow(s[-1])][-1] = len(s) - 1
	for col in reversed(range(len(s) - 1)):
		for row in range(26):
			grid[row][col] = grid[row][col + 1]
		grid[getRow(s[col])][col] = col
	res = 1
	spot = 0
	for c in t:
		if spot >= inf:
			res += 1
			spot = 0
		check = grid[getRow(c)][0]
		if check >= inf:
			res = -1
			break
		spot = grid[getRow(c)][spot]
		if spot >= inf:
			res += 1
			spot = check
		spot += 1
	print(res)


import sys
input = sys.stdin.readline
from bisect import bisect_right
Q = int(input())
Query = []
for _ in range(Q):
	S = list(input().rstrip())
	T = list(input().rstrip())
	Query.append((S, T))
for (S, T) in Query:
	L = len(T)
	dic = {}
	for (i, s) in enumerate(S):
		if not s in dic:
			dic[s] = [i]
		else:
			dic[s].append(i)
	ans = 1
	ind = -1
	for t in T:
		if not t in dic:
			ans = -1
			break
		p = bisect_right(dic[t], ind)
		if p == len(dic[t]):
			ans += 1
			ind = dic[t][0]
		else:
			ind = dic[t][p]
	print(ans)


from collections import defaultdict
import bisect
for x in range(int(input())):
	s = input()
	t = input()
	d = defaultdict(list)
	j = 0
	for i in s:
		d[i].append(j)
		j += 1
	r = 0
	for f in set(t):
		if f not in set(s):
			r = 1
			break
	if r == 1:
		print(-1)
	else:
		k = 1
		c = -1
		for r in d:
			d[i].sort()
		for l in t:
			if d[l][-1] <= c:
				c = d[l][0]
				k += 1
			else:
				p = bisect.bisect_right(d[l], c)
				c = d[l][p]
		print(k)


import math
import bisect
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	alpha = list('abcdefghijklmnopqrstuvwxyz')
	dic_s = {alpha[i]: 0 for i in range(26)}
	dic_t = {alpha[i]: 0 for i in range(26)}
	a = {alpha[i]: [] for i in range(26)}
	b = {alpha[i]: [] for i in range(26)}
	for i in range(len(s)):
		if dic_s[s[i]] == 0:
			dic_s[s[i]] = +1
		a[s[i]].append(i + 1)
	for j in range(len(t)):
		if dic_t[t[j]] == 0:
			dic_t[t[j]] = +1
		b[t[j]].append(j + 1)
	for i in range(26):
		a[alpha[i]].append(10 ** 9)
	flag = True
	for i in range(26):
		if dic_t[alpha[i]] > 0 and dic_s[alpha[i]] == 0:
			flag = False
	place = [0, 0]
	if flag:
		cnt = 1
		for i in range(len(t)):
			string = t[i]
			num = bisect.bisect_right(a[string], place[0])
			if a[string][num] == 10 ** 9:
				place[1] += 1
				place[0] = a[string][0]
				cnt += 1
			else:
				place[0] = a[string][num]
		print(cnt)
	else:
		print(-1)


T = int(input().strip())
for _ in range(T):
	s = input().strip()
	t = input().strip()
	lt = len(t)
	if lt == 0:
		print(0)
		continue
	s_letters = set((el for el in s))
	impossible = False
	for el in t:
		if el not in s_letters:
			impossible = True
			break
	if impossible:
		print(-1)
		continue
	ls = len(s)
	nxt = [[-1 for _ in range(26)] for _ in range(ls)]
	for i in range(ls - 1, -1, -1):
		letter = s[i]
		k = ord(letter) - 97
		for j in range(26):
			if j == k:
				nxt[i][j] = i
			elif i != ls - 1:
				nxt[i][j] = nxt[i + 1][j]
	ct = 0
	cnext = 0
	total = 0
	while ct < len(t):
		letter = ord(t[ct]) - 97
		if nxt[cnext][letter] != -1:
			if cnext == 0:
				total += 1
			cnext = (nxt[cnext][letter] + 1) % ls
		else:
			total += 1
			cnext = (nxt[0][letter] + 1) % ls
		ct += 1
	print(total)


from math import *
import sys
input = sys.stdin.readline

def qdk(n):
	return ord(n) - ord('a')
tt = int(input())
while tt > 0:
	tt -= 1
	s = list(input().rstrip())
	t = list(input().rstrip())
	d = {}
	for i in range(len(s)):
		if qdk(s[i]) not in d:
			d[qdk(s[i])] = [i]
		else:
			d[qdk(s[i])].append(i)
	prev = -9
	c = 1
	flag = 0
	for i in range(len(t)):
		s = 0
		ans = -9
		p = qdk(t[i])
		if p not in d:
			flag = 1
			break
		e = len(d[qdk(t[i])]) - 1
		while s <= e:
			mid = (s + e) // 2
			if d[p][mid] > prev:
				ans = d[p][mid]
				e = mid - 1
			else:
				s = mid + 1
		if ans == -9:
			c += 1
			prev = d[p][0]
		else:
			prev = ans
	print(c if flag == 0 else -1)


alphabet = 'abcdefghijklmnopqrstuvwxyz'
T = int(input())
for t in range(T):
	s = input()
	t = input()
	ls = len(s)
	lt = len(t)
	bs = [0 for _ in range(26)]
	bt = [0 for _ in range(26)]
	check = 0
	for e in t:
		bt[ord(e) - 97] = 1
	for e in s:
		bs[ord(e) - 97] = 1
	for i in range(26):
		if bt[i] and (not bs[i]):
			check = 1
			break
	if check:
		print(-1)
	else:
		a = [[float('inf') for i in range(26)] for j in range(ls + 1)]
		for i in range(ls - 1, -1, -1):
			for j in alphabet:
				if s[i] == j:
					a[i][ord(j) - 97] = i
				else:
					a[i][ord(j) - 97] = a[i + 1][ord(j) - 97]
		sum = 1
		last = a[0][ord(t[0]) - 97] + 1
		for i in range(1, lt):
			if a[last][ord(t[i]) - 97] == float('inf'):
				sum += 1
				last = a[0][ord(t[i]) - 97] + 1
			else:
				last = a[last][ord(t[i]) - 97] + 1
		print(sum)