Daisy loves playing games with words. Recently, she has been playing the following Deletive Editing word game with Daniel.

Daisy picks a word, for example, "DETERMINED". On each game turn, Daniel calls out a letter, for example, 'E', and Daisy removes the first occurrence of this letter from the word, getting "DTERMINED". On the next turn, Daniel calls out a letter again, for example, 'D', and Daisy removes its first occurrence, getting "TERMINED". They continue with 'I', getting "TERMNED", with 'N', getting "TERMED", and with 'D', getting "TERME". Now, if Daniel calls out the letter 'E', Daisy gets "TRME", but there is no way she can get the word "TERM" if they start playing with the word "DETERMINED".

Daisy is curious if she can get the final word of her choice, starting from the given initial word, by playing this game for zero or more turns. Your task it help her to figure this out.


-----Input-----

The first line of the input contains an integer $n$ — the number of test cases ($1 \le n \le 10000$). The following $n$ lines contain test cases.

Each test case consists of two words $s$ and $t$ separated by a space. Each word consists of at least one and at most 30 uppercase English letters; $s$ is the Daisy's initial word for the game; $t$ is the final word that Daisy would like to get at the end of the game.


-----Output-----

Output $n$ lines to the output — a single line for each test case. Output "YES" if it is possible for Daisy to get from the initial word $s$ to the final word $t$ by playing the Deletive Editing game. Output "NO" otherwise.


-----Examples-----

Input
6
DETERMINED TRME
DETERMINED TERM
PSEUDOPSEUDOHYPOPARATHYROIDISM PEPA
DEINSTITUTIONALIZATION DONATION
CONTEST CODE
SOLUTION SOLUTION
Output
YES
NO
NO
YES
NO
YES


-----Note-----

None

Difficulty: EASY

Solutions:
import sys

def solve():
	input = sys.stdin.readline
	(s1, s2) = input().split()
	for i in range(len(s1) - 1, -1, -1):
		if len(s2) == 0 or (s1[i] in s2 and s2[-1] != s1[i]):
			break
		if s1[i] in s2 and s2[-1] == s1[i]:
			s2 = s2[:-1]
	if len(s2) == 0:
		print('YES')
	else:
		print('NO')

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


for _ in range(int(input())):
	(a, b) = input().split()
	(x, b) = (len(b), ' ' + b)
	for i in a[::-1]:
		if i == b[x]:
			x -= 1
		elif i in b[:x]:
			break
	if b[x] == ' ':
		print('YES')
		continue
	print('NO')


from os import error
import sys
input = sys.stdin.readline
DEBUG = False

def inp():
	return int(input())

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

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

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

def solve(start, tgt):
	start = start[::-1]
	tgt = tgt[::-1]
	(i, j) = (0, 0)
	collected = set()
	while i < len(tgt) and j < len(start):
		if tgt[i] in collected:
			if DEBUG:
				print(f"\tWe've seen that character: {tgt[i]} at {collected}")
			return 'NO'
		while j < len(start) and tgt[i] != start[j]:
			collected.add(start[j])
			j += 1
		if DEBUG:
			print(f'\tRemoving: {tgt[i]} at {collected}')
		if tgt[i] in collected:
			collected.remove(tgt[i])
		if j < len(start):
			i += 1
			j += 1
	if i == len(tgt):
		return 'YES'
	if DEBUG:
		print(f'\tfinishing outside?')
	return 'NO'
N = inp()
for i in range(N):
	s = input().strip('\n')
	(s, t) = s.split(' ')
	result = solve(s, t)
	print(result)


def verify_word_possibility(s, t):
	letter_position = 0
	for letter in t:
		try:
			new_letter_position = s.index(letter)
			if not isinstance(new_letter_position, int) or new_letter_position < letter_position:
				print('NO')
				return
			s.pop(new_letter_position)
			letter_position = new_letter_position
		except ValueError:
			print('NO')
			return
	print('YES')
	return
n = int(input())
for i in range(n):
	(s, t) = list(input().split())
	s = list(s)
	s.reverse()
	t = list(t)
	t.reverse()
	verify_word_possibility(s, t)


