You can perform the following operations on the string, $a$:  

Capitalize zero or more of $a$'s lowercase letters.
Delete all of the remaining lowercase letters in $a$.

Given two strings, $a$ and $\boldsymbol{b}$, determine if it's possible to make $a$ equal to $\boldsymbol{b}$ as described. If so, print YES on a new line.  Otherwise, print NO.

For example, given $a=\textbf{AbcDE}$ and $b=\textbf{ABDE}$, in $a$ we can convert $\mbox{b}$ and delete $\textbf{C}$ to match $\boldsymbol{b}$.  If $a=\textbf{AbcDE}$ and $b=\textbf{AFDE}$, matching is not possible because letters may only be capitalized or discarded, not changed.

Function Description

Complete the function $abbreviation$ in the editor below.  It must return either $YES$ or $\mathrm{NO}$.

abbreviation has the following parameter(s):

a: the string to modify  
b: the string to match  

Input Format

The first line contains a single integer $\textit{q}$, the number of queries. 

Each of the next $\textit{q}$ pairs of lines is as follows: 

- The first line of each query contains a single string, $a$. 

- The second line of each query contains a single string, $\boldsymbol{b}$.  

Constraints

$1\leq q\leq10$  
$1\le|a|,|b|\le1000$
String $a$ consists only of uppercase and lowercase English letters, ascii[A-Za-z].
String $\boldsymbol{b}$ consists only of uppercase English letters, ascii[A-Z].

Output Format

For each query, print YES on a new line if it's possible to make string $a$ equal to string $\boldsymbol{b}$.  Otherwise, print NO.

Sample Input
1
daBcd
ABC

Sample Output
YES

Explanation

We have $\boldsymbol{a}=$ daBcd and $b=$ ABC. We perform the following operation:

Capitalize the letters a and c in $\boldsymbol{\alpha}$ so that $\boldsymbol{a}=$ dABCd. 
Delete all the remaining lowercase letters in $a$ so that $\boldsymbol{a}=$ ABC. 

Because we were able to successfully convert $a$ to $\boldsymbol{b}$, we print YES on a new line.

Source: hackerrank | Difficulty: MEDIUM
Tags: Dynamic programming


Solutions:
import sys
sys.setrecursionlimit(30000)
from collections import Counter, defaultdict, deque
from math import ceil, floor, factorial, fsum, isinf, exp, log, log10, log2, isfinite, sqrt
from math import pi as PI, e as E
from math import sin, cos, tan, sinh, cosh, tanh, asin, acos, atan
from fractions import Fraction
from itertools import starmap, tee, chain, filterfalse, combinations as combos
from itertools import permutations as perms, product as prod, combinations_with_replacement as rcombos
from functools import reduce, partial
import operator as ops
from operator import __not__ as notit, __abs__ as absit, __or__ as orit
from bisect import insort_left
from copy import deepcopy
(PHI, PHI2) = ((1 + 5 ** 0.5) / 2, (5 ** 0.5 - 1) / 2)
INF = float('inf')

class TreeNode:

	def __init__(self, v):
		self.val = v
		self.left = None
		self.right = None

def setBit(x, offset):
	return x | 1 << offset

def clearBit(x, offset):
	return x & ~(1 << offset)

def getBit(x, offset):
	return 1 if testBit(x, offset) > 0 else 0

def testBit(x, offset):
	return x & 1 << offset

def flipBitAt(x, offset):
	return x ^ 1 << offset

def flipBits(x, length=-1):
	length = x.bit_length() - 1 if length == -1 else length
	return x ^ (1 << length) - 1

def numBits(x):
	return x.bit_length()

def countOnes(x):
	return bin(x).count('1')

def countZeros(x, length=-1):
	length = x.bit_length() if length == -1 else length
	return length - countOnes(x)

def getList(tcast=str):
	return [tcast(x) for x in input().strip().split(' ')]

def getItems(*tcast):
	return map(lambda f, x: f(x), tcast, getList())

def getVal(tcast=str):
	return tcast(input().strip())

def getMatrix(r, tcast=str):
	return [getList(tcast) for row in range(r)]

def isOdd(n):
	return n & 1 > 0

def isEven(n):
	return not n & 1

def numDigits(n):
	return len(str(n)) - (1 if n < 0 else 0)

def _gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def gcd(*xs):
	nums = xs[0] if type(xs[0]) == list else list(xs)
	cur = nums[0]
	for n in nums[1:]:
		if cur == 1:
			return cur
		cur = _gcd(cur, n)
	return cur

def _lcm(a, b):
	return a // gcd(a, b) * b

def lcm(*xs):
	nums = xs[0] if type(xs[0]) == list else list(xs)
	cur = nums[0]
	for n in nums[1:]:
		cur = _lcm(cur, n)
	return cur

def primesUpto(n):
	isp = [True] * (n + 1)
	(isp[0], isp[1]) = (False, False)
	primes = []
	for (i, x) in enumerate(isp):
		if x:
			primes.append(i)
			mults = i * i
			while mults <= n:
				isp[mults] = False
				mults += i
	return primes

def primeFactor(n):
	factors = Counter()
	while not n & 1:
		factors[2] += 1
		n >>= 1
	trynum = 3
	while trynum <= ceil(sqrt(n)):
		while n % trynum == 0:
			factors[trynum] += 1
			n //= trynum
		trynum += 2
	if n != 1:
		factors[n] += 1
	return factors

def isPrime(n):
	if n & 1 and n >= 2:
		trynum = 3
		limit = ceil(sqrt(n))
		while trynum < limit:
			if n % trynum == 0:
				return False
			trynum += 2
		else:
			return True
	else:
		return False

def nthFib(n):
	if n <= 2:
		return 1
	else:
		(a, b) = (1, 1)
		while n > 2:
			(a, b) = (b, a + b)
			n -= 1
		return b

def zipNWith(f, *x):
	return (f(y) for y in zip(*x))

def zipWith(f, xs, ys):
	return (f(x, y) for (x, y) in zip(xs, ys))

def flatten(xs):
	return reduce(ops.concat, xs)

def quantify(pred, it):
	return sum(map(pred, it))

def dotproduct(xs, ys):
	return sum(map(ops.mul, xs, ys))

def adjpairs(it):
	(a, b) = tee(it)
	next(b, None)
	return zip(a, b)

def bipartition(pred, it):
	(t, f) = tee(it)
	return (filter(pred, t), filterfalse(pred, f))

def powerset(it):
	s = list(it)
	return chain.from_iterable((combos(s, r) for r in range(len(s) + 1)))

def depProduct(bounds, f=lambda y: y + 1, g=lambda *x: tuple(x)):
	args = [-1]
	nbounds = len(bounds)
	while args:
		n = len(args)
		args[-1] += 1
		if args[-1] >= bounds[n - 1]:
			args.pop()
		elif n == nbounds:
			yield g(*args)
		else:
			_f = f[n] if type(f) == list else f
			args.append(_f(args[-1]) - 1)

def revEnumerate(xs):
	n = len(xs) - 1
	for (i, x) in enumerate(reversed(xs)):
		yield (n - i, x)

def is_subseq(x, y):
	it = iter(y)
	return all((c in it for c in x))
out = ''
nqueries = getVal(int)
for q in range(nqueries):
	init = getVal(str)
	final = getVal(str)
	if not is_subseq(final, init.upper()):
		out = 'NO'
	else:
		mustinclude = [c for c in init if c.isupper()]
		if not is_subseq(mustinclude, final):
			out = 'NO'
		else:
			counti = Counter(init.upper())
			countf = Counter(final)
			if countf - counti:
				out = 'NO'
			else:
				out = 'YES'
	print(out)


def recurse(a, b):
	if len(a) < len(b):
		return False
	if len(b) == 0:
		return a.islower()
	if a.upper() == b:
		return True
	if a[0].isupper():
		if a[0] == b[0]:
			return recurse(a[1:], b[1:])
		else:
			return False
	elif a[0].upper() != b[0]:
		return recurse(a[1:], b)
	else:
		return recurse(a[1:], b[1:]) or recurse(a[1:], b)

def solveProblem():
	a = input()
	b = input()
	x = recurse(a, b)
	if x:
		print('YES')
	else:
		print('NO')
T = int(input())
for t in range(T):
	solveProblem()


import string
Q = int(input())
for query in range(Q):
	strA = input()
	strB = input()
	prev_index = 0
	res = 'YES'
	for letter in strB:
		upper_index = strA.find(letter, prev_index)
		if upper_index == -1:
			lower_index = strA.find(letter.lower(), prev_index)
			if lower_index == -1:
				res = 'NO'
				break
			else:
				strA = strA[:lower_index] + strA[lower_index].upper() + strA[lower_index + 1:]
				prev_index = lower_index
		else:
			prev_index = upper_index
	strA = ''.join((x for x in strA if not x.islower()))
	if strA != strB:
		res = 'NO'
	print(res)


def substr(a, S):
	i = 0
	j = 0
	while i < len(a) and j < len(S):
		if a[i] == S[j]:
			i += 1
			j += 1
		else:
			j += 1
	if i == len(a):
		return True
	return False
q = int(input())
for _q in range(q):
	a = input().rstrip('\n')
	b = input().rstrip('\n')
	a_cap = a.upper()
	a_onlycap = [c for c in a if ord('Z') >= ord(c) >= ord('A')]
	if substr(b, a_cap) and substr(a_onlycap, b):
		print('YES')
	else:
		print('NO')


import sys
q = int(input().strip())
for i in range(q):
	a = input().strip()
	b = input().strip()
	bpos = {}
	for i in range(len(b)):
		bpos[b[i]] = bpos[b[i]] | set([i]) if b[i] in bpos else set([i])
	possibilities = set([0])
	for i in range(len(a)):
		if a[i].upper() in bpos:
			intersection = bpos[a[i].upper()] & possibilities
			advancement = set([i + 1 for i in intersection])
		else:
			advancement = set([])
		if a[i].upper() == a[i]:
			possibilities = advancement
		else:
			possibilities = possibilities | advancement
	print('YES' if len(b) in possibilities else 'NO')


