You are given three strings $s$, $t$ and $p$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.

During each operation you choose any character from $p$, erase it from $p$ and insert it into string $s$ (you may insert this character anywhere you want: in the beginning of $s$, in the end or between any two consecutive characters). 

For example, if $p$ is aba, and $s$ is de, then the following outcomes are possible (the character we erase from $p$ and insert into $s$ is highlighted):

  aba $\rightarrow$ ba, de $\rightarrow$ ade;  aba $\rightarrow$ ba, de $\rightarrow$ dae;  aba $\rightarrow$ ba, de $\rightarrow$ dea;  aba $\rightarrow$ aa, de $\rightarrow$ bde;  aba $\rightarrow$ aa, de $\rightarrow$ dbe;  aba $\rightarrow$ aa, de $\rightarrow$ deb;  aba $\rightarrow$ ab, de $\rightarrow$ ade;  aba $\rightarrow$ ab, de $\rightarrow$ dae;  aba $\rightarrow$ ab, de $\rightarrow$ dea; 

Your goal is to perform several (maybe zero) operations so that $s$ becomes equal to $t$. Please determine whether it is possible.

Note that you have to answer $q$ independent queries.


-----Input-----

The first line contains one integer $q$ ($1 \le q \le 100$) — the number of queries. Each query is represented by three consecutive lines.

The first line of each query contains the string $s$ ($1 \le |s| \le 100$) consisting of lowercase Latin letters.

The second line of each query contains the string $t$ ($1 \le |t| \le 100$) consisting of lowercase Latin letters.

The third line of each query contains the string $p$ ($1 \le |p| \le 100$) consisting of lowercase Latin letters.


-----Output-----

For each query print YES if it is possible to make $s$ equal to $t$, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).


-----Example-----
Input
4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa

Output
YES
YES
NO
NO



-----Note-----

In the first test case there is the following sequence of operation:   $s = $ ab, $t = $ acxb, $p = $ cax;  $s = $ acb, $t = $ acxb, $p = $ ax;  $s = $ acxb, $t = $ acxb, $p = $ a. 

In the second test case there is the following sequence of operation:   $s = $ a, $t = $ aaaa, $p = $ aaabbcc;  $s = $ aa, $t = $ aaaa, $p = $ aabbcc;  $s = $ aaa, $t = $ aaaa, $p = $ abbcc;  $s = $ aaaa, $t = $ aaaa, $p = $ bbcc.

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation


Solutions:
for _ in range(int(input())):
	s = str(input())
	t = str(input())
	p = str(input())
	if len(s) > len(t):
		print('NO')
	elif s == t:
		print('YES')
	else:
		count = -1
		e = 0
		for i in s:
			for j in range(len(t)):
				if i == t[j] and count < j:
					count = j
					e = e + 1
					break
		if e == len(s):
			y = 0
			c = s + p
			c1 = list(s + p)
			for l in t:
				if l in c1:
					c1.remove(l)
					y = y + 1
			if y == len(t):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