n = int(input())
ans = []
for i in range(n):
	(str1, str2) = map(str, input().split())
	k = len(str1) - 1
	fl1 = 0
	for j in range(len(str2) - 1, -1, -1):
		str3 = str2[0:j]
		let = str2[j]
		fl = 0
		while k >= 0:
			if str1[k] in str3 and str1[k] != let:
				fl = 0
				break
			if str1[k] == let:
				fl = 1
				k -= 1
				break
			else:
				k -= 1
		if fl == 0:
			ans.append('NO')
			fl1 = 1
			break
	if fl1 == 0:
		ans.append('YES')
for i in range(n):
	print(ans[i])


def main():
	size = int(input())
	lines = []
	for i in range(size):
		lines.append(input().split(' ')[:2])
	for (word, output) in lines:
		letters_left = len(output)
		j = len(word) - 1
		forbidden_words = set(output[:letters_left - 1])
		next_letter = output[letters_left - 1]
		while letters_left != 0:
			if word[j] == next_letter:
				letters_left -= 1
				forbidden_words = set(output[:letters_left - 1])
				next_letter = output[letters_left - 1]
			elif word[j] in forbidden_words:
				break
			j -= 1
			if j == -1:
				break
		if letters_left == 0:
			print('YES')
		else:
			print('NO')
main()


def calculate(k):
	word = k.split(' ')[0]
	sollution = k.split(' ')[1]
	word = word[::-1]
	sollution = sollution[::-1]
	length = len(word) - 1
	if sollution[0] not in word:
		return 'NO'
	temp = length - word.index(sollution[0])
	for i in sollution:
		if i not in word:
			return 'NO'
		sth = length - word.index(i)
		word = word[:word.index(i)] + word[word.index(i) + 1:]
		if sth > temp:
			return 'NO'
		temp = sth
	return 'YES'

def main():
	answers = []
	t = int(input())
	for i in range(t):
		k = input()
		answers.append(calculate(k))
	for i in answers:
		print(i)
main()


def deletive_editing(word, result):
	if len(result) > len(word):
		return 'NO'
	(word_dicc, result_dicc) = ({}, {})
	for char in word:
		word_dicc[char] = word_dicc.get(char, 0) + 1
	for char in result:
		if char not in word_dicc:
			return 'NO'
		result_dicc[char] = result_dicc.get(char, 0) + 1
	new_string = list(word)
	for (index, char) in enumerate(word):
		if char not in result_dicc:
			new_string[index] = ''
		elif word_dicc[char] > result_dicc[char]:
			new_string[index] = ''
			word_dicc[char] -= 1
	return 'YES' if result == ''.join(new_string) else 'NO'

def generator():
	tests = []
	times = int(input())
	while times > 0:
		(word, result) = input().split(' ')
		tests.append((word, result))
		times -= 1
	return tests
for (i, j) in generator():
	print(deletive_editing(i, j))


def solve(first, second):
	positions = set()
	idx = len(first) - 1
	for ch in reversed(second):
		while idx >= 0 and first[idx] != ch:
			idx -= 1
		if idx >= 0:
			positions.add(idx)
			idx -= 1
		else:
			return False
	used_chars = set()
	for (idx, ch) in enumerate(first):
		if idx in positions:
			used_chars.add(ch)
		elif ch in used_chars:
			return False
	return True

def main():
	n = int(input())
	words = []
	for i in range(n):
		(first, second) = input().split()
		print('YES' if solve(first, second) else 'NO')
main()


import sys
input = sys.stdin.readline
ans = 'YES'
for i in range(int(input())):
	(a, b) = input()[:-1][::-1].split()
	c = list(a)
	d = ''
	for j in range(len(b)):
		if b[j] in c:
			d += b[j]
			c.remove(b[j])
	if d == a:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(s, t) = input().split()
	(x, t) = (len(t), ' ' + t)
	for i in s[::-1]:
		if i == t[x]:
			x -= 1
		elif i in t[:x]:
			break
	else:
		if t[x] == ' ':
			print('YES')
			continue
	print('NO')


cases = int(input(''))
to_solve = []
for case in range(0, cases):
	(ori, new) = input('').split(' ')
	to_solve.append((ori, new))
for (ori, new) in to_solve:
	ori_copy = list(ori)
	new_copy = list(new)
	for letter in new_copy:
		try:
			ori_copy.remove(letter)
		except:
			pass
	list_to_remove = list(ori_copy)
	new_ori = list(ori)
	for letter in list_to_remove:
		try:
			new_ori.remove(letter)
		except:
			pass
	if ''.join(new_ori) == new:
		print('YES')
	else:
		print('NO')