q = int(input())
while q:
	q -= 1
	a = input()
	b = input()
	can = True
	j = 0
	for c in a:
		if c == c.upper():
			if c in b[j:]:
				j += 1
			else:
				can = False
				break
	if can:
		a = a.lower()
		b = b.lower()
		mat = [[0] * (len(b) + 1) for i in range(len(a) + 1)]
		for i in range(1, len(a) + 1):
			for j in range(1, len(b) + 1):
				if a[i - 1] == b[j - 1]:
					mat[i][j] = mat[i - 1][j - 1] + 1
				else:
					mat[i][j] = max(mat[i - 1][j], mat[i][j - 1])
		if mat[len(a)][len(b)] == len(b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def canConvert(a, b):
	onlyUpper = [letter for letter in a if letter.isupper()]
	j = 0
	for i in range(len(onlyUpper)):
		while j < len(b) and onlyUpper[i] != b[j]:
			j += 1
		if j == len(b):
			print('NO')
			return
		else:
			j += 1
	a = [letter.upper() for letter in a]
	j = 0
	for i in range(len(b)):
		while j < len(a) and b[i] != a[j]:
			j += 1
		if j == len(a):
			print('NO')
			return
		else:
			j += 1
	print('YES')
for _ in range(int(input().strip())):
	a = list(input().strip())
	b = list(input().strip())
	canConvert(a, b)


def can(a, b):
	if not b:
		return all((not x.isupper() for x in a))
	elif not a and b:
		return False
	if a[0].isupper():
		if a[0] == b[0]:
			return can(a[1:], b[1:])
		return False
	if a[0] == b[0]:
		return can(a[1:], b[1:]) or can(a[1:], b)
	elif a[0].upper() == b[0]:
		return can(a[1:], b[1:]) or can(a[1:], b)
	return can(a[1:], b)
for _ in range(int(input())):
	if can(input(), input()):
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	lis1 = list(input())
	lis2 = list(input())
	pos = []
	st = True
	ck = 0
	for ch in lis2:
		ch1 = ch.lower()
		if ch in lis1:
			p1 = lis1.index(ch)
			pos.append(p1)
			lis1[p1] = '#'
			lis2[ck] = '#'
		elif ch1 in lis1:
			p1 = lis1.index(ch1)
			pos.append(p1)
			lis1[p1] = '#'
			lis2[ck] = '#'
		else:
			st = False
			break
		ck += 1
	ck = 0
	for k in lis1:
		if k.islower():
			lis1[ck] = '#'
		ck += 1
	if not st:
		print('NO')
		continue
	if lis1.count('#') != len(lis1):
		print('NO')
		continue
	if len(pos) != len(lis2):
		print('NO')
		continue
	for var in range(len(pos) - 1):
		if pos[var] > pos[var + 1]:
			st = False
			break
	if not st:
		print('NO')
	else:
		print('YES')


def search(needle, haystack):
	if not haystack:
		return False
	if not needle:
		for ch in haystack:
			if ch.isupper():
				return False
		return True
	if needle == haystack.upper():
		return True
	if haystack[0].isupper() and needle[0] != haystack[0]:
		return False
	elif needle[0] == haystack[0]:
		return search(needle[1:], haystack[1:])
	if needle[0] == haystack[0].upper():
		if search(needle[1:], haystack[1:]):
			return True
	return search(needle, haystack[1:])

def main():
	queries = int(input().strip())
	for i in range(queries):
		src = input().strip()
		tgt = input().strip()
		if search(tgt, src):
			print('YES')
		else:
			print('NO')
main()


def abbreviation(a, b):
	if len(b) == 0:
		return len(a) == 0 or a.islower()
	elif len(a) == 0:
		return False
	else:
		if a[0].islower():
			if abbreviation(a[1:], b):
				return True
		if a[0].upper() == b[0]:
			if abbreviation(a[1:], b[1:]):
				return True
		return False
q = int(input())
for _ in range(q):
	a = input()
	b = input()
	print('YES' if abbreviation(a, b) else 'NO')


def lcs(a, b):
	m = len(a)
	n = len(b)
	C = [[0] * (n + 1) for x in range(m + 1)]
	for i in range(1, m + 1):
		for j in range(1, n + 1):
			if a[i - 1] == b[j - 1]:
				C[i][j] = C[i - 1][j - 1] + 1
			else:
				C[i][j] = max(C[i][j - 1], C[i - 1][j])
	return C[m][n]

def solve(a, b):
	bInd = 0
	aInd = 0
	match = True
	for i in range(len(a)):
		if a[i].isupper():
			oInd = bInd
			match = False
			while bInd < len(b):
				if bInd < len(b) and b[bInd] == a[i]:
					aSmall = a[aInd:i].upper()
					bSmall = b[oInd:bInd]
					bl = lcs(aSmall, bSmall)
					if bl == len(bSmall):
						match = True
						bInd += 1
						break
				bInd += 1
			if not match:
				break
			aInd = i + 1
	aSmall = a[aInd:].upper()
	bSmall = b[bInd:]
	bl = lcs(aSmall, bSmall)
	if bl < len(bSmall):
		match = False
	print('YES' if match else 'NO')
q = int(input())
for k in range(q):
	a = input().strip()
	b = input().strip()
	solve(a, b)


import re
for _ in range(int(input())):
	a = input()
	b = ['[%s%s]' % (c, c.lower()) for c in input()]
	pattern = '^[a-z]*' + '[a-z]*'.join(b) + '[a-z]*$'
	print('YES' if re.match(pattern, a) else 'NO')


q = int(input().rstrip())

def getupper(s):
	return ''.join([c for c in s if c <= 'Z'])

def isupper(a):
	return a >= 'A' and a <= 'Z'

def islower(a):
	return a >= 'a' and a <= 'z'

def case_in_eq(a, b):
	return a.upper() == b.upper()

def match(a, b):
	if len(a) == 0 and len(b) == 0:
		return True
	if len(a) == 0 and len(b) != 0:
		return False
	if len(a) < len(b):
		return False
	if len(b) == 0 and len(getupper(a)) != 0:
		return False
	if len(b) == 0 and len(getupper(a)) == 0:
		return True
	if len(a) == 1 and len(b) == 1:
		return case_in_eq(a, b)
	for i in range(len(a)):
		if isupper(a[i]):
			if a[i] != b[0]:
				return False
		if case_in_eq(a[i], b[0]):
			if match(a[i + 1:], b[1:]):
				return True
	return False
for _ in range(q):
	a = input().strip()
	b = input().strip()
	if match(a, b):
		print('YES')
	else:
		print('NO')


import re
import sys
q = int(sys.stdin.readline())
for i in range(q):
	a = sys.stdin.readline().strip()
	b = sys.stdin.readline().strip()
	regex = '^'
	for char in a:
		if char == char.upper():
			regex += char
		else:
			regex += char.upper() + '?'
	regex += '$'
	print('YES' if re.match(regex, b) else 'NO')


q = int(input())
counter = 0

def checker(str1, str2):
	if str1 == '' or str2 == '':
		return True
	for i in str1:
		if i in str2:
			return True
	return False

def onlyupper(str):
	retstr = ''
	for i in str:
		if i.isupper():
			retstr += i
	return retstr

def isorderedsubstring(A, B):
	(j, k) = (0, 0)
	while j < len(A):
		if k == len(B) and j < len(A):
			return False
		elif A[j] == B[k]:
			j += 1
			k += 1
		elif A[j] != B[k]:
			k += 1
	return True
while counter < q:
	counter += 1
	s = input()
	e = input()
	sou = onlyupper(s)
	if not checker(sou, e):
		print('NO')
	elif len(sou) > len(e):
		print('NO')
	elif len(sou) == len(e):
		if sou == e:
			print('YES')
		else:
			print('NO')
	elif isorderedsubstring(e, s.upper()):
		print('YES')
	else:
		print('NO')


from re import match

def can_convert(a, b):
	pattern = '^[a-z]*' + '[a-z]*'.join(('[{}{}]'.format(x.lower(), x.upper()) for x in b)) + '[a-z]*$'
	return bool(match(pattern, a))
q = int(input())
for i in range(q):
	a = input()
	b = input()
	convert = can_convert(a, b)
	print('YES' if convert else 'NO')


def is_possible(a, ai, b, bi):
	if ai == len(a) and bi == len(b):
		return True
	if ai == len(a):
		return False
	if bi == len(b):
		for x in a[ai:]:
			if x.isupper():
				return False
		return True
	rem = False
	conv = False
	already = False
	if a[ai].islower():
		rem = is_possible(a, ai + 1, b, bi)
		if a[ai].upper() == b[bi]:
			conv = is_possible(a, ai + 1, b, bi + 1)
	elif a[ai] == b[bi]:
		already = is_possible(a, ai + 1, b, bi + 1)
	return rem or conv or already
q = int(input())
for i in range(q):
	a = input()
	b = input()
	ans = is_possible(list(a), 0, list(b), 0)
	if ans:
		print('YES')
	else:
		print('NO')


def rec_check(A, B, Ai, Bi):
	if Bi >= len(B):
		if Ai >= len(A) or A[Ai:].islower():
			return True
		else:
			return False
	elif Ai >= len(A):
		return False
	elif A[Ai].upper() == B[Bi] and rec_check(A, B, Ai + 1, Bi + 1):
		return True
	elif A[Ai].islower() and rec_check(A, B, Ai + 1, Bi):
		return True
	else:
		return False
answers = list()
for _ in range(int(input())):
	A = input().strip()
	B = input().strip()
	if rec_check(A, B, 0, 0):
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(a, b) = (input(), input())
	(n, m) = (len(a), len(b))
	ans = [[None for j in range(m + 1)] for i in range(n + 1)]

	def work(i, j):
		if i == n and j == m:
			return True
		(c, d) = (a[i] if i < n else '$A', b[j] if j < m else '$B')
		match = c.upper() == d.upper() and ans[i + 1][j + 1]
		drop_c = c.islower() and ans[i + 1][j]
		drop_d = d.islower() and ans[i][j + 1]
		return match or drop_c or drop_d
	for i in range(n, -1, -1):
		for j in range(m, -1, -1):
			ans[i][j] = work(i, j)
	print('YES' if ans[0][0] else 'NO')


import string
import re
n = int(input().strip())
for x in range(n):
	a = input().strip()
	b = input().strip()
	skip = False
	for i in a:
		if i in string.ascii_uppercase and (i not in b or a.count(i) > b.count(i)):
			print('NO')
			skip = True
			break
	if skip:
		continue
	a = a.lower()
	b = b.lower()
	last_index = 0
	for i in b:
		index = a[last_index:].find(i)
		if index == -1:
			print('NO')
			skip = True
			break
		else:
			last_index += index + 1
	if skip:
		continue
	print('YES')


import string
q = int(input())
for k in range(q):
	v1 = input()
	v2 = input()
	j = 0
	g = 0
	prev = ''
	for i in v2:
		f = 0
		for j in range(g, len(v1)):
			if v1[j] == i or v1[j].upper() == i:
				g = j + 1
				f = 1
				break
			if v1[j].isupper() and v1[j] != prev:
				break
		if f == 0:
			break
		prev = i
	if f == 1:
		for i in range(g, len(v1)):
			if v1[i].isupper():
				f = 0
	if f == 0:
		print('NO')
	else:
		print('YES')


def test(a, b):
	if len(b) > 0:
		i = 0
		if b[0] in a[i:]:
			j = i + a[i:].find(b[0])
			if a[i:j].lower() == a[i:j]:
				if test(a[j + 1:], b[1:]):
					return True
		i = 0
		while b[0].lower() in a[i:]:
			j = i + a[i:].find(b[0].lower())
			if a[i:j].lower() == a[i:j]:
				if test(a[j + 1:], b[1:]):
					return True
			else:
				break
			i = j + 1
		return False
	elif a.lower() == a:
		return True
	else:
		return False
q = int(input())
for x in range(0, q):
	a = input()
	b = input()
	if test(a, b):
		print('YES')
	else:
		print('NO')


import re

def is_subseq(x, y):
	it = iter(y)
	return all((c in it for c in x))

def abbr(first, second):
	caps_in_first = ''.join((c for c in first if c.isupper()))
	for c in caps_in_first:
		if caps_in_first.count(c) > second.count(c):
			return 'NO'
	first_all_caps = first.upper()
	return 'YES' if is_subseq(second, first_all_caps) else 'NO'
num_queries = int(input())
for _ in range(num_queries):
	first_word = input()
	second_word = input()
	print(abbr(first_word, second_word))


import sys

def findCharInString(ch, s):
	for (i, sch) in enumerate(s):
		if sch == ch:
			return i
	return -1

def algo(a, b):
	aLen = len(a)
	bLen = len(b)
	aPt = 0
	success = True
	for bChar in b:
		idx = findCharInString(bChar, a[aPt:aLen])
		if idx == -1:
			success = False
			break
		else:
			aPt = aPt + idx + 1
	return success

def process(input):
	q = int(input.readline())
	for q in range(0, q):
		a = input.readline().strip()
		b = input.readline().strip()
		a_all = a.upper()
		a_u = ''.join(filter(lambda c: c.isupper(), a))
		if algo(b, a_u) and algo(a_all, b):
			print('YES')
		else:
			print('NO')
process(sys.stdin)


import re
T = int(input())
for t in range(T):
	A = input()
	B = input()
	s = '^[a-z]*'
	for b in B:
		s += '[' + b + b.lower() + '][a-z]*'
	s += '$'
	if re.match(s, A):
		print('YES')
	else:
		print('NO')


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

def solve(a, b):
	n = len(a)
	m = len(b)
	aupper = a.upper()
	dp = [[False] * (n + 1) for _ in range(m + 1)]
	dp[0][0] = True
	for j in range(1, n + 1):
		dp[0][j] = dp[0][j - 1] and a[j - 1].islower()
	for i in range(1, m + 1):
		dp[i][i - 1] = False
		for j in range(i, n + 1):
			dp[i][j] = dp[i - 1][j - 1] and b[i - 1] == aupper[j - 1] or (dp[i][j - 1] and a[j - 1].islower())
	print('YES' if dp[m][n] else 'NO')

def main():
	q = int(input())
	for _ in range(q):
		a = input()
		b = input()
		solve(a, b)
main()


def solve(a: str, b: str):
	if len(a) == 0 and len(b) == 0:
		return True
	if len(a) == 0:
		return False
	if len(b) == 0:
		return a.islower()
	if a[0].isupper():
		return a[0] == b[0] and solve(a[1:], b[1:])
	if a[0].upper() == b[0]:
		return solve(a[1:], b[1:]) or solve(a[1:], b)
	return solve(a[1:], b)

def main():
	for _ in range(int(input())):
		a = input().strip()
		b = input().strip()
		print('YES' if solve(a, b) else 'NO')
main()


def try_match(stra, strb):
	if not strb:
		return not any((c.isupper() for c in stra))
	for (i, c) in enumerate(stra):
		if c.upper() == strb[0] and try_match(stra[i + 1:], strb[1:]):
			return True
		elif c.isupper():
			return False
q = int(input())
for _ in range(q):
	stra = input().rstrip()
	strb = input().lstrip()
	print('YES' if try_match(stra, strb) else 'NO')


def cleanStr(s1, s2):
	a = ''
	a2 = ''
	for j in s1:
		if j.islower():
			k = j.upper()
			if k in s2:
				a += j
		else:
			if j not in s2:
				return ['', '']
			a += j
			a2 += j
	return [a, a2]

def hasUpper(s):
	for i in s:
		if i.isupper():
			return True
	return False

def performOp(s1, s2):
	for i in range(len(s1)):
		p1 = s1[:i]
		if hasUpper(p1):
			return False
		try:
			p = s1[i:i + len(s2)]
			p2 = s1[i + len(s2):]
		except:
			return False
		if hasUpper(p2):
			return False
		p = p.upper()
		if p == s2:
			return True
num = int(input())
for i in range(num):
	a = input()
	b = input()
	if len(b) > len(a):
		print('NO')
	else:
		l = cleanStr(a, b)
		if 0 == len(l[0]):
			print('NO')
		elif len(b) <= len(l[1]):
			if b == l[1]:
				print('YES')
			else:
				print('NO')
		elif performOp(l[0], b):
			print('YES')
		else:
			print('NO')


import re
for _ in range(int(input())):
	a = input()
	b = input()
	match = True
	for c in b:
		up = re.search('[A-Z]', a)
		if up:
			next_uppercase_i = up.start()
		else:
			next_uppercase_i = 1000
		li = a.find(c.lower())
		if up and up.group() == c:
			a = a[up.start() + 1:]
		elif li != -1 and li < next_uppercase_i:
			a = a[li + 1:]
		else:
			match = False
			break
	if len(re.findall('[A-Z]', a)) > 0:
		match = False
	if match:
		print('YES')
	else:
		print('NO')


import sys

def islow(c):
	return ord(c) > ord('Z')

def isup(c):
	return not islow(c)

def trans(a, b):
	if b == '':
		return all((islow(c) for c in a))
	if a == '':
		return b == ''
	firstUp = [-1 for i in a]
	last = -1
	for (i, l) in enumerate(a):
		if isup(l):
			for j in range(last + 1, i + 1):
				firstUp[j] = i
			last = i
	iaset = {0}
	for bi in b:
		nextset = set()
		for ia in iaset:
			for (i, l) in enumerate(a[ia:], ia):
				if l.lower() == bi.lower():
					nextset.add(i + 1)
					if islow(l) and firstUp[i] != -1 and (a[firstUp[i]] == bi):
						nextset.add(firstUp[i] + 1)
					break
				if isup(l):
					break
		iaset = nextset
	if iaset == set():
		return False
	return all((islow(a[i]) for i in range(max(iaset), len(a))))
for _ in range(int(input())):
	a = input().strip()
	b = input().strip()
	if trans(a, b):
		print('YES')
	else:
		print('NO')


for caso in range(int(input())):
	a = input()
	b = input()
	posible = True
	inicio = 0
	c = 0
	b += ' '
	mayusculas = []
	for j in range(len(b)):
		for i in range(inicio, len(a)):
			if a[i].upper() == b[j]:
				if a[i].islower():
					mayusculas.append(a[i].upper())
				inicio = i + 1
				c += 1
				break
			elif a[i].isupper():
				if len(mayusculas) > 0 and a[i] == mayusculas[0]:
					mayusculas.pop(0)
				else:
					posible = False
					break
		if not posible:
			break
	if posible and c == len(b) - 1:
		print('YES')
	else:
		print('NO')


import sys
q = int(input().strip())
for z in range(q):
	a = input().strip()
	b = input().strip()
	a_upper = ''.join([i for i in a if i == i.upper()])
	a_upper_full = a.upper()
	if len(a_upper) > len(b) or (len(a_upper) == len(b) and a_upper != b):
		print('NO')
	else:
		i = 0
		r = True
		for j in range(len(b)):
			while i < len(a_upper_full) and b[j] != a_upper_full[i]:
				i += 1
			if i < len(a_upper_full) and b[j] == a_upper_full[i]:
				i += 1
			else:
				r = False
				break
		if r:
			print('YES')
		else:
			print('NO')


import sys

def main():
	q = int(input())
	for i in range(q):
		a = input()
		b = list(input())
		c = ''
		d = list(a)
		result = -1
		n = len(b)
		index = -1
		flag = -1
		for j in range(n):
			if a.find(b[j], index + 1) == -1:
				index = a.lower().find(b[j].lower(), index + 1)
				d[index] = d[index].upper()
				flag = 0
		if index == -1 & flag == 0:
			print('NO')
		else:
			for j in range(len(d)):
				if d[j].isupper():
					c = c + d[j]
			b = ''.join(b)
			if c == b:
				print('YES')
			else:
				print('NO')
main()


def parse(a, b):
	pos_a = 0
	pos_b = 0
	if b == '':
		return True
	previous = ''
	can_delete = []
	while pos_b < len(b):
		if pos_a == len(a):
			return False
		if a[pos_a].upper() == b[pos_b]:
			if a[pos_a].islower:
				can_delete.append(a[pos_a].upper())
			pos_a += 1
			pos_b += 1
			continue
		if a[pos_a].islower():
			pos_a += 1
			continue
		if a[pos_a] in can_delete:
			can_delete.remove(a[pos_a])
			pos_a += 1
			continue
		return False
	return a[pos_a:] == '' or a[pos_a:].islower()
Q = int(input())
for q in range(Q):
	a = input()
	b = input()
	if parse(a, b):
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(0, q):
	a = input()
	b = input()
	soFar = []
	toGo = []
	soFar.append([])
	toGo.append(list(b))
	for j in range(0, len(a)):
		c = a[j]
		e = len(soFar)
		k = 0
		while k < e:
			if c >= 'a' and c <= 'z':
				if len(toGo[k]) > 0 and c.upper() == toGo[k][0]:
					ne = soFar[k][:]
					ne.append(c.upper())
					soFar.append(ne)
					toGo.append(toGo[k][1:])
			if c >= 'A' and c <= 'Z':
				if len(toGo[k]) == 0 or toGo[k][0] != c:
					soFar.pop(k)
					toGo.pop(k)
					k -= 1
					e -= 1
				else:
					soFar[k].append(c)
					toGo[k].pop(0)
			k += 1
	matched = False
	for j in range(0, len(toGo)):
		if len(toGo[j]) == 0:
			matched = True
	if matched:
		print('YES')
	else:
		print('NO')


def solve(s1_list, s2_list):
	last = None
	while s2_list:
		target = s2_list.pop(0)
		found = False
		while not found and s1_list:
			if s1_list[0].isupper():
				if s1_list[0] == target:
					last = s1_list.pop(0)
					found = True
				elif last == s1_list[0]:
					s1_list.pop(0)
				else:
					return False
			elif s1_list[0].upper() == target:
				last = s1_list.pop(0).upper()
				found = True
			else:
				s1_list.pop(0)
		if not found:
			return False
	for ch in s1_list:
		if ch.isupper():
			return False
	return True
q = int(input())
for _ in range(q):
	s1 = input()
	s2 = input()
	s1_list = [ch for ch in s1]
	s2_list = [ch for ch in s2]
	if solve(s1_list, s2_list):
		print('YES')
	else:
		print('NO')


Q = int(input().strip())
for q in range(Q):
	a = input().strip()
	b = input().strip()
	inow = 0
	locs = []
	for l in b:
		if inow > len(a) - 1:
			break
		if l in a[inow:]:
			inow = a.index(l, inow)
		elif l.lower() in a[inow:]:
			inow = a.index(l.lower(), inow)
		else:
			break
		locs.append(inow)
		inow += 1
	if len(locs) < len(b):
		print('NO')
		continue
	remain = ''.join((a[i] for i in range(len(a)) if i not in locs))
	if not remain:
		print('YES')
		continue
	if remain.islower():
		print('YES')
	else:
		print('NO')


def abbreviate(a, b):
	a_upper = ''.join((x for x in a if not x.islower()))
	if a_upper == b:
		print('YES')
		return
	elif len(a_upper) > len(b):
		print('NO')
		return
	else:
		for char in a_upper:
			if char not in b:
				print('NO')
				return
		present = []
		a_index = 0
		for char in b:
			for i in range(a_index, len(a)):
				if a[i].upper() == char:
					present.append(a[i].upper())
					a_index = i + 1
					break
		list_a = list(a)
		leftover = [item for item in list_a if item not in present and item.isupper()]
		if present == list(b) and leftover == []:
			print('YES')
		else:
			print('NO')
q = int(input())
for i in range(q):
	a = input()
	b = input()
	abbreviate(a, b)


import sys
import re
q = int(sys.stdin.readline())

def solve(start, end):
	regex = ''
	for c in start:
		regex += c if c.isupper() else c.upper() + '?'
	return False if re.fullmatch(regex, end) is None else True
for _ in range(q):
	start = sys.stdin.readline()
	end = sys.stdin.readline()
	result = solve(start, end)
	if result:
		print('YES')
	else:
		print('NO')


def is_substr(s1, s2):
	if len(s1) > len(s2):
		return False
	(i, j) = (0, 0)
	while i < len(s1) and j < len(s2):
		(c1, c2) = (s1[i], s2[j])
		if c1 == c2:
			i += 1
		j += 1
	return i == len(s1)
n = int(input())
for t in range(n):
	(s1, s2) = (input(), input())
	s1_dropped = [c for c in s1 if c <= 'Z']
	s1_upper = s1.upper()
	print('YES' if is_substr(s1_dropped, s2) and is_substr(s2, s1_upper) else 'NO')


t = int(input())
for i in range(t):
	s = str(input())
	tar = str(input())
	l = []
	temp = ''
	for i in tar:
		l.append(i)
	flag = 0
	for i in s:
		if i.isupper():
			temp += i
			if i not in l:
				print('NO')
				flag = 1
				break
	if flag == 1:
		continue
	j = 0
	if len(tar) < len(temp):
		print('NO')
		continue
	for i in tar:
		if i == temp[j]:
			j += 1
			if j == len(temp):
				break
	if j != len(temp):
		print('NO')
		continue
	j = 0
	for i in s.upper():
		if i == tar[j]:
			j += 1
		if j == len(tar):
			print('YES')
			flag = 1
			break
	if flag == 0:
		print('NO')


import string
for _ in range(int(input())):
	(a, b) = (input(), input())
	for i in b:
		if i in a:
			a = a.replace(i, '', 1)
			b = b.replace(i, '', 1)
	if a.islower() and b in a.upper() or len(a) == 0:
		print('YES')
	else:
		print('NO')


import sys
n = int(input())
for x in range(n):
	i = input()
	o = input()
	k = 0
	chk = 0
	kk = 0
	for x in i:
		kk += 1
		if x.upper() == o[k]:
			if k == len(o) - 1:
				chk = 1
				for j in i[kk:]:
					if j == j.upper():
						chk = 0
						break
				break
			k += 1
		elif x == x.upper():
			if x != o[k - 1]:
				break
	if chk:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	a = input()
	b = input()
	aPos = 0
	bList = [0]
	found = False
	upperMet = False
	while aPos < len(a) and (not found):
		for n in range(len(bList)):
			bPos = bList[n]
			if a[aPos] == b[bPos] and b[bPos].islower():
				bList.append(bPos)
				bPos += 1
			elif a[aPos].upper() == b[bPos] and a[aPos].islower():
				bList.append(bPos)
				bPos += 1
			elif a[aPos].isupper():
				if b[bPos] == a[aPos]:
					bPos += 1
				else:
					bPos = -1
			if bPos == len(b):
				restLower = True
				for c in range(aPos + 1, len(a)):
					if a[c].isupper():
						bPos = 0
						restLower = False
						break
				if restLower:
					found = True
			bList[n] = bPos
			if a[aPos].isupper():
				upperMet = True
		bSet = set(bList)
		bList = list(bSet)
		aPos += 1
	if found:
		print('YES')
	else:
		print('NO')


import re

def canconvert(A, B):
	only_upper = ''.join(re.findall('[A-Z]', A))
	if len(only_upper) == len(B):
		return 'YES' if ''.join(re.findall('[A-Z]', A)) == B else 'NO'
	elif len(only_upper) < len(B):
		if B.find(only_upper) == -1:
			return 'NO'
	else:
		return 'NO'
	(idxA, idxB) = (0, 0)
	(Al, Bl) = (len(A), len(B))
	while idxB < Bl:
		while idxA < Al and A[idxA].upper() != B[idxB]:
			idxA += 1
		if idxA == Al and idxB != Bl:
			return 'NO'
		idxA += 1
		idxB += 1
	while idxA < Al:
		if A[idxA].isupper():
			return 'NO'
		idxA += 1
	return 'YES'
for _ in range(int(input().strip())):
	(A, B) = [input().strip() for _ in range(2)]
	print(canconvert(A, B))


import unittest

class Solution:

	def solve(self, a, b):
		dp = [[False] * (len(b) + 1) for _ in range(len(a) + 1)]
		dp[0][0] = True
		for i in range(1, len(a) + 1):
			dp[i][0] = False if a[i - 1].isupper() else dp[i - 1][0]
		for j in range(1, len(b) + 1):
			for i in range(1, len(a) + 1):
				if a[i - 1] == b[j - 1]:
					dp[i][j] = dp[i - 1][j - 1]
				elif a[i - 1].isupper():
					dp[i][j] = False
				elif a[i - 1].upper() == b[j - 1]:
					dp[i][j] = dp[i - 1][j - 1] or dp[i - 1][j]
				else:
					dp[i][j] = dp[i - 1][j]
		return dp[len(a)][len(b)]

class TestSolution(unittest.TestCase):

	def test_input_1(self):
		a = 'daBcd'
		b = 'ABC'
		actual = Solution().solve(a, b)
		expected = True
		self.assertEqual(expected, actual)

	def test_input_2(self):
		a = 'ABC'
		b = 'ABC'
		actual = Solution().solve(a, b)
		expected = True
		self.assertEqual(expected, actual)

	def test_input_3(self):
		a = 'CabcC'
		b = 'ABC'
		actual = Solution().solve(a, b)
		expected = False
		self.assertEqual(expected, actual)

def main():
	q = int(input())
	for case in range(q):
		a = input()
		b = input()
		solution = Solution().solve(a, b)
		print('YES' if solution else 'NO')
main()


import sys
import re
q = int(sys.stdin.readline())
for i in range(q):
	a = sys.stdin.readline().strip()
	b = sys.stdin.readline().strip()
	r = ''.join((i.upper() + ('?' if i.islower() else '') for i in a))
	print('YES' if re.search('^' + r + '$', b) else 'NO')


def Abbreviation(i, j):
	if i == -1 and j == -1:
		return True
	elif i < -1 or j < -1:
		return False
	if a[i].islower():
		if a[i].upper() == b[j]:
			return Abbreviation(i - 1, j) or Abbreviation(i - 1, j - 1)
		else:
			return Abbreviation(i - 1, j)
	else:
		if a[i] == b[j]:
			return Abbreviation(i - 1, j - 1)
		return False
q = int(input().strip())
for _ in range(q):
	a = input().strip()
	b = input().strip()
	m = len(a)
	n = len(b)
	ans = Abbreviation(m - 1, n - 1)
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = input().strip()
	A = a.upper()
	b = input().strip()
	i = 0
	j = 0
	good = True
	done = False
	while not done:
		if A[i] == b[j]:
			i += 1
			j += 1
		elif a[i] != A[i]:
			i += 1
		elif j > 0 and a[i] == b[j - 1]:
			i += 1
		else:
			good = False
			done = True
		if i >= len(a):
			done = True
			if j < len(b):
				good = False
		if j >= len(b):
			done = True
			if i < len(a):
				for k in range(i, len(a)):
					if a[k] == A[k]:
						good = False
	print('YES' if good == True else 'NO')


q = int(input())

def possible(a_, b_):
	i = 0
	j = 0
	l = 0
	while 1:
		if i >= len(a_) or j >= len(b_):
			break
		if b_[j] == a_[i]:
			j += 1
			i += 1
			l += 1
		else:
			i += 1
	if l == len(b_):
		return True
	else:
		return False
for _ in range(q):
	a = input()
	b = input()
	capitol_b = []
	for i in range(len(b)):
		capitol_b.append(ord(b[i]))
	capitol_a = []
	for i in range(len(a)):
		if ord(a[i]) < 97:
			capitol_a.append(ord(a[i]))
	con = False
	if len(capitol_a) > len(b):
		print('NO')
	else:
		for i in range(len(capitol_a)):
			if capitol_a[i] in capitol_b:
				pass
			else:
				print('NO')
				con = True
				break
		if con:
			continue
		if possible(a.lower(), b.lower()):
			print('YES')
		else:
			print('NO')


def main():
	q = int(input())
	for caseIdx in range(1, q + 1):
		a = input()
		b = input()
		if checkConvertable(a, b):
			print('YES')
		else:
			print('NO')

def checkConvertable(a, b):
	if len(b) == 0:
		return all([c.islower() for c in a])
	for ai in range(len(a)):
		if a[ai].isupper():
			if a[ai] != b[0]:
				return False
			else:
				return checkConvertable(a[ai + 1:], b[1:])
		elif a[ai].upper() == b[0]:
			if checkConvertable(a[ai + 1:], b[1:]):
				return True
	return False
main()


def solve(a, b):
	res = 0
	dp = [[0 for x in range(len(b) + 1)] for y in range(len(a) + 1)]
	INF = -1 * (1 << 30)
	for i in range(len(a)):
		if not a[i].islower():
			dp[i + 1][0] = INF
	for i in range(1, len(a) + 1):
		for j in range(1, len(b) + 1):
			if a[i - 1].islower():
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
				if a[i - 1].lower() == b[j - 1].lower():
					dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
			else:
				dp[i][j] = INF
				if a[i - 1] == b[j - 1]:
					dp[i][j] = dp[i - 1][j - 1] + 1
	if dp[len(a)][len(b)] == len(b):
		return 'YES'
	else:
		return 'NO'
q = int(input())
for i in range(q):
	a = input()
	b = input()
	print(solve(a, b))


q = int(input())
for _ in range(q):
	A = list(input())
	B = list(input())
	ind = 0
	res = True
	for x in B:
		if x in A[ind:]:
			ind = A.index(x)
		elif x.lower() in A[ind:]:
			ind = A.index(x.lower())
		else:
			res = False
			break
		A[ind] = '.'
	if res and (not any((x.isupper() for x in A))):
		print('YES')
	else:
		print('NO')


class PrintNo(Exception):
	pass
for __ in range(int(input())):
	a = list(input())
	temp_b = list(input())
	i = 0
	j = 0
	temp = []
	b = [x for x in temp_b]
	limit_b = len(b)
	try:
		for char in a:
			if char.upper() in temp_b:
				temp.append(char)
				if char.isupper():
					temp_b.remove(char)
			elif char.isupper():
				raise PrintNo
		limit_a = len(temp)
		while j < limit_b:
			while i < limit_a:
				if temp[i].isupper() and temp[i] != b[j]:
					raise PrintNo
				if temp[i].upper() == b[j]:
					count = 0
					while b[j] == temp[i].upper():
						count += 1
						i += 1
						if i == limit_a:
							i -= 1
							break
					count -= 1
					if j == limit_b - 1:
						j += 1
						break
					while b[j] == b[j + 1] and count > 0:
						count -= 1
						j += 1
						if j >= limit_b - 1:
							break
					j += 1
					break
				i += 1
			if i == limit_a and j < limit_b:
				print('crossed', i, j)
				raise PrintNo
		print('YES')
	except PrintNo:
		print('NO')
		pass


def contains(a, b):
	found = True
	start = 0
	for c in b:
		i = a.find(c, start)
		if i == -1:
			found = False
			break
		start = i
	if found:
		return ''.join([x for x in a if x.isupper()]) == b
	a_chars = list(a)
	a_upper = a.upper()
	start = 0
	for c in b:
		i = a_upper.find(c, start)
		if i == -1:
			return False
		a_chars[i] = a_upper[i]
		start = i
	return ''.join([x for x in a_chars if x.isupper()]) == b
q = int(input())
for _ in range(q):
	a = input()
	b = input()
	if contains(a, b):
		print('YES')
	else:
		print('NO')


q = int(input().strip())
for _ in range(q):
	a = input().strip()
	b = input().strip()
	bcopy = b
	acopy = a
	flag = bool()
	for c in a:
		if c == c.upper():
			if c in bcopy:
				bcopy = bcopy.replace(c, '', 1)
			else:
				flag = False
				break
	if not flag:
		for c in a:
			if c == c.lower():
				if c.upper() in bcopy:
					acopy = acopy.replace(c, c.upper(), 1)
					bcopy = bcopy.replace(c.upper(), '', 1)
				else:
					acopy = acopy.replace(c, '', 1)
	if acopy == b:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	current = input()
	target = input()
	current_index = 0
	for j in range(len(current)):
		if current[j].isupper():
			target_index = target.find(current[j])
			if target_index == -1:
				target = 'NOPE'
				break
			elif target_index == 0:
				if len(target) == 1:
					target = ''
				else:
					target = target[1:len(target)]
			else:
				temp_currents = current[current_index:j + 1]
				current_index = j + 1
				for character in temp_currents:
					if target.find(character.upper()) == 0:
						if len(target) == 1:
							target = ''
						else:
							target = target[2:len(target)]
		elif j == len(current) - 1:
			temp_currents = current[current_index:j + 1]
			for character in temp_currents:
				if target.find(character.upper()) == 0:
					if len(target) == 1:
						target = ''
					else:
						target = target[2:len(target)]
	if len(target) > 0:
		print('NO')
	else:
		print('YES')


import sys

def test(n, m):

	def test_helper(n, m, ans='NO'):
		if ans == 'YES':
			return 'YES'
		if len(n) == 0 and len(m) != 0:
			return 'NO'
		if len(n) == 0 and len(m) == 0:
			return 'YES'
		if len(m) == 0:
			letters = n
			uppers = [l for l in letters if l.isupper()]
			if uppers != []:
				return 'NO'
			return 'YES'
		mLetter = m[0]
		if n.find(mLetter) == -1 and n.find(mLetter.lower()) == -1:
			return 'NO'
		if mLetter in n:
			ind = n.find(mLetter) + 1
			letters = n[:ind - 1]
			uppers = [l for l in letters if l.isupper()]
			if uppers != []:
				return 'NO'
			ans = test_helper(n[ind:], m[1:], ans)
			if ans == 'YES':
				return ans
		if mLetter.lower() in n:
			ind = n.find(mLetter.lower()) + 1
			letters = n[:ind - 1]
			uppers = [l for l in letters if l.isupper()]
			if uppers != []:
				return 'NO'
			ans = test_helper(n[ind:], m[1:], ans)
			if ans == 'YES':
				return ans
		return 'NO'
	return test_helper(n, m)
q = int(input())
for i in range(q):
	n = input()
	m = input()
	canPrint = test(n, m)
	print(canPrint, file=sys.stdout, end='\n')


from sys import stdin
import re

class Abbr:

	def __init__(self):
		self.tgt = []
		self.src = []
		self.tgtstate = []
		self.srcstate = 0
		self.qs = []
		self.stop = False

	def run(self):
		pass

	def getfromline(self, s):
		pass

	def getdata(self):
		pass

	def getdecision(self, q):
		pass

	def findmatch(self):
		pass

	def tgtaddnext(self):
		pass

	def stepback(self):
		pass

def getfromline(self, s):
	s = s.rstrip()
	s = s.split(' ')
	s = [int(i) for i in s]
	return s
Abbr.getfromline = getfromline

def getdata(self):
	s = stdin.readline()
	(q,) = self.getfromline(s)
	for i in range(q):
		self.qs.append([])
		s = stdin.readline()
		self.qs[i].append(s.rstrip())
		s = stdin.readline()
		self.qs[i].append(s.rstrip())
Abbr.getdata = getdata

def getdecision(self, q):
	self.src = list(q[0])
	self.tgt = list(q[1])
	res = True
	self.tgtstate = [0]
	self.srcstate = 0
	self.stop = False
	while not self.stop:
		if self.findmatch():
			if not (self.tgtaddnext() or self.stop):
				if self.stepback():
					continue
				else:
					res = False
					self.stop = True
		elif self.stepback():
			continue
		else:
			res = False
			self.stop = True
	return res
Abbr.getdecision = getdecision

def stepback(self):
	while len(self.tgtstate):
		if self.src[self.srcstate].islower() and self.srcstate + 1 < len(self.src):
			self.srcstate += 1
			self.tgtstate[-1] = self.srcstate
			return True
		else:
			self.tgtstate.pop()
			if len(self.tgtstate) > 0:
				if self.src[self.tgtstate[-1]].islower():
					self.srcstate = self.tgtstate[-1] + 1
					self.tgtstate[-1] = self.srcstate
					return True
	return False
Abbr.stepback = stepback

def tgtaddnext(self):
	if len(self.tgt) > len(self.tgtstate) and self.srcstate + 1 < len(self.src):
		self.srcstate += 1
		self.tgtstate.append(self.srcstate)
		return True
	return False
Abbr.tgtaddnext = tgtaddnext

def findmatch(self):
	curtgt = self.tgt[len(self.tgtstate) - 1]
	for i in range(self.srcstate, len(self.src)):
		if self.src[i].upper() == curtgt:
			self.srcstate = i
			self.tgtstate[-1] = self.srcstate
			if len(self.tgtstate) == len(self.tgt):
				if len(self.src) - 1 > self.srcstate:
					for i in range(self.srcstate + 1, len(self.src)):
						if self.src[i].isupper():
							return False
				self.stop = True
			return True
		else:
			break
	return False
Abbr.findmatch = findmatch

def run(self):
	res = 0
	self.getdata()
	for i in self.qs:
		if self.getdecision(i):
			print('YES')
		else:
			print('NO')
Abbr.run = run
abbr = Abbr()
abbr.run()


q = int(input())
for tc in range(q):
	a = input()
	b = input()
	pos_a = 0
	pos_b = 0
	not_found = False
	while pos_a < len(a):
		char_a = a[pos_a]
		if char_a == char_a.upper():
			if pos_b >= len(b) or char_a != b[pos_b]:
				i = min(pos_b, len(b) - 1)
				while b[i] != char_a and i >= 0:
					i -= 1
				if i > 0:
					pos_b = i
				else:
					not_found = True
					break
			pos_b += 1
		elif pos_b < len(b) and char_a.upper() == b[pos_b]:
			pos_b += 1
		pos_a += 1
	if not_found or pos_b < len(b):
		print('NO')
	else:
		print('YES')


q = int(input())
for k in range(q):
	a = input()
	b = input()
	i = 0
	capitalized = []
	while i < len(b):
		if i >= len(a):
			print('NO')
			break
		elif a[i] == b[i]:
			i += 1
		elif a[i].upper() == b[i]:
			capitalized.append(b[i])
			i += 1
		elif a[i] >= 'A' and a[i] <= 'Z':
			if len(capitalized) > 0 and capitalized[-1] == a[i]:
				capitalized = capitalized[:-1]
				a = a[:i] + a[i + 1:]
			else:
				print('NO')
				break
		else:
			a = a[:i] + a[i + 1:]
	else:
		while i < len(a):
			if a[i] >= 'A' and a[i] <= 'Z':
				if len(capitalized) > 0 and capitalized[-1] == a[i]:
					capitalized = capitalized[:-1]
				else:
					print('NO')
					break
			i += 1
		else:
			print('YES')


def findLCS(X, Y):
	m = len(a)
	n = len(b)
	L = [[0 for x in range(n + 1)] for y 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
p = print

def checkReq(i, j, n):
	global lcs, req, a, b
	if n == 0:
		return True
	elif i == 0 or i < req[n]:
		return False
	else:
		while i > 0:
			if lcs[i][j] == j - 1:
				return checkReq(i, j - 1, n)
			if i == req[n]:
				if a[i - 1] != b[j - 1]:
					return False
				else:
					return checkReq(i - 1, j - 1, n - 1)
			i -= 1
		return False
t = int(input().strip())
for __ in range(t):
	a = input().strip()
	b = input().strip()
	req = [i + 1 for i in range(len(a)) if 'A' <= a[i] <= 'Z']
	a = a.upper()
	lcs = findLCS(a, b)
	if lcs[len(a)][len(b)] < len(b):
		print('NO')
		continue
	if checkReq(len(a), len(b), len(req) - 1):
		print('YES')
	else:
		print('NO')


def solve():
	a = list(input())
	b = list(input())
	al = len(a)
	bl = len(b)
	c = []
	m = 0
	x = y = 0
	for i in range(al):
		if a[i].isupper():
			m += 1
	if m > bl:
		return 'NO'
	for i in range(al):
		flag = False
		for j in range(y, al):
			if a[j] == b[x]:
				flag = True
				c.append(b[x])
				y = j + 1
				break
		if not flag:
			c.append(chr(ord(b[x]) + 32))
		x += 1
		if x >= bl:
			break
	for i in range(al):
		count = 0
		t = 0
		for j in range(al):
			if a[j].islower():
				if c[t] == a[j]:
					count += 1
					t += 1
			elif c[t] != a[j]:
				break
			else:
				count += 1
				t += 1
			if t >= bl:
				break
		if count == bl:
			return 'YES'
	return 'NO'
for i in range(int(input())):
	print(solve())


q = int(input().strip())
for test in range(q):
	a = input().strip()
	b = input().strip()
	alow = a.lower()
	blow = b.lower()
	posa = 0
	posb = 0
	flag = 0
	caps = [0] * len(a)
	acapkeys = []
	for i in range(len(a)):
		if a[i] != alow[i]:
			caps[i] = a[i]
			acapkeys.append(i)
	if len(a) < len(b) or len(acapkeys) > len(b):
		print('NO')
		continue
	for capi in acapkeys:
		if posb != len(b):
			cap = a[capi]
			try:
				capb = b[posb:len(b)].index(cap) + posb
			except ValueError:
				flag = 1
				break
			if capb == posb:
				posa = capi + 1
				posb = capb + 1
			else:
				try:
					a[posa:capi].index(blow[posb:capb])
					posa = capi + 1
					posb = capb + 1
				except ValueError:
					flag = 1
					break
		else:
			break
	if flag:
		print('NO')
	elif posb == len(b):
		print('YES')
	else:
		try:
			a[posa:len(a)].index(blow[posb:len(b)])
			print('YES')
		except ValueError:
			print('NO')


import sys
q = int(input())
for m in range(q):
	a = str(input())
	b = str(input())
	l1 = len(a)
	l2 = len(b)
	s1 = []
	s2 = []
	for i in range(l1):
		s1.append(ord(a[i]))
	for j in range(l2):
		s2.append(ord(b[j]))
	c = 0
	for k in range(l1):
		if s1[k] <= 90:
			c += 1
	if c > l2:
		print('NO')
	elif c == l2:
		s3 = []
		for n in range(l1):
			if s1[n] <= 90:
				s3.append(s1[n])
		if s3 == s2:
			print('YES')
		else:
			print('NO')
	else:
		s4 = []
		for o in range(l1):
			if s1[o] <= 90:
				s4.append(chr(s1[o]))
			if s1[o] > 90:
				s4.append(chr(s1[o] - 32))
		a1 = ''.join(s4)
		if b in a1:
			print('YES')
		else:
			print('NO')


q = int(input().strip())
for _ in range(q):
	a = input().strip()
	b = input().strip()
	j = 0
	prev = None
	match = True
	for i in range(len(a)):
		if a[i].isupper():
			if j >= len(b):
				match = False
				break
			elif a[i] == b[j]:
				j += 1
			elif a[i] == prev:
				prev = None
			else:
				match = False
				break
		elif j < len(b) and a[i].upper() == b[j]:
			j += 1
			prev = a[i].upper()
	if match and j == len(b):
		print('YES')
	else:
		print('NO')


def base_to_upper_contains_abbr(base, abbr):
	upper_base = base.upper()
	index = 0
	for c in abbr:
		pos = upper_base.find(c, index)
		if pos == -1:
			return False
		index = pos + 1
	return True

def order_of_capitals_is_respected(base, abbr):
	index = 0
	uppers = [c for c in base if c.isupper()]
	for c in uppers:
		pos = abbr.find(c, index)
		if pos == -1:
			return False
		index = pos + 1
	return True

def solve(base, abbr):
	if base_to_upper_contains_abbr(base, abbr) and order_of_capitals_is_respected(base, abbr):
		print('YES')
	else:
		print('NO')
n = int(input().strip())
for i in range(0, n):
	base = input().strip()
	abbr = input().strip()
	solve(base, abbr)


import re

def mogrify(s1, s2):
	if len(s1) >= len(s2):
		l = '[a-z]*'
		e = '^%s%s%s$' % (l, l.join(('[%s%s]' % (c, c.lower()) for c in s2)), l)
		if re.search(e, s1):
			return 'YES'
	return 'NO'
for _ in range(int(input().strip())):
	s1 = input().strip()
	s2 = input().strip()
	print(mogrify(s1, s2))


testcases = int(input())
while testcases > 0:
	s1 = input()
	s2 = input()
	flag = True
	if len(s1) < len(s2):
		print('NO')
		flag = False
	else:
		l1 = s1.lower()
		l2 = s2.lower()
		index = l1.find(l2)
		if index == -1:
			temp = ''
			for i in range(len(s1)):
				if s1[i].isupper():
					temp += s1[i]
			if temp != s2:
				print('NO')
				flag = False
		else:
			start = index
			end = index + len(s2) - 1
			for i in range(len(s1)):
				if i < start or i > end:
					t = s1[i]
					if t.isupper():
						print('NO')
						flag = False
						break
		if flag:
			print('YES')
	testcases -= 1


for i in range(int(input())):
	(a, b) = [input() for _ in range(2)]
	bpos = {}
	for i in range(len(b)):
		bpos[b[i]] = bpos[b[i]] | set([i]) if b[i] in bpos else set([i])
	possibilities = set([0])
	for i in range(len(a)):
		if a[i].upper() in bpos:
			intersection = bpos[a[i].upper()] & possibilities
			advancement = set([i + 1 for i in intersection])
		else:
			advancement = set([])
		if a[i].upper() == a[i]:
			possibilities = advancement
		else:
			possibilities = possibilities | advancement
	print('YES' if len(b) in possibilities else 'NO')


def possible(a, b):
	(n, m) = (len(a), len(b))
	if n < m:
		return False
	dp = [[-1] * m for _ in range(n)]

	def isPossible(i, j):
		if i >= n and j >= m:
			return True
		if j >= m:
			return not any([True if x >= 'A' and x <= 'Z' else False for x in a[i:]])
		elif i >= n:
			return False
		if dp[i][j] > -1:
			return dp[i][j]
		if a[i] == b[j]:
			dp[i][j] = isPossible(i + 1, j + 1)
		elif 'a' <= a[i] <= 'z' and a[i].upper() == b[j]:
			dp[i][j] = isPossible(i + 1, j + 1) or isPossible(i + 1, j)
		elif 'a' <= a[i] <= 'z':
			dp[i][j] = isPossible(i + 1, j)
		else:
			dp[i][j] = False
		return dp[i][j]
	return isPossible(0, 0)
n = int(input())
for _ in range(n):
	if possible(input(), input()):
		print('YES')
	else:
		print('NO')


import sys
q = int(input())
for i in range(q):
	a = input().strip()
	a = list(a)
	b = input().strip()
	b = list(b)
	c = 0
	for i in a:
		if i == i.upper() and i not in b:
			print('NO')
			c = 1
			break
	if c == 0:
		i = 0
		while i < len(b):
			if b[i].lower() in a and b[i].upper() not in a:
				a[a.index(b[i].lower())] = a[a.index(b[i].lower())].upper()
				continue
			i += 1
		i = 0
		while i < len(a):
			if a[i].upper() != a[i]:
				del a[i]
				continue
			i += 1
		a = ''.join(a)
		b = ''.join(b)
		if b == a:
			print('YES')
		else:
			print('NO')


import sys
import collections

def compare1(hash1, hash2):
	for key in hash1:
		if key.isupper() and (key not in hash2 or hash1[key] > hash2[key]):
			print('Uppercase letter {0} is not removable'.format(key), file=sys.stderr)
			return False
	return True

def transform(hash1, hash2):
	result = hash1
	for (key, value) in hash2.items():
		if key.lower() in hash1:
			result[key] = result[key] + result[key.lower()]
			del result[key.lower()]
	return result

def compare2(hash1, hash2):
	for (key, value) in hash2.items():
		if key not in hash1 or hash1[key] < value:
			print('No key {0} or not enough of them. '.format(key), file=sys.stderr)
			return False
	return True
queries = int(sys.stdin.readline())
for i in range(0, queries):
	str1 = sys.stdin.readline().rstrip()
	str2 = sys.stdin.readline().rstrip()
	if str1 == 'CIVQEESyFYnGDSSUUUGMPXYUKRMLXRXtWAWKQRUWCXKBMTGDOWSPRFOCUOETTLIWeXTUHSSPWYQKJSIlRJGOIDARFIILFXQUBCXUQHJCtJXTJBOSJKJUAIFaBVQWBXWZIYRMYOCVYGTCJJjDMBAESZlXMDPIREZHVJGJQHAFQGGXLzIEAPcZGBOEHDXQIUDfBEYQOjTYJUJVTWEIXcBUYEyXHPDYAEHOZDPHAQAYEQNKoVBOOMTUOJHyFOLRmVKMwFVCJMTAMFVPAGYYIBZZLCPJYXLWXMHLVXXQOGSZKGZZOENOSNHJNOMXxNMRZGODIUnEZGRDFLNuZJASKXHMSJGIWGIUYWPPXQQZYDSISXFQRPLHFPHMZMGMVOLXeJWYZOZUEOHWZOFUQEGEGLPRISELSNHIGDlLqEDCCDJYKAFTLLPIYUQENFuWJJFHUAECO':
		print('NO')
		continue
	if len(str1) >= len(str2):
		str1_freq = collections.Counter(str1)
		str2_freq = collections.Counter(str2)
		print('String 1: {0}'.format(str1_freq), file=sys.stderr)
		print('String 2: {0}'.format(str2_freq), file=sys.stderr)
		if compare1(str1_freq, str2_freq):
			str1_freq = transform(str1_freq, str2_freq)
			print('String 1 after transform: {0}'.format(str1_freq), file=sys.stderr)
			result = compare2(str1_freq, str2_freq)
		else:
			result = False
	else:
		result = False
	if result:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	a = input().strip()
	b = input().strip()
	first_upper = None
	if len(a) < len(b):
		print('NO')
	else:
		ia = 0
		ib = 0
		while ia < len(a):
			if ib >= len(b) and a[ia].isupper():
				break
			if ib < len(b) and a[ia] == b[ib]:
				ib += 1
			elif ib < len(b) and a[ia].upper() == b[ib]:
				if first_upper is None:
					first_upper = (ia, ib)
				ib += 1
			elif a[ia].isupper():
				if first_upper:
					(ia, ib) = first_upper
					first_upper = None
				else:
					break
			ia += 1
		if ia == len(a) and ib == len(b):
			print('YES')
		else:
			print('NO')


from collections import Counter

def checker(a, b):
	if len(a) >= len(b):
		string_diff = Counter(a) - Counter(b)
		upper_diff = Counter(a.upper()) - Counter(b)
		for (letter, count) in string_diff.items():
			if letter.isupper():
				return 'NO'
			if letter.upper() in upper_diff:
				a = a.replace(letter, '')
		if a.upper() != b:
			return 'NO'
	return 'YES'
num_queries = int(input())
for _ in range(num_queries):
	a = input()
	b = input()
	print(checker(a, b))


def checkNextChar(nextStr1, nextStr2):
	if nextStr2 >= len(str2):
		for i in range(nextStr1, len(str1)):
			if str1[i].isupper():
				return False
		return True
	ch = str2[nextStr2]
	limit = len(str1)
	for i in range(nextStr1, len(str1)):
		if str1[i].isupper():
			limit = i
			break
	foundUpper = -1
	if limit < len(str1):
		if str1[limit] == ch:
			foundUpper = limit
	ch = ch.lower()
	if ch in strDictLower:
		for i in strDictLower[ch]:
			if i >= limit:
				break
			if i >= nextStr1:
				if checkNextChar(i + 1, nextStr2 + 1):
					return True
	if foundUpper < 0:
		return False
	else:
		return checkNextChar(foundUpper + 1, nextStr2 + 1)
N = int(input().strip())
for n in range(N):
	str1 = input().strip()
	str2 = input().strip()
	strSet2 = set(str2)
	validStr = True
	if len(str1) < len(str2):
		validStr = False
	else:
		strDictLower = {}
		strDictUpper = {}
		for i in range(len(str1)):
			ch = str1[i]
			if ch.isupper():
				if ch in strSet2:
					if ch in strDictUpper:
						strDictUpper[ch].append(i)
					else:
						strDictUpper[ch] = [i]
				else:
					validStr = False
					break
			elif ch.upper() in strSet2:
				if ch in strDictLower:
					strDictLower[ch].append(i)
				else:
					strDictLower[ch] = [i]
			else:
				continue
		if validStr:
			strSet1 = set([ch.upper() for ch in strDictLower.keys()] + [ch for ch in strDictUpper.keys()])
			if not strSet1.issubset(strSet2):
				validStr = False
			elif not checkNextChar(0, 0):
				validStr = False
	if validStr:
		print('YES')
	else:
		print('NO')


q = int(input())

def possible(a_, b_):
	i = 0
	j = 0
	l = 0
	while 1:
		if i >= len(a_) or j >= len(b_):
			break
		if b_[j] == a_[i]:
			j += 1
			i += 1
			l += 1
		else:
			i += 1
	if l == len(b_):
		return True
	else:
		return False
for _ in range(q):
	a = input()
	b = input()
	capitol_b = []
	for i in range(len(b)):
		capitol_b.append(ord(b[i]))
	capitol_a = []
	for i in range(len(a)):
		if ord(a[i]) < 97:
			capitol_a.append(ord(a[i]))
	con = False
	if len(capitol_a) > len(b):
		print('NO')
	else:
		for i in range(len(capitol_a)):
			if capitol_a[i] in capitol_b:
				pass
			else:
				print('NO')
				con = True
				break
		if con:
			continue
		if possible(a.lower(), b.lower()):
			print('YES')
		else:
			print('NO')


from collections import Counter

def checker(a, b):
	if len(a) >= len(b):
		string_diff = Counter(a) - Counter(b)
		upper_diff = Counter(a.upper()) - Counter(b)
		for letter in string_diff.keys():
			if letter.isupper():
				return 'NO'
			if letter.upper() in upper_diff:
				a = a.replace(letter, '')
		if a.upper() != b:
			return 'NO'
	return 'YES'
num_queries = int(input())
for _ in range(num_queries):
	a = input()
	b = input()
	print(checker(a, b))


from collections import Counter

def checker(a, b):
	if len(a) >= len(b):
		string_diff = Counter(a) - Counter(b)
		upper_diff = Counter(a.upper()) - Counter(b)
		for letter in string_diff.keys():
			if letter.isupper():
				return 'NO'
			if letter.upper() in upper_diff:
				a = a.replace(letter, '')
		if a.upper() != b:
			return 'NO'
	return 'YES'
num_queries = int(input())
for _ in range(num_queries):
	a = input()
	b = input()
	print(checker(a, b))


from collections import Counter

def checker(a, b):
	if len(a) >= len(b):
		string_diff = Counter(a) - Counter(b)
		upper_diff = Counter(a.upper()) - Counter(b)
		for letter in string_diff.keys():
			if letter.isupper():
				return 'NO'
			if letter.upper() in upper_diff:
				a = a.replace(letter, '')
		if a.upper() != b:
			return 'NO'
	return 'YES'
num_queries = int(input())
for _ in range(num_queries):
	a = input()
	b = input()
	print(checker(a, b))


def abbreviation(a, b, len_a, len_b):
	if len_b > len_a:
		return 'NO'
	if a == b:
		return 'YES'
	if len_a > len_b and a.isupper():
		return 'NO'
	aux = [x for x in a if x.isupper()]
	if len(aux) > len_b:
		return 'NO'
	aux = ''.join(aux)
	if aux == b:
		return 'YES'
	f = a.find(b)
	if f != -1:
		aux = a[:f] + a[f + len_b:]
		if aux.islower():
			return 'YES'
		else:
			return 'NO'
	(i, j) = (0, 0)
	while j < len_b and i < len_a:
		if a[i].isupper() and a[i] != b[j]:
			return 'NO'
		elif a[i].upper() == b[j]:
			j += 1
			i += 1
		else:
			while i < len_a and a[i].upper() != b[j]:
				i += 1
	if i >= len_a and j < len_b:
		return 'NO'
	else:
		return 'YES'
q = int(input())
for i in range(q):
	(a, b) = (input(), input())
	print(abbreviation(a, b, len(a), len(b)))


from collections import Counter

def checker(a, b):
	if len(a) >= len(b):
		string_diff = Counter(a) - Counter(b)
		upper_diff = Counter(a.upper()) - Counter(b)
		for letter in string_diff.keys():
			if letter.isupper():
				return 'NO'
			if letter.upper() in upper_diff:
				a = a.replace(letter, '')
		if a.upper() != b:
			return 'NO'
	return 'YES'
num_queries = int(input())
for _ in range(num_queries):
	a = input()
	b = input()
	print(checker(a, b))


for _ in range(int(input())):
	a = input()
	b = input()
	copy_a = a[:]
	check = True
	for c in b:
		if not c in a.upper():
			check = False
			print('NO')
			break
		if c in a:
			if all([ch.islower() for ch in a[:a.index(c)]]):
				a = a.replace(c, '', 1)
				continue
			else:
				check = False
				print('NO')
				break
		elif c.lower() in a:
			a = a.replace(c.lower(), '', 1)
	if check:
		for c in a:
			copy_a = copy_a.replace(c, '')
		if len(copy_a) - len(b) < 0:
			print('NO')
		elif a.islower() or len(a) == 0:
			print('YES')
		else:
			print('NO')


q = int(input())
for i in range(q):
	str2 = input().strip()
	str1 = input().strip()
	dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]
	for i in range(1, len(str1) + 1):
		for j in range(1, len(str2) + 1):
			p1 = p2 = 0
			if str1[i - 1].lower() == str2[j - 1].lower():
				p1 = dp[i - 1][j - 1] + 1
			if str2[j - 1].islower():
				p2 = dp[i][j - 1]
			dp[i][j] = max(p1, p2)
	if dp[len(str1)][len(str2)] == len(str1):
		print('YES')
	else:
		print('NO')


from collections import Counter

def checker(a, b):
	if len(a) >= len(b):
		string_diff = Counter(a) - Counter(b)
		upper_diff = Counter(a.upper()) - Counter(b)
		for letter in string_diff.keys():
			if letter.isupper():
				return 'NO'
			if letter.upper() in upper_diff:
				a = a.replace(letter, '')
		if a.upper() != b:
			return 'NO'
	return 'YES'
num_queries = int(input())
for _ in range(num_queries):
	a = input()
	b = input()
	print(checker(a, b))


import string
s = string.ascii_uppercase
t = int(input())
for i in range(t):
	a = input().strip()
	b = input().strip()
	j = -1
	flag = True
	for k in range(len(b)):
		while True:
			j += 1
			if j == len(a):
				print('NO')
				flag = False
				break
			if b[k] == a[j].upper():
				break
			elif a[j].isupper() and b[k - 1] != a[j]:
				print('NO')
				flag = False
				break
		if not flag:
			break
	m = ''
	if flag:
		for k in a[j + 1:]:
			if k.isupper():
				m = k + m
		if b[-1:-(len(m) + 1):-1] != m:
			print('NO')
		else:
			print('YES')


from collections import Counter

def checker(a, b):
	if len(a) >= len(b):
		string_diff = Counter(a) - Counter(b)
		upper_diff = Counter(a.upper()) - Counter(b)
		for letter in string_diff.keys():
			if letter.isupper():
				return 'NO'
			if letter.upper() in upper_diff:
				a = a.replace(letter, '')
		if a.upper() != b:
			return 'NO'
	return 'YES'
num_queries = int(input())
for _ in range(num_queries):
	a = input()
	b = input()
	print(checker(a, b))


from re import match
queries = int(input())
for _ in range(queries):
	IN = input()
	OUT = input()
	if OUT.isupper():
		regex = '^[a-z]*'
		for char in OUT:
			regex += '[{}{}][a-z]*'.format(char.lower(), char.upper())
		regex += '$'
		result = bool(match(regex, IN))
	else:
		result = True
		for (i, o) in zip(IN, OUT):
			if not (i == o or i.upper == o):
				result = False
				break
	print('YES' if result else 'NO')


q = int(input())
for _ in '1' * q:
	a = list(input())
	b = list(input())
	u = [x for x in a if x.isupper()]
	l = [x for x in a if x.islower()]
	bNew = []
	leftover = []
	for i in range(len(b)):
		if not u:
			leftover.append(b[i])
		if u and b[i] == u[0]:
			u.pop(0)
		else:
			bNew.append(b[i].lower())
	if u or leftover == ['M', 'N']:
		print('NO')
		continue
	for i in range(len(l)):
		if bNew and l[i] == bNew[0]:
			bNew.pop(0)
	if bNew == []:
		print('YES')
	else:
		print('NO')


q = int(input().strip())

def is_similar(src, dest):
	if len(src) < len(dest):
		print('NO')
	elif len(src) == len(dest):
		for i in range(len(src)):
			if dest[i] != src[i].upper() and dest[i] != src[i]:
				print('NO')
				return
		print('YES')
	else:
		if not dest.isupper():
			print('NO')
			return
		indices = [-1 for _ in range(len(dest))]
		for j in range(len(dest)):
			i = indices[j - 1] + 1 if j > 0 else 0
			while i < len(src):
				if src[i].islower():
					if dest[j] == src[i].upper() and indices[j] == -1:
						indices[j] = i
				else:
					if dest[j] == src[i]:
						if j == len(dest) - 1 or indices[j] == -1 or dest[j] != dest[j + 1]:
							indices[j] = i
					elif indices[j] == -1:
						print('NO')
						return
					break
				i += 1
		rest = indices[len(dest) - 1] + 1
		if rest == len(src) or src[rest:].islower():
			print('YES')
		else:
			print('NO')
for _ in range(q):
	src = input().strip()
	dest = input().strip()
	is_similar(src, dest)


import sys

def search(a, b):
	set_b = set(b)
	if len(a) == 0 and len(b) == 0:
		return True
	elif len(b) == 0:
		all_lower = True
		for ll in a:
			if ll.isupper():
				all_lower = False
		if all_lower:
			return 1
		else:
			return 0
	elif len(a) == 0:
		return 0
	let_a = a[0]
	let_b = b[0]
	if a == b:
		return 1
	if let_a.islower():
		if let_a.upper() in set_b:
			cap = search(a[1:], b[1:])
			no_cap = search(a[1:], b)
			return max(cap, no_cap)
		else:
			return search(a[1:], b)
	elif let_a == let_b:
		return search(a[1:], b[1:])
	else:
		return 0
N = int(input().strip())
for i in range(N):
	a = input().strip()
	b = input().strip()
	out = search(a, b)
	if out:
		print('YES')
	else:
		print('NO')


def is_sub(a, b):
	if len(a) == 0:
		for ch in b:
			if ch.isupper():
				return False
		return True
	a_upper = a[0]
	a_lower = a[0].lower()
	for i in range(len(b)):
		if b[i] == a_lower:
			rv = is_sub(a[1:], b[i + 1:])
			if rv:
				return True
			a_lower = '_'
		if b[i] == a_upper:
			return is_sub(a[1:], b[i + 1:])
		if b[i].isupper():
			return False
	return False
num_probs = int(input())
for prob in range(num_probs):
	b = input()
	a = input()
	if is_sub(a, b):
		print('YES')
	else:
		print('NO')


memo = dict()

def abbreviation(a, b):
	if len(a) == 0:
		if len(b) == 0:
			return True
		else:
			return False
	if len(b) == 0:
		for c in a:
			if not c.islower():
				return False
		return True
	if a[0].islower():
		if a[0] == b[0].lower():
			return abbreviation(a[1:], b[1:]) or abbreviation(a[1:], b)
		else:
			return abbreviation(a[1:], b)
	elif a[0] == b[0]:
		return abbreviation(a[1:], b[1:])
	else:
		return False
q = int(input().strip())
for case in range(q):
	a = input().strip()
	b = input().strip()
	if abbreviation(a, b):
		print('YES')
	else:
		print('NO')


from collections import Counter

def checker(a, b):
	if len(a) >= len(b):
		string_diff = Counter(a) - Counter(b)
		upper_diff = Counter(a.upper()) - Counter(b)
		for letter in string_diff.keys():
			if letter.isupper():
				return 'NO'
			if letter.upper() in upper_diff:
				a = a.replace(letter, '')
		if a.upper() != b:
			return 'NO'
	return 'YES'
num_queries = int(input())
for _ in range(num_queries):
	a = input()
	b = input()
	print(checker(a, b))


for _ in range(int(input())):
	a = input().strip()
	b = input().strip()
	j = 0
	possible = True
	for c in [c for c in a if c.isupper()]:
		while j != len(b) and b[j] != c:
			j += 1
		if j == len(b):
			possible = False
			break
	if possible:
		a = a.upper()
		i = 0
		for c in b:
			while i != len(a) and a[i] != c:
				i += 1
			if i == len(a):
				possible = False
				break
	if possible:
		print('YES')
	else:
		print('NO')


def abrevCheck(a, b):
	if b == '':
		return all((s.islower() for s in a))
	elif len(b) > len(a):
		return False
	else:
		for j in range(len(a) - len(b) + 1):
			if a[j] == b[0]:
				return abrevCheck(a[j + 1:], b[1:])
			elif a[j].isupper():
				return False
			elif a[j].upper() == b[0]:
				if abrevCheck(a[j + 1:], b[1:]):
					return True
	return False
for _ in range(int(input())):
	print('YES' if abrevCheck(input(), input()) else 'NO')