def lcs(X, Y):
	m = len(X)
	n = len(Y)
	L = [[None] * (n + 1) for i in range(m + 1)]
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				L[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				L[i][j] = L[i - 1][j - 1] + 1
			else:
				L[i][j] = max(L[i - 1][j], L[i][j - 1])
	return L[m][n]
for q in range(int(input())):
	s = input()
	t = input()
	p = input()
	l = len(s)
	l1 = len(s)
	l2 = len(t)
	l3 = len(p)
	l = lcs(s, t)
	if l1 == l:
		a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
		b = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
		for i in range(l1):
			a[ord(s[i]) - ord('a')] += 1
		for i in range(l3):
			a[ord(p[i]) - ord('a')] += 1
		for i in range(l2):
			b[ord(t[i]) - ord('a')] += 1
		g = 0
		for i in range(26):
			if a[i] < b[i]:
				g = 1
		if g == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	j = 0
	arr = []
	pos = 1
	for i in range(len(s)):
		while j < len(t):
			if s[i] != t[j]:
				arr.append(t[j])
				j += 1
			else:
				j += 1
				break
		else:
			print('NO')
			pos = 0
			break
	if j <= len(t) - 1:
		arr += t[j:]
	if pos:
		for k in range(len(arr)):
			if arr[k] in p:
				del p[p.index(arr[k])]
			else:
				print('NO')
				pos = 0
				break
		if pos:
			print('YES')


from collections import Counter

def check(s, t, p):
	p = Counter(p)
	idx = 0
	for ch in t:
		if idx < len(s) and s[idx] == ch:
			idx += 1
		elif ch in p and p[ch] > 0:
			p[ch] -= 1
		else:
			return False
	return idx == len(s)
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	if check(s, t, p):
		print('YES')
	else:
		print('NO')


def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
n = int(input())
for i in range(n):
	s = input()
	m = len(s)
	t = input()
	n = len(t)
	p = input()
	d = {}
	d2 = {}
	d3 = {}
	f = 0
	if isSubSequence(s, t, m, n):
		for i in s:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		for i in t:
			if i in d2:
				d2[i] += 1
			else:
				d2[i] = 1
		for i in p:
			if i in d3:
				d3[i] += 1
			else:
				d3[i] = 1
		for i in t:
			if i not in s and i not in p:
				f = 1
				break
			elif i in s and i in p:
				if d2[i] <= d[i] + d3[i]:
					continue
				else:
					f = 1
					break
			elif i not in p:
				if d2[i] <= d[i]:
					continue
				else:
					f = 1
					break
			elif d2[i] <= d3[i]:
				continue
			else:
				f = 1
				break
		print(('YES', 'NO')[f == 1])
	else:
		print('NO')


from collections import defaultdict
t = int(input())
for _ in range(t):
	hash = defaultdict(int)
	s = input()
	t = input()
	p = input()
	for i in p:
		hash[i] += 1
	if len(s) == len(t):
		if s == t:
			print('YES')
		else:
			print('NO')
	elif len(s) > len(t):
		print('NO')
	else:
		j = 0
		flag = 0
		for i in range(len(t)):
			if j < len(s):
				if t[i] == s[j]:
					j += 1
				elif hash[t[i]] > 0:
					hash[t[i]] -= 1
				else:
					flag = 1
					break
			elif hash[t[i]] > 0:
				hash[t[i]] -= 1
			else:
				flag = 1
				break
		if j > len(s) - 1 and flag == 0:
			print('YES')
		else:
			print('NO')


from sys import stdin, stdout
import collections
import math

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
T = int(input())
for t in range(T):
	s = input()
	t = input()
	p = input()
	freq_s = {}
	freq_t = {}
	freq_p = {}
	for i in range(26):
		freq_s[chr(97 + i)] = 0
		freq_t[chr(97 + i)] = 0
		freq_p[chr(97 + i)] = 0
	for letter in s:
		freq_s[letter] += 1
	for letter in t:
		freq_t[letter] += 1
	for letter in p:
		freq_p[letter] += 1
	sub = isSubSequence(s, t)
	if sub == 0:
		print('NO')
	else:
		flag = 0
		for i in range(26):
			d = freq_t[chr(97 + i)] - freq_s[chr(97 + i)]
			if d > 0:
				if freq_p[chr(97 + i)] < d and flag == 0:
					print('NO')
					flag = 1
		if flag == 0:
			print('YES')


q = int(input())
for w in range(q):
	s = input()
	t = input()
	p = input()
	d = 26 * [0]
	d1 = 26 * [0]
	d2 = 26 * [0]
	for i in s:
		d[ord(i) - 97] += 1
	for i in t:
		d1[ord(i) - 97] += 1
	for i in p:
		d2[ord(i) - 97] += 1
	flag = False
	x = 0
	for i in range(len(t)):
		if t[i] == s[x]:
			x += 1
		if x == len(s):
			flag = True
			break
	if not flag:
		print('NO')
		continue
	f1 = True
	for i in range(26):
		if d[i] + d2[i] < d1[i]:
			f1 = False
			break
	if f1:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	first = dict()
	for letter in p:
		first[letter] = first.get(letter, 0) + 1
	i = 0
	j = 0
	while i < len(s) or j < len(t):
		if i < len(s) and j < len(t) and (s[i] == t[j]):
			i = i + 1
			j = j + 1
		elif i < len(s) and j < len(t) and (s[i] != t[j]) and (first.get(t[j], 0) > 0):
			first[t[j]] = first[t[j]] - 1
			j = j + 1
		elif j >= len(t):
			print('NO')
			break
		elif i >= len(s):
			if first.get(t[j], 0) > 0:
				first[t[j]] = first[t[j]] - 1
				j = j + 1
			else:
				print('NO')
				break
		else:
			print('NO')
			break
	else:
		print('YES')


from collections import *
for _ in [0] * int(input()):
	(s, t, p) = (input(), input(), Counter(input()))
	i = 0
	for c in t:
		if (s + ' ' * 99)[i] == c:
			i += 1
		elif p[c]:
			p[c] -= 1
		else:
			i = 0
			break
	print('YNEOS'[i < len(s)::2])


for _ in ' ' * int(input()):
	r = lambda : input().replace('', ' ').split()
	(a, b, c) = (r(), r(), r())
	ans = 'YES'
	(x, y) = (len(a), len(b))
	j = 0
	for i in range(y):
		if a and b[i] == a[0]:
			a.pop(0)
		elif b[i] in c:
			c.remove(b[i])
		else:
			ans = 'NO'
			break
	if a:
		ans = 'NO'
	print(ans)


q = int(input())
for l in range(q):
	s = input()
	t = input()
	p = input()
	ar_p = [0] * 28
	for i in range(len(p)):
		ar_p[ord(p[i]) - 97] += 1
	ok = True
	i = 0
	j = 0
	while j < len(t):
		if i < len(s) and t[j] == s[i]:
			i += 1
		elif ar_p[ord(t[j]) - 97] > 0:
			ar_p[ord(t[j]) - 97] -= 1
		else:
			ok = False
			break
		j += 1
	if i != len(s):
		ok = False
	if ok:
		print('YES')
	else:
		print('NO')


from collections import Counter
for i in range(int(input())):
	s = input()
	t = input()
	p = input()
	d = Counter(p)
	j = k = 0
	if len(s) >= len(t) and s != t:
		print('No')
		continue
	while j < len(t):
		if k == len(s) or s[k] != t[j]:
			if d[t[j]] > 0:
				d[t[j]] -= 1
			else:
				print('No')
				break
		else:
			k += 1
		j += 1
	else:
		print('Yes') if k == len(s) else print('No')


def ain():
	return map(int, input().split())
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	fl = False
	i = 0
	for x in s:
		while i < len(t) and t[i] != x:
			i += 1
		if i == len(t):
			fl = True
			break
		i += 1
	if fl:
		print('NO')
	else:
		for x in t:
			if s.count(x) + p.count(x) < t.count(x):
				print('NO')
				fl = True
				break
		if not fl:
			print('YES')


from collections import defaultdict
T = int(input())
while T:
	T -= 1
	s = list(input())
	t = list(input())
	count = defaultdict(lambda : 0)
	p = list(input())
	for ch in p:
		count[ch] += 1
	curr = 0
	i = 0
	found = True
	while i < len(t):
		if curr < len(s) and t[i] == s[curr]:
			curr += 1
			i += 1
		elif count[t[i]] > 0:
			count[t[i]] -= 1
			i += 1
		else:
			found = False
			break
	if not found or curr != len(s):
		print('NO')
	else:
		print('YES')


t = int(input())
ans = list()
for i in range(t):
	s = input()
	t = input()
	p = input()
	ss = set(s)
	ts = set(t)
	ps = set(p)
	flag = 0
	for j in ts:
		if t.count(j) > s.count(j) + p.count(j):
			ans.append('NO')
			flag = 1
			break
	if flag == 1:
		continue
	k = 0
	c = 0
	for j in range(len(s)):
		if s[j] in t[k:]:
			k = t[k:].index(s[j]) + 1 + k
			c += 1
	if c < len(s):
		ans.append('NO')
		continue
	ans.append('YES')
for i in ans:
	print(i)


from collections import defaultdict, Counter
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	cas = False
	added = defaultdict(int)
	i = 0
	for c in t:
		if not cas and c == s[i]:
			i += 1
		else:
			added[c] += 1
		if i == len(s):
			cas = True
	if not cas:
		print('NO')
		continue
	cs = Counter(p)
	stop = False
	for c in added:
		if added[c] > cs[c]:
			print('NO')
			stop = True
			break
	if stop:
		continue
	print('YES')


from collections import Counter
q = int(input())
for x in range(q):
	s = input()
	t = input()
	p = input()
	replace = []
	t_pos = 0
	for i in range(len(s)):
		while t_pos < len(t) and t[t_pos] != s[i]:
			replace.append(t[t_pos])
			t_pos += 1
		if t_pos == len(t):
			print('NO')
			break
		t_pos += 1
	else:
		for i in range(t_pos, len(t)):
			replace.append(t[i])
		p = Counter(p)
		for i in range(len(replace)):
			if p[replace[i]] > 0:
				p[replace[i]] -= 1
			else:
				print('NO')
				break
		else:
			print('YES')


t = int(input())
for x in range(t):
	a = input()
	b = input()
	c = input()
	l = []
	m = []
	la = len(a)
	lb = len(b)
	lc = len(c)
	idx = 0
	for i in b:
		if idx < la:
			if i == a[idx]:
				idx += 1
			else:
				l.append(i)
		else:
			l.append(i)
	if idx != la:
		print('NO')
		continue
	for y in c:
		m.append(y)
	l.sort()
	m.sort()
	idx = 0
	ll = len(l)
	for i in m:
		if idx < ll:
			if i == l[idx]:
				idx += 1
	print('YES' if idx == ll else 'NO')


for _ in range(int(input())):
	(s, t, p) = [input() for i in range(3)]
	j = -1
	flag = 0
	for i in s:
		j += 1
		if j == len(t):
			flag = 1
			break
		while t[j] != i:
			j += 1
			if j == len(t):
				flag = 1
				break
		if flag:
			break
	if flag:
		print('NO')
		continue
	(ds, dt, dp) = ({}, {}, {})
	for i in s:
		ds[i] = ds.get(i, 0) + 1
	for i in t:
		dt[i] = dt.get(i, 0) + 1
	for i in p:
		dp[i] = dp.get(i, 0) + 1
	for i in dt:
		if dt[i] - ds.get(i, 0) > dp.get(i, 0):
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	i = 0
	j = 0
	u = True
	while i < len(s):
		while j < len(t):
			if t[j] == s[i]:
				t[j] = ''
				j += 1
				break
			j += 1
		i += 1
	if t.count('') != len(s):
		print('NO')
		continue
	for i in p:
		for j in range(len(t)):
			if t[j] == i:
				t[j] = ''
				break
	t = ''.join(t)
	if t == '':
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	if s == t:
		print('YES')
	elif len(s) == len(t) or len(s) > len(t):
		print('NO')
	else:
		(i, j) = (0, 0)
		count = 0
		while j < len(t):
			if i < len(s):
				if s[i] == t[j]:
					count += 1
					i += 1
			j += 1
		if count != len(s):
			print('NO')
		else:
			freq_s = [0] * 26
			freq_t = [0] * 26
			freq_p = [0] * 26
			i = 0
			while i < max(max(len(s), len(t)), len(p)):
				if i < len(s):
					freq_s[ord(s[i]) - ord('a')] += 1
				if i < len(t):
					freq_t[ord(t[i]) - ord('a')] += 1
				if i < len(p):
					freq_p[ord(p[i]) - ord('a')] += 1
				i += 1
			flag = 0
			for i in range(26):
				if freq_s[i] + freq_p[i] < freq_t[i]:
					flag = 1
					break
			if flag == 1:
				print('NO')
			else:
				print('YES')


for j in range(int(input())):
	(a, b) = [[0 for i in range(26)] for j in range(2)]
	(s, t, p) = [input() for i in range(3)]
	check = True
	for i in s:
		a[ord(i) - 97] += 1
	for i in t:
		b[ord(i) - 97] += 1
	for i in p:
		a[ord(i) - 97] += 1
	if len(s) > len(t):
		check = False
	else:
		cc = len(t) - 1
		for i in range(len(s) - 1, -1, -1):
			while t[cc] != s[i]:
				cc -= 1
				if cc < 0:
					break
			cc -= 1
		if cc < -1:
			check = False
	for i in range(len(a)):
		if a[i] < b[i]:
			check = False
	print('Yes' if check else 'No')


n = int(input())
for _ in range(n):
	a = input()
	b = input()
	c = input()
	x = [0] * 125
	for i in c:
		x[ord(i)] += 1
	AA = 0
	BB = 0
	while BB < len(b):
		if AA < len(a) and a[AA] == b[BB]:
			AA += 1
			BB += 1
		elif x[ord(b[BB])] > 0:
			x[ord(b[BB])] -= 1
			BB += 1
		else:
			break
	if BB == len(b) and AA == len(a):
		print('YES')
	else:
		print('NO')


from collections import Counter

def oneTest():
	ss = input()
	tt = input()
	pp = input()
	ttsegs = []
	tail = tt
	for s in ss:
		(h, s1, tail) = tail.partition(s)
		if s1 == '':
			print('NO')
			return
		ttsegs.append(h)
	ttsegs.append(tail)
	remainder = ''.join(ttsegs)
	ttcounts = Counter(remainder)
	ppcounts = Counter(pp)
	for (c, i) in ttcounts.items():
		if c not in ppcounts or ppcounts[c] < i:
			print('NO')
			return
	print('YES')
q = int(input())
for _ in range(q):
	oneTest()


def mp():
	return map(int, input().split())
q = int(input())
for qq in range(q):
	s = input()
	t = input()
	p = input()
	if len(s) > len(t):
		print('NO')
		continue
	s = s + ' '
	cnt = [0] * 200
	for i in p:
		cnt[ord(i)] += 1
	i = j = 0
	fail = False
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
			continue
		if cnt[ord(t[j])] == 0:
			fail = True
			break
		cnt[ord(t[j])] -= 1
		j += 1
	if fail or i != len(s) - 1 or j != len(t):
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	flag = True
	for ch in t:
		if len(s) != 0 and s[0] == ch:
			s.pop(0)
		elif ch not in p:
			flag = False
			break
		else:
			p.remove(ch)
	if flag and len(s) == 0:
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	flg = 0
	x = input()
	y = input()
	z = input()
	x = list(x)
	y = list(y)
	z = list(z)
	for ch in y:
		if x != [] and ch == x[0]:
			x.pop(0)
		elif ch not in z:
			flg = 1
		else:
			z.remove(ch)
	if flg == 0 and x == []:
		print('YES')
	else:
		print('NO')


from collections import Counter

def solve(s, t, p):
	if len(s) > len(t):
		return 0
	if len(s) == len(t):
		if s == t:
			return 1
		else:
			return 0
	(s1, p1) = (Counter(s), Counter(p))
	d1 = s1 + p1
	d2 = Counter(t)
	for i in d2.keys():
		if d1.get(i) == None:
			return 0
		if d1.get(i) and d1[i] < d2[i]:
			return 0
	for key in s1.keys():
		if d2.get(key) == None:
			return 0
	k = 0
	for i in range(len(s)):
		ok = True
		for j in range(k, len(t)):
			if s[i] == t[j]:
				ok = False
				k = j + 1
				break
		if ok:
			return 0
	return 1
t = int(input())
for _ in range(t):
	s = input()
	t = input()
	p = input()
	if solve(s, t, p):
		print('YES')
	else:
		print('NO')


for T in range(int(input())):
	s = input()
	t = input()
	p = input()
	(cur, flag) = (0, 0)
	for i in range(len(t)):
		if t[i] == s[cur]:
			cur += 1
		if cur >= len(s):
			break
	if cur != len(s):
		print('NO')
		continue
	need = [0] * 26
	avail = need[:]
	for i in t:
		need[ord(i) - 97] += 1
	s += p
	for i in s:
		avail[ord(i) - 97] += 1
	for (i, j) in zip(need, avail):
		if i > j:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	counter_s = {}
	for ch in s:
		counter_s[ch] = counter_s.get(ch, 0) + 1
	counter_t = {}
	for ch in t:
		counter_t[ch] = counter_t.get(ch, 0) + 1
	counter_p = {}
	for ch in p:
		counter_p[ch] = counter_p.get(ch, 0) + 1
	result = True
	i = 0
	for ch in s:
		if i >= len(t):
			result = False
			break
		while result and t[i] != ch:
			i += 1
			if i >= len(t):
				result = False
				break
		i += 1
	for (t_key, t_value) in counter_t.items():
		if not result or t_value > counter_s.get(t_key, 0) + counter_p.get(t_key, 0):
			result = False
			break
	if result:
		print('YES')
	else:
		print('NO')


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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 main():
	t = int(input())
	for i in range(t):
		s = str(input())
		t = str(input())
		p = str(input())
		cnt = [0] * 26
		for j in range(len(p)):
			cnt[ord(p[j]) - ord('a')] += 1
		(index, k) = (0, 0)
		f = True
		while index < len(t):
			if k > len(s) - 1:
				tmp = ord(t[index]) - ord('a')
				if cnt[tmp] <= 0:
					f = False
					break
				cnt[tmp] -= 1
				index += 1
				continue
			if s[k] == t[index]:
				index += 1
				k += 1
			else:
				tmp = ord(t[index]) - ord('a')
				if cnt[tmp] <= 0:
					f = False
					break
				cnt[tmp] -= 1
				index += 1
		if f and k == len(s):
			print('Yes')
		else:
			print('No')
main()


n = int(input())
for x in range(n):
	s = input()
	t = input()
	p = input()
	arrt = [0 for i in range(26)]
	arrsp = [0 for i in range(26)]
	for i in range(len(s)):
		arrsp[ord(s[i]) - 97] += 1
	for i in range(len(p)):
		arrsp[ord(p[i]) - 97] += 1
	for i in range(len(t)):
		arrt[ord(t[i]) - 97] += 1
	flag = True
	lf = 0
	for j in range(len(s)):
		tmp = t.find(s[j], lf)
		lf = tmp
		if tmp == -1:
			flag = False
			break
		lf += 1
	if flag:
		flag2 = True
		for i in range(26):
			if arrt[i] > arrsp[i]:
				flag2 = False
				break
		if flag2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


request_count = int(input())
for request in range(request_count):
	s = input()
	t = input()
	p = input()
	counter_s = 0
	ok = True
	for i in range(len(t)):
		if t.count(t[i]) > s.count(t[i]) + p.count(t[i]):
			ok = False
		try:
			if s[counter_s] == t[i]:
				counter_s += 1
		except:
			pass
	t_contains_s = counter_s >= len(s)
	if ok and t_contains_s:
		print('YES')
	else:
		print('NO')


q = int(input())
for query in range(q):
	s = input()
	t = input()
	p = input()
	pointer_s = 0
	pointer_t = 0
	no = 0
	miejsca = []
	while pointer_s < len(s):
		while True:
			if pointer_t >= len(t):
				no = 1
				break
			elif t[pointer_t] != s[pointer_s]:
				pointer_t += 1
			else:
				pointer_s += 1
				miejsca.append(pointer_t)
				pointer_t += 1
				break
		if no == 1:
			break
	if no == 0:
		literki = [0] * 400
		for i in range(len(t)):
			if i not in miejsca:
				literki[ord(t[i])] += 1
		for i in range(len(p)):
			literki[ord(p[i])] -= 1
		for i in range(400):
			if literki[i] > 0:
				no = 1
				break
	if no == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	st = dict()
	for el in p:
		st[el] = st.get(el, 0) + 1
	si = 0
	ti = 0
	while ti < len(t):
		if si == len(s) or t[ti] != s[si]:
			cnt = st.get(t[ti], 0)
			if cnt == 0:
				print('NO')
				break
			st[t[ti]] -= 1
		else:
			si += 1
		ti += 1
	else:
		if si < len(s) or ti < len(t):
			print('NO')
		else:
			print('YES')


query = int(input())

def check(s, t, p):
	len_t = len(t)
	len_s = len(s)
	flag = 0
	if len_s > len_t:
		print('NO')
	else:
		for char in t:
			if s == []:
				if char in p:
					p.remove(char)
				else:
					flag = 1
					break
			elif char == s[0]:
				del s[0]
			elif char in p:
				p.remove(char)
			else:
				flag = 1
				break
		if s != []:
			flag = 1
		if flag == 0:
			print('YES')
		elif flag == 1:
			print('NO')
for i in range(query):
	ss = list(input())
	tt = list(input())
	pp = list(input())
	check(ss, tt, pp)


t = int(input())
for _ in range(t):
	s = input()
	t = input()
	p = input()
	l = [0] * 26
	for i in range(len(p)):
		l[ord(p[i]) - 97] += 1
	i = 0
	j = 0
	ans = 1
	m = [1] * len(t)
	while True:
		if j > len(s) - 1:
			break
		if i > len(t) - 1:
			ans = 0
			break
		if s[j] == t[i]:
			m[i] = 0
			j += 1
			i += 1
		else:
			i += 1
	for i in range(len(t)):
		if m[i] == 1:
			if l[ord(t[i]) - 97] > 0:
				l[ord(t[i]) - 97] -= 1
				m[i] = 0
			else:
				ans = 0
				break
	if sum(m) > 0:
		ans = 0
	if ans:
		print('YES')
	else:
		print('NO')


def len_of_lcs(massive1, massive2):
	lengths = [[0 for i in range(len(massive2) + 1)] for j in range(len(massive1) + 1)]
	for i in range(1, len(massive1) + 1):
		for j in range(1, len(massive2) + 1):
			if massive1[i - 1] == massive2[j - 1]:
				lengths[i][j] = 1 + lengths[i - 1][j - 1]
			else:
				lengths[i][j] = max(lengths[i - 1][j], lengths[i][j - 1])
	return lengths[-1][-1]
for i in range(int(input())):
	s = input()
	t = input()
	p = input()
	if len(s) > len(t):
		print('NO')
		continue
	if s == t:
		print('YES')
		continue
	length = len_of_lcs(s, t)
	if length < len(s):
		print('NO')
		continue
	dict1 = {}
	for j in range(len(t)):
		if t[j] in dict1:
			dict1[t[j]] += 1
		else:
			dict1[t[j]] = 1
	for j in range(len(s)):
		dict1[s[j]] -= 1
	for j in range(len(p)):
		if p[j] in dict1:
			dict1[p[j]] -= 1
	if any((j > 0 for j in dict1.values())):
		print('NO')
	else:
		print('YES')


ord_a = ord('a')
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	if len(s) > len(t):
		print('NO')
		continue
	s += '#'
	counts = [0] * 26

	def pool(letter: str):
		return counts[ord(letter) - ord_a]

	def pool_pop(letter: str):
		counts[ord(letter) - ord_a] -= 1
	for c in p:
		counts[ord(c) - ord_a] += 1
	j = 0
	answer = 'YES'
	for i in range(len(t)):
		if s[j] != t[i]:
			if pool(t[i]) > 0:
				pool_pop(t[i])
			else:
				answer = 'NO'
				break
		elif j < len(s) - 1:
			j += 1
	if j != len(s) - 1:
		answer = 'NO'
	print(answer)


for i in range(int(input())):
	s = input()
	t = input()
	p = list(input())
	i = j = 0
	while i < len(t):
		if j < len(s) and t[i] == s[j]:
			j += 1
			i += 1
		elif t[i] in p:
			p.remove(t[i])
			i += 1
		else:
			break
	else:
		if j < len(s):
			print('NO')
		else:
			print('YES')
		continue
	print('NO')


q = int(input())
for you in range(q):
	s = input()
	t = input()
	p = input()
	poss = 1
	curr = 0
	for i in range(len(s)):
		found = 0
		for j in range(curr, len(t)):
			if t[j] == s[i]:
				curr = j + 1
				found = 1
				break
		if found == 0:
			poss = 0
			break
	if poss == 0:
		print('NO')
		continue
	freq = [0 for i in range(26)]
	for i in t:
		freq[ord(i) - 97] += 1
	for i in s:
		freq[ord(i) - 97] -= 1
	freqp = [0 for i in range(26)]
	for i in p:
		freqp[ord(i) - 97] += 1
	poss = 1
	for i in range(26):
		if freq[i] > freqp[i]:
			poss = 0
			break
	if poss:
		print('YES')
	else:
		print('NO')


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().strip()
print = lambda x: sys.stdout.write(f'{x}\n')
dp = 0

def LCS(str1, str2):
	XY = 0
	nonlocal dp
	_max = -1
	(len1, len2) = (len(str1), len(str2))
	dp = [[0 for x in range(len1 + 1)] for x in range(len2 + 1)]
	for x in range(1, len2 + 1):
		for y in range(1, len1 + 1):
			if str2[x - 1] == str1[y - 1]:
				dp[x][y] = dp[x - 1][y - 1] + 1
			else:
				dp[x][y] = max(dp[x - 1][y], dp[x][y - 1])
			if _max < dp[x][y]:
				_max = dp[x][y]
				XY = [x, y]
	return (_max, XY)

def LCSSTRING(str1, str2, XY, answer):
	nonlocal dp
	(X, Y) = (XY[0], XY[1])
	if dp[X][Y] == 0:
		return answer
	if str2[X - 1] == str1[Y - 1]:
		answer = str2[X - 1] + answer
		XY[0] -= 1
		XY[1] -= 1
	elif dp[X - 1][Y] > dp[X][Y - 1]:
		XY[0] -= 1
	else:
		XY[1] -= 1
	return LCSSTRING(str1, str2, XY, answer)
for t in range(int(input())):
	(s, t, p) = (input(), input(), input())
	(m, xy) = LCS(s, t)
	lcs = LCSSTRING(s, t, xy, '')
	if lcs != s:
		print('NO')
		continue
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	for i in t:
		d1[i] += 1
	for i in p:
		d2[i] += 1
	for i in lcs:
		d2[i] += 1
	flag = True
	for i in t:
		if d1[i] > d2[i]:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for z in range(t):
	s = input()
	t = input()
	p = input()
	arr = [[0 for i in range(260)] for j in range(3)]
	nxt = 0
	for i in range(len(t)):
		if t[i] == s[nxt]:
			nxt += 1
			if nxt >= len(s):
				break
	if nxt < len(s):
		print('NO')
		continue
	for i in range(len(s)):
		arr[0][ord(s[i])] += 1
	for i in range(len(t)):
		arr[1][ord(t[i])] += 1
	for i in range(len(p)):
		arr[2][ord(p[i])] += 1
	for i in range(260):
		if arr[0][i] + arr[2][i] < arr[1][i]:
			print('NO')
			break
	else:
		print('YES')


def issubseq(s, t):
	i = 0
	st = 0
	l = 0
	k = 0
	while i != len(s):
		if l == 1000:
			k += 1
			break
		for j in range(st, len(t)):
			if s[i] == t[j]:
				i += 1
				st = j + 1
				break
		l += 1
	if k == 1:
		return False
	else:
		return True

def segsub(s, t):
	if issubseq(s, t):
		try:
			d = {}
			k = {}
			for i in range(len(s)):
				d[s[i]] = 0
			for i in range(len(s)):
				d[s[i]] += 1
			for i in range(len(t)):
				k[t[i]] = 0
			for i in range(len(t)):
				k[t[i]] += 1
			for key in d:
				k[key] -= d[key]
			return k
		except:
			return 0
	else:
		return 0
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	d = {}
	for i in range(len(p)):
		d[p[i]] = 0
	for i in range(len(p)):
		d[p[i]] += 1
	l = segsub(s, t)
	if l != 0:
		z = 0
		for key in l:
			try:
				if d[key] < l[key]:
					z += 1
			except:
				if l[key] > 0:
					z += 1
		if z >= 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


querynum = int(input())
for i in range(0, querynum):
	result = True
	s = list(input())
	t = input()
	p = list(input())
	for x in t:
		if len(s) > 0 and x == s[0]:
			s.remove(x)
		elif x in p:
			p.remove(x)
		else:
			result = False
			break
	if len(s) > 0:
		result = False
	if result:
		print('YES')
	else:
		print('NO')


def gns():
	return list(map(int, input().split()))
t = int(input())

def one():
	s = input()
	t = input()
	p = input()
	j = 0
	for c in s:
		while j < len(t) and t[j] != c:
			j += 1
		if j == len(t):
			print('NO')
			return
		j += 1

	def get_num(x):
		ans = [0] * 26
		for c in x:
			c = ord(c) - ord('a')
			ans[c] += 1
		return ans
	ss = get_num(s)
	tt = get_num(t)
	pp = get_num(p)
	for i in range(26):
		if ss[i] + pp[i] < tt[i]:
			print('NO')
			return
	print('YES')
for i in range(t):
	one()


from collections import *
a = int(input())
for i in range(a):
	s = input()
	t = input()
	p = input()
	glag = 0
	al = defaultdict(int)
	for i in range(len(p)):
		al[p[i]] += 1
	ans = []
	j = 0
	i = 0
	while i < len(s) and j < len(t):
		if t[j] == s[i]:
			ans.append(j)
			i += 1
			j += 1
		else:
			j += 1
	if len(ans) != len(s):
		print('No')
		continue
	ans.append(len(t))
	ans = [-1] + ans
	flag = 0
	for i in range(1, len(ans)):
		for j in range(ans[i - 1] + 1, ans[i]):
			if al[t[j]] > 0:
				al[t[j]] -= 1
			else:
				flag = -1
				break
	if flag == -1:
		print('No')
	else:
		print('Yes')


T = int(input())
for _ in range(T):
	s = input()
	t = input()
	p = input()
	d = dict()
	for i in range(97, ord('z') + 1):
		d[i] = 0
	for i in p:
		d[ord(i)] += 1
	j = 0
	flag = 0
	k = 0
	b = 0
	while j != len(t):
		if k != len(s) and s[k] == t[j]:
			k += 1
		elif d[ord(t[j])] > 0:
			d[ord(t[j])] -= 1
			b += 1
		else:
			flag = 1
			break
		j += 1
		if flag == 1:
			break
	if k != len(s):
		flag = 1
	if flag == 0:
		print('YES')
	else:
		print('NO')


from collections import Counter

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	comp = Counter(s + p)
	ans = Counter(t)
	f = 0
	f1 = isSubSequence(s, t, len(s), len(t))
	for i in ans:
		if ans[i] > comp[i]:
			f = 1
			break
	if f == 1 or f1 == False:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	s = ins()
	t = ins()
	p = list(ins())
	j = 0
	ans = False
	for i in range(len(t)):
		if j < len(s):
			if t[i] != s[j] and t[i] not in p:
				break
			elif t[i] == s[j]:
				j += 1
			elif t[i] in p:
				p.remove(t[i])
			else:
				break
		elif t[i] not in p:
			break
		else:
			p.remove(t[i])
		if i == len(t) - 1 and j == len(s):
			ans = True
	print('YES' if ans else 'NO')


n = int(input())
for _ in range(n):
	s = list(input())
	t = list(input())
	p = list(input())
	j = 0
	i = 0
	tag = True
	while j < len(t):
		if t[j] == s[i]:
			t.pop(j)
			i = i + 1
			if i == len(s):
				tag = False
				break
		else:
			j = j + 1
	if tag:
		print('NO')
	else:
		d = False
		for i in t:
			if i in p:
				ind = p.index(i)
				p.pop(ind)
			else:
				d = True
				break
		if d:
			print('NO')
		else:
			print('YES')


for i in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	check = 1
	for ch in t:
		if len(s) != 0 and s[0] == ch:
			s.pop(0)
		elif ch not in p:
			check = 0
			break
		else:
			p.remove(ch)
	if check and len(s) == 0:
		print('YES')
	else:
		print('NO')


from collections import Counter
q = input()
q = int(q)
arr = []
for i in range(q):
	items = []
	for _ in range(3):
		items.append(input())
	arr.append(items)

def isSubstring(a, b):
	counter = 0
	for x in b:
		if counter == len(a):
			return True
		if x == a[counter]:
			counter = counter + 1
	if counter == len(a):
		return True
	else:
		return False

def queryIsPossible(query):
	s = Counter(query[0])
	t = Counter(query[1])
	p = Counter(query[2])
	if not isSubstring(query[0], query[1]):
		return False
	t.subtract(s)
	for x in t:
		if t[x] > p[x]:
			return False
	return True
for item in arr:
	if queryIsPossible(item):
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	s = input()
	t = input()
	p = input()
	d = dict()
	for x in p:
		d[x] = d.get(x, 0) + 1
	uk1 = 0
	uk = 0
	f = False
	while uk < len(t):
		if uk1 == len(s) and d.get(t[uk], 0) <= 0:
			print('NO')
			f = True
			break
		if uk1 == len(s):
			d[t[uk]] -= 1
			uk += 1
		elif s[uk1] == t[uk]:
			uk += 1
			uk1 += 1
		elif d.get(t[uk], 0) == 0:
			print('NO')
			f = True
			break
		else:
			d[t[uk]] -= 1
			uk += 1
	if not f and uk1 == len(s):
		print('YES')
	elif uk1 != len(s) and (not f):
		print('NO')


n = int(input())

def search():
	s = input()
	t = input()
	p = input()
	tindex = 0
	ans = True
	for j in range(len(s)):
		found = False
		char = s[j]
		while tindex < len(t) and t[tindex] != char:
			tindex += 1
		if tindex < len(t):
			found = True
			t = t[0:tindex] + t[tindex + 1:len(t)]
		elif not found:
			ans = False
	tlist = list()
	for j in range(len(t)):
		tlist.append(t[j:j + 1])
	plist = list()
	for j in range(len(p)):
		plist.append(p[j:j + 1])
	tlist.sort()
	plist.sort()
	pindex = 0
	for j in tlist:
		found = False
		while pindex < len(plist) and plist[pindex] != j:
			pindex += 1
		if pindex < len(plist):
			del plist[pindex]
			found = True
		elif not found:
			ans = False
	return ans
for i in range(n):
	if search():
		print('YES')
	else:
		print('NO')


def check(s, t):
	(n, m) = (len(s), len(t))
	(i, j) = (0, 0)
	while i < n and j < m:
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i == n:
		return True
	return False

def check1(s, t, p):
	if not check(s, t):
		return False
	(s1, t1, p1) = ([0] * 26, [0] * 26, [0] * 26)
	for i in range(len(s)):
		s1[ord(s[i]) % ord('a')] += 1
	for i in range(len(t)):
		t1[ord(t[i]) % ord('a')] += 1
	for i in range(len(p)):
		p1[ord(p[i]) % ord('a')] += 1
	for i in range(26):
		if t1[i] >= s1[i]:
			if p1[i] >= t1[i] - s1[i]:
				pass
			else:
				return False
		else:
			return False
	return True
n = int(input())
for i in range(n):
	s = input()
	t = input()
	p = input()
	if check1(s, t, p):
		print('YES')
	else:
		print('NO')


import sys
q = int(input())

def isSub(a, b):
	i = 0
	for c in a:
		if c == b[i]:
			i += 1
		if i == len(b):
			return True
	return False
while q:
	s = input()
	t = input()
	p = input()
	target = {}
	for c in t:
		if c not in target:
			target[c] = 0
		target[c] += 1
	have = {}
	for c in s:
		if c not in have:
			have[c] = 0
		have[c] += 1
	for c in p:
		if c not in have:
			have[c] = 0
		have[c] += 1
	flag = True
	for c in target:
		if c not in have:
			flag = False
			break
		if have[c] < target[c]:
			flag = False
			break
	if flag:
		if isSub(t, s):
			sys.stdout.write('YES\n')
		else:
			sys.stdout.write('NO\n')
	else:
		sys.stdout.write('NO\n')
	q -= 1


def check(a, b):
	i = 0
	for elem in a:
		if elem == b[i]:
			i += 1
		if i == len(b):
			return True
	return False
q = int(input())
for j in range(q):
	s = input()
	t = input()
	p = input()
	(target, d, flag) = ({}, {}, True)
	for elem in t:
		if elem not in target:
			target[elem] = 0
		target[elem] += 1
	for elem in s:
		if elem not in d:
			d[elem] = 0
		d[elem] += 1
	for elem in p:
		if elem not in d:
			d[elem] = 0
		d[elem] += 1
	for elem in target:
		if elem not in d:
			flag = False
			break
		if d[elem] < target[elem]:
			flag = False
			break
	if flag:
		if check(t, s):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def is_subsequence(x, y):
	(i, j, flag) = (0, 0, False)
	while j < len(y):
		if x[i] == y[j]:
			i += 1
		j += 1
		if i >= len(x):
			flag = True
			break
	return flag

def is_subdict(x, y):
	flag = True
	for i in x:
		if i not in y:
			flag = False
			break
		elif not y[i] >= x[i]:
			flag = False
			break
	return flag
t = int(input())
for m in range(t):
	s = input()
	t = input()
	p = input()
	dictt = dict()
	dicttemp = dict()
	temp = s + p
	for i in temp:
		if i in dicttemp:
			dicttemp[i] += 1
		else:
			dicttemp[i] = 1
	for i in t:
		if i in dictt:
			dictt[i] += 1
		else:
			dictt[i] = 1
	if is_subsequence(s, t) and is_subdict(dictt, dicttemp):
		print('YES')
	else:
		print('NO')


from collections import Counter
outputs = []
for __ in range(int(input())):
	S = [char for char in input()]
	T = [char for char in input()]
	P = [char for char in input()]
	countp = Counter(P)
	req = {}
	i = 0
	j = 0
	wordcount = 0
	while i < len(S) and j < len(T):
		if S[i] == T[j]:
			i += 1
			wordcount += 1
		else:
			req[T[j]] = req.get(T[j], 0) + 1
		j += 1
	while j < len(T):
		req[T[j]] = req.get(T[j], 0) + 1
		j += 1
	if wordcount < len(S):
		outputs.append('NO')
	else:
		flag = True
		for key in req.keys():
			if countp.get(key, 0) < req.get(key):
				flag = False
				break
		if flag:
			outputs.append('YES')
		else:
			outputs.append('NO')
for output in outputs:
	print(output)


q = int(input())
for i in range(q):
	s = input()
	t = input()
	p = input()
	s = list(s)
	t = list(t)
	p = list(p)
	flag = 1
	y = 0
	for c in s:
		if c not in t[y:]:
			flag = 0
			break
		else:
			z = t[y:].index(c)
			del t[y + z]
			y = y + z
	if flag == 0:
		print('NO')
		continue
	for c in t:
		if c not in p:
			flag = 0
			break
		else:
			del p[p.index(c)]
	if flag == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s1 = input()
	t = input()
	p = input()
	(found, pos) = (True, 0)
	for a in s1:
		try:
			pso1 = t.index(a, pos)
			pos = pso1 + 1
		except:
			found = False
			break
	if found:
		for tim in t:
			ast = s1.count(tim)
			ast1 = p.count(tim)
			ast2 = t.count(tim)
			if ast > ast2 or ast1 + ast < ast2:
				found = False
				break
	print('YES' if found else 'NO')


for w in range(int(input())):
	s = str(input())
	t = str(input())
	p = str(input())
	i = 0
	j = 0
	c = 0
	l = []
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			l.append(t[j])
			j += 1
	if i < len(s):
		print('NO')
	else:
		while j < len(t):
			l.append(t[j])
			j += 1
		for i in range(len(l)):
			if p.count(l[i]) >= l.count(l[i]):
				continue
			else:
				c = 1
				break
		if c == 1:
			print('NO')
		else:
			print('YES')


def solve():
	source = list(input())
	target = list(input())
	usable_characters = list(input())
	if source == target:
		print('YES')
		return
	if len(source) >= len(target):
		print('NO')
		return
	boolean_list = [False] * len(target)
	correct = 0
	index = 0
	for c in source:
		try:
			index = target.index(c, index)
		except ValueError:
			print('NO')
			return
		boolean_list[index] = True
		correct += 1
		index += 1
	for (i, tf) in enumerate(boolean_list):
		if tf == False:
			try:
				index = usable_characters.index(target[i])
			except ValueError:
				print('NO')
				return
			usable_characters.pop(index)
			boolean_list[i] = True
			correct += 1
	if correct == len(target):
		print('YES')
	else:
		print('NO')
q = int(input())
for _ in range(q):
	solve()


cases = int(input())
for i in range(cases):
	s = list(input())
	t = list(input())
	p = list(input())
	flag = False
	for ch in t:
		if len(s) != 0 and ch == s[0]:
			s.pop(0)
		elif ch not in p:
			flag = True
			break
		else:
			p.remove(ch)
	print('yes') if flag is False and len(s) == 0 else print('no')


q = int(input())
ans = [None] * q

def checker(s, t):
	global iter
	iter = 0
	for i in range(len(t)):
		if t[i] == s[iter]:
			iter += 1
		if iter == len(s):
			return True
	else:
		return False
for a in range(q):
	s = str(input())
	t = str(input())
	p = str(input())
	if checker(s, t):
		alphabet = 'abcdefghijklmnopqrstuvwxyz'
		ta = [0] * 26
		pa = [0] * 26
		sa = [0] * 26
		for i in range(len(t)):
			for j in range(len(alphabet)):
				if t[i] == alphabet[j]:
					ta[j] += 1
		for i in range(len(p)):
			for j in range(len(alphabet)):
				if p[i] == alphabet[j]:
					pa[j] += 1
		for i in range(len(s)):
			for j in range(len(alphabet)):
				if s[i] == alphabet[j]:
					sa[j] += 1
		for i in range(26):
			if sa[i] + pa[i] - ta[i] >= 0:
				ans[a] = 'Yes'
			else:
				ans[a] = 'No'
				break
	else:
		ans[a] = 'No'
for i in range(q):
	print(ans[i])


q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	freq = {}
	for char in p:
		if char in freq:
			freq[char] += 1
		else:
			freq[char] = 1
	i = 0
	j = 0
	while i < len(t):
		if j < len(s) and s[j] == t[i]:
			j += 1
			i += 1
		elif t[i] in freq:
			if freq[t[i]] > 0:
				freq[t[i]] -= 1
				i += 1
			else:
				break
		else:
			break
	if i == len(t) and j == len(s):
		print('YES')
	else:
		print('NO')


import sys
import math as mt
import bisect
t = int(input())

def issub(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	l1 = [0] * 27
	l2 = [0] * 27
	l3 = [0] * 27
	for i in s:
		l1[ord(i) - ord('a')] += 1
	for i in s1:
		l2[ord(i) - ord('a')] += 1
	for i in p:
		l3[ord(i) - ord('a')] += 1
	for i in range(27):
		if l1[i] > l2[i]:
			return 'NO'
		elif l2[i] - l1[i] <= l3[i]:
			pass
		else:
			return 'NO'
	if issub(s, s1):
		return 'YES'
	return 'NO'
for _ in range(t):
	s = input()
	s1 = input()
	p = input()
	print(solve())


x = int(input())
for __ in range(x):
	a = list(input())
	b = list(input())
	c = list(input())
	s = ''
	f = 1
	j = 0
	for i in range(len(b)):
		if j < len(a):
			if b[i] == a[j]:
				s += b[i]
				b[i] = '0'
				a[j] = '-1'
				j += 1
	for i in range(len(b)):
		if b[i] in c:
			c[c.index(b[i])] = '-1'
			s += b[i]
			b[i] = '0'
	f = 0
	for i in b:
		if i != '0':
			f = 1
			break
	for i in a:
		if i != '-1':
			f = 1
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	index_v_s = 0
	ostavajuce = []
	for j in range(len(t)):
		if index_v_s < len(s) and s[index_v_s] == t[j]:
			index_v_s += 1
		else:
			ostavajuce.append(t[j])
	if index_v_s != len(s):
		print('NO')
	else:
		ostavajuce.sort()
		p.sort()
		vypisalo = False
		for pismeno in ostavajuce:
			if pismeno in set(p):
				p.remove(pismeno)
			else:
				print('NO')
				vypisalo = True
				break
		if not vypisalo:
			print('YES')


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
for _ in range(int(input())):
	s = input()[:-1]
	t = input()[:-1]
	p = input()[:-1]
	q = s + p
	x = dc(int)
	y = dc(int)
	n = len(s)
	m = len(t)
	l = [[0 for j in range(m + 1)] for i in range(n + 1)]
	for i in range(n + 1):
		for j in range(m + 1):
			if i == 0 or j == 0:
				l[i][j] = 0
			elif s[i - 1] == t[j - 1]:
				l[i][j] = 1 + l[i - 1][j - 1]
			else:
				l[i][j] = max(l[i - 1][j], l[i][j - 1])
	if l[n][m] != n:
		print('NO')
	else:
		for i in q:
			x[i] += 1
		for i in t:
			y[i] += 1
		f = 1
		for i in y.keys():
			if x[i] < y[i]:
				f = 0
				break
		if f:
			print('YES')
		else:
			print('NO')


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(int(input())):
	s = [x for x in input()]
	t = [x for x in input()]
	p = list(input())
	ps = set(p)
	if len(s) >= len(t) and s != t:
		print('NO')
		continue
	i = 0
	j = 0
	while i < len(t):
		if j < len(s) and t[i] == s[j]:
			j += 1
			i += 1
		elif t[i] in p:
			p.remove(t[i])
			i += 1
		else:
			break
	else:
		if j >= len(s):
			print('YES')
			continue
	print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	mp = {}
	for i in range(len(p)):
		if p[i] in mp:
			mp[p[i]] += 1
		else:
			mp[p[i]] = 1
	ans = True
	(i, j) = (0, 0)
	while True:
		if i <= len(t) - 1 and j <= len(s) - 1:
			if t[i] == s[j]:
				i += 1
				j += 1
				continue
		elif i > len(t) - 1:
			if j > len(s) - 1:
				break
			ans = False
			break
		if t[i] in mp:
			mp[t[i]] -= 1
			if mp[t[i]] == 0:
				del mp[t[i]]
			i += 1
			continue
		else:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input().strip())):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	i = 0
	for data in t:
		if i < len(s) and data == s[i]:
			i = i + 1
	if i != len(s):
		print('NO')
	else:
		temp = s + p
		j = 0
		for data in t:
			if data not in temp:
				print('NO')
				break
			else:
				j = j + 1
				temp = temp.replace(data, '', 1)
		if j == len(t):
			print('YES')


def isSubsequence(a, b, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if a[m - 1] == b[n - 1]:
		return isSubsequence(a, b, m - 1, n - 1)
	return isSubsequence(a, b, m, n - 1)
n = int(input())
for i in range(n):
	(a, b, c) = (list(input()), list(input()), list(input()))
	stat = isSubsequence(a, b, len(a), len(b))
	if stat == False:
		print('NO')
	else:
		d1 = dict()
		d2 = dict()
		d3 = dict()
		for i in range(len(a)):
			if a[i] in d1:
				d1[a[i]] += 1
			else:
				d1[a[i]] = 1
		for i in range(len(b)):
			if b[i] in d2:
				d2[b[i]] += 1
			else:
				d2[b[i]] = 1
		for i in range(len(c)):
			if c[i] in d1:
				d1[c[i]] += 1
			else:
				d1[c[i]] = 1
		flag = 0
		for item in d2:
			try:
				if d2[item] > d1[item]:
					flag = 1
					break
			except KeyError:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')


from collections import Counter
q = int(input())

def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
for _ in range(q):
	s = input()
	t = input()
	p = input()
	if len(s) > len(t) or (len(s) == len(t) and s != t):
		print('NO')
		continue
	d_s = Counter(s)
	d_t = Counter(t)
	d_p = Counter(p)
	posible = True
	for char in d_t:
		if d_t[char] < d_s[char] or d_t[char] > d_s[char] + d_p[char]:
			posible = False
	if posible == False:
		print('NO')
		continue
	if isSubSequence(s, t, len(s), len(t)):
		print('YES')
	else:
		print('NO')


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

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

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

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)

def print_list(l, delim=' '):
	print(delim.join(map(str, l)))

def check_subseq(a, b):
	if len(a) > len(b):
		return 0
	(start_a, start_b) = (0, 0)
	while start_a < len(a) and start_b < len(b):
		if a[start_a] == b[start_b]:
			start_a += 1
			start_b += 1
		else:
			start_b += 1
	return start_a == len(a)