def solv(s, t):
	d = {}
	for i in range(len(s)):
		c = s[i]
		if c not in d:
			d[c] = []
		d[c].append(i)
	p = 99
	t = t[::-1]
	for i in range(len(t)):
		c = t[i]
		if c not in d:
			return 'NO'
		if not len(d[c]):
			return 'NO'
		pp = d[c].pop()
		if pp > p:
			return 'NO'
		p = pp
	return 'YES'
for _ in range(int(input())):
	(s, t) = input().split()
	print(solv(s, t))


def solve(beg: str, end: str):
	to_remove = beg
	res = beg
	for e in end:
		to_remove = to_remove.replace(e, '', 1)
	for e in to_remove:
		res = res.replace(e, '', 1)
	if res == end:
		return 'YES'
	return 'NO'

def main():
	t = int(input())
	for x in range(t):
		str = []
		str = [s for s in input().split()]
		print(solve(str[0], str[1]))
main()


for _ in range(int(input())):
	(main, sub) = map(str, input().split())
	main1 = list(main[::-1])
	l = []
	broke = False
	for i in sub[::-1]:
		if i in main1:
			l.append(main1.index(i))
			main1.remove(i)
		else:
			broke = True
			break
	if broke == False:
		l1 = l.copy()
		l1.sort()
		if l == l1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def solve_line(s: str):
	s = s.split()
	trash = list(s[0])
	query = list(s[1])
	detrash = True
	trash_dict = {}
	query_dict = {}
	for char in query:
		if char in query_dict:
			query_dict[char] = query_dict[char] + 1
		else:
			query_dict[char] = 1
	for char in trash:
		if char in trash_dict:
			trash_dict[char] = trash_dict[char] + 1
		else:
			trash_dict[char] = 1
	for key in trash_dict:
		if key in query_dict:
			if trash_dict[key] - query_dict[key] != 0:
				for i in range(trash_dict[key] - query_dict[key]):
					trash.remove(key)
		else:
			for i in range(trash_dict[key]):
				trash.remove(key)
	if trash == query:
		return 'YES'
	else:
		return 'NO'

def main():
	n = input('')
	n = int(n)
	answers = []
	for i in range(n):
		ln = input('')
		answers.append(solve_line(ln))
	for a in answers:
		print(a)
main()


c = int(input())
for i in range(c):
	s = input().split()
	s1 = list(s[0])
	s2 = list(s[1])
	s1.reverse()
	s2.reverse()
	cc = 0
	rec = []
	key = False
	kk = False
	for b in s1:
		if b != s2[cc] and b in s2[cc + 1:]:
			print('NO')
			kk = True
			key = True
			break
		if b == s2[cc]:
			rec.append(b)
			cc += 1
			if cc == len(s2):
				print('YES')
				key = True
				break
		if key:
			break
	if len(rec) < len(s2) and (not kk):
		print('NO')


def canget(s, t):
	n = len(s)
	m = len(t)
	indices = [[] for _ in range(26)]
	for i in range(n):
		indices[ord(s[i]) - ord('A')].append(i)
	pre = n
	for i in range(m - 1, -1, -1):
		od = ord(t[i]) - ord('A')
		if not indices[od]:
			return False
		idx = indices[od].pop()
		if idx >= pre:
			return False
		else:
			pre = idx
	return True
t = int(input())
for _ in range(t):
	(s, t) = input().split()
	if canget(s, t):
		print('YES')
	else:
		print('NO')


n = int(input())

def test_case():
	line = input().split(' ')
	s = line[0]
	t = line[1]
	dicS = {}
	dicT = {}
	for j in s:
		dicS[j] = dicS.get(j, 0) + 1
	for j in t:
		if j not in dicS:
			return 'NO'
		dicT[j] = dicT.get(j, 0) + 1
	for m in dicS:
		if m not in dicT:
			s = s.replace(m, '')
		else:
			difference = dicS[m] - dicT[m]
			if difference < 0:
				return 'NO'
			elif difference > 0:
				s = s.replace(m, '', difference)
	if s == t:
		return 'YES'
	else:
		return 'NO'
for i in range(n):
	print(test_case())


n = int(input())
i = 0
while i < n:
	(word1, word2) = input().split()
	word2 = word2[::-1]
	Ans = 'YES'
	LastIndex0 = len(word1) + 1
	for letter in word2:
		if letter in word1:
			LastIndex1 = word1.rindex(letter)
			word1 = word1[:LastIndex1] + ' ' + word1[LastIndex1 + 1:]
			if LastIndex0 < LastIndex1:
				Ans = 'NO'
				print(Ans)
				break
			LastIndex0 = LastIndex1
		else:
			Ans = 'NO'
			print(Ans)
			break
	if Ans == 'YES':
		print('YES')
	i += 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = input().split()
	a1 = list(a)
	b1 = list(b)
	a1.reverse()
	b1.reverse()
	t = 0
	check = 0
	for i in range(len(b1)):
		if b1[i] not in a1:
			check = 1
			break
		elif a1.index(b1[i]) >= t:
			t = a1.index(b1[i])
			a1[t] = 8
		else:
			check = 1
			break
	if check == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(s, t) = input().split()
	check = ''
	for ch in s[::-1]:
		if ch in t and check.count(ch) < t.count(ch):
			check += ch
	if check == t[::-1]:
		print('YES')
	else:
		print('NO')


n = int(input())

def deletive_edit(string, edited):
	for i in string:
		if i not in edited:
			string = string.replace(i, '')
		if string.count(i) != edited.count(i):
			s = string.count(i)
			t = edited.count(i)
			string = string.replace(i, '', s - t)
	if string == edited:
		return 'YES'
	else:
		return 'NO'
results = []
for i in range(n):
	(string, edited) = input().split()
	results.append(deletive_edit(string, edited))
for i in results:
	print(i)


final = []
test = eval(input())
for iteration in range(test):
	(x, y) = map(str, input().split(' '))
	flag = 0
	if len(y) > len(x):
		final.append('NO')
		continue
	for ch1 in y:
		if x.count(ch1) < y.count(ch1):
			final.append('NO')
			flag = 1
			break
	if flag == 1:
		continue
	for ch2 in x:
		if ch2 not in y:
			x = x.replace(ch2, '')
	i = 0
	while len(x) != len(y):
		x = x.replace(y[i], '', x.count(y[i]) - y.count(y[i]))
		i += 1
	if x == y:
		final.append('YES')
	else:
		final.append('NO')
for item in final:
	print(item)


from collections import defaultdict

def solve(n):
	string = n[0]
	target = n[1]
	countStr = defaultdict(int)
	countTar = defaultdict(int)
	for i in target:
		countStr[i] = string.count(i)
		countTar[i] = target.count(i)
	for i in countStr:
		dif = countStr[i] - countTar[i]
		if dif < 0:
			return 'NO'
		string = string.replace(i, '', dif)
	index = 0
	for i in string:
		if i in target:
			if i == target[index]:
				index += 1
			else:
				return 'NO'
	return 'YES'
t = int(input())
for T in range(t):
	n = input().split(' ')
	print(solve(n))


tests = int(input())

def something(given, aim):
	aim = aim[::-1]
	given = given[::-1]
	place = 0
	for a in aim:
		ending = given[0:place]
		if ending.find(a) > -1:
			return False
		if given[place:].find(a) == -1:
			return False
		place = place + given[place:].find(a)
		given = given[0:place] + given[place + 1:]
	return True
for _ in range(tests):
	(given, aim) = input().split()
	print('YES' if something(given, aim) else 'NO')


def solution(s1, s2):
	list_s1 = list(s1)
	list_s1.reverse()
	list_s2 = list(s2)
	final_compiled = []
	for i in range(0, len(list_s1)):
		if len(list_s2) == 0:
			break
		elif list_s1[i] in list_s2:
			final_compiled.append(list_s1[i])
			list_s2.remove(list_s1[i])
	if len(list_s2) != 0:
		print('NO')
	else:
		final_compiled.reverse()
		s3 = ''.join(final_compiled)
		if s3 == s2:
			print('YES')
		else:
			print('NO')
n = int(input())
for i in range(0, n):
	testcase = input().split()
	(s1, s2) = (testcase[0], testcase[1])
	solution(s1, s2)