q = read_int()
for _ in range(q):
	s = read_string()
	t = read_string()
	p = read_string()
	if check_subseq(s, t):
		avail_dic = {}
		for _s in s:
			avail_dic[_s] = avail_dic.get(_s, 0) + 1
		for _p in p:
			avail_dic[_p] = avail_dic.get(_p, 0) + 1
		target_dic = {}
		for _t in t:
			target_dic[_t] = target_dic.get(_t, 0) + 1
		broken = 0
		for k in target_dic:
			if k not in avail_dic or avail_dic[k] < target_dic[k]:
				broken = 1
				break
		if broken:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


def s(string1, string2, m, n):
	if m == 0:
		return 1
	if n == 0:
		return -1
	if string1[m - 1] == string2[n - 1]:
		return s(string1, string2, m - 1, n - 1)
	return s(string1, string2, m, n - 1)
n = int(input())
for i in range(n):
	a = []
	b = []
	c = []
	A = input()
	B = input()
	C = input()
	for p in A:
		a.append(p)
	for p in B:
		b.append(p)
	for p in C:
		c.append(p)
	if len(a) > len(b):
		print('NO')
	elif s(A, B, len(a), len(b)) != 1:
		print('NO')
	else:
		t = 0
		k = set(b)
		for p in k:
			q = b.count(p)
			r = a.count(p)
			o = c.count(p)
			if r + o < q:
				t = 1
				break
		if t == 1:
			print('NO')
		else:
			print('YES')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

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

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		s = S()
		t = S()
		p = S()
		c = collections.Counter(p)
		si = 0
		s += '#'
		ok = 1
		for u in t:
			if u == s[si]:
				si += 1
			elif c[u] > 0:
				c[u] -= 1
			else:
				ok = 0
				break
		rr.append(YES(ok and si == len(s) - 1))
	return JA(rr, '\n')
print(main())


q = int(input())
for _ in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	ans = 'YES'
	for i in range(len(t)):
		try:
			if t[i] != s[i]:
				if t[i] in p:
					s.insert(i, t[i])
					p.remove(t[i])
				else:
					ans = 'NO'
					break
		except:
			if t[i] in p:
				s.insert(i, t[i])
				p.remove(t[i])
			else:
				ans = 'NO'
				break
	if len(s) > len(t):
		ans = 'NO'
	print(ans)


t = int(input())
alphabet = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm']
for tc in range(t):
	s = input()
	t = input()
	p = input()
	(q, z) = (0, 0)
	while q < len(s) and z < len(t):
		if t[z] == s[q]:
			q += 1
		z += 1
	flag = q == len(s)
	sp = s + p
	c = 0
	for l in alphabet:
		c += 1
		if sp.count(l) >= t.count(l):
			c -= 1
	if c == 0 and flag:
		print('YES')
	else:
		print('NO')


def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def find(s, t, p):
	if not isSubSequence(s, t):
		return False
	from collections import defaultdict
	dic1 = defaultdict(int)
	dic2 = defaultdict(int)
	dic3 = defaultdict(int)
	for x in s:
		dic1[x] += 1
	for x in t:
		dic2[x] += 1
	for x in p:
		dic3[x] += 1
	for x in dic1:
		dic2[x] = dic2[x] - dic1[x]
	for x in dic2:
		if dic2[x] == 0:
			continue
		if dic2[x] > dic3[x]:
			return False
	return True
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	if find(s, t, p):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(s, t, p) = (input(), input(), input())
	tt = {}
	st = {}
	pt = {}
	dp = [[0] * (len(s) + 1) for i in range(len(t) + 1)]
	for i in range(1, len(t) + 1):
		for j in range(1, len(s) + 1):
			if t[i - 1] == s[j - 1]:
				dp[i][j] = dp[i - 1][j - 1] + 1
			else:
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
	if dp[len(t)][len(s)] < len(s):
		print('NO')
		continue
	ans = 'YES'
	from string import ascii_lowercase
	for i in ascii_lowercase:
		tt[i] = 0
		st[i] = 0
		pt[i] = 0
	for i in s:
		st[i] += 1
	for i in p:
		pt[i] += 1
	for i in t:
		tt[i] += 1
	for i in ascii_lowercase:
		if st[i] > tt[i] or tt[i] - st[i] > pt[i]:
			ans = 'NO'
			break
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	t = input()
	p = input()
	toadd = []
	i = 0
	found = False
	for j in range(len(t)):
		if s[i] == t[j]:
			i += 1
			if i == len(s):
				toadd += t[j + 1:]
				break
		else:
			toadd += [t[j]]
	if i != len(s):
		found = True
	p = list(p)
	for char in toadd:
		if char not in p:
			found = True
			break
		else:
			p.remove(char)
	if found:
		print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(0, T):
	s = input()
	t = input()
	p = input()
	temp = 0
	ptr = 0
	c = 0
	for i in range(0, len(s)):
		for j in range(ptr, len(t)):
			if s[i] == t[j]:
				c += 1
				ptr = j + 1
				break
	if c == len(s):
		temp = 1
	if temp == 1:
		L = [0] * 26
		for i in range(0, len(t)):
			L[ord(t[i]) - 97] += 1
		L1 = [0] * 26
		for i in range(0, len(p)):
			L1[ord(p[i]) - 97] += 1
		for i in range(0, len(s)):
			L1[ord(s[i]) - 97] += 1
		flag = 0
		for i in range(0, 26):
			if L1[i] < L[i]:
				flag = 1
				break
		if flag == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from collections import Counter
q = int(input())
for i in range(0, q):
	s = input()
	t = input()
	p = input()
	k = 0
	neededToFormT = []
	possible = True
	for j in range(0, len(s)):
		if possible == False:
			break
		while k < len(t) and t[k] != s[j]:
			neededToFormT.append(t[k])
			k += 1
		if k < len(t) and t[k] == s[j]:
			k += 1
		else:
			possible = False
	if possible:
		for n in range(k, len(t)):
			neededToFormT.append(t[n])
		have = Counter(p)
		need = Counter(neededToFormT)
		for c in need:
			if not possible:
				break
			if c not in have or have[c] < need[c]:
				possible = False
	if possible:
		print('YES')
	else:
		print('NO')


n = input()
for i in range(int(n)):
	s = input()
	t = input()
	p = input()
	counter = 0
	load = []
	for k in list(t):
		if counter < len(s):
			if s[counter] == k:
				counter += 1
			else:
				load.append(k)
		else:
			load.append(k)
	check = True
	if counter == 0 or len(s) > len(t) or counter != len(s):
		check = False
	load = sorted(load)
	for k in range(len(list(load))):
		if check:
			if load.count(load[k]) <= p.count(load[k]):
				k += load.count(load[k]) - 1
			else:
				check = False
		else:
			break
	if check:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	s = input()
	ls = len(s)
	t = input()
	lt = len(t)
	p = input()
	nt = ''
	pos = 0
	for i in range(len(t)):
		if pos == ls:
			nt += t[i:]
			break
		if t[i] == s[pos]:
			pos += 1
		else:
			nt += t[i]
	if pos != ls:
		print('NO')
	else:
		cnt = [0] * 26
		check = 'abcdefghijklmnopqrstuvwxyz'
		flag = True
		for char in p:
			for i in range(26):
				if char == check[i]:
					cnt[i] += 1
		for char in nt:
			for i in range(26):
				if char == check[i]:
					cnt[i] -= 1
					if cnt[i] < 0:
						flag = False
		if flag == True:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	L = len(t)
	i = 0
	while i < L:
		if len(s) > L or (len(s) == L and s != t):
			break
		if i < len(s) and s[i] == t[i]:
			i += 1
		elif t[i] in p:
			p.remove(t[i])
			s.insert(i, t[i])
			i += 1
		else:
			break
	if i < L:
		print('NO')
	else:
		print('YES')


import collections

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	D_s = collections.Counter(s)
	D_t = collections.Counter(t)
	D_p = collections.Counter(p)
	if isSubSequence(s, t, len(s), len(t)):
		flag = 1
		for i in D_t.keys():
			cnt = D_t[i] - D_s[i]
			if cnt <= D_p[i]:
				pass
			else:
				flag = 0
				print('NO')
				break
		if flag:
			print('YES')
	else:
		print('NO')


n = int(input())
for i in range(0, n):
	s = input().rstrip()
	r = input().rstrip()
	t = input().rstrip()
	x = list(s)
	y = list(r)
	z = list(t)
	A = [0] * 257
	B = [0] * 257
	C = [0] * 257
	D = [0] * 257
	G = 0
	if x[0] != y[0] and y[0] not in z or len(x) > len(y):
		print('NO')
	else:
		T = []
		AA = 0
		for j in range(0, len(y)):
			if AA < len(x) and y[j] == x[AA]:
				AA += 1
				T.append(j)
		if len(T) < len(x):
			print('NO')
		else:
			for j in range(0, len(y)):
				A[ord(y[j])] += 1
			for j in range(0, len(x)):
				A[ord(x[j])] -= 1
			for j in range(0, len(z)):
				A[ord(z[j])] -= 1
			for j in range(0, 257):
				if A[j] > 0:
					G = 1
					break
			if G == 0:
				print('YES')
			else:
				print('NO')


q = int(input())
for _ in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	n = []
	i = 0
	not_found = False
	for s_i in s:
		while True:
			if i == len(t):
				not_found = True
				break
			if t[i] == s_i:
				i += 1
				break
			n.append(t[i])
			i += 1
		if not_found:
			break
	if not_found:
		print('NO')
		continue
	n += t[i:]
	for n_i in n:
		try:
			p.remove(n_i)
		except ValueError:
			not_found = True
			break
	if not_found:
		print('NO')
	else:
		print('YES')


from collections import Counter
from sys import stdin
read = stdin.readline
q = int(read())
for _q in range(q):
	(s, t, p) = (read(), read(), read())
	c = Counter()
	n = len(s)
	m = len(t)
	i = 0
	for ch in s:
		found = False
		for j in range(i, m):
			if t[j] == ch:
				i = j + 1
				found = True
				break
			else:
				c[t[j]] += 1
		if not found:
			print('NO')
			break
	if found:
		c2 = Counter(p)
		c2.subtract(c)
		for k in c2:
			if c2[k] < 0:
				print('NO')
				break
		else:
			print('YES')


for _ in range(int(input())):
	a = list(input())
	b = list(input())
	c = list(input())
	i = 0
	f = 0
	x = len(a)
	y = len(b)
	if x < y:
		a += ['.'] * (y - x)
	while i < len(b):
		if x > y:
			f = 1
			break
		if a[i] != b[i]:
			if b[i] in c:
				a.insert(i, b[i])
				c.remove(b[i])
			else:
				f = 1
				break
		i += 1
	while '.' in a:
		a.remove('.')
	if f == 1:
		print('NO')
	elif a == b:
		print('YES')
	else:
		print('NO')


import os

def _f(s, t, p):
	try:
		i = 0
		for c in s:
			i = t.index(c, i)
			i += 1
	except Exception:
		return 'NO'
	s_dict = {}
	for c in s:
		if s_dict.get(c, None) is None:
			s_dict[c] = 1
		else:
			s_dict[c] += 1
	for c in p:
		if s_dict.get(c, None) is None:
			s_dict[c] = 1
		else:
			s_dict[c] += 1
	try:
		for c in t:
			if s_dict[c] == 0:
				raise Exception()
			else:
				s_dict[c] -= 1
	except Exception:
		return 'NO'
	return 'YES'

def f(s, t, p):
	return _f(s, t, p)
if os.environ.get('DEBUG', False):
	print(f"{f('ab', 'acxb', 'cax')} = Y")
	print(f"{f('a', 'aaaa', 'aaabbcc')} = Y")
	print(f"{f('a', 'aaaa', 'aabbcc')} = N")
	print(f"{f('ab', 'baaa', 'aaaaa')} = N")
else:
	q = int(input())
	for i in range(q):
		print(f(input(), input(), input()))


T = int(input())

def build_char(a):
	result = {}
	for char in a:
		if char not in result:
			result[char] = 0
		result[char] += 1
	return result

def solve(s, t, p):
	left = {}
	idx_t = 0
	idx_s = 0
	while idx_t < len(t) and idx_s < len(s):
		if s[idx_s] == t[idx_t]:
			idx_s += 1
		else:
			left_char = t[idx_t]
			if left_char not in left:
				left[left_char] = 0
			left[left_char] += 1
		idx_t += 1
	if idx_s < len(s):
		return False
	for i in range(idx_t, len(t)):
		left_char = t[i]
		if left_char not in left:
			left[left_char] = 0
		left[left_char] += 1
	b_p = build_char(p)
	for char in left:
		if char not in b_p or b_p[char] < left[char]:
			return False
	return True
for i in range(T):
	s = input()
	t = input()
	p = input()
	r = solve(s, t, p)
	if r == True:
		print('YES')
	else:
		print('NO')


import collections

def answer():
	s = input()
	t = input()
	p = input()
	s_count = 0
	s_count_max = len(s)
	cur_s = s[s_count]
	fukumu = False
	for t_c in t:
		if t_c == cur_s:
			s_count += 1
			if s_count == s_count_max:
				fukumu = True
				break
			else:
				cur_s = s[s_count]
	if not fukumu:
		return 'NO'
	t_counter = collections.Counter(t)
	s_counter = collections.Counter(s)
	p_counter = collections.Counter(p)
	for (key, val) in s_counter.items():
		t_counter[key] -= val
	ok = True
	for (key, val) in t_counter.items():
		if val == 0:
			continue
		try:
			if p_counter[key] < val:
				ok = False
				break
		except:
			ok = False
			break
	out = 'YES' if ok else 'NO'
	return out
q = int(input())
for _ in range(q):
	out = answer()
	print(out)


Input = lambda : map(int, input().split())
for i in range(int(input())):
	s = input()
	t = input()
	p = input()
	ind1 = len(s)
	ind2 = len(t)
	a = b = 0
	while a < ind1 and b < ind2:
		if s[a] == t[b]:
			a += 1
			b += 1
		else:
			b += 1
	if a == ind1:
		s = s + p
		s = sorted(s)
		t = sorted(t)
		in1 = len(t)
		in2 = len(s)
		if in1 > ind2:
			print('NO')
		else:
			a = b = 0
			while a < in1 and b < in2:
				if t[a] == s[b]:
					a += 1
					b += 1
				else:
					b += 1
			if a == in1:
				print('YES')
			else:
				print('NO')
	else:
		print('NO')


q = int(input())
while q:
	q -= 1
	s = input()
	t = input()
	p = input()
	pdict = {}
	for i in range(97, 97 + 26):
		pdict[chr(i)] = 0
	for i in range(len(p)):
		pdict[p[i]] += 1
	if len(s) > len(t) or len(t) > len(s) + len(p):
		print('NO')
		continue
	ans = True
	scurr = 0
	for i in range(len(t)):
		if scurr < len(s) and t[i] == s[scurr]:
			scurr += 1
		elif pdict[t[i]] > 0:
			pdict[t[i]] -= 1
		else:
			ans = False
			break
	if scurr != len(s):
		ans = False
	if ans:
		print('YES')
	else:
		print('NO')


from math import *
import sys
from collections import Counter
input = lambda : sys.stdin.readline().strip()

def subsq(s, t):
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i < len(s):
		return False
	return True
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	p = input()
	dl = dict(Counter(s + p))
	ds = dict(Counter(t))
	for (k, v) in ds.items():
		try:
			if dl[k] < ds[k]:
				print('NO')
				break
		except:
			print('NO')
			break
	else:
		if subsq(s, t):
			print('YES')
		else:
			print('NO')