n = int(input())
for i in range(n):
	(s, a) = map(str, input().split())
	arr = list(s)
	brr = list(a)
	arr.reverse()
	brr.reverse()
	j = 0
	k = 0
	while j < len(s):
		if arr[j] == brr[k]:
			brr[k] = 1
			j += 1
			k += 1
		else:
			if arr[j] in brr:
				k = 0
				break
			j += 1
		if k == len(brr):
			break
	if k == len(brr):
		print('YES')
	else:
		print('NO')


def solve():
	(a, b) = input().split()
	count = []
	for i in range(30):
		count.append(0)
	for c in a:
		n = ord(c) - ord('A')
		count[n] += 1
	for c in b:
		n = ord(c) - ord('A')
		count[n] -= 1
		if count[n] < 0:
			print('NO')
			return
	res = ''
	for c in a:
		n = ord(c) - ord('A')
		if count[n] == 0:
			res += c
		else:
			count[n] -= 1
	if res == b:
		print('YES')
	else:
		print('NO')
N = int(input())
for test in range(N):
	solve()


n = int(input())
for k in range(n):
	words = input().split(' ')
	(s, t) = words
	sett = set(t)
	sss = ''
	for ch in s[::-1]:
		if sss.count(ch) < t.count(ch):
			sss = ch + sss
	if sss == t:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(s, t) = map(str, input().strip().split())
	(i, j) = (len(s) - 1, len(t) - 1)
	ar = []
	while i > -1 and j > -1:
		if s[i] == t[j]:
			ar.append(i)
			j -= 1
		i -= 1
	if len(ar) != len(t):
		print('NO')
	else:
		ar.reverse()
		for i in range(len(ar)):
			if s[ar[i]:].count(t[i]) > t[i:].count(t[i]):
				print('NO')
				break
		else:
			print('YES')


from collections import Counter
T = int(input())
for i in range(T):
	(a, b) = input().split()
	l = []
	d = Counter(b)
	for c in reversed(a):
		if d[c]:
			l.append(c)
			d[c] -= 1
	l.reverse()
	s = ''.join(l)
	print('YES' if s == b else 'NO')


t = int(input())

def func(a, b):
	d = []
	a = a[::-1]
	b = b[::-1]
	j = []
	for i in a:
		j.append(i)
	a = j
	for i in range(len(b)):
		if a.count(b[i]) == 0:
			return 'NO'
		k = a.index(b[i])
		d.append(k)
		a[k] = ''
	f = d.copy()
	f.sort()
	if d == f:
		return 'YES'
	return 'NO'
for i in range(t):
	(a, b) = map(str, input().split())
	print(func(a, b))


for _ in range(int(input())):
	(x, y) = input().split()
	d = {i: [-1] for i in y}
	for i in range(len(x)):
		if x[i] in y:
			d[x[i]].append(i)
	p = 100
	z = 'YES'
	for i in y[::-1]:
		c = d[i][-1]
		if c > p or c < 0:
			z = 'NO'
			break
		p = c
		d[i].pop()
	print(z)


for _ in range(int(input())):
	(s, t) = input().split()
	n = len(s)
	m = len(t)
	j = m - 1
	flag = True
	c0 = [True] * 26
	for i in range(n - 1, -1, -1):
		if s[i] == t[j]:
			if c0[ord(s[i]) - ord('A')] == False:
				flag = False
				break
			j -= 1
		else:
			c0[ord(s[i]) - ord('A')] = False
		if j < 0:
			break
	if j >= 0:
		flag = False
	if flag:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	(s, t) = [x for x in input().split()]
	flag = 1
	abc_dict = {}
	for i in list(map(chr, range(65, 91))):
		abc_dict[i] = []
	for (idx, value) in enumerate(s):
		abc_dict[value].append(idx)
	curr_idx = len(s) + 1
	t = list(t)
	t.reverse()
	for i in t:
		if abc_dict[i] == []:
			flag = 0
			break
		c = abc_dict[i].pop()
		if c <= curr_idx:
			curr_idx = c
		else:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(a, b) = input().split()
	for i in a:
		if i not in b:
			a = a.replace(i, '', 1)
	for i in a:
		a = a.replace(i, '', abs(b.count(i) - a.count(i)))
	print('YES' if a == b else 'NO')