def issub(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
n = int(input())
for _ in range(n):
	s = input()
	t = input()
	q = input()
	if issub(s, t):
		ds = {}
		dt = {}
		dq = {}
		for i in s:
			if i in ds:
				ds[i] += 1
			else:
				ds[i] = 1
		for i in t:
			if i in dt:
				dt[i] += 1
			else:
				dt[i] = 1
		for i in q:
			if i in dq:
				dq[i] += 1
			else:
				dq[i] = 1
		f = 0
		for i in dt:
			if i in ds:
				if ds[i] < dt[i]:
					if i not in dq:
						f = 1
						break
					elif dq[i] + ds[i] < dt[i]:
						f = 1
						break
			elif i not in dq:
				f = 1
				break
			elif dq[i] < dt[i]:
				f = 1
				break
		if f == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	s = input()
	t = input()
	p = input()
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
		j += 1
	if i != len(s):
		print('NO')
	else:
		sp = s + p
		dt = {}
		dsp = {}
		for i in range(len(t)):
			if t[i] not in dt:
				dt[t[i]] = 1
			else:
				dt[t[i]] += 1
		i = 0
		for i in range(len(sp)):
			if sp[i] not in dsp:
				dsp[sp[i]] = 1
			else:
				dsp[sp[i]] += 1
		ok = True
		for key in dt:
			if key not in dsp or dt[key] > dsp[key]:
				ok = False
				break
		if ok:
			print('YES')
		else:
			print('NO')


from collections import Counter
for _ in range(int(input())):
	s1 = input()
	t = input()
	p = input()
	(found, pos) = (True, 0)
	for a in s1:
		try:
			pso1 = t.index(a, pos)
			pos = pso1 + 1
		except:
			found = False
			break
	if found:
		t1 = dict(Counter(t))
		m1 = dict(Counter(p + s1))
		for tim in t1:
			if tim not in m1 or m1[tim] < t1[tim]:
				found = False
				break
	print('YES' if found else 'NO')


ll = lambda : list(map(int, input().split()))
testcases = 1
testcases = int(input())
for testcase in range(testcases):
	(s, t, p) = (input(), input(), input())
	fap = [0] * 200
	fas = [0] * 200
	for i in p:
		fap[ord(i)] += 1
	cp = 0
	for i in t:
		if cp < len(s):
			if i == s[cp]:
				cp += 1
				continue
		if fap[ord(i)] > 0:
			fap[ord(i)] -= 1
		else:
			print('NO')
			break
	else:
		if cp < len(s):
			print('NO')
		else:
			print('YES')


from collections import defaultdict

def solve(test):
	s = input()
	t = input()
	p = input()
	d = defaultdict(int)
	for c in p:
		d[c] += 1
	pos_in_s = 0
	for c in t:
		if pos_in_s >= len(s) or c != s[pos_in_s]:
			d[c] -= 1
			if d[c] < 0:
				print('NO')
				return
		else:
			pos_in_s += 1
	if pos_in_s >= len(s):
		print('YES')
	else:
		print('NO')
q = int(input())
for test in range(q):
	solve(test)


import sys
input = sys.stdin.readline
u = int(input())
for i in range(u):
	s = input()
	t = input()
	p = input()
	s1 = [0] * 26
	t1 = [0] * 26
	p1 = [0] * 26
	s = s[:-1]
	t = t[:-1]
	p = p[:-1]
	for j in range(len(s)):
		index = ord(s[j]) - 97
		s1[index] += 1
	for j in range(len(t)):
		index = ord(t[j]) - 97
		t1[index] += 1
	for j in range(len(p)):
		index = ord(p[j]) - 97
		p1[index] += 1
	for j in range(26):
		t1[j] = t1[j] - s1[j]
	flag = True
	count = 0
	for j in range(len(s)):
		for k in range(len(t)):
			if s[j] == t[k]:
				t = t[k + 1:]
				count += 1
				break
		if j != len(s) - 1 and len(t) == 0:
			flag = False
	if count != len(s):
		flag = False
	for j in range(26):
		if t1[j] < 0:
			flag = False
			break
	for j in range(26):
		t1[j] = t1[j] - p1[j]
	for j in range(26):
		if t1[j] > 0:
			flag = False
			break
	if flag == True:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	t = input()
	p = input()
	x = []
	j = 0
	for i in range(len(t)):
		if j < len(s) and s[j] == t[i]:
			j += 1
		else:
			x.append(t[i])
	if j != len(s):
		print('NO')
		continue
	for z in p:
		if z in x:
			g = x.index(z)
			x.pop(g)
	if len(x) == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	j = 0
	flg = 0
	if len(s) + len(p) < len(t):
		flg = 1
	else:
		c = 0
		for i in range(len(t)):
			if j < len(s) and t[i] == s[j] or t[i] in p:
				if j < len(s) and t[i] == s[j]:
					j += 1
					continue
				else:
					p.remove(t[i])
					c += 1
			else:
				flg = 1
				break
		if len(s) + c != len(t):
			flg = 1
	if flg == 0:
		print('YES')
	else:
		print('NO')


from sys import *
from math import *
t = int(stdin.readline())
for _ in range(t):
	x = input()
	y = input()
	z = input()
	a = [0] * 26
	b = [0] * 26
	for i in range(len(y)):
		a[ord(y[i]) - 97] += 1
	for i in range(len(x)):
		b[ord(x[i]) - 97] += 1
	for i in range(len(z)):
		b[ord(z[i]) - 97] += 1
	f = 0
	for i in range(26):
		if a[i] > b[i]:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		j = 0
		n = len(x)
		for i in y:
			if j == n:
				break
			if i == x[j]:
				j += 1
		if j < n:
			print('NO')
		else:
			print('YES')


q = int(input())

def sub(s, t):
	l = 0
	for i in range(len(t)):
		if t[i] == s[l]:
			l += 1
		if l == len(s):
			break
	return l == len(s)
for _ in range(q):
	(s, t, p) = (input(), input(), input())
	sp = [0] * 26
	tx = [0] * 26
	for i in s + p:
		sp[ord(i) - 97] += 1
	for i in t:
		tx[ord(i) - 97] += 1
	if not sub(s, t):
		print('NO')
		continue
	for i in range(26):
		if sp[i] < tx[i]:
			print('NO')
			break
	else:
		print('YES')


q = int(input())
for _ in range(q):
	s = input()
	t = input()
	q = input()
	p = 0
	flag = 0
	l = []
	for i in range(len(t)):
		if p < len(s) and t[i] == s[p]:
			p += 1
		else:
			flag1 = 0
			for j in range(len(q)):
				if t[i] == q[j] and (not j in l):
					l.append(j)
					flag1 = 1
					break
			if flag1 == 0:
				flag = 1
		if flag == 1:
			break
	if flag == 1 or p != len(s):
		print('NO')
	else:
		print('YES')


def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	found = True
	if not isSubSequence(s, t, len(s), len(t)):
		print('NO')
	else:
		aMap = {}
		for i in s:
			if i not in aMap:
				aMap[i] = -1
			else:
				aMap[i] -= 1
		for j in p:
			if j in aMap:
				aMap[j] -= 1
			else:
				aMap[j] = -1
		for k in t:
			if k not in aMap:
				print('NO')
				found = False
				break
			aMap[k] += 1
		if found:
			for val in aMap:
				if aMap[val] > 0 and val in t:
					print('NO')
					found = False
					break
		if found:
			print('YES')


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, deque
from itertools import permutations
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().replace('\n', '').strip()

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(I()):
	s = S()
	t = S()
	p = S()
	ds = defaultdict(int)
	dp = defaultdict(int)
	if s == t:
		print('YES')
	else:
		for i in s:
			ds[i] += 1
		for i in p:
			dp[i] += 1
		i = 0
		st = []
		n = len(t)
		c = 0
		s += ' '
		while i < n:
			if s[c] != t[i]:
				if dp[t[i]] > 0:
					dp[t[i]] -= 1
				else:
					break
				st.append(t[i])
			else:
				st.append(s[c])
				c += 1
			i += 1
		if ''.join(st) == t and c == len(s) - 1:
			print('YES')
		else:
			print('NO')
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


for _ in range(int(input(''))):
	s = input('')
	t = input('')
	p = input('')
	ans = 0
	ls = len(s)
	lt = len(t)
	lp = len(p)
	k = 0
	for i in range(ls):
		if ans == -1 or k >= lt:
			ans = -1
			break
		for j in range(k, lt):
			if s[i] == t[j]:
				k = j + 1
				break
			if j == lt - 1:
				ans = -1
				break
	if ans == -1:
		print('NO')
	else:
		ans = 0
		a = [0] * 26
		b = [0] * 26
		for i in range(ls):
			a[97 - ord(s[i])] += 1
		for i in range(lp):
			a[97 - ord(p[i])] += 1
		for i in range(lt):
			b[97 - ord(t[i])] += 1
		for i in range(26):
			if a[i] < b[i]:
				ans = -1
				break
		if ans == -1:
			print('NO')
		else:
			print('YES')


import sys
import math as mt
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	s = list(input().strip())
	t = list(input().strip())
	p = list(input().strip())
	k = 0
	x = True
	for a in range(len(s)):
		try:
			l = t.index(s[a], k)
			k = l + 1
		except:
			x = False
	for T in t:
		if s.count(T) + p.count(T) < t.count(T):
			x = False
	if x:
		print('YES')
	else:
		print('NO')


from collections import *

def subsequence():
	ix = 0
	for i in s:
		while ix < len(t) and i != t[ix]:
			ix += 1
		ix += 1
		if ix > len(t):
			return False
	return True

def count1():
	(ct, cs, cp) = (Counter(t), Counter(s), Counter(p))
	for (i, j) in ct.items():
		if cp[i] + cs[i] < j:
			return False
	return True
for i in range(int(input())):
	(s, t, p) = [input() for j in range(3)]
	print('yes' if subsequence() and count1() else 'no')


n = int(input())
for i in range(n):
	s = list(input())
	t = list(input())
	p = list(input())
	result = True
	for ch in t:
		if len(s) != 0 and ch == s[0]:
			s.pop(0)
		elif ch in p:
			p.remove(ch)
		else:
			result = False
			break
	print('yes') if result == True and len(s) == 0 else print('no')


q = int(input())
for i in range(0, q):
	s = input()
	t = input()
	p = input()
	if len(s) > len(t):
		print('NO')
		continue
	Palpha = [0] * 26
	for j in range(0, len(p)):
		Palpha[ord(p[j]) - ord('a')] += 1
	doable = True
	for j in range(0, max(len(s), len(t))):
		if j >= len(s) or s[j] != t[j]:
			if Palpha[ord(t[j]) - ord('a')] > 0:
				Palpha[ord(t[j]) - ord('a')] -= 1
				s = s[:j] + t[j] + s[j:]
			else:
				doable = False
				break
	print('YES' if doable == True and s == t else 'NO')


q = int(input())
alphabets = list('abcdefghijklmnopqrstuvwxyz')
for _ in range(q):
	s = input()
	t = input()
	p = input()
	memo = {alphabets[i]: 0 for i in range(26)}
	for char in p:
		memo[char] += 1
	answer = True
	a = len(s)
	b = len(t)
	(i, j) = (0, 0)
	while j < b:
		if i < a:
			if s[i] == t[j]:
				i += 1
				j += 1
			elif memo[t[j]] > 0:
				memo[t[j]] -= 1
				j += 1
			else:
				answer = False
				break
		elif memo[t[j]] > 0:
			memo[t[j]] -= 1
			j += 1
		else:
			answer = False
			break
	if i != a:
		answer = False
	if answer:
		print('YES')
	else:
		print('NO')


def calculate(s, t, p):
	replaces = {}
	for char in p:
		if char not in replaces:
			replaces[char] = 1
		else:
			replaces[char] += 1
	sub_index = 0
	for i in range(len(t)):
		char = t[i]
		if sub_index < len(s) and s[sub_index] == char:
			sub_index += 1
		elif char in replaces:
			replaces[char] -= 1
			if replaces[char] == 0:
				del replaces[char]
		else:
			return 'NO'
	if sub_index < len(s):
		return 'NO'
	else:
		return 'YES'

def solve(queries):
	memo = {}
	solutions = []
	for (s, t, p) in queries:
		if (s, t, p) not in memo:
			memo[s, t, p] = calculate(s, t, p)
		solution = memo[s, t, p]
		solutions.append(solution)
	return solutions
queries_count = int(input())
queries = []
for i in range(queries_count):
	s = input().rstrip('\r\n')
	t = input().rstrip('\r\n')
	p = input().rstrip('\r\n')
	queries.append((s, t, p))
solutions = solve(queries)
for solution in solutions:
	print(solution)


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
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		s = rs()
		t = rs()
		p = rs()
		d = {}
		z = p + s
		dt = {}
		for i in t:
			if i in dt:
				dt[i] += 1
			else:
				dt[i] = 1
		for i in z:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		yo = 0
		kk = 0
		for i in range(len(s)):
			kk = 0
			for j in range(yo, len(t)):
				if s[i] == t[j]:
					kk = 1
					break
			yo = j + 1
			if kk == 0:
				print('NO')
				break
		if kk == 1:
			l = 0
			for i in dt:
				if i in d and d[i] < dt[i]:
					print('NO')
					l = 1
					break
				if i not in d:
					print('NO')
					l = 1
					break
			if l == 0:
				print('YES')
	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()


q = int(input())
for query in range(q):
	s = input()
	s_list = list(s)
	t = input()
	t_list = list(t)
	p = input()
	p_list = list(p)
	temp = []
	p_temp = p_list
	leftovers = []
	i = 0
	j = 0
	while i < len(s_list):
		while j < len(t_list):
			if s_list[i] == t_list[j]:
				temp.append(t_list[j])
				j += 1
				break
			else:
				leftovers.append(t_list[j])
			j += 1
		i += 1
	while j < len(t_list):
		leftovers.append(t_list[j])
		j += 1
	if temp != s_list:
		print('NO')
	else:
		for x in leftovers:
			if x in p_temp:
				p_temp.remove(x)
			else:
				print('NO')
				break
		else:
			print('YES')


q = int(input())
for bagai in range(q):
	s = input()
	t = input()
	p = input()
	(i, j) = (0, 0)
	while j < len(t) and i < len(s):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i != len(s):
		print('NO')
		continue
	(i, j) = (0, 0)
	flag = True
	notuse = set()
	while j < len(t):
		if i < len(s) and s[i] == t[j]:
			i += 1
			j += 1
		else:
			flag = False
			for k in range(len(p)):
				if k in notuse:
					continue
				if p[k] == t[j]:
					j += 1
					notuse.add(k)
					flag = True
					break
			if not flag:
				break
	if not flag:
		print('NO')
	else:
		print('YES')


Q = int(input())
for q in range(Q):
	s = input()
	t = input()
	p = input()
	hvp = [0] * 26
	for i in p:
		hvp[ord(i) - 97] += 1
	r = 0
	can = 1
	for l in range(len(s)):
		while r < len(t) and t[r] != s[l]:
			nn = ord(t[r]) - 97
			r += 1
			if hvp[nn] == 0:
				can = 0
				break
			hvp[nn] -= 1
		if r == len(t):
			can = 0
		r += 1
		if can == 0:
			break
	while r < len(t):
		nn = ord(t[r]) - 97
		r += 1
		hvp[nn] -= 1
		if hvp[nn] < 0:
			can = 0
			break
	print('YNEOS'[1 - can::2])


def test(s, t, p):
	if len(s) > len(t):
		return 'NO'
	j = 0
	k = [i for i in p]
	for i in range(len(t)):
		if j < len(s) and t[i] == s[j]:
			j += 1
		elif t[i] in k:
			k.remove(t[i])
		else:
			return 'NO'
	if j == len(s):
		return 'YES'
	return 'NO'
n = int(input())
f = []
for i in range(n):
	s = input()
	t = input()
	p = input()
	f += [test(s, t, p)]
for i in f:
	print(i)


n = int(input())

def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
for x in range(n):
	s = input()
	t = input()
	p = input()
	k = s + p
	listk = []
	listt = []
	flag = 0
	for x in range(0, 26):
		listk.append(0)
		listt.append(0)
	for x in range(len(k)):
		listk[ord(k[x]) - ord('a')] += 1
	for x in range(len(t)):
		listt[ord(t[x]) - ord('a')] += 1
	if isSubSequence(s, t, len(s), len(t)):
		for x in range(26):
			if listk[x] < listt[x]:
				flag = 1
				break
		if flag == 1:
			print('No')
		if flag == 0:
			print('Yes')
	else:
		print('No')


def isSubsequence(s, t):
	i = 0
	j = 0
	n = len(s)
	m = len(t)
	while i < n and j < m:
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i == n:
		return True
	else:
		return False
q = int(input())
while q > 0:
	q -= 1
	s = input()
	t = input()
	p = input()
	if isSubsequence(s, t) == False:
		print('NO')
		continue
	count = [0 for i in range(0, 26)]
	for c in t:
		count[int(ord(c) - ord('a'))] += 1
	for c in s:
		count[int(ord(c) - ord('a'))] -= 1
	for c in p:
		if count[int(ord(c) - ord('a'))] > 0:
			count[int(ord(c) - ord('a'))] -= 1
	flag = False
	for i in count:
		if i > 0:
			flag = True
			break
	if flag == False:
		print('YES')
	else:
		print('NO')


def sol():
	s = list(input())
	t = list(input())
	p = list(input())
	c1 = [0] * 26
	c2 = [0] * 26
	for i in range(len(s)):
		c1[ord(s[i]) - 97] += 1
	for i in range(len(p)):
		c1[ord(p[i]) - 97] += 1
	for i in range(len(t)):
		c2[ord(t[i]) - 97] += 1
	for i in range(26):
		if c1[i] < c2[i]:
			print('NO')
			return 0
	ind = 0
	for i in range(len(s)):
		for g in range(ind, len(t)):
			if s[i] == t[g]:
				ind = g + 1
				break
		else:
			print('NO')
			return 0
	print('YES')
for i in range(int(input())):
	sol()


def abc(c):
	l = {}
	for i in c:
		if i in l:
			l[i] += 1
		else:
			l[i] = 1
	return l

def subs(s, t):
	m = len(s)
	x = len(t)
	i = 0
	j = 0
	while i < x and j < m:
		if s[j] == t[i]:
			j += 1
		i += 1
	return j == m
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	ds = abc(s)
	dt = abc(t)
	dp = abc(p)
	f = 0
	if subs(s, t):
		for i in ds:
			if i not in t:
				f = 1
				break
			else:
				dt[i] -= ds[i]
				if dt[i] < 0:
					f = 1
					break
		if f == 0:
			for i in dt:
				if dt[i] != 0:
					if i not in p:
						f = 1
						break
					elif dt[i] > dp[i]:
						f = 1
						break
					else:
						dt[i] = 0
		if f == 0:
			for i in dt:
				if dt[i] != 0:
					f = 1
					break
	else:
		f = 1
	if f == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	t = input()
	p = input()
	la = list(s)
	lb = list(t)
	for i in range(len(lb)):
		if la == []:
			break
		if lb[i] == la[0]:
			la.pop(0)
	if la != []:
		print('NO')
		continue
	ls = {}
	lt = {}
	lp = {}
	for i in s:
		if i not in ls:
			ls[i] = 1
		else:
			ls[i] += 1
	for i in t:
		if i not in lt:
			lt[i] = 1
		else:
			lt[i] += 1
	for i in p:
		if i not in lp:
			lp[i] = 1
		else:
			lp[i] += 1
	count = 1
	for i in lt:
		if i not in lp:
			x = 0
		else:
			x = lp[i]
		if i not in ls:
			y = 0
		else:
			y = ls[i]
		if x + y < lt[i]:
			print('NO')
			count = 0
			break
	if count:
		print('YES')


import sys
input = sys.stdin.readline
from collections import Counter
Q = int(input())
for testcases in range(Q):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	L = len(s)
	ind = 0
	for te in t:
		if te == s[ind]:
			ind += 1
		if ind == L:
			break
	if ind != L:
		print('NO')
		continue
	C = Counter(s) + Counter(p)
	CT = Counter(t)
	for ct in CT:
		if CT[ct] > C[ct]:
			print('NO')
			break
	else:
		print('YES')


for q in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	k = 0
	x = True
	for a in range(len(s)):
		try:
			l = t.index(s[a], k)
			k = l + 1
		except:
			x = False
	for T in t:
		if s.count(T) + p.count(T) < t.count(T):
			x = False
	if x:
		print('YES')
	else:
		print('NO')


def check(s, t, p):
	for i in range(26):
		x = chr(i + ord('a'))
		if s.count(x) + p.count(x) < t.count(x):
			return 'NO'
	(i, j) = (0, 0)
	while j < len(s) and i < len(t):
		if t[i] == s[j]:
			j += 1
		i += 1
	return 'YES' if j == len(s) else 'NO'
res = []
t = int(input())
for _ in range(t):
	s = input()
	t = input()
	p = input()
	res.append(check(s, t, p))
print('\n'.join(res))


q = int(input())
for v in range(q):
	s = input()
	t = input()
	p = input()
	s += '0'
	d = dict()
	for u in p:
		if u in d:
			d[u] += 1
		else:
			d[u] = 1
	nt = len(t)
	(i, k) = (0, 0)
	while i < nt:
		x = t[i]
		if x == s[k]:
			k += 1
		elif x in d:
			if d[x] > 0:
				d[x] -= 1
			else:
				break
		else:
			break
		i += 1
	if i == nt and k == len(s) - 1:
		print('YES')
	else:
		print('NO')


def main():
	s = input()
	t = input()
	p = input()
	for i in range(len(t)):
		if len(s) > i and t[i] != s[i] or len(s) <= i:
			if p.find(t[i]) == -1:
				print('NO')
				return
			if len(s) > i:
				s = s[:i] + t[i] + s[i:]
			else:
				s = s + t[i]
			p = p.replace(t[i], '', 1)
	if s == t:
		print('YES')
		return
	print('NO')
	return
q = int(input())
for i in range(q):
	main()


q = int(input())
for t in range(q):
	s = input()
	t = input()
	p = input()
	dp = {}
	for c in p:
		if c in dp:
			dp[c] += 1
		else:
			dp[c] = 1
	flag = True
	i = 0
	for j in range(len(t)):
		if i < len(s):
			if s[i] == t[j]:
				i += 1
				continue
			if t[j] in dp and dp[t[j]] > 0:
				dp[t[j]] -= 1
				continue
			flag = False
			break
		elif t[j] in dp and dp[t[j]] > 0:
			dp[t[j]] -= 1
		else:
			flag = False
			break
	if flag and i == len(s):
		print('YES')
	else:
		print('NO')


q = int(input())
for it in range(q):
	flag = 0
	s = input()
	t = input()
	p = input()
	s = list(s)
	t = list(t)
	p = list(p)
	for chr in t:
		if s != [] and chr == s[0]:
			s.pop(0)
		elif chr not in p:
			flag = 1
		else:
			p.remove(chr)
	if flag == 0 and s == []:
		print('YES')
	else:
		print('NO')


def is_transformable(s, t, d):
	i = 0
	j = 0
	while i < len(t) and j < len(s):
		if t[i] != s[j]:
			if t[i] not in d or d[t[i]] == 0:
				return False
			d[t[i]] -= 1
			i += 1
		else:
			i += 1
			j += 1
	if i == len(t) and j < len(s):
		return False
	while i < len(t):
		if t[i] not in d or d[t[i]] == 0:
			return False
		d[t[i]] -= 1
		i += 1
	return True

def count_word(s):
	d = {}
	for c in s:
		if c not in d:
			d[c] = 1
		else:
			d[c] += 1
	return d
T = int(input())
for t in range(T):
	s = input()
	t = input()
	p = input()
	d_s = count_word(s)
	d_t = count_word(t)
	d_p = count_word(p)
	ans = None
	for char in t:
		count_char_s = d_s[char] if char in d_s else 0
		count_char_t = d_t[char] if char in d_t else 0
		count_char_p = d_p[char] if char in d_p else 0
		if count_char_t - count_char_s < 0:
			ans = 'NO'
			break
		if count_char_t - count_char_s > count_char_p:
			ans = 'NO'
			break
	if ans is not None:
		print(ans)
	else:
		transformable = is_transformable(s, t, d_p)
		if transformable:
			print('YES')
		else:
			print('NO')


ts = int(input())
for tc in range(ts):
	s = input()
	t = input()
	p = input()
	dicks = {}
	dickp = {}
	dickt = {}
	for j in p + s + t:
		if j not in dickp.keys():
			dickp[j] = 0
			dicks[j] = 0
			dickt[j] = 0
	for j in p:
		if j in dickp.keys():
			dickp[j] += 1
		else:
			dickp[j] = 1
	for j in s:
		if j in dicks.keys():
			dicks[j] += 1
		else:
			dicks[j] = 1
	for j in t:
		if j in dickt.keys():
			dickt[j] += 1
		else:
			dickt[j] = 1
	j = 0
	flag = -1
	i = 0
	while i < len(t):
		if j < len(s) and s[j] == t[i]:
			j += 1
			if i > j:
				i += 1
			elif j == i:
				i += 1
			else:
				i = j
		else:
			dickp[t[i]] -= 1
			if dickp[t[i]] < 0:
				flag = 1
				break
			i += 1
	if flag == -1 and j == len(s):
		print('YES')
	else:
		print('NO')


import sys
import os
import collections
n = int(input())
while n != 0:
	dick = {x: 0 for x in range(97, 123)}
	s = input()
	t = input()
	p = input()
	for i in s:
		dick[ord(i)] += 1
	for i in p:
		dick[ord(i)] += 1
	flag = 1
	x = 0
	for i in s:
		d = 1
		for j in range(x, len(t)):
			if t[j] == i:
				x = j + 1
				d = 0
				break
		if d == 1:
			flag = 0
	if flag == 1:
		for i in t:
			if dick[ord(i)] > 0:
				dick[ord(i)] -= 1
			else:
				flag = 0
				break
	if flag == 1:
		print('yes')
	else:
		print('no')
	n -= 1


q = int(input())
for i in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	h1 = [0] * 26
	h2 = [0] * 26
	for i in range(len(s)):
		h1[ord(s[i]) - 97] = 1
	for i in range(len(t)):
		h2[ord(t[i]) - 97] = 1
	ones_in_s = 0
	ones_in_t = 0
	for i in h1:
		if i == 1:
			ones_in_s += 1
	for i in h2:
		if i == 1:
			ones_in_t += 1
	flag = 0
	if ones_in_s > ones_in_t:
		flag = -1
	i = 0
	j = 0
	eqivalent = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
			eqivalent += 1
		else:
			j += 1
	if eqivalent < len(s):
		flag = -1
	strength_s = [0] * 26
	strength_t = [0] * 26
	for i in range(len(s)):
		strength_s[ord(s[i]) - 97] += 1
	for i in range(len(t)):
		strength_t[ord(t[i]) - 97] += 1
	reqiured = [0] * 26
	for i in range(26):
		reqiured[i] = strength_t[i] - strength_s[i]
	present = [0] * 26
	for i in range(len(p)):
		present[ord(p[i]) - 97] += 1
	for i in range(26):
		if present[i] < reqiured[i]:
			flag = -1
	if flag == -1:
		print('NO')
	else:
		print('YES')


letters = 'qwertyuioplkjhgfdsazxcvbnm'
dic = {}
for q in range(int(input())):
	s = input()
	t = input()
	p = input()
	for l in letters:
		dic[l] = 0
	for l in p:
		dic[l] += 1
	len_s = len(s)
	ch = len(t) - len_s
	ind_s = 0
	s += '#'
	good = True
	for i in range(len(t)):
		l = t[i]
		if l == s[ind_s]:
			ind_s += 1
		elif dic[l] > 0:
			dic[l] -= 1
			ch -= 1
		else:
			good = False
			break
		if ch < 0:
			good = False
			break
	if good:
		print('YES')
	else:
		print('NO')


for k in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	u = ''
	for j in t:
		h = 0
		if len(s) > 0:
			if s[0] == j:
				u += j
				s.remove(j)
			elif j in p:
				u += j
				p.remove(j)
		elif j in p:
			p.remove(j)
			u += j
		else:
			print('NO')
			h += 1
			break
	if h == 0:
		if u == ''.join(t):
			if len(s) > 0:
				print('NO')
			else:
				print('YES')
		else:
			print('NO')


from collections import Counter

def isSubsequence(pattern, text):
	t = len(text)
	p = len(pattern)
	i = 0
	j = 0
	while i < p and j < t:
		if pattern[i] == text[j]:
			i += 1
		j += 1
	if i == p:
		return True
	else:
		return False
q = int(input())
for _ in range(q):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	if isSubsequence(s, t) == False:
		print('NO')
	else:
		ds = Counter(s)
		dt = Counter(t)
		dp = Counter(p)
		temp = ds + dp
		flag = 0
		for k in dt:
			if dt[k] > temp[k]:
				flag = 1
				print('NO')
				break
		if flag == 0:
			print('YES')


def is_substr_it(a, b):
	(p1, p2) = (0, 0)
	while True:
		if p1 >= len(a) or p2 >= len(b):
			break
		if b[p2] == a[p1]:
			p1 += 1
			b[p2] = '?'
		p2 += 1
	p2 = 0
	while True:
		if p2 >= len(b):
			break
		if b[p2] == '?':
			(b[p2], b[-1]) = (b[-1], b[p2])
			b.pop()
		else:
			p2 += 1
	return p1 == len(a)
q = int(input())
for _ in range(q):
	(s, t, p) = (list(input()), list(input()), list(input()))
	if not is_substr_it(s, t):
		print('NO')
		continue
	print('Yes' if is_substr_it(sorted(t), sorted(p)) else 'No')


from math import *
from collections import *
from itertools import *
from functools import *
from random import *

def getl(t=int):
	return [t(x) for x in input().split()]

def get(t=int):
	return t(input())
alphabet = [chr(x) for x in range(ord('a'), ord('z') + 1)]
alnum = lambda x: ord(x) - ord('a')

def main():
	for i in range(int(input())):
		if test():
			print('YES')
		else:
			print('NO')

def isSubSequence(str1, str2):
	j = 0
	i = 0
	while j < len(str1) and i < len(str2):
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == len(str1)

def test():
	s = input()
	t = input()
	p = input()
	if isSubSequence(s, t):
		c1 = Counter(s + p)
		c2 = Counter(t)
		return all((c1[x] >= c2[x] for x in c2.keys()))
	return False
main()


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	for i in range(len(t)):
		try:
			if t[i] == s[i]:
				None
			elif t[i] in p:
				p.remove(t[i])
				s.insert(i, t[i])
		except:
			if t[i] in p:
				p.remove(t[i])
				s.insert(i, t[i])
	if s == t:
		print('Yes')
	else:
		print('No')


def find(x, idx, a):
	for i in range(idx, len(a)):
		if a[i] == x:
			return i
	return -1
q = int(input())
for i in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	k = 0
	for j in s:
		k = find(j, k, t)
		if k == -1:
			break
		t[k] = '#'
	if k == -1:
		print('NO')
	else:
		impossible = False
		for j in t:
			if j != '#':
				if t.count(j) > p.count(j):
					impossible = True
					break
		if impossible:
			print('NO')
		else:
			print('YES')


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
q = rint()
for _ in range(q):
	s = input()
	t = input()
	pc = [0] * 26
	for c in input():
		pc[ord(c) - ord('a')] += 1
	i = j = 0
	while i < len(t):
		if j < len(s) and t[i] == s[j]:
			i += 1
			j += 1
		else:
			pc[ord(t[i]) - ord('a')] -= 1
			if pc[ord(t[i]) - ord('a')] < 0:
				j = 0
				break
			i += 1
	print('YES' if j == len(s) else 'NO')


q = int(input())
for w in range(q):
	s = input()
	t = input()
	p = input()
	k1 = len(s)
	k2 = len(t)
	k3 = len(p)
	if k1 > k2:
		print('NO')
	else:
		j = 0
		for i in range(k2):
			if j == k1:
				break
			if t[i] == s[j]:
				j += 1
		if j < k1:
			print('NO')
		else:
			c = 1
			(l1, l2, l3) = ([0] * 26, [0] * 26, [0] * 26)
			for i in range(k1):
				l1[ord(s[i]) - ord('a')] += 1
			for i in range(k2):
				l2[ord(t[i]) - ord('a')] += 1
			for i in range(k3):
				l3[ord(p[i]) - ord('a')] += 1
			for i in range(26):
				if l1[i] + l3[i] < l2[i]:
					c = 0
					break
			if c == 1:
				print('YES')
			else:
				print('NO')


q = int(input())

def cmp(a, b):
	for c in b:
		if c not in a or a[c] < b[c]:
			return False
	return True

def is_sub(s, t):
	if len(s) > len(t):
		return False
	(i, j) = (0, 0)
	while j < len(t) and i < len(s):
		if s[i] == t[j]:
			i += 1
		j += 1
	return i == len(s)
for _ in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	if not is_sub(s, t):
		print('NO')
		continue
	a = {}
	for c in s:
		if c not in a:
			a[c] = 0
		a[c] += 1
	for c in p:
		if c not in a:
			a[c] = 0
		a[c] += 1
	b = {}
	for c in t:
		if c not in b:
			b[c] = 0
		b[c] += 1
	if cmp(a, b):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	d = {}
	for i in p:
		try:
			d[i] += 1
		except:
			d[i] = 1
	p = d
	ans = 'YES'
	ind = 0
	for i in t:
		if ind < len(s) and i == s[ind]:
			ind += 1
		elif i in p:
			p[i] -= 1
			if p[i] == 0:
				p.pop(i)
		else:
			ans = 'NO'
			break
	if ind != len(s):
		ans = 'NO'
	print(ans)


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	f = 0
	for i in range(len(s)):
		if s[i] not in t or t.count(s[i]) < s.count(s[i]):
			f = 1
			break
	if f == 1:
		print('NO')
		continue
	a = 0
	b = 0
	while a < len(s) and b < len(t):
		if s[a] == t[b]:
			a += 1
			b += 1
		elif s[a] != t[b]:
			b += 1
	s = s + p
	D = set(t)
	ans = 0
	for i in D:
		if t.count(i) <= s.count(i):
			ans += 1
	if ans == len(D) and a == len(s) - len(p):
		print('YES')
	else:
		print('NO')


def hash(s):
	n = len(s)
	alpha = {'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}
	for i in range(n):
		alpha[s[i]] += 1
	return alpha

def isPossible(s, t, p):
	letters = 'abcdefghijklmnopqrstuvwxyz'
	for i in letters:
		if s[i] + p[i] < t[i]:
			print('NO')
			return
	print('YES')
	return
q = int(input())
for i in range(q):
	s = str(input())
	t = str(input())
	p = str(input())
	j = 0
	k = 0
	sLen = len(s)
	tLen = len(t)
	matchers = 0
	for j in range(tLen):
		if t[j] == s[matchers]:
			matchers += 1
			if matchers == sLen:
				break
	if matchers == sLen:
		isPossible(hash(s), hash(t), hash(p))
	else:
		print('NO')


def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)

def check(sarr, tarr, parr, s, t, p):
	if len(sarr) > len(tarr):
		return False
	if not isSubSequence(s, t, len(s), len(t)):
		return False
	for i in range(26):
		if sarr[i] > tarr[i]:
			return False
	for j in range(26):
		if sarr[j] + parr[j] < tarr[j]:
			return False
	return True
q = int(input())
ans_arr = []
for i in range(q):
	s = input()
	t = input()
	p = input()
	sarr = [0] * 26
	tarr = [0] * 26
	parr = [0] * 26
	for i in range(len(s)):
		sarr[ord(s[i]) - 97] += 1
	for i in range(len(t)):
		tarr[ord(t[i]) - 97] += 1
	for i in range(len(p)):
		parr[ord(p[i]) - 97] += 1
	if check(sarr, tarr, parr, s, t, p):
		ans_arr.append('YES')
	else:
		ans_arr.append('NO')
print('\n'.join(ans_arr))


import sys

def piece_search(txt1, txt2):
	l = 0
	count = 0
	for item in txt2:
		while l < len(txt1):
			if item != txt1[l]:
				l += 1
			else:
				count += 1
				l += 1
				break
	if count != len(txt2):
		return False
	else:
		return True
q = int(input())
for i in range(q):
	s = input()
	t = input()
	p = input()
	mems = dict()
	memt = dict()
	flag = 0
	for item in s:
		if item not in mems:
			mems[item] = 1
		else:
			mems[item] += 1
	for item in t:
		if item not in memt:
			memt[item] = 1
		else:
			memt[item] += 1
	for item in p:
		if item not in mems:
			mems[item] = 1
		else:
			mems[item] += 1
	for item in memt:
		try:
			if memt[item] > mems[item]:
				print('NO')
				flag = 1
				break
		except KeyError:
			print('NO')
			flag = 1
			break
	if flag == 0 and (not piece_search(t, s)):
		print('NO')
		flag = 1
	if flag == 0:
		print('YES')


def cnt(d):
	ret = [0 for _ in range(30)]
	for c in d:
		ret[ord(c) - ord('a')] += 1
	return ret
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	p = input()
	p_cnt = cnt(p)
	(si, ti) = (0, 0)
	flag = True
	while ti < len(t):
		if si < len(s) and s[si] == t[ti]:
			si += 1
			ti += 1
		elif p_cnt[ord(t[ti]) - ord('a')] > 0:
			p_cnt[ord(t[ti]) - ord('a')] -= 1
			ti += 1
		else:
			flag = False
			break
	if flag and si == len(s):
		print('YES')
	else:
		print('NO')


import os
tc = int(input())
while tc:
	tc -= 1
	s = input()
	t = input()
	p = input()
	checked = False
	if len(s) <= len(t):
		k = 0
		for i in range(len(t)):
			if t[i] == s[k]:
				k += 1
			if k >= len(s):
				break
		if k == len(s):
			checked = True
	arr = list(s) + list(p)
	arr = sorted(arr)
	t = sorted(t)
	isprinted = False
	for i in range(len(t)):
		if t[i] in arr:
			arr.remove(t[i])
		else:
			isprinted = True
			break
	if isprinted:
		print('NO')
	elif checked:
		print('YES')
	else:
		print('NO')


def f():
	it = iter(t)
	if not all((c in it for c in s)):
		return False
	d = [0] * 26
	for c in s:
		d[ord(c) - 97] += 1
	for c in p:
		d[ord(c) - 97] += 1
	for c in t:
		d[ord(c) - 97] -= 1
		if d[ord(c) - 97] < 0:
			return False
	return True
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	print('yes' if f() else 'no')


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	ans = 0
	for i in range(len(t)):
		if i > len(s) - 1:
			for tt in p:
				if t[i] == tt:
					p.remove(tt)
					s.insert(i, tt)
					break
		elif t[i] != s[i]:
			for tt in p:
				if t[i] == tt:
					p.remove(tt)
					s.insert(i, tt)
					break
	if len(t) != len(s):
		print('NO')
	else:
		xx = 0
		for ty in range(len(t)):
			if t[ty] != s[ty]:
				xx = 1
		if xx == 0:
			print('YES')
		else:
			print('NO')


for q in range(int(input())):
	(s1, t1, p1) = (input(), input(), input())
	(s, t, p) = ([], [], [])
	for i in s1:
		s.append(i)
	for i in t1:
		t.append(i)
	for i in p1:
		p.append(i)
	si = 0
	ans = 1
	for ti in t:
		if si < len(s) and s[si] == ti:
			si += 1
		elif (ti in p) == False:
			ans = 0
			break
		else:
			p[p.index(ti)] = '$'
	if si != len(s):
		ans = 0
	print('YES' if ans == 1 else 'NO')


q = int(input())

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def solve():
	s = input()
	t = input()
	p = input()
	if not isSubSequence(s, t, len(s), len(t)):
		return 'NO'

	def char_count(x):
		foo = {}
		for xx in x:
			if xx not in foo:
				foo[xx] = 0
			foo[xx] += 1
		return foo
	s_count = char_count(s)
	t_count = char_count(t)
	p_count = char_count(p)
	sp_count = char_count(s + p)
	for cs in s_count:
		if cs not in t_count:
			return 'NO'
		if t_count[cs] < s_count[cs]:
			return 'NO'
	for ts in t_count:
		if ts not in sp_count:
			return 'NO'
		if t_count[ts] > sp_count[ts]:
			return 'NO'
	return 'YES'
for _ in range(q):
	print(solve())


q = int(input())
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for i in range(q):
	s = input()
	t = input()
	k = [s[j] for j in range(len(s))]
	l = [t[j] for j in range(len(t))][::-1]
	remainingLetters = []
	p = input()
	z = [p[j] for j in range(len(p))]
	m = len(s)
	pos = True
	for i in range(len(k)):
		item = k.pop()
		if item not in l:
			pos = False
			break
		else:
			g = l.index(item)
			for i in range(g):
				h = l.pop(0)
				remainingLetters.append(h)
			l.pop(0)
	if pos == False:
		print('NO')
	else:
		for itemLeft in l:
			remainingLetters.append(itemLeft)
		for i in range(26):
			if p.count(alphabet[i]) < remainingLetters.count(alphabet[i]):
				pos = False
				break
		if pos == False:
			print('NO')
		else:
			print('YES')


q = int(input())
alth = 'qwertyuiopasdfghjklzxcvbnm'
for i in range(q):
	s = input()
	t = input()
	p = input()
	s1 = [0] * 26
	p1 = [0] * 26
	t1 = [0] * 26
	for i in s:
		s1[alth.find(i)] += 1
	for i in p:
		p1[alth.find(i)] += 1
	for i in t:
		t1[alth.find(i)] += 1
	ans = 1
	for i in range(26):
		if s1[i] + p1[i] < t1[i]:
			ans = 0
			break
	if ans == 0:
		print('NO')
	else:
		n = len(s)
		m = len(t)
		i = 0
		j = 0
		while i < n and j < m:
			if t[j] == s[i]:
				i += 1
			j += 1
		if i != n:
			ans = 0
		if ans == 0:
			print('NO')
		else:
			print('YES')


def f():
	(s, t, p) = (input(), input(), input())
	if len(s) > len(t):
		print('NO')
		return
	i = j = 0
	while i < len(s):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
		if j == len(t) and i != len(s):
			print('NO')
			return
	d = {}
	for i in s + p:
		if d.get(i, 0):
			d[i] += 1
		else:
			d[i] = 1
	for i in t:
		if d.get(i, 0):
			d[i] -= 1
		else:
			print('NO')
			return
	if any([i < 0 for i in d.values()]):
		print('NO')
	else:
		print('YES')
Q = int(input())
for q in range(Q):
	f()


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	s_pointer = 0
	flag = True
	for letter in t:
		if s_pointer < len(s):
			if letter == s[s_pointer]:
				s_pointer += 1
				continue
			elif letter not in p:
				flag = False
				break
			else:
				p = p.replace(letter, '', 1)
		elif letter not in p:
			flag = False
			break
		else:
			p = p.replace(letter, '', 1)
	if flag and s_pointer == len(s):
		print('Yes')
	else:
		print('No')


q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	flag = True
	dictionary_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}
	dictionary_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}
	dictionary_p = {'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}
	for i in s:
		dictionary_s[i] += 1
	for i in p:
		dictionary_p[i] += 1
	for i in t:
		dictionary_t[i] += 1
	for i in range(26):
		char = chr(97 + i)
		if dictionary_t[chr(97 + i)] > dictionary_s[chr(97 + i)] + dictionary_p[chr(97 + i)]:
			print('no')
			flag = False
			break
	start = -1
	if flag:
		for i in s:
			try:
				start = t[start + 1:].index(i) + start + 1
			except ValueError:
				print('no')
				flag = False
				break
	if flag:
		print('yes')


q = int(input())
for _ in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	ans = 'YES'
	flag = 0
	for i in range(len(t)):
		if i < len(s):
			if t[i] != s[i]:
				if t[i] in p:
					ind = p.index(t[i])
					p[ind] = 0
					s.insert(i, t[i])
				else:
					ans = 'NO'
					flag = 1
		elif t[i] in p:
			ind = p.index(t[i])
			p[ind] = 0
			s.append(t[i])
		else:
			ans = 'NO'
			flag = 1
		if flag == 1:
			break
	if flag == 1 or s != t:
		print('NO')
	else:
		print('YES')


from sys import stdin

def ii():
	return int(stdin.readline())

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

def li():
	return list(mi())

def fsi():
	return stdin.readline()

def si():
	return input()
for _ in range(ii()):
	a = [0] * 27
	s = si()
	t = si()
	i = j = f = 0
	for j in range(len(t)):
		if i < len(s) and s[i] == t[j]:
			i += 1
		else:
			a[ord(t[j]) - 97] += 1
		if f:
			break
	if len(s) > len(t) or i < len(s):
		f = 1
	p = si()
	if not f:
		for j in range(len(p)):
			if a[ord(p[j]) - 97]:
				a[ord(p[j]) - 97] -= 1
	if any(a):
		f = 1
	print(['YES', 'NO'][f])


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

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

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
c = cinn()
x = c.cin()
for i in range(x):
	s = c.cin(str)
	t = c.cin(str)
	p = c.cin(str)
	if not isSubSequence(s, t, len(s), len(t)):
		print('NO')
		continue
	tcount = c.countlist(t)
	poss = True
	for el in s:
		if el not in tcount:
			poss = False
			break
		else:
			tcount[el] -= 1
			if tcount[el] == 0:
				tcount.pop(el, None)
	if not poss:
		print('NO')
	else:
		for el in p:
			if el in tcount:
				tcount[el] -= 1
				if tcount[el] == 0:
					tcount.pop(el, None)
		if tcount:
			print('NO')
		else:
			print('YES')


from collections import defaultdict

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	if isSubSequence(s, t) == True:
		flag = True
		d1 = {}
		for i in s:
			if i in d1:
				d1[i] += 1
			else:
				d1[i] = 1
		d2 = {}
		for i in t:
			if i in d2:
				d2[i] += 1
			else:
				d2[i] = 1
		for i in d2:
			if i in d1:
				d2[i] -= d1[i]
		d3 = {}
		for i in p:
			if i in d3:
				d3[i] += 1
			else:
				d3[i] = 1
		for i in d2:
			if i in d3:
				if d3[i] < d2[i]:
					flag = False
					break
			elif d2[i] > 0:
				flag = False
				break
		if flag:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

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

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def solve():
	t = nu()
	for tt in range(t):
		s = input()
		t = input()
		p = input()
		ff = [0] * 26
		for i in range(len(s)):
			ff[ord(s[i]) - ord('a')] += 1
		pq = [0] * 26
		for i in range(len(t)):
			pq[ord(t[i]) - ord('a')] += 1
		of = [0] * 26
		for i in range(len(p)):
			of[ord(p[i]) - ord('a')] += 1
		fl = True
		op = 0
		ll = 0
		while op < len(s) and ll < len(t):
			if s[op] != t[ll]:
				if of[ord(t[ll]) - ord('a')] > 0:
					of[ord(t[ll]) - ord('a')] -= 1
					ll += 1
				else:
					fl = False
					break
			else:
				op += 1
				ll += 1
		if ll == len(t) and op != len(s):
			fl = False
		if ll != len(t) and op == len(s):
			while ll < len(t):
				if of[ord(t[ll]) - ord('a')] > 0:
					of[ord(t[ll]) - ord('a')] -= 1
					ll += 1
				else:
					fl = False
					break
		if fl:
			print('yes')
		else:
			print('no')
solve()


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	a = [0] * 200
	for i in p:
		a[ord(i)] += 1
	j = 0
	flag = True
	for i in s:
		if j == len(t):
			flag = False
			break
		if i == t[j]:
			j += 1
			continue
		while i != t[j]:
			if not a[ord(t[j])]:
				flag = False
				break
			a[ord(t[j])] -= 1
			j += 1
			if j == len(t):
				flag = False
				break
		j += 1
		if not flag:
			break
	for i in range(j, len(t)):
		if not a[ord(t[i])]:
			flag = False
			break
		else:
			a[ord(t[i])] -= 1
	print('YES' if flag else 'NO')


for i in range(int(input())):
	a = list(input())
	b = list(input())
	lb = len(b)
	c = list(input())
	lc = len(c)
	z = 0
	c1 = False
	r = [''] * len(b)
	if len(a) >= lb:
		if a == b:
			print('YES')
		else:
			print('NO')
	else:
		for i in range(lb):
			if b[i] == a[z]:
				z += 1
				r[i] = b[i]
			if z == len(a):
				c1 = True
				break
		for i in range(lb):
			if r[i] == '':
				for j in range(lc):
					if b[i] == c[j]:
						r[i] = b[i]
						c[j] = ''
						break
		if c1:
			if ''.join(r) == ''.join(b):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


from collections import Counter
for _ in range(int(input())):
	s1 = input()
	t = input()
	p = input()
	if len(s1) > len(t):
		print('NO')
	elif len(s1) == len(t):
		print('YES' if s1 == t else 'NO')
	else:
		(found, pos) = (True, 0)
		for a in s1:
			try:
				pso1 = t.index(a, pos)
				pos = pso1 + 1
			except:
				found = False
				break
		if found:
			for tim in t:
				ast = s1.count(tim)
				ast1 = p.count(tim)
				ast2 = t.count(tim)
				if ast > ast2 or ast1 + ast < ast2:
					found = False
					break
		print('YES' if found else 'NO')


t = int(input())
for _ in range(t):
	s = input()
	t = input()
	p = input()
	if len(t) < len(s):
		print('NO')
	elif len(t) == len(s):
		if t == s:
			print('YES')
		else:
			print('NO')
	else:
		j = 0
		c = 0
		for i in s:
			while j < len(t):
				if t[j] == i:
					c += 1
					j += 1
					break
				j += 1
		if c == len(s):
			f = 0
			s = s + ' '
			for i in range(len(t)):
				if t[i] != s[i]:
					if t[i] in p:
						s = s[:i] + t[i] + s[i:]
						index = p.index(t[i])
						p = p[:index] + p[index + 1:]
					else:
						print('NO')
						f = 1
						break
			if f == 0:
				print('YES')
		else:
			print('NO')


for test in range(int(input())):
	s = input()
	t = input()
	p = input()
	i = 0
	j = 0
	flag = 0
	count = 0
	while i < len(s):
		while j < len(t):
			if s[i] == t[j]:
				i += 1
				j += 1
				count += 1
				break
			else:
				j += 1
			if j == len(t):
				flag = 1
				break
		if j == len(t):
			break
		if flag == 1:
			break
	subsequence = False
	if count == len(s):
		subsequence = True
	sOccur = [0] * 26
	pOccur = [0] * 26
	tOccur = [0] * 26
	for i in range(len(s)):
		sOccur[ord(s[i]) - 97] += 1
	for i in range(len(p)):
		pOccur[ord(p[i]) - 97] += 1
	for i in range(len(t)):
		tOccur[ord(t[i]) - 97] += 1
	ans = 0
	for i in range(len(t)):
		if pOccur[ord(t[i]) - 97] + sOccur[ord(t[i]) - 97] >= tOccur[ord(t[i]) - 97]:
			ans += 1
	if subsequence and ans == len(t):
		print('Yes')
	else:
		print('No')


def order(a):
	return ord(a) - 97

def letter(a):
	return chr(a + 97)
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	remain = [p.count(letter(i)) for i in range(26)]
	cur = 0
	for i in t:
		if len(s) > cur and i == s[cur]:
			cur += 1
			continue
		if remain[order(i)] == 0:
			cur = -1
			break
		else:
			remain[order(i)] -= 1
	if cur == len(s):
		print('YES')
	else:
		print('NO')


import math
from collections import deque, defaultdict
from sys import stdin, stdout
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	cs = defaultdict(int)
	ct = defaultdict(int)
	cp = defaultdict(int)
	for i in s:
		cs[i] += 1
	for i in t:
		ct[i] += 1
	for i in p:
		cp[i] += 1
	flag = True
	for i in ct.keys():
		if ct[i] > cs[i] + cp[i]:
			flag = False
	if flag:
		i = 0
		j = 0
		while i < len(s) and j < len(t):
			if s[i] == t[j]:
				i += 1
			j += 1
		if i == len(s):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	i = 0
	j = 0
	while j < len(t):
		if s[i] == t[j]:
			i += 1
		j += 1
	if i < len(s):
		print('NO\n')
	else:
		hash1 = [0] * 26
		hash2 = [0] * 26
		for i in range(len(s) - 1):
			hash1[ord(s[i]) - ord('a')] += 1
		for i in range(len(p) - 1):
			hash1[ord(p[i]) - ord('a')] += 1
		for i in range(len(t) - 1):
			hash2[ord(t[i]) - ord('a')] += 1
		flag = True
		for i in range(26):
			if hash1[i] < hash2[i]:
				flag = False
				break
		print('YES\n' if flag else 'NO\n')


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	s1 = {}
	p1 = {}
	f1 = {}
	t1 = {}
	for i in range(97, 97 + 26):
		i = chr(i)
		s1[i] = 0
		p1[i] = 0
		f1[i] = 0
		t1[i] = 0
	if s == t:
		print('YES')
	else:
		for i in s:
			s1[i] += 1
			f1[i] += 1
		for i in p:
			p1[i] += 1
			f1[i] += 1
		for i in t:
			t1[i] += 1
		ans = 0
		z = 0
		zz = len(s)
		for i in t:
			if i == s[z]:
				z += 1
			if z == zz:
				break
		if z != zz:
			ans = 1
		for i in range(97, 97 + 26):
			ii = chr(i)
			if t1[ii] > f1[ii] or s1[ii] > t1[ii]:
				ans = 1
				break
		if ans == 0:
			print('YES')
		else:
			print('NO')


import sys
import math

def get_num():
	return int(input())

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

def get_numbers_list():
	return list(get_numbers())

def solve(s, t, p):
	count_p = [0] * 26
	for c in p:
		count_p[ord(c) - ord('a')] += 1
	(i, j) = (0, 0)
	while len(s) < len(t):
		if i >= len(s) or s[i] != t[j]:
			index = ord(t[j]) - ord('a')
			if count_p[index] > 0:
				count_p[index] -= 1
				mid = chr(index + ord('a'))
				s = s[:i] + mid + s[i:]
				i += 1
			else:
				return 'NO'
		else:
			i += 1
		j += 1
	if s == t:
		return 'YES'
	return 'NO'

def main():
	q = get_num()
	for _ in range(q):
		(s, t, p) = (input(), input(), input())
		print(solve(s, t, p))
main()


def solve(s, t, p):
	if len(t) < len(s):
		return 'NO'
	if len(t) == len(s):
		if s == t:
			return 'YES'
		else:
			return 'NO'
	si = 0
	needed = dict()
	for ti in range(len(t)):
		if si < len(s) and t[ti] == s[si]:
			si += 1
		else:
			needed[t[ti]] = 1 + needed.get(t[ti], 0)
	if si != len(s):
		return 'NO'
	needed_letters = set(needed.keys())
	for pc in p:
		if pc in needed_letters:
			needed[pc] = max(0, needed.get(pc, 0) - 1)
	for k in needed.keys():
		if needed[k] > 0:
			return 'NO'
	return 'YES'

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


def main():
	q = int(input())
	for _ in range(q):
		s = input()
		t = input()
		p = input()
		dico = {}
		for char in p:
			if not char in dico:
				dico[char] = 1
			else:
				dico[char] += 1
		ns = ''
		i = 0
		yess = True
		x = 0
		while x < len(s):
			if i == len(t):
				yess = False
				break
			elif s[x] == t[i]:
				i += 1
				x += 1
			elif t[i] in dico and dico[t[i]] > 0:
				dico[t[i]] -= 1
				i += 1
			else:
				yess = False
				break
		while i < len(t):
			if t[i] in dico and dico[t[i]] > 0:
				dico[t[i]] -= 1
				i += 1
			else:
				yess = False
				break
		if yess == True:
			print('Yes')
		else:
			print('No')
main()


def get(a, b, c):
	pb = len(b) - 1
	for i in range(len(a) - 1, -1, -1):
		while pb >= 0 and b[pb] != a[i]:
			pb -= 1
		if pb < 0:
			return 'NO'
		else:
			b = b[:pb] + b[pb + 1:]
			pb -= 1
	for elm in b:
		pc = c.find(elm)
		if pc < 0:
			return 'NO'
		else:
			c = c[:pc] + c[pc + 1:]
	return 'YES'
q = int(input())
for i in range(q):
	a = input()
	b = input()
	c = input()
	print(get(a, b, c))


from collections import Counter
from itertools import combinations

def is_subsequences(s_1, s_2) -> bool:
	i = j = 0
	while i < len(s_1) and j < len(s_2):
		if s_1[i] == s_2[j]:
			i += 1
		j += 1
	return i == len(s_1)
q = int(input())
while q > 0:
	(s, t, p) = (input(), input(), input())
	if not is_subsequences(s, t):
		print('NO')
	else:
		(s, t, p) = (Counter(s), Counter(t), Counter(p))
		for k in t:
			if not t.get(k) <= s.get(k, 0) + p.get(k, 0):
				print('NO')
				break
		else:
			print('YES')
	q -= 1


num_queries = int(input())
for _ in range(num_queries):
	s = input()
	t = input()
	p = input()
	p_occ = [0] * 125
	for c in p:
		p_occ[ord(c)] += 1
	s_pos = 0
	t_pos = 0
	while t_pos < len(t):
		if s_pos < len(s) and s[s_pos] == t[t_pos]:
			s_pos += 1
			t_pos += 1
		elif p_occ[ord(t[t_pos])] > 0:
			p_occ[ord(t[t_pos])] -= 1
			t_pos += 1
		else:
			break
	if t_pos == len(t) and s_pos == len(s):
		print('YES')
	else:
		print('NO')


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
for _ in range(t):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	dp = defaultdict(int)
	ds = defaultdict(int)
	dt = defaultdict(int)
	for i in p:
		dp[i] += 1
	for i in s:
		ds[i] += 1
	for i in t:
		dt[i] += 1
	d = 1
	for i in t:
		if ds[i] + dp[i] >= dt[i]:
			continue
		else:
			print('NO')
			d = 0
			break
	if d:
		k = isSubSequence(s, t, len(s), len(t))
		if k:
			print('YES')
		else:
			print('NO')


M = 10 ** 9 + 7
R = lambda : map(int, input().split())
n = int(input())
for i in range(n):
	fs = [0] * 26
	ft = [0] * 26
	fp = [0] * 26
	s = [j for j in input()]
	t = input()
	p = input()
	if len(t) < len(s):
		print('NO')
		continue
	for j in p:
		fp[ord(j) - ord('a')] += 1
	f = 0
	for j in range(len(t)):
		if len(s) >= j + 1:
			if t[j] != s[j]:
				if fp[ord(t[j]) - ord('a')] > 0:
					fp[ord(t[j]) - ord('a')] -= 1
					k = s[:j] + [t[j]] + s[j:]
					s = k
				else:
					f = 1
					break
		elif fp[ord(t[j]) - ord('a')] > 0:
			fp[ord(t[j]) - ord('a')] -= 1
			k = s[:j] + [t[j]]
			s = k
		else:
			f = 1
			break
	if f or t != ''.join(s):
		print('NO')
	else:
		print('YES')


def readInts():
	return [int(c) for c in input().split(' ')]

def solve():
	s = input()
	t = input()
	p = input()
	cursor = 0
	counts = {}
	for c in s:
		while cursor < len(t) and t[cursor] != c:
			if not t[cursor] in counts:
				counts[t[cursor]] = 0
			counts[t[cursor]] += 1
			cursor += 1
		if cursor >= len(t) or t[cursor] != c:
			return 'NO'
		cursor += 1
	while cursor < len(t):
		if not t[cursor] in counts:
			counts[t[cursor]] = 0
		counts[t[cursor]] += 1
		cursor += 1
	for c in p:
		if c in counts:
			counts[c] -= 1
	for (c, v) in counts.items():
		if v > 0:
			return 'NO'
	return 'YES'

def main():
	Q = readInts()[0]
	for q in range(Q):
		print(solve())
main()


n = int(input())
mas = [None] * n
for i in range(n):
	mas[i] = [input() for z in range(3)]
for x in range(n):
	beg = [i for i in mas[x][0]] + ['']
	end = [i for i in mas[x][1]]
	elem = [i for i in mas[x][2]]
	cont = beg + elem
	flag = True
	for i in range(len(end)):
		if end[i] != beg[i]:
			if end[i] in set(elem):
				beg.insert(i, end[i])
				elem.remove(end[i])
			else:
				flag = False
				break
	if flag:
		if beg[:-1] == end:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def ok(s, p):
	n = len(s)
	m = len(p)
	(pos, i) = (0, 0)
	while i < m and pos < n:
		if s[pos] == p[i]:
			pos += 1
		i += 1
	if pos == n:
		return True
	return False

def main():
	q = int(input())
	while q > 0:
		q -= 1
		s = input()
		t = input()
		p = input()
		if ok(s, t) == False:
			print('NO')
			continue
		c1 = [0 for _ in range(26)]
		c2 = [0 for _ in range(26)]
		c3 = [0 for _ in range(26)]
		for i in range(len(s)):
			c1[ord(s[i]) - ord('a')] += 1
		for i in range(len(t)):
			c2[ord(t[i]) - ord('a')] += 1
		for i in range(len(p)):
			c3[ord(p[i]) - ord('a')] += 1
		fine = True
		for i in range(26):
			if c2[i] - c1[i] > c3[i]:
				fine = False
				break
		if fine:
			print('YES')
		else:
			print('NO')
main()


def is_subsequence(A, B):
	ib = 0
	for a in A:
		if a == B[ib]:
			ib += 1
		if ib == len(B):
			return True
	return False

def has_more_letters(A, B):
	cnt = [0] * 128
	for a in A:
		cnt[ord(a)] += 1
	for b in B:
		cnt[ord(b)] -= 1
	return all((x >= 0 for x in cnt))

def handle(s, t, p):
	ans = is_subsequence(t, s) and has_more_letters(s + p, t)
	print('YES' if ans else 'NO')

def main():
	nc = int(input())
	for _ in range(nc):
		s = input()
		t = input()
		p = input()
		handle(s, t, p)
main()


from collections import defaultdict

def iss(s1, s2):
	m = len(s1)
	n = len(s2)
	j = 0
	i = 0
	while j < m and i < n:
		if s1[j] == s2[i]:
			j = j + 1
		i += 1
	return j == m
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	d = defaultdict(int)
	d1 = defaultdict(int)
	for j in s:
		d[j] += 1
	for g in p:
		d[g] += 1
	for k in t:
		d1[k] += 1
	f = True
	for k in str(set(t)):
		if d1[k] > d[k]:
			f = False
			break
	if f == False:
		print('NO')
	else:
		f = iss(s, t)
		if f:
			print('YES')
		else:
			print('NO')


q = int(input())
for i in range(q):
	pr = False
	s = input()
	t = input()
	p = input()
	dp = {}
	for el in p:
		if el in dp:
			dp[el] += 1
		else:
			dp[el] = 1
	n = len(s)
	m = len(t)
	count = 0
	dj = {}
	for j in t:
		if count < n and s[count] == j:
			count += 1
		elif j in dj:
			dj[j] += 1
		else:
			dj[j] = 1
	if count != n:
		pr = True
	if not pr:
		for el in dj:
			if el not in dp or dp[el] < dj[el]:
				pr = True
				break
	if pr:
		print('NO')
	else:
		print('YES')


def check_val(s, t, p):
	if s == t:
		return 'YES'
	chars = [0] * 27
	for i in p:
		chars[ord(i) - 96] += 1
	temp = len(t)
	(i, j) = (0, 0)
	while temp >= 0:
		f = s[:i]
		g = t[:i]
		if f == g:
			pass
		else:
			c = g[-1]
			if chars[ord(c) - 96] > 0:
				chars[ord(c) - 96] -= 1
				s = s[:i - 1] + c + s[i - 1:]
			else:
				break
		i += 1
		temp -= 1
	if s == t:
		return 'YES'
	else:
		return 'NO'
for _ in range(int(input())):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	print(check_val(s, t, p))


from sys import stdin, stdout, exit
from collections import defaultdict

def rem(x, y):
	i = 0
	j = 0
	ans = []
	while i < len(x) and j < len(y):
		idx = x[i:].find(y[j])
		if idx == -1:
			return None
		i += idx + 1
		ans.append(i - 1)
		j += 1
	if j < len(y):
		return None
	s = [x[i] for i in range(len(x)) if i not in ans]
	return ''.join(s)
q = int(input())
for it in range(q):
	s = stdin.readline().strip()
	t = stdin.readline().strip()
	p = stdin.readline().strip()
	sub = rem(t, s)
	if sub is None:
		stdout.write('NO\n')
		continue
	cts = defaultdict(int)
	ans = True
	for c in p:
		cts[c] += 1
	for c in sub:
		cts[c] -= 1
		if cts[c] < 0:
			ans = False
	stdout.write(('YES' if ans else 'NO') + '\n')


from collections import Counter
for _ in range(int(input())):
	s = input()
	l = len(s)
	s += '#'
	t = input()
	r = len(t)
	ind = 0
	p = Counter(input())
	nes = True
	for j in range(r):
		if s[ind] != t[j]:
			if p[t[j]]:
				p[t[j]] -= 1
				l += 1
				if p[t[j]] == 0:
					del p[t[j]]
				if l > r:
					nes = False
					break
			else:
				nes = False
				break
		else:
			ind += ind + 1 < len(s)
	print('YES' if nes and l == r else 'NO')


import io, sys
input = lambda f=io.StringIO(sys.stdin.buffer.read().decode()).readline: f().rstrip()
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
out = []
for _ in range(ii()):
	(s, t, p) = (input() for _ in range(3))
	i = j = 0
	req = {c: 0 for c in ALPHA}
	ok = 1
	for i in range(len(s)):
		while j < len(t) and t[j] != s[i]:
			req[t[j]] += 1
			j += 1
		if j == len(t):
			ok = 0
			break
		j += 1
	while j < len(t):
		req[t[j]] += 1
		j += 1
	if ok:
		has = {c: 0 for c in ALPHA}
		for c in p:
			has[c] += 1
		ok = all((has[c] >= req[c] for c in ALPHA))
	out.append('YES' if ok else 'NO')
print(*out, sep='\n')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	q = input()
	i = 0
	f = True
	for c in s:
		while i < len(t) and t[i] != c:
			i += 1
		if i == len(t):
			f = False
			break
		i += 1
	if f:
		a = [0 for i in range(26)]
		b = [0 for i in range(26)]
		c = [0 for i in range(26)]
		f = True
		for c in s:
			a[ord(c) - ord('a')] += 1
		for c in q:
			b[ord(c) - ord('a')] += 1
		for c in t:
			if a[ord(c) - ord('a')] != 0:
				a[ord(c) - ord('a')] -= 1
			elif b[ord(c) - ord('a')] != 0:
				b[ord(c) - ord('a')] -= 1
			else:
				print('NO')
				f = False
				break
		if f:
			print('YES')
	else:
		print('NO')


q = int(input())
for i in range(0, q):
	s = input()
	t = input()
	p = input()
	if len(s) > len(t):
		print('NO')
		continue
	arr = [0] * 26
	for j in range(0, len(p)):
		arr[ord(p[j]) - 97] += 1
	x = len(t)
	k = 0
	m = 0
	flag = 0
	for j in range(0, x):
		if m < len(s) and k < len(t) and (t[k] == s[m]):
			k += 1
			m += 1
			continue
		elif arr[ord(t[k]) - 97] > 0:
			arr[ord(t[k]) - 97] -= 1
			k += 1
			continue
		else:
			flag = 1
			break
	if flag == 1 or m < len(s):
		print('NO')
	else:
		print('YES')


n = int(input())
i = 0
for i in range(n):
	s = input()
	t = input()
	p = input()
	ch = dict()
	for j in s:
		ch[j] = 0
	for j in p:
		ch[j] = 0
	for j in t:
		ch[j] = 0
	for j in s:
		ch[j] = ch[j] + 1
	for j in p:
		ch[j] = ch[j] + 1
	for j in t:
		ch[j] = ch[j] - 1
	ans = 1
	for j in ch:
		if ch[j] < 0:
			ans = 0
	p = 0
	p1 = 0
	while p < len(s):
		if p1 == len(t):
			ans = 0
			break
		while t[p1] != s[p]:
			if p1 == len(t) - 1:
				ans = 0
				break
			p1 = p1 + 1
		p1 = p1 + 1
		p = p + 1
	if ans == 1:
		print('YES')
	else:
		print('NO')


q = int(input())

def process():
	s = input()
	t = input()
	p = sorted(input())
	ti = 0
	missing = []
	for c in s:
		if ti >= len(t):
			return False
		while c != t[ti]:
			missing.append(t[ti])
			ti += 1
			if ti >= len(t):
				return False
		ti += 1
	pi = 0
	for c in sorted(missing + list(t[ti:])):
		if pi >= len(p):
			return False
		while c != p[pi]:
			pi += 1
			if pi >= len(p):
				return False
		pi += 1
	return True
for i in range(q):
	print('yes' if process() else 'no')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	p = input()
	mas1 = [0] * 26
	flag = True
	for i in range(len(s)):
		mas1[ord(s[i]) - 97] += 1
	mas2 = [0] * 26
	x1 = 0
	for i in range(len(t)):
		if x1 < len(s) and s[x1] == t[i]:
			x1 += 1
		mas2[ord(t[i]) - 97] += 1
	if x1 != len(s):
		print('NO')
	else:
		mas3 = [0] * 26
		for i in range(len(p)):
			mas3[ord(p[i]) - 97] += 1
		for i in range(26):
			if mas3[i] + mas1[i] < mas2[i]:
				flag = False
		if flag == True:
			print('YES')
		else:
			print('NO')


def sol(s, t, p):
	have = {}
	for ch in p:
		if not ch in have:
			have[ch] = 1
		else:
			have[ch] += 1
	j = 0
	for i in range(len(t)):
		if j < len(s) and t[i] == s[j]:
			j += 1
		elif t[i] in have and have[t[i]] > 0:
			have[t[i]] -= 1
		else:
			return False
	return j == len(s)
q = int(input())
for test in range(q):
	s = input()
	t = input()
	p = input()
	print('YES' if sol(s, t, p) else 'NO')


t = int(input())
for i in range(t):
	s = input()
	t = input()
	p = input()
	m = len(s)
	n = len(t)
	x = 'a'
	dic3 = {}
	for i in range(26):
		dic3[x] = 0
		x = chr(ord(x) + 1)
	for i in p:
		dic3[i] = dic3[i] + 1
	i = 0
	j = 0
	flag = 0
	while i < m and j < n:
		if s[i] == t[j]:
			i = i + 1
			j = j + 1
		elif dic3[t[j]] > 0:
			dic3[t[j]] = dic3[t[j]] - 1
			j = j + 1
		else:
			flag = 1
			break
	if i == m and j == n:
		print('YES')
	elif j == n and i < m:
		print('NO')
	elif flag == 1:
		print('NO')
	elif i == m and j < n:
		flag2 = 0
		for k in range(j, n):
			if dic3[t[k]] > 0:
				dic3[t[k]] = dic3[t[k]] - 1
			else:
				print('NO')
				flag2 = 1
				break
		if flag2 == 0:
			print('YES')


def solve(s, t, p):
	sa = []
	ta = []
	pa = []
	for i in s:
		sa += [i]
	for i in t:
		ta += [i]
	for i in p:
		pa += [i]
	if len(s) > len(t):
		return 'NO'
	lastindex = -1
	cnt = 0
	for i in sa:
		for j in range(len(ta)):
			if ta[j] == i and j > lastindex:
				cnt += 1
				lastindex = j
				ta[j] = -1
				break
	if cnt != len(sa):
		return 'NO'
	toadd = 0
	added = 0
	for i in ta:
		if i != -1:
			toadd += 1
			if i in pa:
				pa.remove(i)
				added += 1
	if toadd == added:
		return 'YES'
	return 'NO'
t = int(input())
for y in range(t):
	print(solve(input(), input(), input()))


T = int(input())

def is_subseq(x, y):
	it = iter(y)
	return all((any((c == ch for c in it)) for ch in x))
for i in range(T):
	s = input()
	t = input()
	p = input()
	possible = True
	cnt_s = {}
	cnt_t = {}
	for c in s:
		if c in cnt_s:
			cnt_s[c] += 1
		else:
			cnt_s[c] = 1
	for c in t:
		if c in cnt_t:
			cnt_t[c] += 1
		else:
			cnt_t[c] = 1
	for c in cnt_s:
		if c in cnt_t and cnt_s[c] <= cnt_t[c]:
			cnt_t[c] -= cnt_s[c]
			if cnt_t[c] == 0:
				del cnt_t[c]
		else:
			possible = False
			break
	if not possible:
		print('NO')
		continue
	cnt_p = {}
	for c in p:
		if c in cnt_p:
			cnt_p[c] += 1
		else:
			cnt_p[c] = 1
	for c in cnt_t:
		if c in cnt_p and cnt_t[c] <= cnt_p[c]:
			cnt_p[c] -= cnt_t[c]
		else:
			possible = False
			break
	if not possible:
		print('NO')
		continue
	if is_subseq(s, t):
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	s = [''] * 3
	freq = [[0] * 26 for i in range(3)]
	for i in range(3):
		s[i] = input()
		for x in s[i]:
			freq[i][ord(x) - ord('a')] += 1

	def check(m, n):
		if m == 0:
			return True
		if n == 0:
			return False
		if s[0][m - 1] == s[1][n - 1]:
			return check(m - 1, n - 1)
		return check(m, n - 1)
	flag = True
	for i in range(26):
		if freq[0][i] + freq[2][i] < freq[1][i]:
			flag = False
	if flag and check(len(s[0]), len(s[1])):
		print('YES')
	else:
		print('NO')


def f():
	s = input()
	t = input()
	p = input()
	if s == t:
		return True
	it = iter(t)
	if not all((c in it for c in s)):
		return False
	d = [0] * 256
	for c in s:
		d[ord(c)] += 1
	for c in p:
		d[ord(c)] += 1
	for c in t:
		d[ord(c)] -= 1
		if d[ord(c)] < 0:
			return False
	return True
for i in range(int(input())):
	print('yes' if f() else 'no')


from math import floor
quer = 0
quer = int(input())
for x in range(quer):
	s = []
	t = []
	p = []
	s = input()
	t = input()
	p = input()
	alpha = []
	indx = []
	nothappenin = 0
	for i in range(26):
		alpha.append(0)
		indx.append(0)
	for i in range(len(t)):
		alpha[ord(t[i]) - 97] += 1
		indx[ord(t[i]) - 97] = i
	for i in range(len(s)):
		alpha[ord(s[i]) - 97] -= 1
		if alpha[ord(s[i]) - 97] < 0 or i > indx[ord(s[i]) - 97]:
			nothappenin = 1
			print('NO')
			break
	if nothappenin:
		continue
	for i in range(len(p)):
		alpha[ord(p[i]) - 97] -= 1
	for i in range(26):
		if alpha[i] > 0:
			nothappenin = 1
			print('NO')
			break
	if nothappenin:
		continue
	ptr1 = 0
	ptr2 = 0
	while len(t) - ptr2 >= len(s) - ptr1 and ptr2 < len(t) and (ptr1 < len(s)):
		if s[ptr1] == t[ptr2]:
			ptr1 += 1
			ptr2 += 1
		else:
			ptr2 += 1
	if ptr1 != len(s):
		nothappenin = 1
		print('NO')
	if nothappenin == 0:
		print('YES')


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	dic1 = {}
	dic2 = {}
	for i in s:
		dic1.setdefault(i, 0)
		dic1[i] += 1
	for i in p:
		dic1.setdefault(i, 0)
		dic1[i] += 1
	for i in t:
		dic2.setdefault(i, 0)
		dic2[i] += 1
	for i in dic2:
		dic1.setdefault(i, 0)
		if dic1[i] < dic2[i]:
			print('NO')
			break
	else:
		j = 0
		flag = 0
		for i in s:
			while j < len(t):
				if t[j] == i:
					j += 1
					break
				j += 1
			else:
				flag = 1
		print(['YES', 'NO'][flag == 1])


t = int(input())
for i in range(t):
	s = input()
	t = input()
	p = input()
	(i, j) = (0, 0)
	cnt = 0
	while i < len(s):
		while j < len(t):
			if s[i] == t[j]:
				j -= -1
				cnt -= -1
				break
			j -= -1
		i -= -1
	if cnt == len(s):
		abc = 'qwertyuiopasdfghjklzxcvbnm'
		As = [0 for x in range(len(abc))]
		At = [0 for x in range(len(abc))]
		Ap = [0 for x in range(len(abc))]
		for i in range(len(s)):
			for j in range(len(abc)):
				if s[i] == abc[j]:
					As[j] -= -1
		for i in range(len(t)):
			for j in range(len(abc)):
				if t[i] == abc[j]:
					At[j] -= -1
		for i in range(len(p)):
			for j in range(len(abc)):
				if p[i] == abc[j]:
					Ap[j] -= -1
		for i in range(len(abc)):
			As[i] -= -Ap[i]
		ans = 'YES'
		for i in range(len(abc)):
			if As[i] < At[i]:
				ans = 'NO'
		print(ans)
	else:
		print('NO')


from collections import *
I = input
for _ in [0] * int(I()):
	s = (1, *I(), 0)
	(t, p) = (I(), Counter(I()))
	i = 1
	for c in t:
		if c == s[i]:
			i += 1
		elif p[c]:
			p[c] -= 1
		else:
			i = 0
	print('YNEOS'[s[i] != 0::2])


import math
from collections import defaultdict
import functools as f
from itertools import permutations as p
t = 1
t = int(input())
for _ in range(t):
	s = str(input())
	t = str(input())
	p = str(input())
	i = 0
	j = 0
	while True:
		if i == len(s) or j == len(t):
			break
		if t[j] == s[i]:
			i += 1
		j += 1
	if i == len(s):
		s += p
		an = True
		for i in range(len(t)):
			k = t.count(t[i])
			l = s.count(t[i])
			if l < k:
				print('No')
				an = False
				break
		if an == True:
			print('Yes')
	else:
		print('No')


def f2(s1, s2, s3):
	m1 = 26 * [0]
	m2 = 26 * [0]
	m3 = 26 * [0]
	for c in s1:
		m1[ord(c) - ord('a')] += 1
	for c in s2:
		m2[ord(c) - ord('a')] += 1
	for c in s3:
		m3[ord(c) - ord('a')] += 1
	for i in range(26):
		if m3[i] > m2[i] + m1[i]:
			return False
	return True

def f1(s1, s2):
	l1 = len(s1)
	l2 = len(s2)
	p1 = 0
	p2 = 0
	while p2 != l2 and p1 != l1:
		if s1[p1] == s2[p2]:
			p1 += 1
			p2 += 1
		else:
			p2 += 1
	if p1 == l1:
		return True
	return False
z = int(input())
for i in range(z):
	s1 = input()
	s2 = input()
	s3 = input()
	if f1(s1, s2) and f2(s1, s3, s2):
		print('YES')
	else:
		print('NO')


from collections import Counter
from collections import defaultdict
x = int(input())
for i in range(x):
	s = input()
	t = input()
	p = input()
	val = Counter(p)
	match = defaultdict(int)
	index = 0
	for j in range(len(t)):
		if index < len(s) and t[j] == s[index]:
			index += 1
		else:
			match[t[j]] += 1
	if index == len(s):
		flag = 0
		for k in match:
			if match[k] <= val[k]:
				continue
			else:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


w = int(input())
for i in range(w):
	s = input()
	t = input()
	p = input()
	y = 0
	r1 = []
	r2 = []
	for j in range(len(t)):
		if y < len(s) and s[y] == t[j]:
			y += 1
		else:
			r1.append(t[j])
	for j in range(len(p)):
		r2.append(p[j])
	if y < len(s):
		print('NO')
	else:
		r1.sort()
		r2.sort()
		o1 = 0
		o2 = 0
		ans = True
		while o1 < len(r1) and o2 < len(r2):
			if r1[o1] == r2[o2]:
				o1 += 1
				o2 += 1
			elif r1[o1] > r2[o2]:
				o2 += 1
			else:
				ans = False
				print('NO')
				break
		if ans and o1 == len(r1):
			print('YES')
		elif ans:
			print('NO')


for _ in range(int(input())):
	i = 0
	j = 0
	k = 0
	s = input()
	t = input()
	p = input()
	c = [0 for _ in range(26)]
	for v in p:
		c[ord(v) - ord('a')] += 1
	idex = 0
	ans = 1
	while idex < len(t):
		next = t[idex]
		if i < len(s) and s[i] == next:
			idex += 1
			i += 1
		elif c[ord(next) - ord('a')] > 0:
			c[ord(next) - ord('a')] -= 1
			idex += 1
		else:
			ans = 0
			break
	if ans:
		if i == len(s) and idex == len(t):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	j = 0
	for i in range(len(t)):
		if j == len(s):
			break
		if t[i] == s[j]:
			j += 1
	if j != len(s):
		print('NO')
	else:
		dic = {}
		dic_t = {}
		for i in range(len(s)):
			if s[i] not in dic:
				dic[s[i]] = 1
			else:
				dic[s[i]] += 1
		for i in range(len(p)):
			if p[i] not in dic:
				dic[p[i]] = 1
			else:
				dic[p[i]] += 1
		for i in range(len(t)):
			if t[i] not in dic_t:
				dic_t[t[i]] = 1
			else:
				dic_t[t[i]] += 1
		data = list(dic.keys())
		data_t = list(dic_t.keys())
		for i in range(len(data_t)):
			if data_t[i] not in data:
				print('NO')
				break
		else:
			for i in range(len(data)):
				if data[i] in dic_t:
					if dic_t[data[i]] > dic[data[i]]:
						print('NO')
						break
			else:
				print('YES')


from collections import Counter

def isSubseq(s, x):
	(i, j) = (0, 0)
	while True:
		if j == len(x):
			return True
		if i == len(s):
			return False
		if s[i] == x[j]:
			j += 1
		i += 1
for _ in range(int(input().strip())):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	if not isSubseq(t, s):
		print('NO')
		continue
	(cs, ct, cp) = (Counter(s), Counter(t), Counter(p))
	newc = {}
	for key in cs:
		newc[key] = cs[key]
	for key in cp:
		if key in newc.keys():
			newc[key] += cp[key]
		else:
			newc[key] = cp[key]
	wrong = False
	for key in ct:
		if key in newc.keys():
			if newc[key] < ct[key]:
				wrong = True
				break
		else:
			wrong = True
			break
	if wrong:
		print('NO')
	else:
		print('YES')


T = int(input())
for t in range(T):
	s = input()
	t = input()
	p = input()
	if len(t) <= len(s) and t != s:
		print('NO')
	else:
		temp_set = {}
		pointer = 0
		temp_t = ''
		Set_p = {}
		for i in p:
			if i in Set_p.keys():
				Set_p[i] += 1
			else:
				Set_p[i] = 1
		for i in range(len(t)):
			if pointer == len(s):
				break
			if t[i] == s[pointer]:
				pointer += 1
				temp_t += t[i]
		for i in range(len(t)):
			if t[i] in temp_set.keys():
				temp_set[t[i]] += 1
			else:
				temp_set[t[i]] = 1
		for i in temp_t:
			temp_set[i] -= 1
		yo = []
		for i in temp_set.keys():
			if temp_set[i] == 0:
				yo.append(i)
		for i in yo:
			del temp_set[i]
		for i in range(26):
			boi = chr(i + 97)
			if boi not in temp_set.keys():
				temp_set[boi] = 0
			if boi not in Set_p.keys():
				Set_p[boi] = 0
		if temp_t == s:
			q = True
			for i in temp_set.keys():
				if temp_set[i] > Set_p[i]:
					q = False
					break
			if q:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


from sys import stdin
q = int(stdin.readline())
for _ in range(q):
	s = stdin.readline().strip()
	t = stdin.readline().strip()
	p = stdin.readline().strip()
	char_counts = {}
	for c in p:
		char_counts[c] = char_counts.get(c, 0) + 1
	s_pos = 0
	t_pos = 0
	while t_pos < len(t):
		if s_pos < len(s) and s[s_pos] == t[t_pos]:
			s_pos += 1
			t_pos += 1
		elif char_counts.get(t[t_pos], 0) > 0:
			char_counts[t[t_pos]] -= 1
			t_pos += 1
		else:
			break
	if s_pos != len(s) or t_pos != len(t):
		print('NO')
	else:
		print('YES')


import sys
q = int(sys.stdin.readline().strip())
for Q in range(0, q):
	s = sys.stdin.readline().strip()
	t = sys.stdin.readline().strip()
	p = sys.stdin.readline().strip()
	i = 0
	j = 0
	alpha = [0] * 26
	while i != len(s) and j != len(t):
		if s[i] == t[j]:
			i = i + 1
			j = j + 1
		else:
			k = ord(t[j]) - ord('a')
			j = j + 1
			alpha[k] = alpha[k] + 1
	if i != len(s):
		print('NO')
	else:
		while j < len(t):
			k = ord(t[j]) - ord('a')
			j = j + 1
			alpha[k] = alpha[k] + 1
		j = 0
		while j < len(p):
			k = ord(p[j]) - ord('a')
			j = j + 1
			alpha[k] = alpha[k] - 1
		if max(alpha) > 0:
			print('NO')
		else:
			print('YES')


t = input()
n = int(t)
d = {}
qq = []
j = 0
q1 = ''
q2 = ''
q3 = ''

def f(a, b, c):
	nn = len(a)
	j = 0
	for i in b:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
		if j < nn and a[j] == i:
			d[i] -= 1
			j += 1
	if j != nn:
		return 'NO'
	for i in c:
		if i in d and d[i] > 0:
			d[i] -= 1
	if 0 == sum(d.values()):
		return 'YES'
	else:
		return 'NO'
for i in range(n * 3):
	if j == 0:
		q1 = input()
		j = 1
	elif j == 1:
		q2 = input()
		j = 2
	elif j == 2:
		q3 = input()
		j = 3
	else:
		j = 1
		qq.append(f(q1, q2, q3))
		q1 = input()
		d = {}
qq.append(f(q1, q2, q3))
for i in range(n):
	print(qq[i])


from math import *
from collections import *
import re
t = int(input())
for _ in range(t):
	s = list(input())
	t = list(input())
	p = list(input())
	if s == t:
		print('Yes')
		continue
	elif len(s) >= len(t):
		print('No')
		continue
	i = 0
	j = 0
	ct = 0
	missing = ''
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			ct += 1
			j += 1
			i += 1
		else:
			missing += t[j]
			j += 1
	while j < len(t):
		missing += t[j]
		j += 1
	if ct != len(s):
		print('No')
		continue
	done = True
	for i in missing:
		if i in p:
			p.remove(i)
		else:
			print('No')
			done = False
			break
	if done:
		print('Yes')


import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
	q = int(input())
	for _ in range(q):
		s = input()
		t = input()
		p = input()
		need = defaultdict(int)
		ps = pt = 0
		ok = True
		while ps < len(s) and pt < len(t):
			if s[ps] == t[pt]:
				ps += 1
				pt += 1
				continue
			while ps < len(s) and pt < len(t) and (s[ps] != t[pt]):
				need[t[pt]] += 1
				pt += 1
		if ps < len(s):
			ok = False
		if pt < len(t):
			while pt < len(t):
				need[t[pt]] += 1
				pt += 1
		if ok:
			for c in need:
				if need[c] > p.count(c):
					ok = False
					break
		print('YES' if ok else 'NO')
main()


q = int(input())
from collections import Counter
for _ in range(q):
	s = str(input())
	t = str(input())
	p = str(input())
	s = list(s)
	t = list(t)
	s.reverse()
	t.reverse()
	cp = Counter(p)
	flag = True
	while t:
		c = t.pop()
		if s:
			if s[-1] == c:
				s.pop()
			elif c in cp:
				if cp[c]:
					cp[c] -= 1
				else:
					flag = False
					break
			else:
				flag = False
				break
		elif c in cp:
			if cp[c]:
				cp[c] -= 1
			else:
				flag = False
				break
		else:
			flag = False
			break
	if flag:
		if not s:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	(s, t, p) = (input(), input(), input())
	c = {}
	for x in s:
		c[x] = c.get(x, 0) + 1
	for x in p:
		c[x] = c.get(x, 0) + 1
	for x in t:
		c[x] = c.get(x, 0) - 1
	if min(c.values()) < 0:
		print('NO')
	else:
		(i, j) = (0, 0)
		while i < len(s) and j < len(t):
			while j < len(t) and s[i] != t[j]:
				j += 1
			if j < len(t):
				j += 1
			else:
				print('NO')
				break
			i += 1
		else:
			print('NO' if i < len(s) else 'YES')


n_arr = 0
arr_a = []
arr_b = []
arr_c = []

def Input():
	global n_arr, arr_a, arr_b, arr_c
	n_arr = int(input())
	for index in range(n_arr):
		arr_a.append(input())
		arr_b.append(input())
		arr_c.append(input())

def Sub_string(a, b):
	count = 0
	if len(a) > len(b):
		return False
	else:
		next_index = 0
		for index in range(len(a)):
			for index_2 in range(next_index, len(b)):
				if a[index] == b[index_2]:
					count += 1
					next_index = index_2 + 1
					break
		return count == len(a)

def Compare(a, b, c):
	count_source = [0] * 256
	count_dest = [0] * 256
	for index in range(len(a)):
		count_source[ord(a[index])] += 1
	for index in range(len(c)):
		count_source[ord(c[index])] += 1
	for index in range(len(b)):
		count_dest[ord(b[index])] += 1
	for index in range(256):
		if count_dest[index] > count_source[index]:
			return False
	return True

def Processing():
	global n_arr, arr_a, arr_b, arr_c

def Output():
	global n_arr, arr_a, arr_b, arr_c
	for index in range(n_arr):
		if Sub_string(arr_a[index], arr_b[index]) and Compare(arr_a[index], arr_b[index], arr_c[index]):
			print('YES')
		else:
			print('NO')
Input()
Processing()
Output()


def subseq(a, b):
	n = len(a)
	m = len(b)
	i = 0
	j = 0
	c = 0
	while i < n and j < m:
		if a[i] == b[j]:
			i += 1
			j += 1
			c += 1
		else:
			j += 1
	return c == n
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	from collections import Counter
	c1 = Counter(s)
	c2 = Counter(t)
	c3 = Counter(p)
	f = 1
	if not subseq(s, t):
		f = 0
	l = [chr(i) for i in range(97, 123)]
	for x in l:
		if c1[x] > c2[x]:
			f = 0
			break
		req = c2[x] - c1[x]
		if c3[x] < req:
			f = 0
			break
	print('YES' if f else 'NO')


from sys import stdin, stdout
from collections import Counter

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

def r_str():
	return stdin.readline().rstrip()

def rsingle_char():
	return stdin.read(1)

def eq_tile(one, two):
	return one[0] == two[0] and one[1] == two[1]

def is_substring(one, main):
	(i, j) = (0, 0)
	one_len = len(one)
	while i < one_len and j < len(main):
		if one[i] == main[j]:
			i += 1
			j += 1
		else:
			j += 1
	return i == one_len

def main():
	q = rsingle_int()
	for i in range(q):
		s = r_str()
		t = r_str()
		p = r_str()
		if is_substring(s, t):
			s_letter_cnt = Counter(s)
			t_letter_cnt = Counter(t)
			p_letter_cnt = Counter(p)
			t_letter_cnt.subtract(s_letter_cnt)
			t_letter_cnt.subtract(p_letter_cnt)
			not_possible = False
			for key in t_letter_cnt.keys():
				if t_letter_cnt[key] > 0:
					not_possible = True
					break
			if not_possible:
				print('NO')
			else:
				print('YES')
		else:
			print('NO')
main()


tc = int(input())
while tc:
	tc -= 1
	s = input()
	t = input()
	p = input()
	cnt = [0] * 26
	for x in p:
		cnt[ord(x) - ord('a')] += 1
	val = True
	(i, j) = (0, 0)
	while j < len(t):
		if i == len(s) or s[i] != t[j]:
			if cnt[ord(t[j]) - ord('a')] <= 0:
				val = False
				break
			else:
				cnt[ord(t[j]) - ord('a')] -= 1
				j += 1
		else:
			(i, j) = (i + 1, j + 1)
	if not val or i != len(s):
		print('NO')
	else:
		print('YES')


import sys
import math
q = int(input())
for x in range(q):
	s = input()
	t = input()
	p = input()
	tc = [0] * 26
	pc = [0] * 26
	for i in range(len(p)):
		pc[ord(p[i]) - 97] += 1
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i == len(s):
		for y in range(len(t)):
			tc[ord(t[y]) - 97] += 1
		for y in range(len(s)):
			tc[ord(s[y]) - 97] -= 1
		flag = True
		for y in range(26):
			if pc[y] < tc[y]:
				flag = False
				print('NO')
				break
		if flag:
			print('YES')
	else:
		print('NO')


import math
import sys
import collections

def cdiv(n, k):
	return n // k + (n % k != 0)

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

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

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

def check(s, t):
	i = 0
	j = 0
	while i < len(s):
		while j < len(t):
			if t[j] != s[i]:
				j += 1
			else:
				break
		if j >= len(t) or t[j] != s[i]:
			return False
		else:
			i += 1
			j += 1
	return True
q = ii()
for i in range(q):
	s = input()
	t = input()
	p = input()
	ds = collections.Counter(s)
	dt = collections.Counter(t)
	dp = collections.Counter(p)
	f = True
	for i in dt:
		if dt[i] > ds[i] + dp[i]:
			f = False
			break
	print('YES') if check(s, t) and f else print('NO')


def f(s):
	c = {}
	for i in s:
		if c.setdefault(i) != None:
			c[i] += 1
		else:
			c[i] = 1
	return c
for _ in range(int(input())):
	(s, k, t) = (input(), input(), input())
	ind = 0
	inp = True
	for i in k:
		if s[ind] == i:
			ind += 1
		if ind == len(s):
			break
	if ind != len(s):
		inp = False
	else:
		s = f(s)
		k = f(k)
		t = f(t)
		for i in s:
			k[i] -= s[i]
		for i in k:
			if t.setdefault(i) != None:
				t[i] -= k[i]
				if t[i] < 0:
					inp = False
					break
			elif k[i] > 0:
				inp = False
				break
	print('YES' if inp else 'NO')


from collections import Counter
for _ in range(int(input())):
	s = (*input(), 0)
	(t, p) = (input(), Counter(input()))
	i = 0
	for c in t:
		if s[i] == c:
			i += 1
		elif p[c]:
			p[c] -= 1
		else:
			i = 0
			break
	print('YES' if s[i] == 0 else 'NO')


from collections import defaultdict, Counter
q = int(input())
for _ in range(q):
	(s, t, p) = (input(), input(), input())
	i = 0
	j = 0
	d = defaultdict(int)
	possible = True
	while i < len(s) and j < len(t):
		while j < len(t) and s[i] != t[j]:
			d[t[j]] += 1
			j += 1
		if j == len(t):
			possible = False
			break
		i += 1
		j += 1
	if j == len(t) and i < len(s):
		possible = False
	if not possible:
		print('NO')
		continue
	while j < len(t):
		d[t[j]] += 1
		j += 1
	counterp = Counter(p)
	for el in d:
		if d[el] > counterp[el]:
			possible = False
			break
	if not possible:
		print('NO')
		continue
	print('YES')


from collections import Counter
q = int(input())
for _ in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	for i in range(len(t)):
		if s and s[0] == t[i]:
			t[i] = 'O'
			s.pop(0)
	if s:
		print('NO')
		continue
	else:
		t_counter = Counter(t)
		p_counter = Counter(p)
	flag = 1
	for (key, value) in t_counter.items():
		if key == 'O':
			continue
		if key not in p_counter or t_counter[key] > p_counter[key]:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)
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 find_parent(parent, i, cnt):
	cnt += 1
	if parent[i - 1] == i:
		return cnt
	if parent[i - 1] != i:
		find_parent(parent, parent[i - 1], cnt)