t = int(input())
for i in range(t):
	(s, t) = input().split(' ')
	f = [True for x in range(26)]
	flag = True
	idx1 = len(s) - 1
	idx2 = len(t) - 1
	while idx1 >= 0:
		if idx2 == -1 or s[idx1] != t[idx2]:
			f[ord(s[idx1]) - 65] = False
			idx1 -= 1
			continue
		elif s[idx1] == t[idx2] and f[ord(s[idx1]) - 65] == False:
			flag = False
			break
		idx1 -= 1
		idx2 -= 1
	if idx2 == -1 and flag:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	arr = input().split()
	arr1 = arr[0]
	arr2 = arr[1]
	for i in arr1:
		if i not in arr2:
			arr1 = arr1.replace(i, '', 1)
	for j in arr1:
		arr1 = arr1.replace(j, '', abs(arr2.count(j) - arr1.count(j)))
	print('YES' if arr1 == arr2 else 'NO')


def runner(start_word: str, target_word: str):
	if len(target_word) > len(start_word):
		return 'NO'
	for (index, (a, b)) in enumerate(zip(target_word, start_word)):
		if a != b:
			bad_char = b
			break
	else:
		if len(target_word) == len(start_word):
			return 'YES'
		bad_char = start_word[index + 1]
	index = start_word.find(bad_char)
	return runner(start_word[:index] + start_word[index + 1:], target_word)

def read_input():
	n = int(input())
	for _ in range(n):
		(start, target) = input().split(' ')
		print(runner(start, target))
read_input()


for _ in range(int(input())):
	(s, t) = input().split()
	for i in s:
		if i not in t:
			s = s.replace(i, '', 1)
	for i in s:
		s = s.replace(i, '', abs(t.count(i) - s.count(i)))
	print('YES' if s == t else 'NO')


n = int(input())
for i in range(n):
	entrada = input().split()
	letters = {}
	for i in entrada[1]:
		if not i in letters:
			letters[i] = 1
		else:
			letters[i] += 1
	new_word = ''
	for i in range(len(entrada[0]) - 1, -1, -1):
		if entrada[0][i] in letters and letters[entrada[0][i]] > 0:
			letters[entrada[0][i]] -= 1
			new_word = entrada[0][i] + new_word
	if entrada[1] == new_word:
		print('YES')
	else:
		print('NO')


def deletiveEditing(s, t):
	if s == t:
		return 'YES'
	(d1, d2) = (dict(), dict())
	for i in range(len(t)):
		if t[i] in d1.keys():
			d1[t[i]] += 1
		else:
			d1[t[i]] = 1
	for i in range(len(s)):
		if s[i] in d2.keys():
			d2[s[i]] += 1
		else:
			d2[s[i]] = 1
	for x in d1.keys():
		if x not in d2.keys():
			return 'NO'
		elif d1[x] > d2[x]:
			return 'NO'
	for x in d2.keys():
		if x not in d1.keys():
			s = s.replace(x, '', d2[x])
		elif d2[x] != d1[x]:
			s = s.replace(x, '', d2[x] - d1[x])
	if s == t:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	inp = input().split()
	(s, t) = (inp[0], inp[1])
	print(deletiveEditing(s, t))


test = int(input())
for i in range(test):
	(string, req) = str(input()).split(' ')
	our_want = []
	for i in string:
		if i in req:
			our_want.append(i)
	for i in set(req):
		for j in range(our_want.count(i) - req.count(i)):
			our_want.remove(i)
	if our_want == list(req):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(s, s1) = input().split()
	d = dict()
	for i in range(len(s)):
		try:
			d[s[i]].append(i)
		except KeyError:
			d[s[i]] = [i]
	ans = []
	ok = 1
	for i in s1[::-1]:
		try:
			ans.append(d[i][-1])
			d[i].pop(-1)
		except KeyError:
			ok = 0
			break
		except IndexError:
			ok = 0
			break
	if not ok:
		print('NO')
	elif ans == sorted(ans, reverse=True):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(s, t) = input().split()
	d = dict()
	for i in range(len(s)):
		try:
			d[s[i]].append(i)
		except KeyError:
			d[s[i]] = [i]
	res = []
	ok = True
	for c in t[::-1]:
		try:
			res.append(d[c][-1])
			d[c].pop(-1)
		except KeyError:
			ok = False
			break
		except IndexError:
			ok = False
			break
	if not ok:
		print('NO')
	elif res == sorted(res, reverse=True):
		print('YES')
	else:
		print('NO')