from collections import Counter
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	p1 = Counter(p)
	s1 = Counter(s)
	t1 = Counter(t)
	var = t1 - s1
	if var & p1 == var:
		it = iter(t)
		if all((c in it for c in s)):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


class Read:

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def main():
	s = input()
	t = input()
	p = input()
	index_s = 0
	len_s = len(s)
	for i in t:
		if index_s < len_s and s[index_s] == i:
			index_s += 1
		else:
			res = p.find(i)
			if res > -1:
				p = p[:res] + p[res + 1:]
			else:
				print('NO')
				return
	if index_s == len_s:
		print('YES')
	else:
		print('NO')
q = Read.int()
for j in range(q):
	main()


k = range(int(input()))
out = []
for i in k:
	s = input()
	t = input()
	p = input()
	if s == t:
		out += ['YES']
	else:
		try:
			for char in set(t):
				if s.count(char) + p.count(char) < t.count(char):
					raise
			q = '' + t
			for c in s:
				if q:
					for (g, ch) in enumerate(q):
						if c == ch:
							q = q[g + 1:] if g != len(q) - 1 else ''
							break
						elif g == len(q) - 1:
							raise
				else:
					raise
			out += ['YES']
		except:
			out += ['NO']
for i in out:
	print(i)


from collections import Counter
n = int(input())
for k in range(0, n):
	s = input()
	t = input()
	p = input()
	p = Counter(p)
	f = 0
	i = j = 0
	while i < len(s) and j < len(t):
		if s[i] != t[j]:
			if p[t[j]] > 0:
				p[t[j]] -= 1
				j += 1
			else:
				f = 1
				print('NO')
				break
		else:
			i += 1
			j += 1
	if f == 0:
		if j < len(t):
			o = 0
			for x in range(j, len(t)):
				if p[t[x]] > 0:
					p[t[x]] -= 1
				else:
					o = 1
					print('NO')
					break
			if o == 0:
				print('YES')
		elif i < len(s):
			print('NO')
		else:
			print('YES')


t = int(input())
for you in range(t):
	a = input()
	b = input()
	c = input()
	freqa = [0 for i in range(26)]
	freqb = [0 for i in range(26)]
	freqc = [0 for i in range(26)]
	for i in a:
		freqa[ord(i) - ord('a')] += 1
	for i in b:
		freqb[ord(i) - ord('a')] += 1
	for i in c:
		freqc[ord(i) - ord('a')] += 1
	poss = 1
	for i in range(26):
		if freqa[i] + freqc[i] < freqb[i]:
			poss = 0
			break
	if poss == 0:
		print('NO')
		continue
	n = len(a)
	currx = 0
	poss = 1
	for i in range(n):
		while currx < len(b) and a[i] != b[currx]:
			currx += 1
		if currx == len(b):
			poss = 0
			break
		currx += 1
	if poss:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	s1 = []
	t1 = []
	p1 = []
	for i in s:
		s1.append(i)
	for i in t:
		t1.append(i)
	for i in p:
		p1.append(i)
	s1.append('0')
	i = f = j = 0
	while i < len(t1) and s1[j] != '0':
		if s1[j] != t1[i]:
			if t1[i] in p1:
				x = p1.index(t1[i])
				p1[x] = '0'
				s1.append(t1[i])
			else:
				f = 1
				break
		else:
			j += 1
		i += 1
	if f == 1:
		print('NO')
	elif i == len(t1) and s1[j] == '0':
		print('YES')
	elif i == len(t1) and s1[j] != '0':
		print('NO')
	else:
		while i < len(t1):
			if t1[i] in p1:
				x = p1.index(t1[i])
				p1[x] = '0'
				s1.append(t1[i])
			else:
				f = 1
				break
			i += 1
		if f == 1:
			print('NO')
		else:
			print('YES')