for inh in range(int(input())):
	(s, t) = map(str, input().split())
	(n, m) = (len(s), len(t))
	occura_req = {}
	occura_hap = {}
	for i in range(0, m):
		occura_req[t[i]] = 0
		occura_hap[t[i]] = 0
	j = m - 1
	ans = True
	for i in range(n - 1, -1, -1):
		if s[i] == t[j]:
			if occura_hap[s[i]] > occura_req[s[i]]:
				ans = False
			j -= 1
			occura_req[s[i]] += 1
		if j < 0:
			break
		if s[i] in occura_req:
			occura_hap[s[i]] += 1
	if j == -1 and ans:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	(s, p) = map(str, input().split())
	for i in s:
		if i not in p:
			s = s.replace(i, '', 1)
	for i in s:
		s = s.replace(i, '', abs(p.count(i) - s.count(i)))
	if s == p:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	(s, sub) = map(str, input().split())
	l = len(sub)
	n = len(s)
	f = 1
	for i in range(l):
		a = s.find(sub[i])
		if a == -1:
			f = 0
			break
	j = 0
	ans = ''
	if f == 1:
		for i in range(len(s)):
			if sub.find(s[i]) != -1:
				ans = ans + s[i]
		for i in range(len(sub)):
			countst = ans.count(sub[i])
			countsub = sub.count(sub[i])
			ans = ans.replace(sub[i], '_', countst - countsub)
		ans = ans.replace('_', '', ans.count('_'))
		if ans == sub:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for i in range(int(input())):
	(str1, str2) = map(str, input().split())
	len1 = len(str2)
	l1 = list(str1)
	l1.reverse()
	l2 = list(str2)
	l2.reverse()
	x = len(str1)
	c = -1
	ans = True
	for j in l2:
		ans2 = False
		for k in range(x):
			if l1[k] == j:
				l1[k] = 0
				if k > c:
					c = k
					ans2 = True
					break
				else:
					break
		if ans2 == False:
			ans = False
			break
	if ans == True:
		print('YES')
	else:
		print('NO')


from sys import breakpointhook
N = int(input())
for n in range(N):
	(A, B) = input().split(' ')
	(ar, br) = (A[::-1], B[::-1])
	pos = [-1] * len(B)
	(i, j) = (0, 0)
	while i < len(A) and j < len(br):
		if ar[i] == br[j]:
			pos[j] = len(A) - i - 1
			j += 1
		i += 1
	possible = True
	A = list(A)
	for p in pos:
		if A[p] in A[p + 1:]:
			possible = False
			break
		else:
			A[p] = '@'
	if possible:
		print('YES')
	else:
		print('NO')


n = int(input())
from collections import Counter
for _ in range(n):
	words = [i for i in input().split(' ')]
	j = 0
	flag = False
	word = ''
	first = {k[0]: k[1] for k in Counter(words[0]).items()}
	second = {k[0]: k[1] for k in Counter(words[1]).items()}
	for letter in words[0]:
		if first[letter] > second.get(letter, -1):
			first[letter] -= 1
		else:
			word += letter
	if word.__eq__(words[1]):
		print('YES')
	else:
		print('NO')


from collections import defaultdict

def dele(s, c):
	return s[:s.index(c)] + s[s.index(c) + 1:]
for _ in range(int(input())):
	(s, a) = input().split()
	d = defaultdict(lambda : 0)
	for i in s:
		d[i] += 1
	if not all((i in s for i in a)):
		print('NO')
		continue
	for i in a:
		d[i] -= 1
	for (key, value) in d.items():
		for _ in range(value):
			s = dele(s, key)
	if s == a:
		print('YES')
	else:
		print('NO')


def find(string, char, n):
	for i in range(len(string) - 1, -1, -1):
		if string[i] == char:
			if n == 1:
				return i
			n -= 1
	return -1

def func(s, t):
	arr = []
	is_used = []
	for i in t:
		if i not in s:
			return 'NO'
		else:
			if i in is_used:
				n = is_used.count(i)
				index = find(s, i, n + 1)
				if index == -1:
					return 'NO'
				arr.append((i, index))
			else:
				index = find(s, i, 1)
				if index == -1:
					return 'NO'
				arr.append((i, index))
			is_used.append(i)
	arr.sort(key=lambda val: val[1])
	return 'YES' if ''.join(list(map(lambda x: x[0], arr))) == t else 'NO'