q = int(input())

def in_str(a, b):
	if len(a) == 0:
		return True
	else:
		for i in range(len(a)):
			for k in range(len(b)):
				if a[i] == b[k]:
					a_p = a[:i] + a[i + 1:]
					b_p = b[:k] + b[k + 1:]
					return in_str(a_p, b_p)
		return False

def sub_str(a, b):
	if len(a) == 0:
		return True
	else:
		for k in range(len(b)):
			if a[0] == b[k]:
				a_p = a[1:]
				b_p = b[k + 1:]
				return sub_str(a_p, b_p)
		return False
for i in range(q):
	s = input()
	t = input()
	p = input()
	if not sub_str(s, t):
		print('NO')
	else:
		for k in range(len(s)):
			tar = s[k]
			for m in range(len(t)):
				if t[m] == tar:
					t = t[:m] + t[m + 1:]
					break
		if not in_str(t, p):
			print('NO')
		else:
			print('YES')


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b):
	return abs(a[0] - b[0]) + abs(b[1] - a[1])

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def eld(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

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

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	s = [i for i in input()]
	t = [i for i in input()]
	p = [i for i in input()]
	if len(s) > len(t):
		print('no')
	elif len(s) == len(t) and s != t:
		print('no')
	else:
		for j in range(len(t)):
			if j < len(s) and t[j] == s[j]:
				continue
			elif t[j] in p:
				p.remove(t[j])
				s.insert(j, t[j])
		if s == t:
			print('yes')
		else:
			print('no')


from collections import *
for _ in [0] * int(input()):
	(s, t, p) = (input(), input(), Counter(input()))
	i = 0
	for c in t:
		if i < len(s) and c == s[i]:
			i += 1
		else:
			p[c] -= 1
	print('YNEOS'[i < len(s) or any((p[c] < 0 for c in t))::2])


from sys import stdin
c = int(stdin.readline().strip())
for cas in range(c):
	s = list(stdin.readline().strip())
	t = list(stdin.readline().strip())
	p = list(stdin.readline().strip())
	rem = 0
	flag = False
	x = s[0]
	y = 0
	for i in range(len(t)):
		if x == t[i]:
			y += 1
			if y == len(s):
				flag = True
				break
			x = s[y]
	for i in range(len(s)):
		if s[i] in t:
			t.remove(s[i])
			rem += 1
	for i in range(len(p)):
		if p[i] in t:
			t.remove(p[i])
	if len(t) == 0 and rem == len(s) and flag:
		print('YES')
	else:
		print('NO')


n = int(input())
for j in range(n):
	s = str(input())
	t = str(input())
	p = str(input())
	s += '1' * len(t)
	check = 1
	for i in range(0, len(t)):
		if len(s) - len(t) == len(t):
			break
		elif len(s) - len(t) > len(t):
			check = 0
			break
		if s[i] == t[i]:
			continue
		elif t[i] in p:
			p = p.replace(t[i], '', 1)
			s = s[0:i] + t[i] + s[i:]
		else:
			check = 0
			break
	print('YES' if t == s[:len(t)] and check == 1 else 'NO')


def solve(s, t, p):
	s_letters = {}
	t_letters = {}
	for i in s:
		if i not in s_letters.keys():
			s_letters[i] = 1
		else:
			s_letters[i] += 1
	for i in t:
		if i not in t_letters.keys():
			t_letters[i] = 1
		else:
			t_letters[i] += 1
	for i in s_letters.keys():
		if i not in t_letters.keys():
			print('NO')
			return
		if s_letters[i] > t_letters[i]:
			print('NO')
			return
	p_letters = {}
	for i in p:
		if i not in p_letters.keys():
			p_letters[i] = 1
		else:
			p_letters[i] += 1
	i = j = 0
	while True:
		if i < len(s) and j < len(t) and (s[i] == t[j]):
			i += 1
			j += 1
		else:
			if j == len(t):
				break
			if t[j] not in p_letters.keys():
				print('NO')
				return
			if p_letters[t[j]] == 0:
				print('NO')
				return
			p_letters[t[j]] -= 1
			j += 1
	if i != len(s):
		print('NO')
		return
	print('YES')

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


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	res = 1
	for ch in t:
		if len(s) != 0 and ch == s[0]:
			s.pop(0)
		elif ch in p:
			p.remove(ch)
		else:
			res = 0
			break
	print('yEs') if res == 1 and len(s) == 0 else print('nO')


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	if s == t:
		print('YES')
		continue
	if len(s) >= len(t):
		print('NO')
		continue
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i >= len(s):
		flag = True
		dps = [0] * 26
		dpt = [0] * 26
		dpp = [0] * 26
		for i in s:
			dps[ord(i) - 97] += 1
		for i in t:
			dpt[ord(i) - 97] += 1
		for i in p:
			dpp[ord(i) - 97] += 1
		for i in range(26):
			if dpt[i] > dpp[i] + dps[i]:
				flag = False
				break
		if flag:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from sys import stdin
input = stdin.readline
T = int(input())
for _ in range(1, T + 1):
	s = input()
	t = input()
	p = input()
	count_x = dict()
	count_y = dict()
	idx = 0
	for i in range(len(s) - 1):
		yes = True
		while idx < len(t) and s[i] != t[idx]:
			idx += 1
		if idx == len(t) or s[i] != t[idx]:
			yes = False
			break
		idx += 1
	if len(s) > len(t):
		yes = False
	if yes == False:
		print('NO')
		continue
	for i in range(len(s) - 1):
		if s[i] not in count_x.keys():
			count_x[s[i]] = 1
		else:
			count_x[s[i]] += 1
	for i in range(len(t) - 1):
		if t[i] not in count_y.keys():
			count_y[t[i]] = 1
		else:
			count_y[t[i]] += 1
	for i in count_x.keys():
		if i not in count_y.keys():
			yes = False
			break
		elif count_y[i] < count_x[i]:
			yes = False
			break
	if yes == False:
		print('NO')
		continue
	for i in range(len(p) - 1):
		if p[i] not in count_x.keys():
			count_x[p[i]] = 1
		else:
			count_x[p[i]] += 1
	for i in count_y.keys():
		if i not in count_x.keys():
			yes = False
			break
		elif count_x[i] < count_y[i]:
			yes = False
			break
	print('YES' if yes else 'NO')


for _ in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	i = 0
	l = len(t)
	while i < l:
		if i < len(s) and s[i] == t[i]:
			pass
		elif t[i] in p:
			p.remove(t[i])
			s.insert(i, t[i])
		else:
			break
		i += 1
	s = ''.join(s)
	t = ''.join(t)
	if s == t:
		print('YES')
	else:
		print('NO')


from sys import stdin
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')
for _ in range(I()):
	(s, t, p) = (list(S()), list(S()), list(S()))
	flg = 1
	for i in t:
		if s and i == s[0]:
			del s[0]
		elif i in p:
			p.remove(i)
		else:
			flg = 0
			break
	if flg and (not s):
		print('YES')
	else:
		print('NO')


for u in range(int(input())):
	s = list(input())
	t = list(input())
	p = list(input())
	f = 0
	for i in t:
		if len(s) != 0 and s[0] == i:
			s.pop(0)
		elif i in p:
			p.remove(i)
		else:
			f = 1
			break
	if f == 0 and len(s) == 0:
		print('YES')
	else:
		print('NO')


def subseq(s, t):
	m = len(s)
	n = len(t)
	j = 0
	i = 0
	while j < m and i < n:
		if s[j] == t[i]:
			j += 1
		i += 1
	return j == m
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	if not subseq(s, t):
		print('NO')
		continue
	s = s + p
	s = list(s)
	t = list(t)
	flag = True
	for i in range(len(t)):
		if t[i] not in s or s.count(t[i]) < t.count(t[i]):
			flag = False
	if not flag:
		print('NO')
	else:
		print('YES')


test = int(input())
while test:
	test -= 1
	s = list(input())
	t = list(input())
	q = set(t)
	p = list(input())
	k = 0
	for i in q:
		l1 = s.count(i)
		l2 = t.count(i)
		l3 = p.count(i)
		if l1 + l3 < l2:
			k = 1
	i = 0
	j = 0
	m = len(s)
	n = len(t)
	while j < m and i < n:
		if s[j] == t[i]:
			j = j + 1
		i = i + 1
	if j != m or k == 1:
		print('NO')
	else:
		print('YES')


from collections import Counter
T = int(input())
for _ in range(T):
	s = input()
	t = input()
	p = Counter(input())
	c = 0
	for v in t:
		if c < len(s) and s[c] == v:
			c += 1
		elif p[v] > 0:
			p[v] -= 1
		else:
			print('NO')
			break
	else:
		print('NO' if c < len(s) else 'YES')


from collections import Counter

def go():
	s = input()
	t = input()
	p = input()
	n = len(s)
	m = len(t)
	i = 0
	j = 0
	while i < n:
		while j < m and s[i] != t[j]:
			j += 1
		if j == m:
			return 'NO'
		i += 1
		j += 1
	if i != n:
		return 'NO'
	c1 = Counter(t)
	c2 = Counter(s + p)
	for key in c1:
		if key not in c2 or c1[key] > c2[key]:
			return 'NO'
	return 'YES'
o = ''
q = int(input())
for _ in range(q):
	o += f'{go()}\n'
print(o)


from collections import Counter
for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	cp = dict(Counter(p))
	i = 0
	j = 0
	lt = len(t)
	arr = [0] * lt
	ls = len(s)
	while i < ls and j < lt:
		if s[i] == t[j]:
			arr[j] = t[j]
			i += 1
			j += 1
		else:
			j += 1
	if i != ls:
		print('NO')
	else:
		flag = 0
		for i in range(lt):
			if arr[i] == 0:
				try:
					cp[t[i]] -= 1
					if cp[t[i]] < 0:
						flag = 1
						break
					arr[i] = t[i]
				except:
					flag = 1
					break
		print('YES' if flag == 0 else 'NO')


def comp(a, b):
	i = 0
	k = len(a)
	while i < k:
		if a.count(a[i]) > b.count(a[i]):
			return 0
		i += 1
	return 1

def fff():
	x = 0
	s = input()
	t = input()
	p = list(input())
	i = 0
	l = 0
	try:
		while i < len(s):
			k = t.find(s[i], l)
			l = k
			if k == -1:
				print('NO')
				return 0
			t = list(t)
			del t[k]
			t = ''.join(t)
			i += 1
	except:
		print('NO')
		return 0
	t = list(t)
	t.sort()
	t = ''.join(t)
	p.sort()
	p = ''.join(p)
	if comp(t, p):
		print('YES')
	else:
		print('NO')
	return 0
o = int(input())
u = 0
while u < o:
	fff()
	u += 1


from collections import Counter
q = int(input())
for i in range(q):
	(s, t, p) = (input(), input(), input())
	l = len(t)
	c = Counter(p)
	ptr = 0
	for (idx, char) in enumerate(t):
		if ptr == len(s) and c[char] > 0:
			c[char] -= 1
			continue
		elif ptr == len(s) and c[char] == 0:
			break
		if char == s[ptr]:
			ptr += 1
		elif c[char] > 0:
			c[char] -= 1
		else:
			break
	else:
		print('yes' if ptr == len(s) else 'no')
		continue
	print('no')


import sys
from collections import Counter
Q = int(input())

def check(a, b):
	a = a[::-1]
	b = b[::-1]
	for i in b[::-1]:
		if a and i == a[-1]:
			a.pop()
	if a:
		return False
	else:
		return True
for _ in range(Q):
	s = [ord(s) for s in sys.stdin.readline().strip()]
	t = [ord(s) for s in sys.stdin.readline().strip()]
	p = [ord(s) for s in sys.stdin.readline().strip()]
	if not check(s, t):
		sys.stdout.write('NO\n')
	else:
		Cs = Counter(s)
		Ct = Counter(t)
		Cp = Counter(p)
		if all((Ct[k] - Cs[k] <= Cp[k] for k in Ct.keys())):
			sys.stdout.write('YES\n')
		else:
			sys.stdout.write('NO\n')


Q = int(input())

def is_subsq(s, t):
	i = j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i == len(s):
		return True
	return False

def solve(s, t, p):
	_s = [0 for i in range(27)]
	_t = [0 for i in range(27)]
	_p = [0 for i in range(27)]
	if not is_subsq(s, t):
		return 'NO'
	for i in range(len(s)):
		_s[ord(s[i]) - 97] += 1
	for i in range(len(t)):
		_t[ord(t[i]) - 97] += 1
	for i in range(len(p)):
		_p[ord(p[i]) - 97] += 1
	for i in range(26):
		if _s[i] + _p[i] < _t[i]:
			return 'NO'
	return 'YES'
for _ in range(Q):
	s = input()
	t = input()
	p = input()
	print(solve(s, t, p))


from collections import defaultdict as dc

def eauql(s, p, t, ns, nt, np, ds, dt, dp):
	for i in range(max(ns, np, nt)):
		if i < ns:
			if dt[s[i]] == 0:
				return 0
		if i < nt:
			if dp[t[i]] == 0 and ds[t[i]] == 0 or dt[t[i]] > dp[t[i]] + ds[t[i]]:
				return 0
	i = 0
	j = 0
	while i < ns and j < nt:
		if s[i] == t[j]:
			i += 1
		j += 1
	if i != ns:
		return 0
	return 1
import sys
import math

def inp():
	p = sys.stdin.readline()
	return p
for _ in range(int(inp())):
	s = str(inp())
	t = str(inp())
	p = str(inp())
	ns = len(s) - 1
	np = len(p) - 1
	nt = len(t) - 1
	ds = dc(int)
	dp = dc(int)
	dt = dc(int)
	for i in range(max(ns, np, nt)):
		if i < ns:
			ds[s[i]] += 1
		if i < np:
			dp[p[i]] += 1
		if i < nt:
			dt[t[i]] += 1
	if eauql(s, p, t, ns, nt, np, ds, dt, dp):
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	i1 = i2 = 0
	while i1 < len(s) and i2 < len(t):
		if s[i1] == t[i2]:
			i1 += 1
		i2 += 1
	if i1 < len(s):
		print('NO')
	else:
		sCnt = Counter(s)
		tCnt = Counter(t)
		pCnt = Counter(p)
		ans = 'YES'
		for key in tCnt:
			if tCnt[key] > sCnt[key] + pCnt[key]:
				ans = 'NO'
				break
		print(ans)


import sys
from collections import Counter
import itertools
from math import floor, ceil

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

def dinput():
	return int(input())

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

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

def rt(x1, x2, y3):
	print(0.5 * (x2 + x1) * y3)

def main():
	s = input()
	t = input()
	p = input()
	z = {}
	for i in t:
		if i in z:
			z[i] += 1
		else:
			z[i] = 1
	for i in s:
		if i in z:
			if z[i] != 0:
				z[i] -= 1
	for i in p:
		if i in z:
			if z[i] != 0:
				z[i] -= 1
	for i in z:
		if z[i] > 0:
			print('NO')
			return 0
	i = 0
	o = 0
	while i < len(s) and o < len(t):
		if s[i] == t[o]:
			i += 1
			o += 1
		else:
			o += 1
	if i < len(s):
		print('NO')
		return 0
	print('YES')
for i in range(int(input())):
	main()


def solve():
	s = str(input())
	t = str(input())
	p = str(input())
	X = {}
	for each in p:
		if each in X:
			X[each] += 1
		else:
			X[each] = 1
	(n, m) = (len(s), len(t))
	(i, j) = (0, 0)
	while j < len(t):
		if i < len(s) and s[i] == t[j]:
			(i, j) = (i + 1, j + 1)
			continue
		need = t[j]
		if need in X and X[need] > 0:
			if i > 0:
				s = s[:i] + need + s[i:]
			else:
				s = need + s[i:]
			X[need] -= 1
		else:
			return 'NO'
	return 'YES' if s == t else 'NO'
for _ in range(int(input())):
	print(solve())


q = int(input())
B = []
for k in range(q):
	s = input()
	t = input()
	p = input()
	vs = 0
	ost = ''
	e = False
	vt = 0
	while vt < len(t) and vs < len(s):
		if t == s:
			e = True
			break
		if s[vs] == t[vt]:
			vs += 1
			vt += 1
		else:
			ost += t[vt]
			t = t[:vt] + t[vt + 1:]
		if vs == len(s):
			e = True
			ost += t[vs:]
	P = [0] * 26
	OST = [0] * 26
	for i in range(len(p)):
		P[ord(p[i]) - 97] += 1
	for i in range(len(ost)):
		OST[ord(ost[i]) - 97] += 1
	for i in range(26):
		if OST[i] > P[i]:
			e = False
	if e:
		B.append('YES')
	else:
		B.append('NO')
for i in range(q):
	print(B[i])


n = int(input())
for _ in range(n):
	s = input()
	t = input()
	p = input()
	ans = True
	l = [0 for _ in range(26)]
	for x in p:
		l[ord(x) - 97] += 1
	n = len(s)
	m = len(t)
	i = 0
	j = 0
	while j < m:
		y = t[j]
		if i >= n:
			if l[ord(y) - 97] > 0:
				l[ord(y) - 97] -= 1
				j += 1
			else:
				ans = False
				break
		else:
			x = s[i]
			if x == y:
				i += 1
				j += 1
			elif l[ord(y) - 97] > 0:
				l[ord(y) - 97] -= 1
				j += 1
			else:
				ans = False
				break
	if ans and i == n:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	i = 0
	n = len(s)
	j = 0
	m = len(t)
	while i < n and j < m:
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i != n:
		print('NO')
		continue
	freq = [0] * 26
	for i in s:
		freq[ord(i) - 97] += 1
	for i in p:
		freq[ord(i) - 97] += 1
	flag = True
	tarfreq = [0] * 26
	for i in t:
		tarfreq[ord(i) - 97] += 1
	for i in range(26):
		if freq[i] < tarfreq[i]:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


q = int(input())
res_list = []
for i in range(q):
	s = input()
	t = input()
	p = input()
	letter_bank = [0 for j in range(26)]
	for c in p:
		letter_bank[ord(c) - 97] += 1
	tind = 0
	letter_need = [0 for j in range(26)]
	exit_no = False
	for j in range(len(s)):
		match_pos = t[tind:].find(s[j])
		if match_pos < 0:
			exit_no = True
			break
		else:
			for k in range(tind, tind + match_pos):
				letter_need[ord(t[k]) - 97] += 1
			tind += match_pos + 1
	if exit_no:
		res_list.append('NO')
	else:
		for k in range(tind, len(t)):
			letter_need[ord(t[k]) - 97] += 1
		letters_ok = True
		for j in range(26):
			if letter_need[j] > letter_bank[j]:
				letters_ok = False
				break
		if letters_ok:
			res_list.append('YES')
		else:
			res_list.append('NO')
for res in res_list:
	print(res)


def main():
	s = str(input())
	t = str(input())
	p = str(input())
	arr = []
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		elif s[i] != t[j]:
			arr.append(t[j])
			j += 1
	if j >= len(t) and i < len(s):
		print('NO')
		return
	while j < len(t):
		arr.append(t[j])
		j += 1
	arr.sort()
	p = list(p)
	p.sort()
	i = 0
	j = 0
	while i < len(arr) and j < len(p):
		if arr[i] == p[j]:
			i += 1
			j += 1
		elif arr[i] != p[j]:
			j += 1
	if i == len(arr):
		print('YES')
	else:
		print('NO')
	return

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


q = int(input())
for w in range(q):
	s = input()
	t = input()
	p = input()
	A = []
	j = 0
	ans = 'YES'
	for i in range(len(s)):
		while j < len(t):
			if s[i] == t[j]:
				j += 1
				break
			else:
				A.append(t[j])
				j += 1
		else:
			ans = 'NO'
			break
	else:
		A.extend(list(t[j:]))
		P = list(p)
		for i in A:
			if i in P:
				P.remove(i)
			else:
				ans = 'NO'
				break
	print(ans)


def count_letters(s):
	res = dict()
	for c in s:
		if c in res:
			res[c] += 1
		else:
			res[c] = 1
	return res

def is_subsequence(s1, s2):
	if len(s1) == 0:
		return True
	if len(s2) == 0:
		return False
	if s1[-1] == s2[-1]:
		return is_subsequence(s1[:-1], s2[:-1])
	return is_subsequence(s1, s2[:-1])
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	s_counts = count_letters(s)
	t_counts = count_letters(t)
	p_counts = count_letters(p)
	possible = True
	for x in t_counts:
		counts = 0
		if x in s_counts:
			counts += s_counts[x]
		if x in p_counts:
			counts += p_counts[x]
		if counts < t_counts[x]:
			possible = False
	if possible and is_subsequence(s, t):
		print('YES')
	else:
		print('NO')


q = int(input())
while q > 0:
	q -= 1
	s = input()
	t = input()
	p = input()
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
		j += 1
	if i == len(s):
		count1 = [0 for i in range(26)]
		for i in s:
			count1[ord(i) - 97] += 1
		for i in p:
			count1[ord(i) - 97] += 1
		for i in t:
			count1[ord(i) - 97] -= 1
		flag = True
		for i in range(26):
			if count1[i] < 0:
				flag = False
				break
		if flag:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from collections import Counter
t = int(input())
for _ in range(t):
	s = list(input().strip())
	t = list(input().strip())
	p = list(input().strip())
	f = True
	for i in range(len(t)):
		try:
			if s[i] == t[i]:
				continue
			else:
				raise Exception
		except:
			try:
				p.remove(t[i])
				s.insert(i, t[i])
				continue
			except:
				f = False
				break
	if s == t:
		print('YES')
	else:
		print('NO')


def str_in_str(s1, s2):
	beg = 0
	for c in s1:
		beg = s2.find(c, beg) + 1
		if not beg:
			return False
	return True

def get_ans(s, t, p):
	if len(t) > len(p) + len(s):
		return 'NO'
	set_s = set(s)
	set_t = set(t)
	set_p = set(p)
	set_ps = set_p | set_s
	if not set_t.issubset(set_ps):
		return 'NO'
	if not str_in_str(s, t):
		return 'NO'
	ps = p + s
	for c in set_t:
		if t.count(c) > ps.count(c):
			return 'NO'
	return 'YES'
q = int(input())
anss = [''] * q
for ansi in range(q):
	s = input()
	t = input()
	p = input()
	anss[ansi] = get_ans(s, t, p)
for ans in anss:
	print(ans)


q = int(input())
for _ in range(q):
	s = input()
	t = input()
	p = input()
	pl = {}
	for x in p:
		if not pl.get(x):
			pl[x] = 1
		else:
			pl[x] += 1
	i = 0
	j = 0
	flag = True
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			while j < len(t) and s[i] != t[j]:
				if pl.get(t[j]) and pl[t[j]] > 0:
					pl[t[j]] -= 1
				else:
					flag = False
					break
				j += 1
		if not flag:
			break
	if i != len(s):
		flag = False
	else:
		while j < len(t):
			if pl.get(t[j]) and pl[t[j]] > 0:
				pl[t[j]] -= 1
			else:
				flag = False
				break
			j += 1
	if flag:
		print('YES')
	else:
		print('NO')


import sys, string
tc = int(sys.stdin.readline())
for _ in range(tc):
	s = list(sys.stdin.readline().rstrip())
	t = list(sys.stdin.readline().rstrip())
	p = list(sys.stdin.readline().rstrip())
	now = dict().fromkeys(string.ascii_lowercase, 0)
	need = dict().fromkeys(string.ascii_lowercase, 0)
	avail = dict().fromkeys(string.ascii_lowercase, 0)
	for i in s:
		now[i] += 1
	for i in t:
		need[i] += 1
	for i in p:
		avail[i] += 1
	can = True
	for i in string.ascii_lowercase:
		if now[i] < need[i]:
			if avail[i] < need[i] - now[i]:
				can = False
				break
		elif now[i] > need[i]:
			can = False
			break
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i < len(s):
		can = False
	print('YES' if can else 'NO')


import sys
n = int(input())
for ni in range(n):
	s = input()
	t = input()
	p = input()
	if len(s) <= len(t):
		(si, ti) = (0, 0)
		while si < len(s) and ti < len(t):
			if s[si] == t[ti]:
				si += 1
			ti += 1
		if si >= len(s):
			d = {}
			for c in t:
				d[c] = d.get(c, 0) + 1
			for c in s:
				d[c] -= 1
			for c in p:
				if c in d:
					d[c] -= 1
			ok = True
			for k in d:
				if d[k] > 0:
					ok = False
					break
			print('YES' if ok else 'NO')
		else:
			print('NO')
	else:
		print('YES' if s == t else 'NO')


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	i = 0
	j = 0
	count = 0
	f = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			count += 1
			i += 1
			j += 1
		else:
			j += 1
	if count == len(s):
		f = 1
		dicks = {}
	if not f:
		print('No')
		continue
	for i in t:
		dicks[i] = dicks.get(i, 0) + 1
	for i in s:
		dicks[i] -= 1
	for i in p:
		if dicks.get(i, -1) > 0:
			dicks[i] -= 1
	if sum(dicks.values()) == 0:
		print('Yes')
	else:
		print('No')


def solve():
	s = input()
	t = input()
	p = list(input())
	if len(s) > len(t):
		return print('NO')
	j = 0
	for c in s:
		while j < len(t) and c != t[j]:
			if t[j] in p:
				p.pop(p.index(t[j]))
			else:
				return print('NO')
			j += 1
		j += 1
	while j < len(t):
		if t[j] in p:
			p.pop(p.index(t[j]))
		else:
			return print('NO')
		j += 1
	if j != len(t):
		return print('NO')
	print('YES')
for _ in range(int(input())):
	solve()


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

def ans(s, t, p):
	ans = 'YES'
	posS = 0
	posT = 0
	while posS < len(s) and posT < len(t):
		if s[posS] == t[posT]:
			posS += 1
		posT += 1
	allS = {}
	for ch in s:
		try:
			allS[ch] += 1
		except:
			allS[ch] = 1
	allT = {}
	for ch in t:
		try:
			allT[ch] += 1
		except:
			allT[ch] = 1
	allP = {}
	for ch in p:
		try:
			allP[ch] += 1
		except:
			allP[ch] = 1
	if posS < len(s):
		ans = 'NO'
	else:
		for need in allT:
			need_count = allT[need]
			accepted = 0
			try:
				accepted += allS[need]
			except:
				False
			try:
				accepted += allP[need]
			except:
				False
			if accepted < need_count:
				ans = 'NO'
				break
	return ans
for user_inp in range(t):
	s = sys.stdin.readline().strip()
	t = sys.stdin.readline().strip()
	p = sys.stdin.readline().strip()
	print(ans(s, t, p))


Q = int(input())
while Q > 0:
	s = input()
	t = input()
	p = input()
	freq = [0 for i in range(26)]
	pos1 = 0
	pos2 = 0
	ln1 = len(s)
	ln2 = len(t)
	ln3 = len(p)
	flag = True
	while pos1 < ln1 and pos2 < ln2:
		if s[pos1] == t[pos2]:
			pos1 += 1
		pos2 += 1
	if pos1 < ln1:
		print('NO')
		Q -= 1
		continue
	for i in range(ln2):
		freq[ord(t[i]) - 97] += 1
	for i in range(ln1):
		if freq[ord(s[i]) - 97] > 0:
			freq[ord(s[i]) - 97] -= 1
		else:
			flag = False
			break
	if flag == False:
		print('NO')
		Q -= 1
		continue
	for i in range(ln3):
		if freq[ord(p[i]) - 97] > 0:
			freq[ord(p[i]) - 97] -= 1
	for i in range(26):
		if freq[i] > 0:
			flag = False
			break
	if flag == False:
		print('NO')
	else:
		print('YES')
	Q -= 1


for _ in range(int(input())):
	(s, t, p) = (input(), input(), input())
	(n, m) = (len(s), len(t))
	if m < n:
		print('NO')
		continue
	d = {}
	for (i, x) in enumerate(p):
		if d.get(x) == None:
			d[x] = 0
		d[x] += 1
	(i, j, result) = (0, 0, 'YES')
	while j < m:
		if i >= n:
			x = ''
		else:
			x = s[i]
		y = t[j]
		if x == y:
			i += 1
			j += 1
		elif d.get(y) != None:
			if d[y] > 0:
				j += 1
				d[y] -= 1
			else:
				result = 'NO'
				break
		else:
			result = 'NO'
			break
	if result == 'NO':
		print('NO')
	elif i != n:
		print('NO')
	else:
		print('YES')


from fractions import gcd
import math

def inverse(a):
	return pow(a, mod - 2, mod)

def usearch(x, a):
	lft = 0
	rgt = len(a) + 1
	while rgt - lft > 1:
		mid = (rgt + lft) // 2
		if a[mid] <= x:
			lft = mid
		else:
			rgt = mid
	return lft

def solve(a, b, c):
	tmp = {}
	for i in c:
		tmp[i] = tmp.get(i, 0) + 1
	c = tmp
	ai = 0
	bi = 0
	while bi < len(b):
		if ai >= len(a) or a[ai] != b[bi]:
			if b[bi] not in c or c[b[bi]] <= 0:
				print('NO')
				return
			c[b[bi]] -= 1
			bi += 1
		else:
			ai += 1
			bi += 1
	if ai != len(a) or bi != len(b):
		print('NO')
		return
	print('YES')

def main():
	q = int(input())
	for i in range(q):
		solve(input(), input(), input())
main()


Q = int(input())
for q in range(Q):
	s = input()
	t = input()
	p = input()
	pcount = {}
	for ch in p:
		pcount[ch] = pcount.get(ch, 0) + 1
	T = len(t)
	S = len(s)
	i = 0
	j = 0
	result = True
	while j < T:
		if i < S and s[i] == t[j]:
			j += 1
			i += 1
		elif pcount.get(t[j], 0) > 0:
			pcount[t[j]] -= 1
			j += 1
		else:
			result = False
			break
	print('YES' if result and i == S else 'NO')


def check():
	s = input()
	t = input()
	p = input()
	if s == t:
		return True
	cnt = [0] * 26
	itr = iter(t)
	if not all((c in itr for c in s)):
		return False
	for c in s:
		cnt[ord(c) - ord('a')] += 1
	for c in p:
		cnt[ord(c) - ord('a')] += 1
	for c in t:
		cnt[ord(c) - ord('a')] -= 1
	for c in cnt:
		if c < 0:
			return False
	return True
q = int(input())
for _ in range(q):
	print('YES' if check() else 'NO')


from collections import Counter
for _ in range(int(input())):
	s = input()
	Counter_s = Counter(s)
	t = input() + '**'
	Counter_t = Counter(t)
	p = input()
	Counter_p = Counter(p)
	(c1, c2) = (0, 0)
	Bool = True
	while True:
		if c2 == len(t):
			Bool = False
			break
		if c1 == len(s):
			break
		if s[c1] == t[c2]:
			c1 += 1
			c2 += 1
		else:
			c2 += 1
	diff = Counter_t - Counter_s
	if Bool == False:
		print('NO')
	else:
		del [diff['*']]
		Bool = False
		for val in diff:
			if val not in Counter_p:
				Bool = True
				break
			elif diff[val] > Counter_p[val]:
				Bool = True
				break
		if Bool == False:
			print('YES')
		else:
			print('NO')


from collections import defaultdict

def res():
	s = input()
	t = input()
	p = input()
	if len(s) > len(t):
		return False
	need = defaultdict(int)
	t_index = 0
	t_lenght = len(t)
	for char in s:
		while t_index < t_lenght and t[t_index] != char:
			need[t[t_index]] += 1
			t_index += 1
		if t_index >= t_lenght:
			return False
		t_index += 1
	while t_index < t_lenght:
		need[t[t_index]] += 1
		t_index += 1
	exist = defaultdict(int)
	for char in p:
		exist[char] += 1
	for (char, count) in need.items():
		if char not in exist or count > exist[char]:
			return False
	return True
q = int(input())
for qq in range(q):
	print('YES' if res() else 'NO')


def solve():
	s = input()
	t = input()
	p = input()
	flag = True
	for i in range(97, 97 + 26):
		x = chr(i)
		if p.count(x) + s.count(x) < t.count(x):
			flag = False
			break
	if flag == False:
		return 'NO'
	n = len(s)
	m = len(t)
	F = [[0] * (m + 1) for i in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if s[i - 1] == t[j - 1]:
				F[i][j] = F[i - 1][j - 1] + 1
			else:
				F[i][j] = max(F[i - 1][j], F[i][j - 1])
	if F[n][m] == n:
		return 'YES'
	return 'NO'
q = int(input())
for i in range(q):
	print(solve())


def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
t = int(input())
for _ in range(t):
	s = input().strip()
	t = input().strip()
	p = input().strip()
	flag = False
	if not isSubSequence(s, t, len(s), len(t)):
		print('NO')
		flag = True
	if not flag:
		sp = s + p
		cntt = {}
		cntsp = {}
		for i in t:
			try:
				cntt[i] += 1
			except:
				cntt[i] = 1
		for i in sp:
			try:
				cntsp[i] += 1
			except:
				cntsp[i] = 1
		flag = False
		for i in cntt.keys():
			try:
				if cntt[i] <= cntsp[i]:
					continue
				else:
					flag = True
					break
			except:
				flag = True
				break
		if flag:
			print('NO')
		else:
			print('YES')


probs = []
Q = int(input())
for _ in range(Q):
	s = input()
	t = input()
	p = input()
	probs.append([s, t, p])
for prob in probs:
	(s, t, p) = prob
	ks = 0
	kt = 0
	want = []
	while ks < len(s) and kt < len(t):
		if s[ks] == t[kt]:
			ks += 1
			kt += 1
		else:
			want.append(t[kt])
			kt += 1
	ans = 'YES'
	if ks < len(s):
		ans = 'NO'
	else:
		want.extend(t[kt:])
		P = list(p)
		checked = [False for _ in range(len(P))]
		for w in want:
			OK = False
			for (i, a) in enumerate(P):
				if a == w and (not checked[i]):
					checked[i] = True
					OK = True
					break
			if not OK:
				ans = 'NO'
				break
	print(ans)


q = int(input())
for i in range(q):
	s = list(input())
	t = list(input())
	p = list(input())
	j = 0
	count = 0
	while j < len(t):
		if j < len(s):
			if t[j] == s[j]:
				j += 1
				continue
			elif t[j] in p:
				s.insert(j, t[j])
				p.remove(t[j])
				j += 1
			else:
				count += 1
				print('NO')
				break
		else:
			s.append('')
	x = ''
	for i in t:
		x += i
	y = ''
	for j in s:
		y += j
	if x == y:
		print('YES')
	elif count == 0:
		print('NO')


from collections import Counter
for q in range(int(input())):
	s = input()
	t = input()
	p = input()
	b = Counter(list(p))
	i = 0
	j = 0
	a = set()
	for i in range(len(s)):
		for k in range(j, len(t)):
			if s[i] == t[k]:
				j = k + 1
				a.add(k)
				break
		else:
			print('NO')
			break
	else:
		for i in range(len(t)):
			if not i in a:
				if not t[i] in b or b[t[i]] == 0:
					print('NO')
					break
				else:
					b[t[i]] -= 1
		else:
			print('YES')


for _ in range(int(input())):
	s = input()
	t = input()
	p = input()
	sl = len(s)
	tl = len(t)
	a = [0] * 26
	i = 0
	j = 0
	while i < sl and j < tl:
		x = s[i]
		while j < tl and t[j] != x:
			a[ord(t[j]) - 97] += 1
			j += 1
		if j != tl:
			i += 1
		j += 1
	if i != sl:
		print('NO')
		continue
	while j < tl:
		a[ord(t[j]) - 97] += 1
		j += 1
	for x in p:
		a[ord(x) - 97] -= 1
	res = True
	for x in a:
		res &= x <= 0
	print('NYOE S'[res::2])


T = int(input())
for i in range(T):
	s = input()
	t = input()
	p = input()
	x = 0
	y = s + p
	for j in t:
		if x < len(s):
			if j == s[x]:
				x = x + 1
		else:
			break
	if x == len(s):
		for j in range(0, len(t)):
			if t[j] in y:
				y = y[0:y.index(t[j])] + '*' + y[y.index(t[j]) + 1:len(y)]
			else:
				x = -1
				break
	if x == len(s):
		print('YES')
	else:
		print('NO')


t = int(input())
for w in range(t):
	s = [i for i in input()]
	t = [i for i in input()]
	p = [i for i in input()]
	j = 0
	for i in range(len(t)):
		if t[i] == s[j]:
			j += 1
		if j >= len(s):
			break
	if j != len(s):
		print('NO')
	else:
		sf = [0] * 26
		tf = [0] * 26
		pf = [0] * 26
		for i in range(len(s)):
			sf[ord(s[i]) - 97] += 1
		for i in range(len(t)):
			tf[ord(t[i]) - 97] += 1
		for i in range(len(p)):
			pf[ord(p[i]) - 97] += 1
		f = 0
		for i in range(26):
			if tf[i] != 0:
				if sf[i] + pf[i] < tf[i]:
					f = 1
			if f == 1:
				break
		if f == 1:
			print('NO')
		else:
			print('YES')


import sys

def included_string(s, t, p):
	i = 0
	B = True
	while i < len(t) and B == True:
		if s.count(t[i]) + p.count(t[i]) < t.count(t[i]):
			B = False
		i = i + 1
	return B

def index_ok(s, t):
	i = 0
	IN = True
	while i < len(s) and IN == True:
		if t.find(s[i]) == -1:
			IN = False
			break
		else:
			Index = t.index(s[i])
			t = t[Index + 1:len(t)]
		i += 1
	return IN
q = int(input())
for x in range(q):
	s = input()
	t = input()
	p = input()
	if len(t) < len(s):
		print('NO')
	elif len(t) == len(s) and t != s:
		print('NO')
	elif len(t) == len(s) and t == s:
		print('YES')
	else:
		IN = index_ok(s, t)
		B = included_string(s, t, p)
		if IN == True and B == True:
			print('YES')
		else:
			print('NO')


def is_subseq(x, y):
	it = iter(y)
	return all((c in it for c in x))
q = int(input())
for i in range(q):
	s = input()
	t = input()
	p = input()
	dt = {chr(i): 0 for i in range(ord('a'), ord('z') + 1)}
	ds = {chr(i): 0 for i in range(ord('a'), ord('z') + 1)}
	dp = {chr(i): 0 for i in range(ord('a'), ord('z') + 1)}
	if is_subseq(s, t):
		for j in t:
			dt[j] += 1
		for j in s:
			ds[j] += 1
		for j in p:
			dp[j] += 1
		vt = list(dt.values())
		vs = list(ds.values())
		vp = list(dp.values())
		for k in range(26):
			if vt[k] > vs[k] + vp[k]:
				print('NO')
				break
		else:
			print('YES')
	else:
		print('NO')


import sys, math
input = sys.stdin.readline

def qw():
	s = input()
	t = input()
	p = input()
	if s == t:
		return True
	it = iter(t)
	if not all((c in it for c in s)):
		return False
	d = [0] * 256
	for c in s:
		d[ord(c)] += 1
	for c in p:
		d[ord(c)] += 1
	for c in t:
		d[ord(c)] -= 1
		if d[ord(c)] < 0:
			return False
	return True
for i in range(int(input())):
	print('YES' if qw() else 'NO')


from collections import Counter
x = int(input())
for i in range(x):
	(s, t, p) = (input(), input(), input())
	(w, e) = (dict(Counter(list(t))), dict(Counter(list(s) + list(p))))
	flag = flag1 = 0
	for (k, v) in w.items():
		if k in e:
			if e[k] < v:
				print('No')
				flag = 1
				break
		else:
			print('No')
			flag = 1
			break
	if flag == 1:
		continue
	count = 0
	for wer in t:
		if wer == s[count]:
			count += 1
			if count == len(s):
				print('Yes')
				flag1 = 1
				break
	if flag1 == 0:
		print('No')


def matches(A, B):
	ib = 0
	for l in A:
		if l == B[ib]:
			ib += 1
		if ib == len(B):
			return True
	return False

def has_more_letters(A, B):
	cnt = [0] * 128
	for a in A:
		cnt[ord(a)] += 1
	for b in B:
		cnt[ord(b)] -= 1
	return min(cnt) >= 0

def main():
	S = input()
	T = input()
	P = input()
	print('YES' if matches(T, S) and has_more_letters(S + P, T) else 'NO')
T = int(input())
for _ in range(T):
	main()


from collections import defaultdict as dd, deque
q = int(input())

def solve():

	def f(x):
		C = dd(int)
		for a in x:
			C[a] += 1
		return C
	s = input()
	t = input()
	p = input()
	cs = f(s)
	ct = f(t)
	cp = f(p)
	needed = dd(int)
	for k in ct:
		needed[k] += ct[k]
	for k in cs:
		needed[k] -= cs[k]
	for k in needed:
		if needed[k] > cp[k] or needed[k] < 0:
			return False
	i = 0
	j = 0
	while j < len(t):
		if i < len(s) and s[i] == t[j]:
			i += 1
			j += 1
		else:
			if ct[t[j]] > 0:
				ct[t[j]] -= 1
			else:
				return False
			j += 1
	return i == len(s) and j == len(t)
for _ in range(q):
	if solve():
		print('YES')
	else:
		print('NO')