for i in range(int(input())):
	print(func(*input().split()))


t = int(input())

def solve():
	(s1, s2) = input().split(' ')
	mp1 = []
	for i in range(26):
		mp1.append([])
	mp2 = [0] * 26
	for i in range(len(s1)):
		mp1[ord(s1[i]) - ord('A')].append(i)
	for i in range(len(s2)):
		mp2[ord(s2[i]) - ord('A')] += 1
	v = []
	for i in range(26):
		if mp2[i] > len(mp1[i]):
			print('NO')
			return
	for i in range(len(s2)):
		v.append(mp1[ord(s2[i]) - ord('A')][-1 * mp2[ord(s2[i]) - ord('A')]])
		mp2[ord(s2[i]) - ord('A')] -= 1
	for i in range(len(v) - 1):
		if v[i] > v[i + 1]:
			print('NO')
			return
	print('YES')
	return
while t > 0:
	t -= 1
	solve()


for _ in range(int(input())):
	(s, t) = input().split()
	d_s = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0}
	d_t = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0}
	l = list(s)
	ans = 0
	for i in s:
		d_s[i] += 1
	for j in t:
		d_t[j] += 1
	l_s = d_s.keys()
	l_t = d_t.keys()
	for i in l_t:
		if d_t[i] == 0:
			c = d_s[i]
			while c > 0:
				l.remove(i)
				c -= 1
		elif d_s[i] - d_t[i] >= 0:
			c = d_s[i] - d_t[i]
			while c > 0:
				l.remove(i)
				c -= 1
		else:
			continue
	if l == list(t):
		print('YES')
	else:
		print('NO')


for _ in range(0, int(input())):
	(s, t) = input().split()
	w = set(t)
	r = s[::-1]
	x = [a for a in s if a in w]
	d = dict.fromkeys(x)
	for i in range(0, len(x)):
		if d[x[i]] is None:
			d[x[i]] = [i]
		else:
			d[x[i]].append(i)
	o = [''] * len(x)
	for i in t:
		if i not in d:
			continue
		if len(d[i]) < 1:
			continue
		o[d[i][-1]] = i
		d[i].pop(-1)
	v = [x for x in o if x != '']
	print(['NO', 'YES'][''.join(v) == t])


for i in range(int(input())):
	(a, b) = input().split()
	c = []
	for i in a:
		if i not in c:
			c.append(i)
			temp = a.count(i) - b.count(i)
			if temp < 0:
				break
			else:
				for j in range(temp):
					y = a.find(i)
					a = a[:y] + a[y + 1:]
	if a == b:
		print('YES')
	else:
		print('NO')


for _ in range(int(input(''))):
	(x, y) = input().split()
	lx = []
	for i in x:
		lx.append(i)
	for i in range(len(x)):
		if x[i] not in y:
			lx.remove(x[i])
		elif x[i] in y:
			if x[i + 1:].count(x[i]) >= y.count(x[i]):
				lx.remove(x[i])
	s1 = ''
	for i in lx:
		s1 += i
	if s1 == y:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(s, t) = input().split()
	s = [i for i in s]
	t = [i for i in t]
	u = []
	for i in s:
		if i in t:
			u.append(i)
	for i in t:
		while u.count(i) > t.count(i):
			u.remove(i)
	if t == u:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(s, t) = input().split()
	S = [i for i in s]
	T = [j for j in t]
	A = []
	for ele in S:
		if ele in T:
			A.append(ele)
	for ele in T:
		while A.count(ele) > T.count(ele):
			A.remove(ele)
	if A == T:
		print('YES')
	else:
		print('NO')


def removeFirstOccurrence(string, char):
	i = string.index(char)
	return string[:i] + string[i + 1:]

def isPossible(s, t):
	index = ''.join(sorted(set(s), key=s.index))
	counts = []
	countt = []
	for i in range(len(index)):
		counts.append(s.count(index[i]))
		countt.append(t.count(index[i]))
		if countt[-1] > counts[-1]:
			return False
	for i in range(len(index)):
		for j in range(counts[i] - countt[i]):
			s = removeFirstOccurrence(s, index[i])
	if s == t:
		return True
	return False
n = int(input())
for i in range(n):
	(s, t) = input().split()
	if s == t or isPossible(s, t):
		print('YES')
	else:
		print('NO')