Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).

For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".

Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.

For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.

You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 10^5$) — the number of pairs to check. Further input contains $n$ descriptions of pairs.

The first line of each description contains a single non-empty word $s$ consisting of lowercase Latin letters. The second line of the description contains a single non-empty word $t$ consisting of lowercase Latin letters. The lengths of both strings are not greater than $10^6$.

It is guaranteed that the total length of all words $s$ in the input is not greater than $10^6$. Also, it is guaranteed that the total length of all words $t$ in the input is not greater than $10^6$.


-----Output-----

Output $n$ lines. In the $i$-th line for the $i$-th pair of words $s$ and $t$ print YES if the word $t$ could be printed by typing the word $s$. Otherwise, print NO.


-----Examples-----
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo

Output
YES
YES
NO
NO

Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz

Output
NO
NO
YES
NO
NO

Difficulty: EASY
Tags: String algorithms

Implementation

Starter code:

Solutions:
def solve(a, b):
	i = 0
	for j in range(len(b)):
		if j and i < len(a) - 1 and (a[i + 1] == b[j]):
			i += 1
		elif b[j] != a[i]:
			return False
	return i == len(a) - 1
t = int(input())
for _ in range(t):
	a = input()
	b = input()
	print('YES' if solve(a, b) else 'NO')


import sys
from collections import Counter
from itertools import zip_longest

def countergenerator(word):
	count = 1
	n = len(word)
	for i in range(1, n):
		if word[i] != word[i - 1]:
			yield (word[i - 1], count)
			count = 1
		else:
			count += 1
	yield (word[n - 1], count)
n = int(sys.stdin.readline().strip())
for pairnumber in range(0, n):
	first = sys.stdin.readline().strip()
	second = sys.stdin.readline().strip()
	res = True
	for (tup1, tup2) in zip_longest(countergenerator(first), countergenerator(second), fillvalue=('\n', 0)):
		if tup1[0] != tup2[0] or tup1[1] > tup2[1]:
			res = False
			break
	if res:
		print('YES')
	else:
		print('NO')


cases = int(input())
wds = ['NO', 'YES']
for j in range(0, cases):
	target = list(input())
	word = list(input())
	targetInd = 0
	cor = True
	valid = ''
	tr = target[targetInd]
	for i in range(0, len(word)):
		if word[i] != valid and word[i] != tr:
			cor = False
			break
		elif word[i] == tr:
			targetInd += 1
			if targetInd >= len(target):
				tr = '0'
			else:
				tr = target[targetInd]
		valid = word[i]
	if targetInd < len(target):
		cor = False
	print(wds[cor])


from sys import stdin

def verificar(s, t):
	ls = len(s)
	if len(t) < ls:
		return False
	temp = ''
	j = 0
	for i in t:
		if j < ls and i == s[j]:
			temp = s[j]
			j += 1
		elif i != temp:
			return False
	if ls == j:
		return True
	else:
		return False

def main():
	n = int(stdin.readline().strip())
	for _ in range(n):
		s = stdin.readline().strip()
		t = stdin.readline().strip()
		if verificar(s, t):
			print('YES')
		else:
			print('NO')
main()


n = int(input())
for i in range(n):
	slovo = input()
	vvod = input()
	slovo += '0'
	c = 0
	for j in range(len(vvod)):
		if slovo[c] == vvod[j] and c <= len(slovo):
			c += 1
		elif vvod[j - 1] != vvod[j] or j == 0:
			c = -1
			break
	if c == len(slovo) - 1:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(0, n):
	f = input()
	s = input()
	l = len(s)
	le = len(f)
	f = f + '0'
	c = 0
	for j in range(0, l):
		if f[c] == s[j] and c < le:
			c += 1
		elif s[j - 1] != s[j] or j == 0:
			c = -1
			break
	if c == le:
		print('YES')
	else:
		print('NO')


def main():
	buf = input()
	n = int(buf)
	s = []
	for i in range(n):
		buf = input()
		s1 = buf
		buf = input()
		s2 = buf
		s.append((s1, s2))
	for x in s:
		p1 = 0
		p2 = 0
		last_char = '0'
		no = False
		while p1 < len(x[0]):
			c = x[0][p1]
			if c != last_char:
				while p2 < len(x[1]):
					if x[1][p2] != last_char:
						break
					p2 += 1
				if p2 >= len(x[1]):
					no = True
					break
				if x[1][p2] != c:
					no = True
					break
			else:
				p2 += 1
				if p2 >= len(x[1]):
					no = True
					break
				if x[1][p2] != c:
					no = True
					break
			last_char = c
			p1 += 1
		if no:
			print('NO')
			continue
		while p2 < len(x[1]):
			if x[1][p2] != last_char:
				break
			p2 += 1
		if p1 == len(x[0]) and p2 == len(x[1]):
			print('YES')
		else:
			print('NO')
main()


n = int(input())
for i in range(n):
	ans = True
	o = input()
	e = input()
	oc = 0
	ec = 0
	while oc < len(o) and ec < len(e):
		if o[oc] == e[ec]:
			if oc < len(o) - 1:
				if o[oc + 1] != o[oc]:
					while e[ec] == o[oc]:
						ec += 1
						if ec == len(e):
							break
				else:
					ec += 1
			else:
				while e[ec] == o[oc]:
					ec += 1
					if ec == len(e):
						break
		else:
			ans = False
			break
		oc += 1
	if oc != len(o) or ec != len(e):
		ans = False
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for ti in range(t):
	a = input()
	b = input()

	def g(s):
		ans1 = []
		ans2 = []
		last = None
		for i in range(len(s)):
			c = s[i]
			if c != last:
				ans1.append(c)
				ans2.append(1)
			else:
				ans2[-1] += 1
			last = c
		return (ans1, ans2)
	(a1, a2) = g(a)
	(b1, b2) = g(b)
	y = 'YES'
	n = 'NO'
	ans = True
	if len(a1) != len(b1):
		print(n)
		continue
	l = len(a1)
	for i in range(l):
		if a1[i] != b1[i] or a2[i] > b2[i]:
			ans = False
			break
	if ans:
		print(y)
	else:
		print(n)


n = int(input())
for o in range(n):
	s1 = input()
	s2 = input()
	j = 0
	flag = 1
	s3 = ''
	for i in range(len(s2)):
		if j == len(s1):
			if s2[i] != s1[j - 1]:
				print('NO')
				flag = 0
				break
		elif s2[i] == s1[j]:
			s3 += s2[i]
			j += 1
		elif i == 0 or s2[i] != s2[i - 1]:
			print('NO')
			flag = 0
			break
	if flag == 1:
		if s3 == s1:
			print('YES')
		else:
			print('NO')


from sys import stdin

def main():
	N = int(input())
	ST = stdin.read().splitlines()
	for i in range(0, N * 2, 2):
		(s, t) = ([], [])
		prev = ST[i][0]
		for j in range(1, len(ST[i])):
			if prev[0] == ST[i][j]:
				prev += ST[i][j]
			else:
				s.append(prev)
				prev = ST[i][j]
		s.append(prev)
		prev = ST[i + 1][0]
		for j in range(1, len(ST[i + 1])):
			if prev[0] == ST[i + 1][j]:
				prev += ST[i + 1][j]
			else:
				t.append(prev)
				prev = ST[i + 1][j]
		t.append(prev)
		if len(s) != len(t):
			print('NO')
		else:
			for (s_, t_) in zip(s, t):
				if s_[0] != t_[0] or len(s_) > len(t_):
					print('NO')
					break
			else:
				print('YES')
input = lambda : stdin.readline().rstrip()
main()


def initialChar(x):
	past = x[0]
	num = []
	y = []
	count = 0
	for i in x:
		if i != past:
			y.append(past)
			num.append(count)
			count = 0
		count += 1
		past = i
	y.append(past)
	num.append(count)
	return (num, y)
n = int(input())
for i in range(n):
	check = False
	s = [i for i in input()]
	t = [i for i in input()]
	(a, b) = initialChar(s)
	(p, q) = initialChar(t)
	if b != q:
		print('NO')
		continue
	if a != p:
		for (i, j) in zip(a, p):
			if j < i:
				print('NO')
				check = True
				break
		if check:
			continue
	print('YES')
	continue


from itertools import groupby

def getter(x):
	tmp = list(x)
	return (tmp[0], len(tmp))

def func(x):
	return [getter(j) for (i, j) in groupby(x)]
for _ in range(int(input())):
	(s1, s2) = map(func, (input(), input()))
	flag = True
	if len(s1) == len(s2):
		for i in zip(s1, s2):
			if not (i[0][0] == i[1][0] and i[0][1] <= i[1][1]):
				flag = False
				break
	else:
		flag = False
	print('YES' if flag else 'NO')


n = int(input())
for i in range(0, n):
	a = str(input())
	b = str(input())
	l = len(b)
	le = len(a)
	a = a + '0'
	c = 0
	for j in range(0, l):
		if a[c] == b[j] and c < le:
			c += 1
		elif b[j - 1] != b[j] or j == 0:
			c = -1
			break
	if c == le:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = input()
	b = input()
	flag = True
	l1 = []
	c = 1
	s = a[0]
	for i in a[1:]:
		if i == s:
			c += 1
		else:
			l1.append([s, c])
			c = 1
			s = i
	l1.append([s, c])
	l2 = []
	c = 1
	s = b[0]
	for i in b[1:]:
		if i == s:
			c += 1
		else:
			l2.append([s, c])
			c = 1
			s = i
	l2.append([s, c])
	j = 0
	for i in l1:
		if j == len(l2) or i[0] != l2[j][0]:
			flag = False
			break
		elif l2[j][1] < i[1]:
			flag = False
			break
		else:
			j += 1
	if j == len(l2) and flag:
		print('YES')
	else:
		print('NO')


from itertools import groupby, zip_longest
for i in range(int(input())):
	ans = 'YES'
	a = [list(i[1]) for i in groupby(input())]
	b = [list(i[1]) for i in groupby(input())]
	for (i, j) in zip_longest(a, b, fillvalue=['.']):
		if i[0] != j[0] or len(j) < len(i):
			ans = 'NO'
	print(ans)


T = int(input())
for _ in range(T):
	word = input()
	fail = input()
	wordCounts = []
	failCounts = []
	prevChar = None
	for c in word:
		if prevChar == c:
			wordCounts[-1][1] += 1
		else:
			wordCounts.append([c, 1])
			prevChar = c
	prevChar = None
	for c in fail:
		if prevChar == c:
			failCounts[-1][1] += 1
		else:
			failCounts.append([c, 1])
			prevChar = c
	if len(wordCounts) != len(failCounts):
		print('NO')
	elif all([wordCounts[i][0] == failCounts[i][0] and wordCounts[i][1] <= failCounts[i][1] for i in range(len(wordCounts))]):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	a = []
	b = []
	c = []
	d = []
	s = input()
	t = input()
	k = 1
	for j in range(1, len(s)):
		if s[j] != s[j - 1]:
			a.append(ord(s[j - 1]))
			b.append(k)
			k = 1
		else:
			k += 1
	a.append(ord(s[len(s) - 1]))
	b.append(k)
	k = 1
	for j in range(1, len(t)):
		if t[j] != t[j - 1]:
			c.append(ord(t[j - 1]))
			d.append(k)
			k = 1
		else:
			k += 1
	c.append(ord(t[len(t) - 1]))
	d.append(k)
	yes = True
	if len(a) != len(c):
		print('NO')
	else:
		for j in range(len(a)):
			if a[j] != c[j] or d[j] < b[j]:
				yes = False
				break
		if yes:
			print('YES')
		else:
			print('NO')


for T in range(int(input())):
	s = input().strip()
	t = input().strip()
	a = s[0]
	cnta = [1]
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			cnta.append(1)
			a += s[i]
		else:
			cnta[-1] += 1
	b = t[0]
	cntb = [1]
	for i in range(1, len(t)):
		if t[i] != t[i - 1]:
			cntb.append(1)
			b += t[i]
		else:
			cntb[-1] += 1
	flag = 0
	for (i, j) in zip(cnta, cntb):
		if j < i:
			flag = 1
			break
	if flag or a != b:
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(n):
	a = input()
	b = input()
	ia = 0
	ib = 0
	r = 'YES'
	if a[0] != b[0]:
		print('NO')
		continue
	for x in a:
		if ib < len(b) and x != b[ib]:
			while ib < len(b) and b[ib] == b[ib - 1]:
				ib += 1
		if ib < len(b) and x == b[ib]:
			ib += 1
		else:
			r = 'NO'
			break
	while ib < len(b) and b[ib] == b[ib - 1]:
		ib += 1
	if ib < len(b):
		r = 'NO'
	print(r)


for _ in range(int(input())):
	a = input()
	b = input()
	a_len = len(a)
	b_len = len(b)
	i = j = 0
	cnt_a = cnt_b = 0
	c = ''
	LA = [0]
	while i < a_len and j <= b_len:
		c = a[i]
		while i < a_len and a[i] == c:
			cnt_a += 1
			i += 1
		while j < b_len and b[j] == c:
			cnt_b += 1
			j += 1
		if cnt_a > cnt_b:
			print('NO')
			break
		cnt_a = cnt_b = 0
	else:
		if i == a_len and j == b_len:
			print('YES')
		else:
			print('NO')


def get_input():
	try:
		strg = input()
		return strg
	except EOFError:
		return ''

def make_int_list(strg):
	lst = strg.split()
	int_list = []
	for i in range(0, len(lst)):
		int_list.append(int(lst[i]))
	return int_list

def is_valid(s1, s2):
	pre = s1[0]
	cur = s1[0]
	cnt1 = 0
	cnt2 = 0
	while 1:
		if cnt2 >= len(s2):
			return False
		if cur == s2[cnt2]:
			cnt2 = cnt2 + 1
			cnt1 = cnt1 + 1
			pre = cur
			if cnt1 >= len(s1):
				break
			cur = s1[cnt1]
		elif pre == s2[cnt2]:
			cnt2 += 1
		else:
			return False
	while cnt2 < len(s2):
		if s2[cnt2] != cur:
			return False
		else:
			cnt2 = cnt2 + 1
	return True

def check_the_words(words, recieved, num):
	for i in range(0, num):
		if is_valid(words[i], recieved[i]):
			print('YES')
		else:
			print('NO')
num_of_words = int(get_input())
words = []
recieved = []
for i in range(0, 2 * num_of_words, 2):
	words.append(get_input())
	recieved.append(get_input())
check_the_words(words, recieved, num_of_words)


for _ in range(int(input())):
	s = list(map(str, input()))
	n = len(s)
	t = list(map(str, input()))
	m = len(t)
	arr = []
	cur = s[0]
	cnt = 1
	for i in range(1, n):
		if s[i] == cur:
			cnt += 1
		else:
			arr.append([cur, cnt])
			cnt = 1
			cur = s[i]
	arr.append([cur, cnt])
	brr = []
	cur = t[0]
	cnt = 1
	for i in range(1, m):
		if t[i] == cur:
			cnt += 1
		else:
			brr.append([cur, cnt])
			cnt = 1
			cur = t[i]
	brr.append([cur, cnt])
	if len(arr) != len(brr):
		print('NO')
	else:
		f = 0
		for i in range(len(arr)):
			if arr[i][0] != brr[i][0]:
				f = 1
				break
			elif arr[i][1] > brr[i][1]:
				f = 1
				break
		if f == 1:
			print('NO')
		else:
			print('YES')


def solve(w1, w2, ans):
	i2 = 0
	i1 = 0
	while i1 < len(w1) and i2 < len(w2):
		if w1[i1] == w2[i2]:
			i1 += 1
			i2 += 1
		else:
			if i1 == 0:
				ans.append('NO')
				return
			if w2[i2] == w1[i1 - 1]:
				i2 += 1
			else:
				ans.append('NO')
				return
	if i1 == len(w1):
		for j in range(i2, len(w2)):
			if w2[j] != w1[-1]:
				ans.append('NO')
				return
		ans.append('YES')
	else:
		ans.append('NO')

def main():
	n = int(input())
	ans = []
	for i in range(n):
		w1 = input()
		w2 = input()
		solve(w1, w2, ans)
	for i in ans:
		print(i)
main()


N = int(input())
for _ in range(N):
	a = [ord(s) for s in input().strip()]
	b = [ord(s) for s in input().strip()]
	na = len(a)
	nb = len(b)
	da = []
	sa = []
	pre = -1
	for ai in a:
		if pre == ai:
			da[-1] += 1
		else:
			da.append(0)
			sa.append(ai)
		pre = ai
	db = []
	sb = []
	pre = -1
	for bi in b:
		if pre == bi:
			db[-1] += 1
		else:
			db.append(0)
			sb.append(bi)
		pre = bi
	if sa == sb and all((ai <= bi for (ai, bi) in zip(da, db))):
		print('YES')
	else:
		print('NO')


t = int(input())
for t1 in range(t):
	s1 = input()
	s2 = input()
	n = len(s1)
	m = len(s2)
	i = 0
	j = 0
	flag = 0
	while i < n and j < m:
		if s1[i] == s2[j]:
			i += 1
			j += 1
		elif s1[i - 1] == s2[j] and i > 0:
			j += 1
		else:
			flag = 1
			break
	while j < m:
		if s1[i - 1] == s2[j]:
			j += 1
		else:
			break
	if flag == 0 and i == n and (len(set(s1)) == len(set(s2))) and (j == m):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	a = input()
	b = input()
	ans = []
	fa = 'NO'
	tr = 'YES'
	m1 = len(a)
	m2 = len(b)
	if m1 > m2:
		print(fa)
	elif a[0] != b[0]:
		print(fa)
	else:
		k = 1
		m = 0
		for i in range(1, m2):
			if b[i] != b[i - 1]:
				if k < m1 and a[k] == b[i]:
					k = k + 1
				else:
					m = 1
					print(fa)
					break
			elif b[i] == b[i - 1]:
				if k < m1 and a[k] == b[i]:
					k = k + 1
		if m == 0 and k == m1:
			print(tr)
		elif m == 0 and k < m1:
			print(fa)


n = int(input())
res = []

def splitByLetter(word):
	res = []
	curSeq = ''
	for l in word:
		if l in curSeq:
			curSeq += l
		else:
			res += [curSeq]
			curSeq = l
	res += [curSeq]
	return res[1:len(res)]
for _ in range(n):
	first = splitByLetter(input())
	second = splitByLetter(input())
	if len(first) == len(second):
		suc = True
		for i in range(len(first)):
			fSeq = first[i]
			sSeq = second[i]
			if fSeq[0] == sSeq[0] and len(fSeq) <= len(sSeq):
				pass
			else:
				suc = False
				res += ['NO']
				break
		if suc:
			res += ['YES']
	else:
		res += ['NO']
		continue
for i in res:
	print(i)


import re

def pack(string):
	packed = []
	current = string[0]
	cnt = 0
	for c in string:
		if c == current:
			cnt += 1
		else:
			packed.append((current, cnt))
			current = c
			cnt = 1
	else:
		packed.append((current, cnt))
	return packed

def check(packed_a, packed_b):
	if len(packed_a) != len(packed_b):
		return False
	for (a, b) in zip(packed_a, packed_b):
		if a[0] != b[0] or a[1] > b[1]:
			return False
	return True

def main():
	n = int(input())
	for loop in range(n):
		original = input()
		test_case = input()
		packed_original = pack(original)
		packed_test = pack(test_case)
		if check(packed_original, packed_test):
			print('YES')
		else:
			print('NO')
main()


import sys
from itertools import groupby, zip_longest
t = int(input())
for _ in range(t):
	(s1, s2) = (sys.stdin.readline().rstrip(), sys.stdin.readline().rstrip())
	for (itr1, itr2) in zip_longest(groupby(s1), groupby(s2)):
		if not (itr1 and itr2) or itr1[0] != itr2[0] or len(list(itr1[1])) > len(list(itr2[1])):
			print('NO')
			break
	else:
		print('YES')


T = int(input())
for t in range(T):
	s = str(input())
	k = str(input())
	S = []
	Sp = []
	K = []
	Kp = []
	x = True
	i = 0
	I = 0
	while i + 1 <= len(s):
		cc = 1
		while i + 1 < len(s):
			if s[i] == s[i + 1]:
				i = i + 1
				cc = cc + 1
			else:
				break
		S.append(s[i])
		Sp.append(cc)
		i = i + 1
	while I + 1 <= len(k):
		cc = 1
		while I + 1 < len(k):
			if k[I] == k[I + 1]:
				I = I + 1
				cc = cc + 1
			else:
				break
		K.append(k[I])
		Kp.append(cc)
		I = I + 1
	if S == K:
		for p in range(len(K)):
			if Sp[p] > Kp[p]:
				x = False
				break
		if x:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import sys

class BEmailFromPolycarp:

	def solve(self):

		def cnter(s):
			n = len(s)
			res = []
			i = 0
			while i < n:
				j = i
				while j < n and s[j] == s[i]:
					j += 1
				j -= 1
				res.append((s[i], j - i + 1))
				i = j + 1
			return res
		n = int(input())
		for _ in range(n):
			s = input().strip()
			t = input().strip()
			s_counter = cnter(s)
			t_counter = cnter(t)
			if len(s_counter) != len(t_counter):
				print('NO')
				continue
			for i in range(len(s_counter)):
				if s_counter[i][0] != t_counter[i][0] or s_counter[i][1] > t_counter[i][1]:
					print('NO')
					break
			else:
				print('YES')
solver = BEmailFromPolycarp()
input = sys.stdin.readline
solver.solve()


import sys
input = sys.stdin.readline
Q = int(input())
data = []
for _ in range(Q):
	S = input().rstrip()
	T = input().rstrip()
	data.append((S, T))
for (S, T) in data:
	j = 0
	i = 0
	ok = True
	if S[0] != T[0]:
		ok = False
	else:
		while j < len(S) and i < len(T):
			if S[j] == T[i]:
				j += 1
				i += 1
			elif S[j - 1] == T[i]:
				i += 1
			else:
				ok = False
				break
		if j < len(S):
			ok = False
		if i < len(T):
			for j in range(i, len(T)):
				if S[-1] != T[j]:
					ok = False
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	string = input()
	copy = input()
	a = list()
	ctr = 1
	index = 0
	a.append(string[0])
	for j in range(1, len(string)):
		if string[j] == a[index]:
			ctr += 1
		else:
			a.append(ctr)
			ctr = 1
			a.append(string[j])
			index += 2
	a.append(ctr)
	b = list()
	ctr = 1
	index = 0
	b.append(copy[0])
	for j in range(1, len(copy)):
		if copy[j] == b[index]:
			ctr += 1
		else:
			b.append(ctr)
			ctr = 1
			b.append(copy[j])
			index += 2
	b.append(ctr)
	flag = 1
	if len(b) != len(a):
		print('NO')
	else:
		for j in range(0, len(a), 2):
			if a[j] != b[j]:
				flag = 0
				break
			elif a[j + 1] > b[j + 1]:
				flag = 0
				break
		if flag:
			print('YES')
		else:
			print('NO')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	if len(t) < len(s):
		print('NO')
		continue
	l = 0
	r = 0
	fl = True
	while l < len(s) and r < len(t):
		(k, x) = (1, 1)
		if s[l] != t[r]:
			fl = False
			break
		while l + 1 < len(s) and s[l] == s[l + 1]:
			l += 1
			k += 1
		while r + 1 < len(t) and t[r] == t[r + 1]:
			r += 1
			x += 1
		if x < k:
			fl = False
			break
		l += 1
		r += 1
	if l != len(s) or r != len(t):
		fl = False
	if fl:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	prev = '7'
	j = 0
	for i in range(len(t)):
		if j == len(s):
			if t[i] == prev:
				continue
			else:
				print('NO')
				break
		if t[i] == s[j]:
			prev = s[j]
			j += 1
			continue
		if t[i] == prev:
			continue
		else:
			print('NO')
			break
	else:
		if j == len(s):
			print('YES')
		else:
			print('NO')


q = int(input())
for _ in range(q):
	a1 = list(input())
	b1 = list(input())
	a = []
	b = []
	k = 1
	for i in range(1, len(a1)):
		if a1[i] != a1[i - 1]:
			a.append([a1[i - 1], k])
			k = 1
		else:
			k += 1
	a.append([a1[-1], k])
	k = 1
	for i in range(1, len(b1)):
		if b1[i] != b1[i - 1]:
			b.append([b1[i - 1], k])
			k = 1
		else:
			k += 1
	b.append([b1[-1], k])
	if len(a) != len(b):
		print('NO')
		continue
	ok = True
	for i in range(len(a)):
		if a[i][0] == b[i][0] and a[i][1] <= b[i][1]:
			continue
		print('NO')
		ok = False
		break
	if ok:
		print('YES')


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	(l1, l2) = ([], [])
	l1.append([s1[0], 1])
	for i in range(1, len(s1)):
		if s1[i] == s1[i - 1]:
			l1[-1][1] += 1
		else:
			l1.append([s1[i], 1])
	l2.append([s2[0], 1])
	for i in range(1, len(s2)):
		if s2[i] == s2[i - 1]:
			l2[-1][1] += 1
		else:
			l2.append([s2[i], 1])
	if len(l1) == len(l2):
		f = 0
		for i in range(len(l1)):
			if l1[i][0] == l2[i][0]:
				if l1[i][1] > l2[i][1]:
					f = 1
					break
			else:
				f = 1
				break
		if f == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


n = int(input())
while n > 0:
	a = input()
	b = input()
	c = 0
	k = 0
	fa = [[]]
	fb = [[]]
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			fa[k].append(a[i])
		else:
			fa.append([])
			k += 1
			fa[k].append(a[i])
	k = 0
	for i in range(1, len(b)):
		if b[i] == b[i - 1]:
			fb[k].append(b[i])
		else:
			fb.append([])
			k += 1
			fb[k].append(b[i])
	if len(fa) == 1:
		fa[0].append(a[0])
	elif a[0] == a[1]:
		fa[0].append(a[0])
	else:
		fa[0].append(a[0])
	if len(fb) == 1:
		fb[0].append(b[0])
	elif b[0] == b[1]:
		fb[0].append(b[0])
	else:
		fb[0].append(b[0])
	if len(fa) != len(fb):
		print('NO')
	else:
		for i in range(len(fa)):
			if fa[i][0] == fb[i][0] and len(fa[i]) <= len(fb[i]):
				c += 1
			else:
				break
		if c == len(fa):
			print('YES')
		else:
			print('NO')
	n -= 1


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

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

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

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		a = input()
		b = input()
		i = 0
		j = 0
		counter = 0
		if len(a) > len(b):
			print('NO')
			continue
		while i < len(a) and j < len(b):
			if a[i] == b[j]:
				i += 1
				j += 1
				continue
			elif i - 1 > -1 and a[i - 1] == b[j]:
				j += 1
			else:
				counter = 1
				break
		if i < len(a):
			counter = 1
		for i in range(j, len(b)):
			if b[i] == a[-1]:
				continue
			else:
				counter = 1
				break
		if counter:
			print('NO')
		else:
			print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


from sys import stdin, stdout

def main():
	(le, i, write, read, ra) = (len, int, stdout.write, stdin.readline, range)
	n = i(read())
	while n:
		f = read()
		s = read()
		(c, l1, l2, f) = (0, le(s), le(f), f + '0')
		for j in ra(l1):
			if f[c] == s[j] and c < l2:
				c += 1
			elif s[j - 1] != s[j] or j == 0:
				c -= 1
				break
		if c == l2:
			write('YES\n')
		else:
			write('NO\n')
		n -= 1
main()


n = int(input())
while n:
	n -= 1
	first = str(input())
	second = str(input())
	if len(first) > len(second):
		print('NO')
	else:
		(i, j) = (0, 0)
		(a, b) = (len(first), len(second))
		flag = 0
		while i < a and j < b:
			if first[i] != second[j]:
				print('NO')
				flag = 1
				break
			count = 0
			t = first[i]
			while i < a and first[i] == t:
				count += 1
				i += 1
			count1 = 0
			t = second[j]
			while j < b and second[j] == t:
				j += 1
				count1 += 1
			if count > count1:
				print('NO')
				flag = 1
				break
		if flag == 0 and i >= a and (j >= b):
			print('YES')
		elif flag == 0:
			print('NO')


from sys import stdin, stdout
import math
import collections

def compress(string):
	aux = []
	temp = []
	aux.append(1)
	temp.append(string[0])
	for i in range(1, len(string)):
		if string[i] == temp[-1]:
			aux[-1] += 1
		else:
			aux.append(1)
			temp.append(string[i])
	return (aux, temp)

def check(first, second):
	if len(first) > len(second):
		return False
	else:
		(compress_a, first) = compress(first)
		(compress_b, second) = compress(second)
		if len(first) == len(second) and first == second:
			for i in range(len(compress_a)):
				if compress_a[i] <= compress_b[i]:
					pass
				else:
					return False
			else:
				return True
		else:
			return False
n = int(stdin.readline().strip())
for _ in range(n):
	first = stdin.readline().strip()
	second = stdin.readline().strip()
	if check(first, second):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	a1 = []
	b1 = []
	c = 0
	i = -1
	for i in range(len(a) - 1):
		if a[i] == a[i + 1]:
			c += 1
		else:
			a1.append(c)
			a1.append(a[i])
			c = 0
	a1.append(c)
	a1.append(a[i + 1])
	c = 0
	i = -1
	for i in range(len(b) - 1):
		if b[i] == b[i + 1]:
			c += 1
		else:
			b1.append(c)
			b1.append(b[i])
			c = 0
	b1.append(c)
	b1.append(b[i + 1])
	if len(a1) != len(b1):
		print('NO')
	else:
		for i in range(len(a1)):
			if i % 2 == 0:
				if b1[i] < a1[i]:
					print('NO')
					break
			elif a1[i] != b1[i]:
				print('NO')
				break
		else:
			print('YES')


for _ in range(int(input())):
	(g, k) = (input(), input())
	(i, j) = (0, 0)

	def gen(a, l):
		i = 0
		c = 0
		rem = a[i]
		while i < l:
			if a[i] == rem:
				c += 1
			else:
				yield [a[i - 1], c]
				c = 1
				rem = a[i]
			i += 1
		yield [a[i - 1], c]
	g = gen(g, len(g))
	k = gen(k, len(k))
	(gb, kb) = (True, True)
	while True:
		try:
			ng = next(g)
		except:
			gb = False
		try:
			nk = next(k)
		except:
			kb = False
		if kb == False and gb == False:
			print('YES')
			break
		elif kb ^ gb:
			print('NO')
			break
		elif ng[0] != nk[0]:
			print('NO')
			break
		elif ng[1] > nk[1]:
			print('NO')
			break


for _ in range(int(input())):
	s = input()
	t = input()
	i = 0
	j = 0
	ls = len(s)
	lt = len(t)
	flag = True
	if lt < ls:
		print('NO')
		continue
	while flag and i < ls and (j < lt):
		if s[i] != t[j]:
			flag = False
		elif i == ls - 1:
			while j < lt and s[i] == t[j]:
				j += 1
			if j != lt and s[i] != t[j]:
				flag = False
			i += 1
		elif s[i] != s[i + 1]:
			while j < lt and t[j] == s[i]:
				j += 1
			if j == lt:
				flag = False
			i += 1
		else:
			while i < ls - 1 and s[i] == s[i + 1] and (j < lt - 1):
				if t[j] == t[j + 1]:
					i += 1
					j += 1
				else:
					flag = False
					break
			if j == lt - 1 and s[i] == t[j]:
				i += 1
				j += 1
	while flag and j < lt and (i == ls):
		if s[ls - 1] != t[j]:
			flag = False
	if j == lt and i < ls:
		flag = False
	if flag:
		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())):
	a = input()
	b = input()
	x = []
	y = []
	for i in a:
		if x:
			if x[-1][0] == i:
				x[-1][1] += 1
			else:
				x.append([i, 1])
		else:
			x.append([i, 1])
	for i in b:
		if y:
			if y[-1][0] == i:
				y[-1][1] += 1
			else:
				y.append([i, 1])
		else:
			y.append([i, 1])
	flag = 0
	if len(x) == len(y):
		for i in range(len(x)):
			if x[i][0] != y[i][0] or x[i][1] > y[i][1]:
				flag = 1
		if flag:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	(s, t) = (input(), input())
	(len1, len2) = (len(s), len(t))
	if len1 > len2:
		print('NO')
	elif len1 == len2:
		if s == t:
			print('YES')
		else:
			print('NO')
	else:
		(k, case) = (0, 0)
		for (i, x) in enumerate(t):
			if x != s[k]:
				print('NO')
				case = 1
				break
			if i != len2 - 1 and k != len1 - 1:
				if x != t[i + 1] or t[i + 1] == s[k + 1]:
					k += 1
		if case == 1:
			continue
		if k != len1 - 1:
			print('NO')
		else:
			print('YES')


import re

def run2():
	a = eval(input())
	inputs = []
	for i in range(2 * a):
		inputs.append(input())
	i = 0
	while i < 2 * a:
		m = [char for char in inputs[i]]
		pattern = '+'.join(m)
		pattern = '^' + pattern + '+$'
		text = inputs[i + 1]
		if re.search(pattern, text):
			print('YES')
		else:
			print('NO')
		i += 2

def run():
	a = eval(input())
	inputs = []
	for i in range(2 * a):
		inputs.append(input())
	i = 0
	while i < 2 * a:
		text = inputs[i]
		new_text = inputs[i + 1]
		c = 0
		j = 0
		flag = True
		while j < len(text) and c < len(new_text):
			if text[j] != new_text[c]:
				flag = False
				break
			if j + 1 < len(text) and c + 1 < len(new_text):
				if text[j + 1] == text[j]:
					j += 1
					c += 1
				elif text[j] == new_text[c + 1]:
					c += 1
				else:
					j += 1
					c += 1
			elif j < len(text) and c + 1 < len(new_text):
				c += 1
			else:
				j += 1
				c += 1
		if c < len(new_text) or j < len(text):
			flag = False
		if flag:
			print('YES')
		else:
			print('NO')
		i += 2
run()


def comp(s_1, s_2):
	if s_1[0] != s_2[0]:
		return 'NO'
	i = 1
	j = 1
	n_1 = len(s_1)
	n_2 = len(s_2)
	while i < n_1 and j < n_2:
		if s_1[i] != s_2[j]:
			if s_1[i - 1] != s_2[j]:
				return 'NO'
		else:
			i += 1
		j += 1
	if i == n_1:
		if j == n_2:
			return 'YES'
		else:
			curr = s_2[j - 1]
			while j < n_2:
				if curr != s_2[j]:
					return 'NO'
				j += 1
			return 'YES'
	else:
		return 'NO'
n = int(input())
for i in range(n):
	s_1 = input()
	s_2 = input()
	ans = comp(s_1, s_2)
	print(ans, end='\n')


t = int(input())
for a in range(t):
	actual = input()
	actual_list = []
	actual_list_count = []
	test = input()
	test_list = []
	test_list_count = []
	actual_list_counter = 1
	test_list_counter = 1
	for i in range(len(actual) - 1):
		if actual[i] == actual[i + 1]:
			actual_list_counter = actual_list_counter + 1
		else:
			actual_list.append(actual[i])
			actual_list_count.append(actual_list_counter)
			actual_list_counter = 1
	actual_list.append(actual[-1])
	actual_list_count.append(actual_list_counter)
	for i in range(len(test) - 1):
		if test[i] == test[i + 1]:
			test_list_counter = test_list_counter + 1
		else:
			test_list.append(test[i])
			test_list_count.append(test_list_counter)
			test_list_counter = 1
	test_list.append(test[-1])
	test_list_count.append(test_list_counter)
	if len(actual_list) == len(test_list):
		try:
			for m in range(len(actual_list)):
				if actual_list[m] == test_list[m] and actual_list_count[m] <= test_list_count[m]:
					ans = 'YES'
				else:
					ans = 'NO'
					break
		except IndexError:
			ans = 'NO'
	else:
		ans = 'NO'
	print(ans)


a = []
n = int(input())
for k in range(n):
	s = input()
	t = input()
	i = 0
	j = 0
	while True:
		if s[i] != t[j]:
			a.append('NO')
			break
		else:
			c1 = 0
			c2 = 0
			p = s[i]
			while True:
				if i < len(s):
					if s[i] == p:
						i += 1
						c1 += 1
						continue
					else:
						break
				else:
					break
			while True:
				if j < len(t):
					if t[j] == p:
						j += 1
						c2 += 1
						continue
					else:
						break
				else:
					break
			if c2 >= c1:
				if i == len(s) or j == len(t):
					if i < len(s) or j < len(t):
						a.append('NO')
						break
					else:
						a.append('YES')
						break
				continue
			else:
				a.append('NO')
				break
	else:
		a.append('YES')
for k in range(n):
	print(a[k])


n = int(input())
for i in range(n):
	word = input()
	word2 = input()
	fir = 0
	sec = 0
	n2 = len(word)
	n3 = len(word2)
	ans = 1
	while fir < n2 and sec < n3:
		if fir < n2 - 1 and word[fir] == word[fir + 1]:
			if word[fir] != word2[sec]:
				ans = 0
				break
			fir += 1
			sec += 1
			continue
		while sec < n3 - 1 and word2[sec] == word2[sec + 1]:
			sec += 1
		if word[fir] != word2[sec]:
			ans = 0
			break
		fir += 1
		sec += 1
	if fir < n2 or sec < n3:
		ans = 0
	if ans == 1:
		print('YES')
	else:
		print('NO')


n = int(input())
w = [[input(), input()] for _ in range(n)]
for (o, m) in w:
	(lo, lm) = (len(o), len(m))
	if lo > lm:
		print('NO')
		continue
	(a, b) = (0, 0)
	while a != lo and b != lm:
		if o[a] == m[b]:
			a += 1
			b += 1
		elif a == 0:
			print('NO')
			break
		elif o[a - 1] == m[b]:
			for b in range(b + 1, lm):
				if m[b] != m[b - 1]:
					break
			if m[b] != o[a]:
				print('NO')
				break
		else:
			print('NO')
			break
	else:
		if a == lo and b == lm and (o[-1] == m[-1]):
			print('YES')
		elif b == lm and a != lo:
			print('NO')
		elif set(o[-1]) != set(m[b:]):
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	s = str(input())
	t = str(input())
	(i, j) = (0, 0)
	flag = 0
	while i < len(s) and j < len(t):
		if s[i] != t[j]:
			flag = 1
			break
		(c1, c2) = (0, 0)
		while i + 1 < len(s) and s[i] == s[i + 1]:
			c1 += 1
			i += 1
		while j + 1 < len(t) and t[j] == t[j + 1]:
			j += 1
			c2 += 1
		if c2 < c1:
			flag = 1
			break
		i += 1
		j += 1
	if flag == 1 or (i >= len(s) and j < len(t)) or (j >= len(t) and i < len(s)):
		print('NO')
	else:
		print('YES')


def func(s, s2):
	k = 0
	offset = 0
	while k - offset < len(s):
		if k == len(s2):
			return 'NO'
		if s[k - offset] == s2[k]:
			k += 1
		else:
			offset += 1
			if s[k - offset] != s2[k] or k - offset < 0:
				return 'NO'
	while k < len(s2):
		if s2[k] != s[-1]:
			return 'NO'
		k += 1
	return 'YES'
n = int(input())
for i in range(n):
	s = input()
	s2 = input()
	if len(s2) < len(s):
		print('NO')
		continue
	else:
		print(func(s, s2))


def is_printable(a, b):
	if a[0] != b[0]:
		return False
	(m, n) = (len(a), len(b))
	i = j = 0
	while i < m and j < n:
		if a[i] == b[j]:
			i += 1
			j += 1
		else:
			while j < n and a[i] != b[j]:
				if a[i - 1] != b[j]:
					return False
				j += 1
	while j < n and a[i - 1] == b[j]:
		j += 1
	return i == m and j == n
t = int(input())
for _ in range(t):
	(a, b) = (input(), input())
	print('YES' if is_printable(a, b) else 'NO')


def solve(src, tgt):
	si = 0
	ti = 0
	ans = 'YES'
	while si < len(src) and ti < len(tgt):
		if src[si] == tgt[ti]:
			si += 1
			ti += 1
		else:
			if ti >= 1:
				if tgt[ti] == tgt[ti - 1]:
					ti += 1
					continue
				else:
					ans = 'NO'
					break
			ans = 'NO'
			break
	if si < len(src):
		ans = 'NO'
	elif ti < len(tgt):
		while ti < len(tgt):
			if tgt[ti] == tgt[ti - 1]:
				ti += 1
			else:
				ans = 'NO'
				break
		if ti < len(tgt):
			ans = 'NO'
	return ans
nb_Test = int(input())
for _ in range(nb_Test):
	src = input()
	tgt = input()
	print(solve(src, tgt))


def is_same(s, t):
	i = 0
	for j in range(len(t)):
		if i < len(s) and s[i] == t[j]:
			i += 1
		elif i > 0 and s[i - 1] == t[j]:
			continue
		else:
			return False
	return i == len(s)
cnt = int(input())
for i in range(cnt):
	s = str(input())
	t = str(input())
	print('YES' if is_same(s, t) else 'NO')


n = int(input())
for h in range(0, n):
	p = input().rstrip()
	r = input().rstrip()
	x = list(p)
	y = list(r)
	A = 1
	l = []
	q = []
	w = []
	S = []
	D = []
	for i in range(0, len(x) - 1):
		if x[i] == x[i + 1]:
			A += 1
		else:
			l.append(x[i])
			q.append(A)
			A = 1
	l.append(x[len(x) - 1])
	q.append(A)
	A = 1
	x = y
	for i in range(0, len(x) - 1):
		if x[i] == x[i + 1]:
			A += 1
		else:
			S.append(x[i])
			D.append(A)
			A = 1
	S.append(x[len(x) - 1])
	D.append(A)
	G = 0
	if len(l) != len(S):
		print('NO')
	else:
		for i in range(0, len(l)):
			if l[i] == S[i] and q[i] <= D[i]:
				continue
			else:
				G = 1
				break
		if G == 1:
			print('NO')
		else:
			print('YES')


def getN():
	return int(input())

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

def solve():
	first = input()
	second = input()
	fbuf = []
	sbuf = []
	fcur = '0'
	scur = '0'
	for c in first:
		if fcur[-1] != c:
			fbuf.append(fcur)
			fcur = c
		else:
			fcur += c
	fbuf.append(fcur)
	for c in second:
		if scur[-1] != c:
			sbuf.append(scur)
			scur = c
		else:
			scur += c
	sbuf.append(scur)
	if len(fbuf) != len(sbuf):
		print('NO')
		return
	for (f, s) in zip(fbuf, sbuf):
		if f[0] != s[0]:
			print('NO')
			return
		if len(f) > len(s):
			print('NO')
			return
	print('YES')
	return
n = getN()
for i in range(n):
	solve()


def solve():
	s1 = input()
	s2 = input()
	s1 = s1 + '@'
	s2 = s2 + '@'
	l1 = []
	l2 = []
	var = 1
	for i in range(1, len(s1)):
		if s1[i] == s1[i - 1]:
			var += 1
		else:
			l1.append([s1[i - 1], var])
			var = 1
	for i in range(1, len(s2)):
		if s2[i] == s2[i - 1]:
			var += 1
		else:
			l2.append([s2[i - 1], var])
			var = 1
	if len(l1) != len(l2):
		print('NO')
	else:
		check = True
		for i in range(len(l1)):
			if l1[i][0] == l2[i][0] and l1[i][1] <= l2[i][1]:
				continue
			else:
				check = False
				break
		if check:
			print('YES')
		else:
			print('NO')
t = int(input())
for i in range(t):
	solve()


n = int(input())
while n:
	n -= 1
	s1 = input()
	s2 = input()
	i = 0
	flag = 0
	j = 0
	while i < len(s1):
		ch = s1[i]
		tmp = i
		while tmp + 1 < len(s1) and s1[tmp + 1] == ch:
			tmp += 1
		diff = tmp - i + 1
		for k in range(diff):
			if j < len(s2) and s2[j] != ch:
				flag = 1
				break
			else:
				j += 1
		while j < len(s2) and s2[j] == ch:
			j += 1
		if flag:
			break
		if i == tmp:
			i += 1
		else:
			i = tmp + 1
	if j != len(s2):
		flag = 1
	if flag:
		print('NO')
	else:
		print('YES')


for ii in range(int(input())):
	a = input()
	b = input()
	i = 0
	j = 0
	while i < len(a) and j < len(b):
		if a[i] == b[j]:
			i += 1
			j += 1
		elif j > 0 and j < len(b):
			if b[j] == b[j - 1]:
				j += 1
			else:
				break
		else:
			break
	if j != len(b) and i == len(a):
		while j < len(b) and b[j] == b[j - 1]:
			j += 1
	if i != len(a) or j != len(b):
		print('NO')
	else:
		print('YES')


def fcuk(a, b):
	la = len(a)
	lb = len(b)
	i = 0
	j = 0
	if a == b:
		return 'YES'
	if a[0] != b[0] or la > lb:
		return 'NO'
	while i < la and j < lb:
		if a[i] == b[j]:
			i += 1
			j += 1
		elif a[i - 1] == b[j]:
			while a[i - 1] == b[j]:
				j += 1
				if j == lb:
					break
		else:
			return 'NO'
	if j < lb:
		while a[i - 1] == b[j]:
			j += 1
			if j == lb:
				break
	if j < lb or i < la:
		return 'NO'
	return 'YES'
n = int(input())
for i in range(n):
	x = input()
	y = input()
	print(fcuk(x, y))


from itertools import groupby
for _ in range(int(input())):
	a = input().strip()
	b = input().strip()
	a = [[i, len(list(j))] for (i, j) in groupby(a)]
	b = [[i, len(list(j))] for (i, j) in groupby(b)]
	if len(b) != len(a):
		print('NO')
	else:
		flag = True
		for i in range(len(a)):
			if a[i][0] != b[i][0] or b[i][1] < a[i][1]:
				print('NO')
				flag = False
				break
		if flag:
			print('YES')


n = int(input())
for i in range(n):
	z = 0
	s1 = input()
	s2 = input()
	for j in range(len(s2)):
		if z == len(s1):
			if j == 0 or s2[j - 1] != s2[j]:
				z = 0
				break
		elif s1[z] == s2[j]:
			z += 1
		elif j == 0 or s2[j - 1] != s2[j]:
			z = 0
			break
	if z == len(s1):
		print('YES')
	else:
		print('NO')


def solve(s, t):
	i = 0
	j = 0
	while j < len(t) or i < len(s):
		cS = 0
		cT = 0
		if i == len(s) or j == len(t):
			return False
		if not t[j] == s[i]:
			return False
		c = t[j]
		while j < len(t) and t[j] == c:
			cT += 1
			j += 1
		while i < len(s) and c == s[i]:
			cS += 1
			i += 1
		if cS > cT:
			return False
	return True
	pass
n = int(input())
for i in range(n):
	s = input()
	t = input()
	f = solve(s, t)
	print('YES' if f else 'NO')


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	(x, y) = (len(s1), len(s2))
	i = 0
	j = 0
	count1 = 0
	flag = 1
	count2 = 0
	while True:
		if i != x and j != y:
			a = s1[i]
			b = s2[j]
		if i != x and j != y and (s1[i] != s2[j]) or count2 < count1 or (j == y and i != x) or (j != y and i == x):
			flag = 0
			break
		if i == x and j == y:
			break
		(count1, count2) = (0, 0)
		while i < x and s1[i] == a:
			i += 1
			count1 += 1
		while j < y and s2[j] == b:
			j += 1
			count2 += 1
	if flag:
		print('YES')
	else:
		print('NO')


def myXOR(x, y):
	return (x | y) & (~x | ~y)

def power(a, b, p):
	result = 1
	a = a % p
	while b > 0:
		if b & 1 == 1:
			result = result * a % p
		b = b >> 1
		a = a * a % p
	return result

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
n = int(input())
for i in range(n):
	str1 = input()
	str2 = input()
	f = 0
	j = 0
	l1 = len(str1)
	l2 = len(str2)
	for i in range(len(str1)):
		if j < l2 and str2[j] == str1[i]:
			j = j + 1
			if i + 1 < l1:
				while j < l2 and str2[j] == str1[i] and (str2[j] != str1[i + 1]):
					j = j + 1
			else:
				while j < l2 and str2[j] == str1[i]:
					j = j + 1
		else:
			f = 1
			break
	if f == 0:
		if j < l2:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	yes = True
	cls = []
	p = ' '
	for l in s:
		if l == p:
			cls[-1][1] += 1
		else:
			p = l
			cls += [[l, 1]]
	clt = []
	p = ' '
	for l in t:
		if l == p:
			clt[-1][1] += 1
		else:
			p = l
			clt += [[l, 1]]
	if len(cls) != len(clt):
		print('NO')
		yes = False
		continue
	for j in range(len(cls)):
		if cls[j][0] != clt[j][0] or cls[j][1] > clt[j][1]:
			print('NO')
			yes = False
			break
	if yes:
		print('YES')


n = int(input())
while n > 0:
	n -= 1
	a = input()
	b = input()
	la = len(a)
	lb = len(b)
	if la == lb and a != b:
		print('NO')
		continue
	elif la == lb and a == b:
		print('YES')
		continue
	elif la > lb:
		print('NO')
		continue
	elif lb > la:
		i = 0
		count = lb
		for j in range(0, lb, 1):
			if a[i] == b[j]:
				count -= 1
				if j < lb - 1 and i < la - 1:
					if b[j + 1] == a[i + 1]:
						i += 1
			else:
				print('NO')
				count = 1
				break
	if count == 0:
		if i == la - 1:
			print('YES')
		else:
			print('NO')


def count(s, x):
	if len(s) - 1 == x:
		return (1, x + 1)
	count = 1
	j = 0
	for i in range(x, len(s) - 1):
		if s[i] == s[i + 1]:
			count += 1
		else:
			j = i + 1
			break
	if count > 1 and j == 0:
		j = x + count
	return (count, j)
for test in range(int(input())):
	c = input()
	b = input()
	lc = len(c)
	lb = len(b)
	if lc > lb:
		print('NO')
		continue
	i = 0
	j = 0
	flag = 0
	while i < len(b):
		(ct, i) = count(b, i)
		(ct2, j) = count(c, j)
		if b[i - 1] != c[j - 1]:
			flag = 1
			break
		if ct2 > ct:
			flag = 1
			break
	if i >= lb and j < lc:
		flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


n = int(input())
for _ in range(n):
	s = input()
	t = input()

	def counter(st):
		idx = 0
		arr = [[st[0], 1]]
		for i in range(1, len(st)):
			if st[i - 1] == st[i]:
				arr[-1][1] += 1
			else:
				arr += [[st[i], 1]]
		return arr
	cs = counter(s)
	ct = counter(t)
	if len(cs) != len(ct):
		print('NO')
		continue
	fail = False
	for i in range(len(cs)):
		if cs[i][0] != ct[i][0] or cs[i][1] > ct[i][1]:
			print('NO')
			fail = True
			break
	if fail:
		continue
	print('YES')


def buildArrs(s1, s2):
	n = max(len(s1), len(s2))
	prev1 = s1[0]
	prev2 = s2[0]
	arr1 = []
	count1 = 0
	arr2 = []
	count2 = 0
	for i in range(n):
		if i < len(s1):
			if s1[i] == prev1:
				count1 += 1
			else:
				arr1.append((prev1, count1))
				count1 = 1
				prev1 = s1[i]
			if i == len(s1) - 1:
				arr1.append((prev1, count1))
		if i < len(s2):
			if s2[i] == prev2:
				count2 += 1
			else:
				arr2.append((prev2, count2))
				count2 = 1
				prev2 = s2[i]
			if i == len(s2) - 1:
				arr2.append((prev2, count2))
	return (arr1, arr2)

def compile(arr1, arr2):
	if len(arr1) == len(arr2):
		for i in range(len(arr1)):
			if arr1[i][0] != arr2[i][0] or arr2[i][1] < arr1[i][1]:
				return 'NO'
		return 'YES'
	else:
		return 'NO'
n = int(input())
for _ in range(n):
	s1 = input()
	s2 = input()
	(arr1, arr2) = buildArrs(s1, s2)
	print(compile(arr1, arr2))


from collections import defaultdict
n = int(input())
for i in range(n):
	a = input()
	b = input()
	s = 0
	p = [a[0]]
	q = [b[0]]
	for j in range(len(a)):
		if a[j] != p[-1]:
			p.append(s)
			s = 1
			p.append(a[j])
		else:
			s += 1
	p.append(s)
	s = 0
	for k in range(len(b)):
		if b[k] != q[-1]:
			q.append(s)
			s = 1
			q.append(b[k])
		else:
			s += 1
	q.append(s)
	s = 0
	if len(p) == len(q):
		for j in range(0, len(p) - 1, 2):
			if p[j] != q[j] or p[j + 1] > q[j + 1]:
				print('NO')
				break
		else:
			print('YES')
	else:
		print('NO')


def f(r, s):
	r += '  a'
	s += '  a'
	n = len(r)
	m = len(s)
	i = 0
	j = 0
	c = 0
	f = r[0]
	while i < n:
		if f == r[i]:
			c += 1
		else:
			counter = 0
			while j < m:
				if f == s[j]:
					counter += 1
					j += 1
				else:
					jmem = j
					j = m + 2
			j = jmem
			if counter >= c:
				pass
			else:
				return 'NO'
			f = r[i]
			c = 1
		i += 1
	return 'YES'
n = int(input())
for i in range(n):
	r = str(input())
	s = str(input())
	print(f(r, s))


n = int(input())
for i in range(n):
	s = input()
	t = input()
	i_t = 0
	b = True
	for i_s in range(len(s)):
		if i_t < len(t) and t[i_t] == s[i_s]:
			i_t += 1
			if i_s == len(s) - 1 or s[i_s] != s[i_s + 1]:
				while i_t < len(t) and s[i_s] == t[i_t]:
					i_t += 1
		else:
			b = False
			break
	if b and i_t == len(t):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s1 = input()
	s2 = input()
	if s1 == s2:
		print('YES')
		continue
	if len(s1) == len(s2):
		print('NO')
		continue
	if len(s2) < len(s1):
		print('NO')
		continue
	g1 = [[s1[0], 1]]
	for j in range(1, len(s1)):
		if s1[j] == g1[-1][0]:
			g1[-1][1] += 1
		else:
			g1.append([s1[j], 1])
	g2 = [[s2[0], 1]]
	for q in range(1, len(s2)):
		if s2[q] == g2[-1][0]:
			g2[-1][1] += 1
		else:
			g2.append([s2[q], 1])
	if len(g2) != len(g1):
		print('NO')
	else:
		for a in range(len(g2)):
			if g2[a][0] != g1[a][0]:
				print('NO')
				break
			elif g2[a][1] < g1[a][1]:
				print('NO')
				break
		else:
			print('YES')


def work(a, b):
	k1 = 0
	k2 = 0
	count1 = 0
	count2 = 0
	while True:
		if a[k1] != b[k2]:
			return False
		if count2 < count1:
			return False
		k1 += 1
		count1 = 0
		while k1 < len(a) and a[k1] == a[k1 - 1]:
			k1 += 1
			count1 += 1
		k2 += 1
		count2 = 0
		while k2 < len(b) and b[k2] == b[k2 - 1]:
			k2 += 1
			count2 += 1
		if k1 < len(a) and k2 == len(b) or (k1 == len(a) and k2 < len(b)):
			return False
		if k1 == len(a) and k2 == len(b):
			if count1 <= count2:
				return True
			else:
				return False
n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	if work(s1, s2) == True:
		print('YES')
	else:
		print('NO')


def fun1(cons, temp1, aux):
	count = 0
	for j in range(cons, len(temp1)):
		if temp1[j] == aux:
			count += 1
		else:
			break
	return (count, j)

def fun(temp, temp1):
	aux = temp[0]
	cons = cons1 = 0
	while True:
		(count, cons) = fun1(cons, temp1, aux)
		(count1, cons1) = fun1(cons1, temp, aux)
		aux = temp[cons1]
		if count < count1:
			return 'NO'
		else:
			i = cons1
			j = cons
			if i == len(temp) - 1 and j == len(temp1) - 1:
				if temp[i] == temp1[j]:
					return 'YES'
				else:
					return 'NO'
			elif i == len(temp) - 1 and j < len(temp1) - 1:
				(count, cons) = fun1(cons, temp1, aux)
				if cons < len(temp1) - 1:
					return 'NO'
				elif temp[i] == temp1[cons]:
					return 'YES'
				else:
					return 'NO'
			elif i < len(temp) - 1 and j == len(temp1) - 1:
				return 'NO'
n = int(input())
for i in range(n):
	temp = input()
	temp1 = input()
	print(fun(temp, temp1))


n = int(input())
for i in range(n):
	s = input()
	c = input()
	(i, j, ch, lg, m1, m2) = (0, 0, s[0], 0, len(s), len(c))
	judge = True
	while True:
		while i < m1 and ch == s[i]:
			i += 1
			lg += 1
		rep = 0
		while j < m2 and ch == c[j]:
			rep += 1
			j += 1
		if rep < lg:
			judge = False
			break
		if i == m1:
			break
		ch = s[i]
		lg = 0
	print('YES' if judge and j == m2 else 'NO')


n = int(input())
j = 0
while j < n:
	s1 = input() + ' '
	s2 = input()
	k = 0
	i = 0
	n1 = len(s1)
	n2 = len(s2)
	var = True
	if n2 < n1 - 1:
		print('NO')
		j += 1
		continue
	while k < n1 - 1 and i < n2:
		count1 = 1
		count2 = 0
		while k < n1 - 1 and s1[k] == s1[k + 1]:
			count1 += 1
			k += 1
		k += 1
		while i < n2 and s2[i] == s1[k - 1]:
			count2 += 1
			i += 1
		if count2 < count1:
			var = False
			break
	if k != len(s1) - 1 or i != len(s2):
		var = False
	if var:
		print('YES')
	else:
		print('NO')
	j += 1


def _split(str):
	tmpList = []
	tmp1 = str[0]
	tmp2 = ''
	for i in range(len(str)):
		if str[i] == tmp1:
			tmp2 += str[i]
		else:
			tmpList.append(tmp2)
			tmp2 = str[i]
			tmp1 = str[i]
	tmpList.append(tmp2)
	return tmpList
for i in range(int(input())):
	a = _split(input())
	b = _split(input())
	LENS = [len(a), len(b)]
	if LENS[0] != LENS[1]:
		print('NO')
	else:
		CHECK = True
		for j in range(LENS[1]):
			if a[j][0] != b[j][0] or len(a[j]) > len(b[j]):
				CHECK = False
				break
		if CHECK:
			print('YES')
		else:
			print('NO')


from sys import stdin
n = int(stdin.readline().strip())
for _ in range(n):
	s = stdin.readline().strip()
	t = stdin.readline().strip()
	lo = 0
	last = None
	for c in s:
		ok = False
		if lo < len(t) and t[lo] == c:
			lo += 1
			ok = True
		else:
			while lo < len(t) and t[lo] == last:
				lo += 1
			if lo < len(t) and t[lo] == c:
				lo += 1
				ok = True
		if not ok:
			print('NO')
			break
		last = c
	else:
		while lo < len(t) and t[lo] == last:
			lo += 1
		if lo == len(t):
			print('YES')
		else:
			print('NO')


def prof(a, b):
	pre = a[0]
	k = 0
	povtor = False
	for j in range(len(b)):
		if not povtor and k == len(a):
			if b[j] == pre:
				pass
			else:
				return 'NO'
		elif povtor:
			if b[j] == a[k]:
				pre = a[k]
				k += 1
				povtor = False
			elif b[j] != a[k] and b[j] == pre:
				pass
			else:
				return 'NO'
		elif b[j] == a[k]:
			pre = a[k]
			k += 1
		elif b[j] != a[k] and b[j] == pre:
			povtor = True
		else:
			return 'NO'
	if k == len(a):
		return 'YES'
	return 'NO'
n = int(input())
rez = []
for i in range(n):
	a1 = input()
	b1 = input()
	r = prof(a1, b1)
	rez.append(r)
print(*rez, sep='\n')


for q in range(int(input())):
	s1 = input()
	s2 = input()
	last = 0
	k1 = 0
	k2 = 0
	flag = 0
	while k2 < len(s2):
		if k1 < len(s1) and s2[k2] == s1[k1]:
			k2 += 1
			last = k1
			k1 += 1
		elif s2[k2] == s1[last]:
			k2 += 1
		else:
			flag = 1
			break
	if flag == 0 and len(s2) >= len(s1) and (k1 == len(s1)):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	f = 0
	l = 0
	r = 0
	for i in range(len(s) - 1):
		if s[i + 1] != s[i]:
			while l < len(t) and t[l] == s[i]:
				l += 1
			if l == r:
				f = 1
				break
			r = l
		else:
			if l < len(t) and t[l] == s[i]:
				l += 1
			if l == r:
				f = 1
				break
			r = l
	while l < len(t) and t[l] == s[-1]:
		l += 1
	if l == r:
		f = 1
	if f == 1 or len(t) != l:
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	s1 += '5'
	s2 += '5'
	p1 = 0
	p2 = 0
	count1 = 1
	count2 = 1
	if len(s1) == 1:
		for i in range(len(s2)):
			if s2[i] != s1[0]:
				print('NO')
				break
			if i == len(s2) - 1:
				print('YES')
	else:
		c = 0
		while p1 < len(s1) - 1 and c == 0:
			if s1[p1 + 1] == s1[p1] and p1 < len(s1) - 2:
				count1 += 1
				p1 += 1
			else:
				if p1 == len(s1) - 2 and s1[p1 + 1] == s1[p1]:
					count1 += 1
				if s1[p1] != s2[p2]:
					print('NO')
					c = 1
					break
				else:
					while True:
						if p2 < len(s2) - 1 and s2[p2 + 1] == s2[p2]:
							count2 += 1
							p2 += 1
						else:
							break
				if count2 < count1:
					print('NO')
					c = 1
					break
				count1 = 1
				count2 = 1
				p1 += 1
				p2 += 1
		if c == 0:
			if p1 == len(s1) - 1 and p2 == len(s2) - 1:
				print('YES')
			else:
				print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	(x, y) = (len(s), len(t))
	(S, T) = ([], [])
	temp = [s[0]]
	for i in range(1, x):
		if s[i - 1] != s[i]:
			S.append(temp)
			temp = [s[i]]
		else:
			temp.append(s[i])
	S.append(temp)
	temp = [t[0]]
	for i in range(1, y):
		if t[i - 1] != t[i]:
			T.append(temp)
			temp = [t[i]]
		else:
			temp.append(t[i])
	T.append(temp)
	if len(S) != len(T):
		print('NO')
	else:
		flag = True
		if len(S) <= len(T):
			for i in range(len(S)):
				if S[i][0] != T[i][0] or len(S[i]) > len(T[i]):
					flag = False
			if not flag:
				print('NO')
			else:
				print('YES')
		else:
			print('NO')


n = int(input())
for _ in range(n):
	w1 = input()
	w2 = input()
	i = 0
	j = 0
	while i < len(w1):
		c1 = w1[i]
		count = 1
		while i < len(w1) - 1 and w1[i + 1] == c1:
			i += 1
			count += 1
		c2 = w2[j]
		if c1 != c2:
			print('NO')
			break
		count2 = 1
		while j < len(w2) - 1 and w2[j + 1] == c2:
			j += 1
			count2 += 1
		if count2 >= count:
			i += 1
			j += 1
			if i >= len(w1) and j >= len(w2):
				print('YES')
				break
			if i >= len(w1) and j < len(w2) or (i < len(w1) and j >= len(w2)):
				print('NO')
				break
		else:
			print('NO')
			break


n = int(input())
for i in range(n):
	s = input()
	t = input()
	j = 0
	k = 0
	flag = 1
	last = ''
	while j < len(s):
		if k < len(t):
			if s[j] == t[k]:
				last = s[j]
				j += 1
				k += 1
			elif t[k] == last:
				k += 1
			else:
				flag = 0
				break
		else:
			flag = 0
			break
	while k < len(t):
		if t[k] == last:
			k += 1
		else:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


n = int(input())
for ttt in range(n):
	first = input()
	sec = input()
	f = []
	s = []
	i = 0
	while i < len(first):
		j = i + 1
		while j < len(first) and first[j] == first[i]:
			j += 1
		f.append((first[i], j - i))
		i = j
	i = 0
	while i < len(sec):
		j = i + 1
		while j < len(sec) and sec[j] == sec[i]:
			j += 1
		s.append((sec[i], j - i))
		i = j
	fin = False
	if len(f) != len(s):
		print('NO')
		fin = True
	else:
		for i in range(len(f)):
			if f[i][0] != s[i][0] or f[i][1] > s[i][1]:
				print('NO')
				fin = True
				break
		if not fin:
			print('YES')


from itertools import groupby
n = int(input())
for _ in range(n):
	str1 = input()
	str2 = input()
	li1 = [''.join(k) for (_, k) in groupby(str1)]
	li2 = [''.join(k) for (_, k) in groupby(str2)]
	if len(li1) != len(li2) or len(li2) < len(li1):
		print('NO')
		continue
	for (i, j) in zip(li1, li2):
		a = len(i) < len(j)
		b = set(i) != set(j)
		if len(i) > len(j) or set(i) != set(j):
			print('NO')
			break
	else:
		print('YES')


n = int(input())
l = []
for k in range(n):
	w1 = input()
	w2 = input()
	flag = True
	i = 0
	j = 0
	c = ''
	if len(w2) < len(w1):
		flag = False
	while flag and (i < len(w1) or j < len(w2)):
		if j == len(w2):
			flag = False
		elif i == len(w1):
			if w2[j] == c:
				j += 1
			else:
				flag = False
				break
		elif w1[i] == w2[j]:
			c = w1[i]
			i += 1
			j += 1
		elif w2[j] == c:
			j += 1
		else:
			flag = False
	if flag:
		print('YES')
	else:
		print('NO')


tc = int(input())
for i in range(tc):
	x = input()
	y = input()
	x += '#'
	y += '#'
	z = ''
	for i in range(len(x) - 1):
		if x[i] != x[i + 1]:
			z += x[i]
			z += ','
		else:
			z += x[i]
	l1 = list(z.split(','))
	kk = ''
	for i in range(len(y) - 1):
		if y[i] != y[i + 1]:
			kk += y[i]
			kk += ','
		else:
			kk += y[i]
	l2 = list(kk.split(','))
	if len(l1) != len(l2):
		print('NO')
	else:
		status = 1
		for i in range(len(l1) - 1):
			if l1[i][0] == l2[i][0] and len(l2[i]) >= len(l1[i]):
				pass
			else:
				status = 0
		if status == 1:
			print('YES')
		else:
			print('NO')


def check(a, b):
	n1 = list()
	n2 = list()
	w1 = list()
	w2 = list()
	cnt = 1
	q = a[0]
	for (i, x) in enumerate(a):
		if i == 0:
			continue
		if x == q:
			cnt += 1
		else:
			n1.append(cnt)
			cnt = 1
			w1.append(q)
			q = x
	w1.append(q)
	n1.append(cnt)
	cnt = 1
	q = b[0]
	for (i, x) in enumerate(b):
		if i == 0:
			continue
		if x == q:
			cnt += 1
		else:
			n2.append(cnt)
			cnt = 1
			w2.append(q)
			q = x
	w2.append(q)
	n2.append(cnt)
	if w2 != w1:
		return False
	for i in range(len(w1)):
		if n1[i] > n2[i]:
			return False
	return True
n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	if check(s1, s2):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	t1 = input()
	t2 = input()
	l1 = len(t1)
	l2 = len(t2)
	if t1[0] == t2[0]:
		s1 = t1[0]
		s2 = t2[0]
		n1 = [1]
		n2 = [1]
		r1 = 0
		r2 = 0
		for j in range(1, l1):
			if t1[j] != t1[j - 1]:
				s1 = s1 + t1[j]
				r1 += 1
				n1.append(0)
			else:
				n1[r1] += 1
		for j in range(1, l2):
			if t2[j] != t2[j - 1]:
				s2 = s2 + t2[j]
				r2 += 1
				n2.append(0)
			else:
				n2[r2] += 1
		l1 = len(s1)
		l2 = len(s2)
		if l1 != l2:
			print('NO')
		else:
			r1 = 0
			r2 = 0
			for j in range(0, l1):
				if s1[j] != s2[j]:
					l2 = 0
					break
				elif n1[r1] > n2[r2]:
					l2 = 0
					break
				r1 += 1
				r2 += 1
			if l2 == 0:
				print('NO')
			else:
				print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	p = input()
	(i, j) = (0, 0)
	(n, m) = (len(s), len(p))
	while i < n and j < m and (s[i] == p[j]):
		while i < n and j < m and (s[i] == p[j]):
			i += 1
			j += 1
		while j < m and s[i - 1] == p[j]:
			j += 1
	if i == n and j == m:
		print('YES')
	else:
		print('NO')


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
n = int(input())
for _ in range(n):
	s = input()
	t = input()
	j = 0
	ans = 'YES'
	if s[0] != t[0]:
		print('NO')
		continue
	f = [-1 for i in range(len(s))]
	for i in range(len(s)):
		while j < len(t) and s[i] != t[j]:
			j += 1
		f[i] = j
		j += 1
	if -1 in f or len(t) in f:
		ans = 'NO'
	else:
		for i in range(len(s) - 1):
			for j in range(f[i], f[i + 1]):
				if t[j] != s[i]:
					ans = 'NO'
					break
		for j in range(f[-1], len(t)):
			if t[j] != s[-1]:
				ans = 'NO'
				break
	print(ans)


n = int(input())
for _ in range(n):
	str1 = input()
	str2 = input()
	i = 0
	p = ''
	flag = False
	for c in str2:
		if i < len(str1) and c == str1[i]:
			i += 1
			p = c
			continue
		if c != p:
			break
	else:
		flag = True
	if flag and i < len(str1):
		flag = False
	print('YES' if flag else 'NO')


from collections import defaultdict, Counter
from re import match

def do_match(f, s):
	s_pos = 0
	prev_c = f[0]
	for (i, c) in enumerate(f):
		while c != s[s_pos]:
			if s[s_pos] != prev_c:
				return 'NO'
			s_pos += 1
			if s_pos >= len(s):
				return 'NO'
		prev_c = c
		s_pos += 1
		if i != len(f) - 1 and s_pos >= len(s):
			return 'NO'
	if s_pos < len(s):
		for c in s[s_pos:]:
			if c != s[s_pos - 1]:
				return 'NO'
	return 'YES'
lines = int(input())
for i in range(lines):
	(actual, expected) = (list(input()), list(input()))
	print(do_match(actual, expected))


n = int(input())
for _ in range(n):
	s = input()
	t = input()
	ans = True
	i = 0
	j = 0
	if len(s) == 1:
		for k in range(len(t)):
			if t[k] != s[0]:
				ans = False
		if ans:
			print('YES')
		else:
			print('NO')
	elif len(s) > len(t):
		ans = False
		print('NO')
	else:
		while i < len(s) and j < len(t):
			if s[i] == t[j]:
				if i < len(s) - 1 and s[i + 1] == s[i]:
					i = i + 1
					j = j + 1
				else:
					while j < len(t) and s[i] == t[j]:
						j = j + 1
					i = i + 1
			else:
				ans = False
				break
		if ans and i == len(s) and (j == len(t)):
			print('YES')
		else:
			print('NO')


R = lambda : map(int, input().split())
for _ in range(int(input())):
	a = input()
	b = input()
	(l1, l2) = (len(a), len(b))
	f = 1
	(i, j) = (0, 0)
	while i < l1:
		last = a[i]
		c = 0
		while i < l1 and a[i] == last:
			c += 1
			i += 1
		p = 0
		while j < l2 and b[j] == last:
			p += 1
			j += 1
		if p < c:
			f = 0
			break
	if f and j == l2:
		print('YES')
	else:
		print('NO')


n = int(input())
for t in range(n):
	a = input()
	b = input()
	l1 = len(a)
	l2 = len(b)
	cur = 0
	g = 0
	f = 0
	for i in range(l2):
		if cur == l1:
			cur = l1 - 1
			f = 1
		if a[cur] == b[i]:
			cur += 1
			continue
		elif cur == 0 or f == 1:
			g = 1
			break
		elif a[cur - 1] != b[i]:
			g = 1
			break
		else:
			continue
	if g == 1 or cur != l1:
		print('NO')
	else:
		print('YES')


import re

def compare(fir, sec):
	p = re.compile('+'.join(fir) + '+$')
	if p.match(sec) is not None:
		return True
	else:
		return False

def find_first(s, begin, end):
	assert end >= begin
	element = s[begin]
	counter = 1
	if begin < end:
		while True:
			begin += 1
			if begin > end:
				break
			if s[begin] == element:
				counter += 1
			else:
				break
	return (element, counter)
n = int(input())
results = []
for i in range(n):
	first = input().strip()
	second = input().strip()
	first_end = len(first) - 1
	second_end = len(second) - 1
	first_begin = 0
	second_begin = 0
	while True:
		(first_element, first_count) = find_first(first, first_begin, first_end)
		(second_element, second_count) = find_first(second, second_begin, second_end)
		if first_element != second_element or second_count < first_count:
			results.append(False)
			break
		else:
			first_begin += first_count
			second_begin += second_count
			if first_begin == first_end + 1 and second_begin == second_end + 1:
				results.append(True)
				break
			elif first_begin == first_end + 1 or second_begin == second_end + 1:
				results.append(False)
				break
output = '\n'.join(('YES' if result else 'NO' for result in results))
print(output)


n = int(input())
while n:
	s = input()
	t = input()
	ls = []
	count = 0
	for i in range(len(s)):
		if i == 0:
			count += 1
			if i == len(s) - 1:
				ls.append([s[i], count])
		elif s[i] == s[i - 1]:
			count += 1
			if i == len(s) - 1:
				ls.append([s[i], count])
		else:
			ls.append([s[i - 1], count])
			count = 1
			if i == len(s) - 1:
				ls.append([s[i], count])
	flag = True
	j = 0
	for i in range(len(ls)):
		count = 0
		while j < len(t) and t[j] == ls[i][0]:
			count += 1
			j += 1
		if count < ls[i][1]:
			flag = False
	if j != len(t):
		flag = False
	if flag:
		print('YES')
	else:
		print('NO')
	n -= 1


n = int(input())
for ni in range(n):
	s = input()
	t = input()
	(ls, lt) = (len(s), len(t))
	i = j = 0
	res = ls <= lt
	while i < ls and res:
		(cs, ct) = (1, 0)
		while i + 1 < ls and s[i + 1] == s[i]:
			i += 1
			cs += 1
		while j < lt and t[j] == s[i]:
			j += 1
			ct += 1
		if ct < cs:
			res = False
		i += 1
	if i >= ls and j < lt:
		res = False
	print('YES' if res else 'NO')


n = int(input())
for _ in range(n):
	s1 = input()
	s2 = input()
	l = [i for i in s2][::-1]
	flag = 1
	prev_ct = 0
	for i in range(len(s1)):
		if i > 0 and s1[i] == s1[i - 1]:
			if prev_ct >= 2:
				prev_ct -= 1
				continue
		ct = 0
		while l != [] and l[-1] == s1[i]:
			l.pop()
			ct += 1
		prev_ct = ct
		if ct == 0:
			print('NO')
			flag = 0
			break
	if flag == 1 and l == []:
		print('YES')
	if l != [] and flag == 1:
		print('NO')


n = int(input())
for _ in range(n):
	s = input()
	t = list(input())
	t.reverse()
	last = None
	for c in s:
		ok = False
		if t:
			if t[-1] == c:
				t.pop()
				ok = True
			else:
				while t and t[-1] == last:
					t.pop()
				if t and t[-1] == c:
					t.pop()
					ok = True
		if not ok:
			print('NO')
			break
		last = c
	else:
		while t and t[-1] == last:
			t.pop()
		if not t:
			print('YES')
		else:
			print('NO')


n = int(input())
for i in range(n):
	a = input()
	b = input()
	aIndex = 0
	bIndex = 0
	GEQ = True
	while GEQ and aIndex < len(a) and (bIndex < len(b)):
		aInd = 0
		bInd = 0
		letter = a[aIndex:aIndex + 1]
		while a[aIndex + aInd:aIndex + aInd + 1] == letter:
			aInd += 1
		while b[bIndex + bInd:bIndex + bInd + 1] == letter:
			bInd += 1
		if bInd < aInd:
			GEQ = False
		aIndex += aInd
		bIndex += bInd
	if aIndex == len(a) and bIndex == len(b) and GEQ:
		print('YES')
	else:
		print('NO')


from itertools import groupby
n = int(input())
for i in range(n):
	s = input()
	t = input()
	k = len(s)
	m = len(t)
	if m < k:
		print('NO')
	else:
		grp1 = [''.join(g) for (_, g) in groupby(s)]
		grp2 = [''.join(g) for (_, g) in groupby(t)]
		freq1 = []
		for i in range(len(grp1)):
			freq1.append([grp1[i][0], len(grp1[i])])
		freq2 = []
		for i in range(len(grp2)):
			freq2.append([grp2[i][0], len(grp2[i])])
		if len(grp1) != len(grp2):
			print('NO')
		else:
			x = 0
			for i in range(len(freq1)):
				if freq1[i][0] != freq2[i][0] or freq2[i][1] < freq1[i][1]:
					print('NO')
					x = 1
					break
			if x == 0:
				print('YES')


n = int(input())
for _ in range(n):
	s = input() + '@'
	l = len(s)
	s1 = input() + '$'
	l1 = len(s1)
	ans = 'YES'
	i = 0
	j = 0
	while ans == 'YES':
		if s1[j] == '$':
			if s[i] == '@':
				break
			ans = 'NO'
			break
		if s[i] == s1[j]:
			i += 1
			j += 1
		elif s[i] != s1[j] and s1[j] == s[i - 1]:
			j += 1
		else:
			ans = 'NO'
			break
	print(ans)


n = int(input())
for _ in range(n):
	s = input()
	t = input()
	i = 0
	j = 0
	ok = True
	while i < len(s) and j < len(t):
		if s[i] != t[j]:
			ok = False
			break
		k1 = 1
		k2 = 1
		while i + 1 < len(s) and s[i] == s[i + 1]:
			i += 1
			k1 += 1
		i += 1
		while j + 1 < len(t) and t[j] == t[j + 1]:
			j += 1
			k2 += 1
		j += 1
		if k1 > k2:
			ok = False
			break
	if ok and (i != len(s) or j != len(t)):
		ok = False
	if ok:
		print('YES')
	else:
		print('NO')


n = int(input())
for _ in range(n):
	s1 = input()
	s2 = input()
	ok = True
	(i, j) = (0, 0)
	while i < len(s1):
		if j >= len(s2) or s1[i] != s2[j]:
			ok = False
			break
		n1 = 1
		while i < len(s1) - 1 and s1[i] == s1[i + 1]:
			n1 += 1
			i += 1
		n2 = 1
		while j < len(s2) - 1 and s2[j] == s2[j + 1]:
			n2 += 1
			j += 1
		if n2 < n1:
			ok = False
			break
		i += 1
		j += 1
	if ok and j >= len(s2):
		print('YES')
	else:
		print('NO')


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 main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	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
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
from collections import OrderedDict
for __ in range(iinp()):
	s = stl(ssinp())
	t = stl(ssinp())
	t1 = []
	curr = t[0]
	l = [curr]
	for i in range(1, len(t)):
		if t[i] == curr:
			l.append(t[i])
		else:
			t1.append(l)
			curr = t[i]
			l = [curr]
	t1.append(l)
	s1 = []
	curr = s[0]
	l = [curr]
	for i in range(1, len(s)):
		if s[i] == curr:
			l.append(s[i])
		else:
			s1.append(l)
			curr = s[i]
			l = [curr]
	s1.append(l)
	l1 = len(s1)
	l2 = len(t1)
	if l2 != l1:
		print('NO')
	else:
		f = 0
		for i in range(l1):
			if s1[i][0] != t1[i][0]:
				print('NO')
				f = 1
				break
			elif len(s1[i]) > len(t1[i]):
				print('NO')
				f = 1
				break
		if f == 0:
			print('YES')


def group_by_alph(s):
	groups = []
	prev = s[0]
	for c in s[1:len(s)]:
		if c == prev[0]:
			prev = prev + c
		else:
			groups.append(prev)
			prev = c
	groups.append(prev)
	return groups
n = int(input())
for _ in range(n):
	s = input()
	t = input()
	sg = group_by_alph(s)
	tg = group_by_alph(t)
	tgl = len(tg)
	sgl = len(sg)
	if sgl != tgl:
		print('NO')
	else:
		ind = 1
		for i in range(sgl):
			if tg[i][0] == sg[i][0] and len(tg[i]) >= len(sg[i]):
				continue
			else:
				ind = 0
				break
		if ind == 1:
			print('YES')
		else:
			print('NO')


def solve(s, t):
	if len(t) < len(s):
		return 'NO'
	if set(s) != set(t):
		return 'NO'
	arr = []
	(i, n) = (0, len(s))
	while i < n:
		(cnt, j) = (0, i)
		while j < n and i < n and (s[i] == s[j]):
			j += 1
			cnt += 1
		arr.append([s[i], cnt])
		i = j
	(brr, i, n) = ([], 0, len(t))
	while i < n:
		(cnt, j) = (0, i)
		while j < n and i < n and (t[i] == t[j]):
			j += 1
			cnt += 1
		brr.append([t[i], cnt])
		i = j
	if len(arr) != len(brr):
		return 'NO'
	for i in range(len(arr)):
		if brr[i][0] != arr[i][0] or brr[i][1] < arr[i][1]:
			return 'NO'
	return 'YES'
q = int(input())
for _ in range(q):
	s = input()
	t = input()
	print(solve(s, t))


from sys import stdin, stdout

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

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

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

def op(ans):
	return stdout.write(str(ans) + '\n')
from itertools import groupby, zip_longest
for i in range(int(input())):
	ans = 'YES'
	a = [list(i[1]) for i in groupby(input())]
	b = [list(i[1]) for i in groupby(input())]
	for (i, j) in zip_longest(a, b, fillvalue=['.']):
		if i[0] != j[0] or len(i) > len(j):
			ans = 'NO'
	print(ans)


import sys
input = sys.stdin.readline

def chk(s, t):
	i = 0
	j = 0
	while True:
		if i < len(s) and j < len(t) and (s[i] == t[j]):
			while j < len(t) - 1 and t[j + 1] == t[j] and (i == len(s) - 1 or s[i + 1] != s[i]):
				j += 1
			i += 1
			j += 1
			if i == len(s) and j == len(t):
				return 'YES'
		else:
			return 'NO'
for _ in range(int(input())):
	print(chk(input(), input()))


import sys

def check_str(s, t):
	(i, j) = (0, 0)
	(ls, lt) = (len(s), len(t))
	while i < ls:
		(cur, cnt) = (s[i], 0)
		while i < ls and s[i] == cur:
			cnt += 1
			i += 1
		while j < lt and t[j] == cur:
			cnt -= 1
			j += 1
		if cnt > 0:
			return False
	return True if j == lt else False

def main():
	n = int(input())
	for _ in range(n):
		s = input()
		t = input()
		print('YES' if check_str(s, t) else 'NO')
if len(sys.argv) > 1 and sys.argv[1] == 'True':
	IS_LOCAL = True
main()


def bel(a, b):
	(la, lb) = (len(a), len(b))
	if la != lb:
		return False
	for i in range(la):
		if a[i][0] == b[i][0] and a[i][1] <= b[i][1]:
			continue
		return False
	return True
from itertools import groupby
group = lambda x: [(i, len(tuple(j))) for (i, j) in groupby(x)]
for _ in range(int(input())):
	if bel(group(input()), group(input())):
		print('YES')
	else:
		print('NO')


a = int(input())
AN = []
for i in range(a):
	s1 = input()
	s2 = input()
	z = len(s2)
	k = 0
	if s1[0] != s2[0] or s1[-1] != s2[-1]:
		AN.append('NO')
	else:
		L = True
		for j in range(len(s1)):
			if k < z:
				while s1[j] != s2[k] and k < z - 1:
					if s2[k] != s1[j - 1]:
						L = False
					k += 1
				if s1[j] != s2[k]:
					L = False
				else:
					k += 1
			else:
				L = False
		if L:
			for ii in range(k, z):
				if s2[ii] != s2[k - 1]:
					L = False
		if L:
			AN.append('YES')
		else:
			AN.append('NO')
for an in AN:
	print(an)


n = int(input())
for i in range(n):
	s = str(input())
	t = str(input())
	l1 = len(s)
	l2 = len(t)
	if l1 > l2:
		print('NO')
	else:
		i = 0
		j = 0
		flag = 0
		while i < l1 and j < l2:
			if s[i] == t[j]:
				i += 1
				j += 1
			elif i > 0 and t[j] == s[i - 1]:
				j += 1
			else:
				flag = 1
				break
		if flag == 1 or i < l1:
			print('NO')
		else:
			if j < l2:
				for k in range(j, l2):
					if s[l1 - 1] == t[k]:
						continue
					else:
						flag = 1
						break
			if flag == 1:
				print('NO')
			else:
				print('YES')


t = int(input())
for _ in range(t):
	n = input()
	x = input()
	count1 = 0
	count2 = 0
	flag = True
	while count1 < len(n) or count2 < len(x):
		if count1 < len(n) and count2 < len(x) and (n[count1] == x[count2]):
			count1 += 1
			count2 += 1
			continue
		if count1 == 0:
			flag = False
			break
		while count2 < len(x):
			if x[count2] == n[count1 - 1]:
				count2 += 1
			else:
				break
		if count2 == len(x) and count1 == len(n):
			flag = True
			break
		if count1 < len(n) and count2 < len(x) and (x[count2] == n[count1]):
			count1 += 1
			count2 += 1
		else:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


I = lambda : map(int, input().split())
n = int(input())
for i in range(n):
	(s, t) = (input(), input())
	ls = len(s)
	lt = len(t)
	ct = It = 0
	cs = Is = 1
	h = s[0]
	ans = 'YES'
	while True:
		while Is < ls and s[Is] == h:
			cs += 1
			Is += 1
		while It < lt and t[It] == h:
			ct += 1
			It += 1
		if ct < cs:
			ans = 'NO'
			break
		if Is == ls:
			break
		ct = cs = 0
		h = s[Is]
	if It != lt:
		ans = 'NO'
	print(ans)


for x in range(int(input())):
	s = input()
	t = input()
	n = len(s)
	m = len(t)
	(i, j) = (0, 0)
	while i < n and j < m and (s[i] == t[j]):
		while i < n and j < m and (s[i] == t[j]):
			i += 1
			j += 1
		while j < m and s[i - 1] == t[j]:
			j += 1
	if i == n and j == m:
		print('YES')
	else:
		print('NO')


def makeDict(s):
	l = []
	l.append([s[0], 1])
	(c, count) = (s[0], 1)
	for i in range(1, len(s)):
		if s[i] != c:
			c = s[i]
			count = 1
		else:
			count += 1
		if l[-1][0] != c:
			l.append([c, count])
		else:
			l[-1][-1] = count
	return l
for _ in range(int(input())):
	s = str(input())
	t = str(input())
	l1 = makeDict(s)
	l2 = makeDict(t)
	flag = 1
	if len(l1) != len(l2):
		flag = 0
	else:
		for i in range(len(l1)):
			if l1[i][0] != l2[i][0] or l1[i][-1] > l2[i][-1]:
				flag = 0
				break
	if flag == 1:
		print('YES')
	else:
		print('NO')


from sys import setcheckinterval, stdin
setcheckinterval(1000)
iin = lambda : int(stdin.readline())
lin = lambda : list(map(int, stdin.readline().split()))
n = iin()
for i in range(n):
	(a, b) = (input(), input())
	ord1 = [[a[0], 1]]
	l = len(a)
	for i in range(1, l):
		if a[i] == ord1[-1][0]:
			ord1[-1][1] += 1
		else:
			ord1.append([a[i], 1])
	ord2 = [[b[0], 1]]
	l = len(b)
	for i in range(1, l):
		if b[i] == ord2[-1][0]:
			ord2[-1][1] += 1
		else:
			ord2.append([b[i], 1])
	if len(ord1) != len(ord2):
		print('NO')
		continue
	for (i, j) in enumerate(ord1):
		try:
			if j[0] != ord2[i][0] or j[1] > ord2[i][1]:
				raise ValueError
		except:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	t = input()
	if len(s) > len(t):
		print('NO')
		continue
	(i, j) = (0, 0)
	while i < len(s) and j < len(t):
		cs = s[i]
		ls = 1
		while i + 1 < len(s) and s[i + 1] == cs:
			i += 1
			ls += 1
		ct = t[j]
		lt = 1
		while j + 1 < len(t) and t[j + 1] == ct:
			j += 1
			lt += 1
		if cs != ct or lt < ls:
			print('NO')
			break
		i += 1
		j += 1
		if i == len(s) and j != len(t) or (i != len(s) and j == len(t)):
			print('NO')
			break
	else:
		print('YES')


n = int(input())
for _ in range(n):
	s = input()
	t = input()
	x = 0
	c = 0
	for i in t:
		c = c + 1
		if x == 0:
			if i == s[x]:
				x = x + 1
			else:
				break
		elif i == s[x]:
			x = x + 1
		elif i == s[x - 1]:
			pass
		else:
			break
		if x == len(s):
			t = t[c:]
			break
	if x == len(s) and (len(list(set(t))) == 1 and t[0] == s[len(s) - 1] or t == ''):
		print('YES')
	else:
		print('NO')


test = int(input())
for test1 in range(test):
	s = str(input())
	t = str(input())
	sArr = []
	tArr = []
	curLen = 1
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			curLen += 1
		else:
			sArr.append([s[i - 1], curLen])
			curLen = 1
	sArr.append([s[len(s) - 1], curLen])
	curLen = 1
	for i in range(1, len(t)):
		if t[i] == t[i - 1]:
			curLen += 1
		else:
			tArr.append([t[i - 1], curLen])
			curLen = 1
	tArr.append([t[len(t) - 1], curLen])
	ans = 'YES'
	if len(sArr) == len(tArr):
		for i in range(len(tArr)):
			if not (tArr[i][0] == sArr[i][0] and tArr[i][1] >= sArr[i][1]):
				ans = 'NO'
				break
	else:
		ans = 'NO'
	print(ans)


ll = lambda : list(map(int, input().split()))
testcases = 1
testcases = int(input())
import math as m

def cs(s):
	s = list(s)
	res = []
	res.append([s[0], 1])
	pc = s[0]
	for i in s[1:]:
		if i == pc:
			res[-1][-1] += 1
		else:
			res.append([i, 1])
		pc = i
	return res
for testcase in range(testcases):
	ans = ['NO', 'YES']
	s1 = input()
	s2 = input()
	x = len(s1)
	y = len(s2)
	cs1 = cs(s1)
	cs2 = cs(s2)
	if len(cs1) != len(cs2):
		print('NO')
	else:
		for i in range(len(cs1)):
			if cs1[i][0] == cs2[i][0] and cs1[i][1] <= cs2[i][1]:
				continue
			else:
				print('NO')
				break
		else:
			print('YES')


for n in range(int(input())):
	arr = []
	ctar = []
	brr = []
	ctbr = []
	S = input()
	P = input()
	for i in range(len(S)):
		if len(arr) == 0 or arr[-1] != S[i]:
			arr.append(S[i])
			ctar.append(1)
		else:
			ctar[-1] += 1
	for i in range(len(P)):
		if len(brr) == 0 or brr[-1] != P[i]:
			brr.append(P[i])
			ctbr.append(1)
		else:
			ctbr[-1] += 1
	if len(arr) != len(brr):
		print('NO')
	else:
		flag = 1
		for i in range(len(arr)):
			if arr[i] != brr[i] or ctar[i] > ctbr[i]:
				flag = 0
				break
		if flag:
			print('YES')
		else:
			print('NO')


from itertools import *
for _ in [0] * int(input()):
	print('YNEOS'[any((a != b or len([*g]) > len([*h]) for ((a, g), (b, h)) in zip_longest(*map(groupby, (input(), input())), fillvalue=(0, 0))))::2])


n = int(input())
for i in range(n):
	s = input()
	c = input()
	a = []
	b = []
	p = -1
	cnt = 0
	la = 0
	for el in s:
		if p == -1:
			p = el
			cnt += 1
		elif el == p:
			cnt += 1
		else:
			a.append((cnt, p))
			cnt = 1
			la += 1
		p = el
	if cnt != 0:
		a.append((cnt, p))
		la += 1
	p = -1
	cnt = 0
	lb = 0
	for el in c:
		if p == -1:
			p = el
			cnt += 1
		elif el == p:
			cnt += 1
		else:
			b.append((cnt, p))
			cnt = 1
			lb += 1
		p = el
	if cnt != 0:
		b.append((cnt, p))
		lb += 1
	if la != lb:
		print('NO')
		continue
	r = 'YES'
	for i in range(la):
		if a[i][1] != b[i][1] or a[i][0] > b[i][0]:
			r = 'NO'
	print(r)


import sys, math, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
for i in range(n):
	a = input().strip()
	b = input().strip()
	if len(a) > len(b) or set(a) != set(b):
		print('NO')
	else:
		p = 0
		q = 0
		d = 0
		prev = a[p]
		while p < len(a):
			if a[p] == b[q]:
				p += 1
				q += 1
				if q >= len(b) and p < len(a):
					print('NO')
					d = 1
					break
				prev = a[p - 1]
			elif prev == b[q]:
				q += 1
				if q >= len(b):
					print('NO')
					d = 1
					break
			else:
				print('NO')
				d = 1
				break
		if q < len(b) and d == 0:
			d = 1
			if len(set(b[q:])) == 1 and b[q] == prev:
				print('YES')
			else:
				print('NO')
		if d == 0:
			print('YES')


n = int(input())
for _ in range(n):
	w1 = input()
	w2 = input()
	i = 0
	j = 0
	while True:
		if w1[i] == w2[j]:
			i += 1
			j += 1
			if i == len(w1) and j == len(w2):
				print('YES')
				break
			if i == len(w1) and j < len(w2):
				if len(set(w2[j - 1:])) != 1:
					print('NO')
					break
				else:
					print('YES')
					break
			if i < len(w1) and j == len(w2):
				print('NO')
				break
		elif i == 0 and j == 0:
			print('NO')
			break
		elif w2[j] == w2[j - 1]:
			j += 1
			if j == len(w2):
				print('NO')
				break
		else:
			print('NO')
			break


n = int(input())
for baka in range(n):
	a = input()
	b = input()
	i = 0
	j = 0
	c1 = 0
	c2 = 0
	while i < len(a) and j < len(b):
		if c1 < c2:
			break
		if a[i] != b[j]:
			break
		c1 = 0
		while j < len(b) and a[i] == b[j]:
			c1 += 1
			j += 1
		i += 1
		c2 = 1
		while i < len(a) and a[i] == a[i - 1]:
			c2 += 1
			i += 1
		if c1 < c2:
			break
	if i == len(a) and j == len(b) and (c1 >= c2):
		print('YES')
	else:
		print('NO')


def gamedForLoop(x, y):
	j = 0
	i = 0
	while 1:
		if x[i] != y[j] or len(x) - i > len(y) - j:
			return 'NO'
		elif len(x) - i == 1 and len(y) - j == 1 and (x[i] == y[j]):
			return 'YES'
		else:
			if len(x) - i == 1 and len(y) - j > 1:
				if x[0] == y[0]:
					j += 1
					continue
			if x[i] == y[j] and x[i + 1] == y[j + 1]:
				i += 1
				j += 1
				continue
			if x[i] == y[j] and x[i] == y[j + 1]:
				j += 1
				continue
			else:
				j += 1
				i += 1
				continue
output = []
n = int(input())
for i in range(0, n):
	x = input()
	y = input()
	output.append(gamedForLoop(x, y))
for i in output:
	print(i)


n = int(input())
for _ in range(n):
	s1 = str(input())
	s2 = str(input())
	j = 1
	i = 1
	flag = True
	if s1[0] != s2[0]:
		flag = False
	else:
		while i < len(s1) and j < len(s2):
			if s1[i] == s2[j]:
				i += 1
				j += 1
			elif s2[j] != s2[j - 1]:
				flag = False
				break
			else:
				j += 1
		if i != len(s1):
			flag = False
		if j != len(s2):
			for k in range(j, len(s2)):
				if s2[k] != s2[k - 1]:
					flag = False
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for you in range(t):
	s = input()
	z = input()
	ls = []
	lz = []
	start = 0
	end = 0
	for i in range(1, len(s)):
		if s[i] == s[start]:
			end += 1
		else:
			ls.append((s[start], end - start))
			start = i
			end = i
	ls.append((s[start], end - start))
	start = 0
	end = 0
	for i in range(1, len(z)):
		if z[i] == z[start]:
			end += 1
		else:
			lz.append((z[start], end - start))
			start = i
			end = i
	lz.append((z[start], end - start))
	if len(lz) != len(ls):
		print('NO')
		continue
	k = len(ls)
	poss = 1
	for i in range(k):
		if ls[i][0] != lz[i][0]:
			poss = 0
			break
		if ls[i][1] > lz[i][1]:
			poss = 0
			break
	if poss:
		print('YES')
	else:
		print('NO')


for _ in range(0, int(input())):
	s = input()
	t = input()
	orders = [s[0]]
	ordert = [t[0]]
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			orders.append(s[i])
	for i in range(1, len(t)):
		if t[i] != t[i - 1]:
			ordert.append(t[i])
	if len(orders) == len(ordert):
		temp = True
		for i in range(0, len(orders)):
			if orders[i] != ordert[i]:
				temp = False
				break
		if temp:
			ss = [0] * len(orders)
			tt = [0] * len(ordert)
			s1 = 0
			t1 = 0
			ss[s1] += 1
			tt[t1] += 1
			for i in range(1, len(s)):
				if s[i] == s[i - 1]:
					ss[s1] += 1
				else:
					s1 += 1
					ss[s1] += 1
			for i in range(1, len(t)):
				if t[i] == t[i - 1]:
					tt[t1] += 1
				else:
					t1 += 1
					tt[t1] += 1
			k = 'YES'
			for i in range(0, len(ss)):
				if tt[i] < ss[i]:
					k = 'NO'
					break
			print(k)
		else:
			print('NO')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	t = input()
	mask_s = []
	mask_t = []
	prev_sym = None
	count = 0
	for j in s:
		if prev_sym == None:
			prev_sym = j
		if j != prev_sym:
			mask_s.append([prev_sym, count])
			count = 1
			prev_sym = j
		else:
			count += 1
	mask_s.append([prev_sym, count])
	prev_sym = None
	count = 0
	for j in t:
		if prev_sym == None:
			prev_sym = j
		if j != prev_sym:
			mask_t.append([prev_sym, count])
			count = 1
			prev_sym = j
		else:
			count += 1
	mask_t.append([prev_sym, count])
	if len(mask_s) != len(mask_t):
		print('NO')
	else:
		error = False
		for i in range(len(mask_s)):
			if mask_s[i][0] != mask_t[i][0] or mask_s[i][1] > mask_t[i][1]:
				error = True
				break
		print(['YES', 'NO'][error])


def next_char(str_, index):
	tmp = str_[index]
	count = 0
	while str_[index] == tmp:
		index += 1
		count += 1
		if index == len(str_):
			break
	return (index, count)

def main():
	n = int(input())
	for _ in range(n):
		ans = input()
		que = input()
		pA1 = pA2 = pQ1 = pQ2 = 0
		answered = False
		if ans[pA1] != que[pQ1]:
			print('NO')
			continue
		while pA2 < len(ans) and pQ2 < len(que):
			pA1 = pA2
			pQ1 = pQ2
			(pA2, _) = next_char(ans, pA1)
			(pQ2, _) = next_char(que, pQ1)
			if ans[pA1:pA2] not in que[pQ1:pQ2]:
				print('NO')
				answered = True
				break
		if answered:
			continue
		if pA2 < len(ans) or pQ2 < len(que):
			print('NO')
		else:
			print('YES')
main()


def mp():
	return map(int, input().split())
n = int(input())
for q in range(n):
	s = input()
	t = input()
	cnt_s = []
	i = 0
	while i < len(s):
		c = 1
		while i + 1 < len(s) and s[i] == s[i + 1]:
			i += 1
			c += 1
		cnt_s.append((s[i], c))
		i += 1
	cnt_t = []
	i = 0
	while i < len(t):
		c = 1
		while i + 1 < len(t) and t[i] == t[i + 1]:
			i += 1
			c += 1
		cnt_t.append((t[i], c))
		i += 1
	fail = False
	if len(cnt_s) != len(cnt_t):
		fail = True
	for i in range(min(len(cnt_s), len(cnt_t))):
		if not (cnt_s[i][0] == cnt_t[i][0] and cnt_s[i][1] <= cnt_t[i][1]):
			fail = True
	if fail:
		print('NO')
	else:
		print('YES')


for x in range(int(input())):
	a = input()
	b = input()
	flag = 0
	(i, j) = (0, 0)
	al = len(a)
	bl = len(b)
	bt = 0
	for i in range(al):
		if bt >= bl:
			flag = 0
			break
		if a[i] == b[bt] and i + 1 < al and (a[i] == a[i + 1]):
			bt += 1
			continue
		if a[i] == b[bt]:
			while bt < bl and b[bt] == a[i]:
				bt += 1
		else:
			flag = 0
			break
		flag = 1
	while flag == 1 and bt != bl:
		if b[bt] == b[bt - 1]:
			bt + 1
		else:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	fl = True
	k = 0
	p = 0
	while k < len(s):
		c = 0
		ch = s[k]
		fl1 = True
		fl2 = True
		while fl1:
			if k + 1 < len(s):
				if s[k] == s[k + 1]:
					k = k + 1
					c = c + 1
				else:
					fl1 = False
			else:
				fl1 = False
		for j in range(p, p + c + 1):
			if j < len(t):
				if t[j] == ch:
					p = p + 1
				else:
					fl = False
					k = len(s)
			else:
				fl = False
		while fl2 and fl:
			if p < len(t):
				if t[p] == ch:
					p = p + 1
				else:
					fl2 = False
					if k + 1 == len(s):
						fl = False
			else:
				fl2 = False
		k = k + 1
	if fl == True:
		print('YES')
	else:
		print('NO')


n = int(input())
ans = 0
for i in range(n):
	x1 = input()
	x2 = input()
	i1 = 0
	i2 = 0
	flag = True
	while i2 < len(x2):
		if i2 == 0 and x2[i2] != x1[i1]:
			print('NO')
			flag = False
			break
		elif i1 < len(x1) and x2[i2] == x1[i1]:
			i1 += 1
		elif i2 != 0 and x2[i2] != x2[i2 - 1]:
			print('NO')
			flag = False
			break
		i2 += 1
	if i1 == len(x1) and flag == True:
		print('YES')
	elif flag == True:
		print('NO')


n = int(input())
for itr in range(n):
	real = input()
	actual = input()
	if len(real) > len(actual):
		print('NO')
		continue
	flag = 0
	i = 0
	j = 0
	while i < len(real):
		if j >= len(actual):
			print('NO')
			flag = 1
			break
		if real[i] != actual[j]:
			print('NO')
			flag = 1
			break
		ii = real[i]
		c1 = 0
		i += 1
		while i < len(real) and real[i] == ii:
			c1 += 1
			i += 1
		jj = actual[j]
		c2 = 0
		j += 1
		while j < len(actual) and actual[j] == jj:
			c2 += 1
			j += 1
		if c1 > c2:
			print('NO')
			flag = 1
			break
	if flag == 1:
		continue
	if j < len(actual):
		print('NO')
	else:
		print('YES')


def solve(s1, s2):
	(i1, i2) = (0, 0)
	while i1 < len(s1) and i2 < len(s2):
		(j1, j2) = (i1, i2)
		while j1 < len(s1) and s1[i1] == s1[j1]:
			j1 += 1
		while j2 < len(s2) and s2[i2] == s2[j2]:
			j2 += 1
		if s1[i1] != s2[i2] or j1 - i1 > j2 - i2:
			return 'NO'
		(i1, i2) = (j1, j2)
	return 'NO' if i1 < len(s1) or i2 < len(s2) else 'YES'
t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	print(solve(s1, s2))


t = int(input())
for r in range(t):
	d1 = {}
	d2 = {}
	l1 = []
	l2 = []
	count1 = -1
	count2 = -1
	s1 = input()
	s2 = input()
	x = True
	for i in s1:
		d1[i] = 0
	for i in range(len(s1)):
		d1[s1[i]] += 1
	countalpha1 = 0
	countalpha2 = 0
	for i in range(len(s1)):
		if i == 0 or l1[count1][0] != s1[i]:
			countalpha1 += 1
			if count1 != -1:
				l1[count1].append(countalpha1)
			count1 += 1
			l1.append([s1[i]])
			countalpha1 = 0
		else:
			countalpha1 += 1
	countalpha1 += 1
	l1[count1].append(countalpha1)
	for i in s2:
		d2[i] = 0
	for i in range(len(s2)):
		d2[s2[i]] += 1
	for i in range(len(s2)):
		if i == 0 or l2[count2][0] != s2[i]:
			countalpha2 += 1
			if count2 != -1:
				l2[count2].append(countalpha2)
			count2 += 1
			l2.append([s2[i]])
			countalpha2 = 0
		else:
			countalpha2 += 1
	countalpha2 += 1
	l2[count2].append(countalpha2)
	if len(d1) != len(d2) or len(l1) != len(l2):
		x = False
	else:
		for i in s1:
			try:
				if d2[i] < d1[i]:
					x = False
					break
			except:
				x = False
				break
		for i in range(len(l1)):
			if l1[i][0] != l2[i][0] or l1[i][1] > l2[i][1]:
				x = False
				break
	if x == True:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s1 = str(input())
	s2 = str(input())
	a = []
	ac = []
	b = []
	bc = []
	x = 0
	count = 0
	check = 1
	while x < len(s1):
		if x != 0:
			if s1[x] == s1[x - 1]:
				x += 1
				ac[count] += 1
			else:
				count += 1
				a.append(s1[x])
				ac.append(1)
				x += 1
		else:
			a.append(s1[0])
			ac.append(1)
			x += 1
	x = 0
	count = 0
	while x < len(s2):
		if x != 0:
			if s2[x] == s2[x - 1]:
				x += 1
				bc[count] += 1
			else:
				count += 1
				b.append(s2[x])
				bc.append(1)
				x += 1
		else:
			b.append(s2[0])
			bc.append(1)
			x += 1
	if a == b:
		for j in range(len(ac)):
			if ac[j] > bc[j]:
				check = 0
				break
		if check == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


a = int(input())
for i in range(a):
	c = []
	s = []
	last = ''
	for i in input():
		if last == i:
			c[-1][1] += 1
		else:
			c.append([i, 1])
		last = i
	last = ''
	for i in input():
		if last == i:
			s[-1][1] += 1
		else:
			s.append([i, 1])
		last = i
	if len(c) == len(s):
		key = True
		for i in range(len(c)):
			if c[i][0] != s[i][0] or c[i][1] > s[i][1]:
				key = False
				break
		if key:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def func(str):
	l = list()
	prev = ''
	prevCount = 0
	for x in str:
		if x == prev:
			prevCount += 1
		else:
			if prev != '':
				l.append([prev, prevCount])
			prev = x
			prevCount = 1
	if prev != '':
		l.append([prev, prevCount])
	return l
n = int(input())
for i in range(n):
	one = input()
	two = input()
	l1 = func(one)
	l2 = func(two)
	ans = ''
	if len(l1) == len(l2):
		for c in range(len(l1)):
			if l1[c][0] == l2[c][0]:
				if l1[c][1] > l2[c][1]:
					ans = 'NO'
					break
			else:
				ans = 'NO'
				break
		if ans != 'NO':
			ans = 'YES'
		print(ans)
	else:
		print('NO')


n = int(input())

def iteration():
	f = input()
	s = input()
	s_pos = 0
	prev_c = f[0]
	for (i, c) in enumerate(f):
		while c != s[s_pos]:
			if s[s_pos] != prev_c:
				return 'NO'
			s_pos += 1
			if s_pos >= len(s):
				return 'NO'
		prev_c = c
		s_pos += 1
		if i != len(f) - 1 and s_pos >= len(s):
			return 'NO'
	if s_pos < len(s):
		for c in s[s_pos:]:
			if c != s[s_pos - 1]:
				return 'NO'
	return 'YES'
for i in range(n):
	print(iteration())


for i in range(int(input())):
	s1 = input()
	s2 = input()
	s1 = list(s1)
	s2 = list(s2)
	i = 0
	j = 0
	while i < len(s1) and j < len(s2):
		if i != 0 and j != 0:
			if s1[i] == s2[j]:
				i += 1
				j += 1
			elif i != 0 and s1[i] != s2[j] and (s2[j] != s1[i - 1]):
				break
			else:
				j += 1
		elif s1[0] != s2[0]:
			break
		else:
			i += 1
			j += 1
	f = 0
	if i == len(s1):
		j = j - 1
		while j < len(s2):
			if s1[i - 1] != s2[j]:
				f = 1
				break
			j += 1
		if f == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


n = int(input())
for y in range(n):
	s1 = input()
	s2 = input()
	i = 0
	j = 0
	flag = 0
	while i < len(s1) and j < len(s2):
		if s1[i] == s2[j]:
			ch = s1[i]
			co1 = 0
			co2 = 0
			while i < len(s1):
				if s1[i] == ch:
					co1 = co1 + 1
					i = i + 1
				else:
					break
			while j < len(s2):
				if s2[j] == ch:
					co2 = co2 + 1
					j = j + 1
				else:
					break
			if co2 < co1:
				flag = 1
				print('NO')
				break
		else:
			flag = 1
			print('NO')
			break
	if flag == 0:
		if i < len(s1) or j < len(s2):
			print('NO')
		else:
			print('YES')


n = int(input())
for _ in range(n):
	s1 = input()
	s2 = input()
	d1 = []
	d2 = []
	actual = s1[0]
	cont = 1
	for c in s1[1:]:
		if c != actual:
			d1.append((actual, cont))
			actual = c
			cont = 1
		else:
			cont += 1
	d1.append((actual, cont))
	actual = s2[0]
	cont = 1
	for c in s2[1:]:
		if c != actual:
			d2.append((actual, cont))
			actual = c
			cont = 1
		else:
			cont += 1
	d2.append((actual, cont))
	if len(d1) != len(d2):
		print('NO')
	else:
		for (a, b) in zip(d1, d2):
			if a[0] != b[0] or a[1] > b[1]:
				print('NO')
				break
		else:
			print('YES')


def check(s, t):
	si = 0
	ti = 0
	while si < len(s) and ti < len(t):
		ctr = 0
		prev = s[si]
		while si < len(s) and s[si] == prev:
			ctr += 1
			prev = s[si]
			si += 1
		ctr2 = 0
		done = 0
		while ti < len(t) and t[ti] == prev:
			ctr2 += 1
			ti += 1
			done = 1
		if done == 0:
			ti += 1
		if ctr2 < ctr:
			return 'NO'
	if si < len(s) or ti < len(t):
		return 'NO'
	else:
		return 'YES'
n = int(input())
for x in range(n):
	s = input()
	t = input()
	print(check(s, t))


for _ in range(int(input())):
	a = input()
	b = input()
	n1 = len(a)
	n2 = len(b)
	(i, j) = (0, 0)
	while i < n1:
		ans = a[i]
		c = 0
		while i < n1 and a[i] == ans:
			c += 1
			i += 1
		f = 0
		while j < n2 and b[j] == ans:
			f += 1
			j += 1
		if c > f:
			f = 0
			break
	if f and j == n2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	valid = True
	a = input()
	b = input()
	la = len(a)
	lb = len(b)
	idxA = 0
	idxB = 0
	while idxA < len(a):
		dis = 0
		while dis + idxA + 1 < la and a[dis + idxA] == a[idxA + dis + 1]:
			dis += 1
		if idxB + dis + 1 > lb:
			valid = False
			break
		if a[idxA:idxA + dis + 1] != b[idxB:idxB + dis + 1]:
			valid = False
			break
		else:
			idxB += dis + 1
			while idxB < lb and b[idxB] == b[idxB - 1]:
				idxB += 1
		idxA += 1 + dis
	if valid and idxA == la and (lb == idxB):
		print('YES')
	else:
		print('NO')


import os
import random
import sys
from collections import deque
import heapq
from heapq import *
from bisect import *
from math import *
import itertools as it
sys.setrecursionlimit(999999999)

def ri():
	return [int(i) for i in input().split()]
n = ri()[0]
for i in range(n):
	s1 = list(input().strip())
	s2 = list(input().strip())
	it2 = 0
	i = 0
	while i < len(s1):
		if it2 == len(s2) or s1[i] != s2[it2]:
			print('NO')
			break
		curlet = s1[i]
		letnum1 = 0
		while s1[i] == curlet:
			letnum1 += 1
			i += 1
			if i == len(s1):
				break
		letnum2 = 0
		while s2[it2] == curlet:
			letnum2 += 1
			it2 += 1
			if it2 == len(s2):
				break
		if letnum2 < letnum1:
			print('NO')
			break
	else:
		if it2 == len(s2):
			print('YES')
		else:
			print('NO')


x = input()
x = int(x)
L = []
M = []
for i in range(x):
	L.append(input())
	M.append(input())
for i in range(x):
	NL = []
	NLN = []
	NM = []
	NMN = []
	j = 0
	lj = 0
	LL = L[i]
	while j < len(LL) - 1:
		temp = LL[j]
		if LL[j + 1] == LL[j]:
			j = j + 1
			if j == len(LL) - 1:
				count = j - lj + 1
				lj = j + 1
				letter = LL[j]
				NL.append(letter)
				NLN.append(count)
		else:
			count = j - lj + 1
			lj = j + 1
			letter = LL[j]
			NL.append(letter)
			NLN.append(count)
			j = j + 1
	if LL[len(LL) - 1] != LL[len(LL) - 2]:
		NL.append(LL[len(LL) - 1])
		NLN.append(1)
	j = 0
	lj = 0
	LL = M[i]
	while j < len(LL) - 1:
		temp = LL[j]
		if LL[j + 1] == LL[j]:
			j = j + 1
			if j == len(LL) - 1:
				count = j - lj + 1
				lj = j + 1
				letter = LL[j]
				NM.append(letter)
				NMN.append(count)
		else:
			count = j - lj + 1
			lj = j + 1
			letter = LL[j]
			NM.append(letter)
			NMN.append(count)
			j = j + 1
	if LL[len(LL) - 1] != LL[len(LL) - 2]:
		NM.append(LL[len(LL) - 1])
		NMN.append(1)
	if len(L[i]) == 1:
		NL.append(L[i][0])
		NLN.append(1)
	if len(M[i]) == 1:
		NM.append(M[i][0])
		NMN.append(1)
	if NL != NM:
		print('NO')
	else:
		k = 0
		flag = 1
		while NLN[k] <= NMN[k]:
			if k + 1 == len(NLN):
				flag = 0
				break
			k = k + 1
		if flag == 0:
			print('YES')
		else:
			print('NO')


num_of_words = int(input())
pairs = list()
for i in range(num_of_words):
	s1 = input()
	s2 = input()
	pairs.append((s1, s2))

def check_words(first, second):
	(ind1, ind2) = (0, 0)
	while ind1 < len(first):
		if ind2 == len(second):
			return 'NO'
		if first[ind1] == second[ind2]:
			ind1 += 1
			ind2 += 1
		else:
			if ind2 != 0:
				while second[ind2] == second[ind2 - 1]:
					ind2 += 1
					if ind2 == len(second):
						return 'NO'
			if first[ind1] == second[ind2]:
				ind1 += 1
				ind2 += 1
			else:
				return 'NO'
	while ind2 < len(second):
		if second[ind2] != second[ind2 - 1]:
			return 'NO'
		ind2 += 1
	return 'YES'

def sol_b(words_pairs):
	for pair in words_pairs:
		print(check_words(pair[0], pair[1]))
sol_b(pairs)


from collections import Counter
n = int(input())
for i in range(n):
	a = input()
	b = input()
	flag = 0
	p = 0
	m = 0
	while m < len(a):
		k = m
		count = 0
		countb = 0
		while a[k] == a[m]:
			count += 1
			k += 1
			if k == len(a):
				break
		if p < len(b):
			while b[p] == a[m]:
				countb += 1
				p += 1
				if p == len(b):
					break
		m = m + count
		if countb < count or (m == len(a) and p != len(b)):
			flag = 1
			break
	if flag == 1 or a[-1] != b[-1]:
		print('NO')
	else:
		print('YES')


from itertools import groupby, zip_longest
I = lambda : map(int, input().split())
for _ in range(int(input())):
	res = 0
	g1 = groupby(input())
	g2 = groupby(input())
	for (i, j) in zip_longest(g1, g2, fillvalue=(0, 0)):
		(a, b) = i
		(c, d) = j
		if a != c or len(list(b)) > len(list(d)):
			res = 1
			break
	print('YNEOS'[res::2])


def fun1(s):
	if len(s) <= 0:
		return {}
	else:
		d = []
		count = 0
		x = s[0]
		for i in s:
			if x != i:
				d.append((x, count))
				x = i
				count = 1
			else:
				count += 1
		d.append((x, count))
		return d

def fun2(s1, s2):
	l1 = fun1(s1)
	l2 = fun1(s2)
	if len(l1) != len(l2):
		return False
	else:
		for i in range(len(l1)):
			x = l1[i]
			y = l2[i]
			if x[0] != y[0]:
				return False
			if x[1] > y[1]:
				return False
		return True
n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	x = fun2(s1, s2)
	if x:
		print('YES')
	else:
		print('NO')


from collections import deque as D
t = int(input())
for _ in range(t):
	a = D(list(input()))
	b = D(list(input()))
	p = None
	f = True
	while a and b:
		x = a.popleft()
		if b[0] == x:
			b.popleft()
		elif b[0] == p:
			while b and b[0] == p:
				b.popleft()
			if not b:
				f = False
				break
			if b[0] == x:
				b.popleft()
			else:
				f = False
		else:
			f = False
		p = x
	if a:
		f = False
	if b and set(b) != {p}:
		f = False
	if f:
		print('YES')
	else:
		print('NO')


def gat(s):
	i = 0
	j = 0
	a = []
	while j < len(s) - 1:
		if s[j] != s[j + 1]:
			a.append(s[i:j + 1])
			j += 1
			i = j
		else:
			j += 1
	return a

def id(s1, s2):
	s1 = gat(s1)
	s2 = gat(s2)
	if len(s1) != len(s2):
		return 'NO'
	for i in range(len(s1)):
		if s1[i][0] != s2[i][0] or len(s1[i]) > len(s2[i]):
			return 'NO'
	return 'YES'
for i in range(int(input())):
	s1 = input() + '1'
	s2 = input() + '1'
	print(id(s1, s2))


import io, os
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
out = []
for _ in range(ii()):
	s = input().strip()
	t = input().strip()
	ok = 1
	i = j = 0
	while i < len(s):
		i2 = i + 1
		while i2 < len(s) and s[i] == s[i2]:
			i2 += 1
		j2 = j + 1
		while j2 < len(t) and t[j] == t[j2]:
			j2 += 1
		if j == len(t) or s[i] != t[j] or j2 - j < i2 - i:
			ok = 0
			break
		i = i2
		j = j2
	if j != len(t):
		ok = 0
	out.append('YES' if ok else 'NO')
print(*out, sep='\n')


def make(temp):
	i = 0
	l = len(temp)
	arr = []
	while i < l:
		t = temp[i]
		c = 0
		while i < l and temp[i] == t:
			c += 1
			i += 1
		arr.append([t, c])
	return arr
n = int(input())
for _ in range(n):
	string = input()
	regex = ''
	copy = input()
	l1 = len(string)
	l2 = len(copy)
	if l2 < l1:
		print('NO')
	else:
		flag = 0
		i = 0
		arr1 = make(string)
		arr2 = make(copy)
		if len(arr1) != len(arr2):
			print('NO')
		else:
			l = len(arr1)
			for i in range(l):
				if arr1[i][0] == arr2[i][0]:
					if arr2[i][1] < arr1[i][1]:
						flag = 1
						break
				else:
					flag = 1
					break
			if flag:
				print('NO')
			else:
				print('YES')


import math
import sys
n = int(input())
for i in range(n):
	s = input()
	t = input()
	p = j = 0
	c = 0
	while j < len(s) and p < len(t):
		if s[j] != t[p]:
			break
		else:
			p += 1
			if j == len(s) - 1:
				while p < len(t) and s[j] == t[p]:
					p += 1
				j += 1
				break
			while p < len(t) and s[j] == t[p] and (s[j + 1] != t[p]):
				p += 1
		j += 1
	print('YES') if j == len(s) and p == len(t) else print('NO')


n = int(input())
for _ in range(n):
	s = input()
	t = input()
	(i, j) = (0, 0)
	while i < len(s):
		c = s[i]
		(x, y) = (0, 0)
		while i < len(s) and s[i] == c:
			i += 1
			x += 1
		while j < len(t) and t[j] == c:
			j += 1
			y += 1
		if x > y:
			print('NO')
			break
	else:
		print('YES' if j == len(t) else 'NO')


for i in range(int(input())):
	f = input()
	s = input()
	L = len(f)
	f = f + '0'
	i = 0
	for j in range(len(s)):
		if f[i] == s[j] and i < L:
			i += 1
		elif s[j - 1] != s[j] or j == 0:
			i = -1
			break
	print('YES') if i == L else print('NO')


n = int(input())
for _ in range(n):
	first = input()
	second = input()

	def newWord(oldWord):
		word = []
		i = 0
		while i < len(oldWord):
			repeat = 1
			while i < len(oldWord) - 1 and oldWord[i] == oldWord[i + 1]:
				i += 1
				repeat += 1
			word.append((oldWord[i], repeat))
			i += 1
		return word

	def compare(fw, sw):
		if len(fw) != len(sw):
			return False
		for i in range(len(fw)):
			if fw[i][0] != sw[i][0] or fw[i][1] > sw[i][1]:
				return False
		return True
	print('YES' if compare(newWord(first), newWord(second)) else 'NO')


import itertools
n = int(input())
for _ in range(n):
	s = list(input())
	t = list(input())
	sgr = itertools.groupby(s)
	tgr = itertools.groupby(t)
	slist = []
	tlist = []
	for (key, group) in sgr:
		slist.append([key, len(list(group))])
	for (key, group) in tgr:
		tlist.append([key, len(list(group))])
	if len(slist) != len(tlist):
		print('NO')
	else:
		flag = 1
		for i in range(len(slist)):
			if slist[i][0] == tlist[i][0] and slist[i][1] <= tlist[i][1]:
				continue
			else:
				flag = 0
				break
		if flag == 1:
			print('YES')
		else:
			print('NO')


import math
for i in range(int(input())):
	a = list(input())
	b = list(input())
	lenA = len(a)
	lenB = len(b)
	if lenB < lenA:
		print('NO')
	else:
		Thing = True
		i = 0
		j = 0
		while i != lenA and j != lenB:
			if a[i] == b[j]:
				i += 1
				j += 1
			else:
				if j == 0 or b[j] != a[i - 1]:
					Thing = False
					break
				j += 1
		if i != lenA:
			Thing = False
		elif j != lenB:
			while j != lenB:
				if b[j] == a[lenA - 1]:
					j += 1
				else:
					Thing = False
					break
		if Thing:
			print('YES')
		else:
			print('NO')


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

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

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

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

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

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	a = st()
	b = st()
	x = len(a)
	y = len(b)
	if y < x:
		pr('NO')
		return
	i = 0
	j = 0
	while i < x and j < y:
		if a[i] != b[j]:
			pr('NO')
			return
		cur = i
		c = 0
		while cur < x and a[cur] == a[i]:
			cur += 1
			c += 1
		k = j
		d = 0
		while k < y and b[k] == b[j]:
			k += 1
			d += 1
		if c > d:
			pr('NO')
			return
		i = cur
		j = k
	if i == x and j == y:
		pr('YES')
	else:
		pr('NO')
for _ in range(inp()):
	solve()


n = int(input())
for _ in range(n):
	s = input()
	t = input()
	lo = 0
	last = None
	for c in s:
		ok = False
		if lo < len(t) and t[lo] == c:
			lo += 1
			ok = True
		else:
			while lo < len(t) and t[lo] == last:
				lo += 1
			if lo < len(t) and t[lo] == c:
				lo += 1
				ok = True
		if not ok:
			print('NO')
			break
		last = c
	else:
		while lo < len(t) and t[lo] == last:
			lo += 1
		if lo == len(t):
			print('YES')
		else:
			print('NO')


from collections import Counter
import math
from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
n = int(input())
for _ in range(n):
	s = input()
	t = input()
	i = 0
	for j in range(len(t)):
		if i < len(s) and t[j] == s[i]:
			i += 1
		elif i > 0 and t[j] == s[i - 1]:
			pass
		else:
			i = 0
			break
	print('YES' if i == len(s) else 'NO')


def sol(a, b):
	(pa, pb) = (0, 0)
	while pa < len(a):
		c = a[pa]
		aCount = 0
		bCount = 0
		while pa < len(a) and a[pa] == c:
			aCount += 1
			pa += 1
		while pb < len(b) and b[pb] == c:
			bCount += 1
			pb += 1
		if bCount < aCount:
			return False
	return pb == len(b)
n = int(input())
for i in range(n):
	a = input()
	b = input()
	print('YES' if sol(a, b) else 'NO')


from itertools import groupby
for _ in range(int(input())):
	str1 = list(input())
	str2 = list(input())
	g1 = [(k, sum((1 for i in g))) for (k, g) in groupby(str1)]
	g2 = [(k, sum((1 for i in g))) for (k, g) in groupby(str2)]
	flag = True
	if len(g1) != len(g2):
		flag == False
		print('NO')
		continue
	else:
		for i in range(len(g1)):
			if g1[i][0] != g2[i][0]:
				flag = False
				break
			elif g1[i][1] > g2[i][1]:
				flag = False
				break
	if flag:
		print('YES')
	else:
		print('NO')


n = int(input())
for _ in range(n):
	l = []
	for i in range(2):
		l.append(input())
	d = []
	d.append([l[0][0], 1])
	x = len(l[0])
	for i in range(1, x):
		if l[0][i] == l[0][i - 1]:
			p = d[-1][1] + 1
			d[-1].pop()
			d[-1].append(p)
		else:
			d.append([l[0][i], 1])
	s = []
	s.append([l[1][0], 1])
	y = len(l[1])
	for i in range(1, y):
		if l[1][i] == l[1][i - 1]:
			p = s[-1][1] + 1
			s[-1].pop()
			s[-1].append(p)
		else:
			s.append([l[1][i], 1])
	r = len(d)
	t = len(s)
	if r != t:
		print('NO')
	elif x > y:
		print('NO')
	else:
		c = 0
		for i in range(len(d)):
			if s[i][0] == d[i][0] and s[i][1] >= d[i][1]:
				c += 1
			else:
				break
		if c == r:
			print('YES')
		else:
			print('NO')


t = int(input())
for x in range(t):
	s = input()
	s1 = input()
	n = len(s)
	n1 = len(s1)
	if n > n1 or s[0] != s1[0] or s[-1] != s1[-1]:
		print('NO')
		continue
	(i, j) = (0, 0)
	prev = None
	f1 = False
	while i < n and j < n1:
		if s[i] == s1[j]:
			prev = s[i]
			j += 1
			i += 1
		else:
			while j < n1 and s1[j] == prev:
				j += 1
			if j < n1 and s[i] != s1[j]:
				print('NO')
				f1 = True
				break
	if f1 == True:
		continue
	f1 = False
	if i == n:
		for j in range(j, n1):
			if s1[j] != prev:
				print('NO')
				f1 = True
				break
	else:
		print('NO')
		continue
	if f1 == False:
		print('YES')


t = int(input())
for i in range(t):
	l1 = list(input())
	l2 = list(input())
	cnt1 = []
	cnt2 = []
	cnt1.append([l1[0], 1])
	cnt2.append([l2[0], 1])
	for i in range(1, len(l1)):
		if l1[i] == l1[i - 1]:
			cnt1[-1][1] += 1
		else:
			cnt1.append([l1[i], 1])
	for i in range(1, len(l2)):
		if l2[i] == l2[i - 1]:
			cnt2[-1][1] += 1
		else:
			cnt2.append([l2[i], 1])
	ok = 1
	if len(cnt1) == len(cnt2):
		for i in range(len(cnt1)):
			if cnt1[i][0] != cnt2[i][0] or cnt2[i][1] < cnt1[i][1]:
				ok = 0
				break
	else:
		ok = 0
	if ok:
		print('YES')
	else:
		print('NO')


def ans(s, t):
	k = 0
	if len(s) > len(t):
		return 'NO'
	if set(s) != set(t):
		return 'NO'
	for i in range(len(s)):
		if k < len(t) and t[k] == s[i]:
			if i + 1 < len(s) and s[i] != s[i + 1]:
				while k < len(t) and t[k] == s[i]:
					k += 1
			elif i + 1 < len(s) and s[i] == s[i + 1]:
				k += 1
			else:
				while k < len(t) and t[k] == s[i]:
					k += 1
		else:
			return 'NO'
	if k == len(t):
		return 'YES'
	else:
		return 'NO'
n = int(input())
for i in range(n):
	s = str(input())
	t = str(input())
	print(ans(s, t))


n = int(input())
for i in range(n):
	s = list(str(input()))
	t = list(str(input()))
	if len(t) < len(s):
		print('NO')
	else:
		u = 0
		p = ''
		flag = True
		for i in range(len(t)):
			if u > len(s) - 1:
				u = len(s) - 1
			if t[i] == s[u]:
				u += 1
			elif t[i] != p:
				flag = False
				break
			p = t[i]
		if flag and u == len(s):
			print('YES')
		else:
			print('NO')


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	l1 = len(s1)
	l2 = len(s2)
	char = s1[0]
	c = 1
	a1 = []
	ans = 'YES'
	for i in range(1, l1):
		if s1[i] == char:
			c += 1
		else:
			a1.append([char, c])
			char = s1[i]
			c = 1
	a1.append([char, c])
	char = s2[0]
	c = 1
	a2 = []
	for i in range(1, l2):
		if s2[i] == char:
			c += 1
		else:
			a2.append([char, c])
			char = s2[i]
			c = 1
	a2.append([char, c])
	if len(a1) != len(a2):
		print('NO')
		continue
	for i in range(len(a1)):
		if not (a1[i][0] == a2[i][0] and a1[i][1] <= a2[i][1]):
			ans = 'NO'
			break
	print(ans)


import sys
n = int(sys.stdin.readline().strip())
for i in range(0, n):
	v = True
	s = sys.stdin.readline().strip()
	t = sys.stdin.readline().strip()
	i = 0
	j = 0
	ls = len(s)
	lt = len(t)
	while j < len(t) and i < len(s):
		l = s[i]
		x = 0
		y = 0
		w = True
		while w == True:
			i = i + 1
			x = x + 1
			if i >= ls:
				w = False
			elif s[i] != l:
				w = False
		w = True
		if t[j] != l:
			w = False
		while w == True:
			j = j + 1
			y = y + 1
			if j >= lt:
				w = False
			elif t[j] != l:
				w = False
		if y < x:
			v = False
	if j != lt or i != ls:
		v = False
	if v == True:
		print('YES')
	else:
		print('NO')


for w in range(int(input())):
	s = str(input())
	l = str(input())
	s1 = []
	s2 = []
	l1 = []
	l2 = []
	i = 0
	c = 0
	while i < len(s):
		if i == 0:
			s1.append(s[i])
			s2.append(1)
		elif s[i] == s[i - 1]:
			s2[-1] += 1
		else:
			s1.append(s[i])
			s2.append(1)
		i += 1
	i = 0
	while i < len(l):
		if i == 0:
			l1.append(l[i])
			l2.append(1)
		elif l[i] == l[i - 1]:
			l2[-1] += 1
		else:
			l1.append(l[i])
			l2.append(1)
		i += 1
	if len(s1) != len(l1):
		print('NO')
	else:
		for j in range(len(s1)):
			if s1[j] == l1[j]:
				if l2[j] >= s2[j]:
					continue
				else:
					c = 1
					break
			else:
				c = 1
				break
		if c == 1:
			print('NO')
		else:
			print('YES')


from sys import stdin
for _ in range(int(stdin.readline())):
	flag = True
	s = stdin.readline().strip('\n')
	t = stdin.readline().strip('\n')
	limit = len(t)
	ptr = 0
	prev = ';'
	for i in s:
		if prev != i:
			while ptr != limit and t[ptr] == prev:
				ptr += 1
		if ptr == limit or t[ptr] != i:
			flag = False
			break
		ptr += 1
		prev = i
	while ptr != limit and t[ptr] == s[-1]:
		ptr += 1
	if ptr != limit:
		flag = False
	if flag == True:
		print('YES')
	else:
		print('NO')


z = input
for _ in range(int(input())):
	l1 = z() + '+'
	l2 = z()
	pre = ''
	cur = 0
	c = 0
	for ch in l2:
		if ch == l1[cur]:
			pre = l1[cur]
			cur += 1
		elif ch != pre:
			print('NO')
			c = 1
			break
	if cur > len(l1) - 2 and c == 0:
		print('YES')
	elif c == 0:
		print('NO')


for _ in range(int(input())):
	(a, b) = (input(), input())
	i = j = 0
	z = len(b)
	x = len(a)
	a += '~'
	while i < x and j < z and (a[i] == b[j]):
		if a[i] == a[i + 1]:
			i += 1
			j += 1
			continue
		while j < z and a[i] == b[j]:
			j += 1
		i += 1
	if i == x and j == z:
		print('YES')
	else:
		print('NO')


z = input
for _ in range(int(input())):
	l1 = z() + '.'
	l2 = z()
	l3 = ''
	t = ''
	j = 0
	c = 0
	for i in l2:
		try:
			if i == l1[j]:
				l3 += i
				j += 1
				t = i
			elif i != t:
				c = 1
				print('NO')
				break
		except:
			break
	if l3 == l1[:-1] and c == 0:
		c = 1
		print('YES')
	if l3 != l1[::-1] and c == 0:
		print('NO')


n = int(input())
for _ in range(n):
	st1 = input()
	st2 = input()
	x = 0
	le1 = len(st1)
	le2 = len(st2)
	if le2 < le1:
		print('NO')
	else:
		i = 0
		flag = True
		while i < le1 and x < le2:
			st = st1[i]
			count1 = count2 = 0
			while st1[i] == st:
				i += 1
				count1 += 1
				if i == le1:
					break
			while st2[x] == st:
				x += 1
				count2 += 1
				if x >= le2:
					break
			if count2 < count1:
				flag = False
				break
		if x < le2:
			while x < le2:
				if st2[x] != st1[i - 1]:
					flag = False
					break
		if i == le1 and count1 <= count2 and (st2[-1] == st1[-1]) and flag:
			print('YES')
		else:
			print('NO')


testcase = int(input())
for i in range(testcase):
	string1 = [i for i in input()]
	string2 = [j for j in input()]
	buffer = [0]
	buffer1 = [0]
	for i in range(0, len(string2) - 1):
		if string2[i] != string2[i + 1]:
			buffer.append(i + 1)
	buffer.append(len(string2))
	for i in range(0, len(string1) - 1):
		if string1[i] != string1[i + 1]:
			buffer1.append(i + 1)
	buffer1.append(len(string1))
	if set(string1) == set(string2):
		if len(buffer) == len(buffer1):
			if buffer[-1] - buffer[-2] >= buffer1[-1] - buffer1[-2]:
				for i in range(0, len(buffer) - 1):
					if string2[buffer[i]] == string1[buffer1[i]] and buffer[i + 1] - buffer[i] >= buffer1[i + 1] - buffer1[i]:
						output = 'YES'
					else:
						output = 'NO'
						break
			else:
				output = 'NO'
		else:
			output = 'NO'
	else:
		output = 'NO'
	print(output)


n = int(input())
for i in range(n):
	s = input()
	t = input()
	if s[0] == t[0]:
		r = 'YES'
		posT = 0
		for posS in range(0, len(s)):
			if posT >= len(t):
				r = 'NO'
				break
			if s[posS] == t[posT]:
				posT += 1
				continue
			else:
				if t[posT] != t[posT - 1]:
					r = 'NO'
					break
				while posT < len(t) - 1 and t[posT + 1] == t[posT]:
					posT += 1
				posT += 1
				if posT >= len(t):
					r = 'NO'
					break
				if t[posT] != s[posS]:
					r = 'NO'
					break
				else:
					posT += 1
		if r == 'YES' and posT < len(t):
			if t[posT - 1] * (len(t) - posT + 1) != t[posT - 1:]:
				r = 'NO'
	else:
		r = 'NO'
	print(r)


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def read_int():
	return int(input())

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

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

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

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(A, B):

	def f(B_, c, l):
		bc = 0
		while B_ and B_[-1] == c:
			B_.pop()
			bc += 1
		return bc >= l
	B_ = [b for b in B[::-1]]
	c = None
	l = 0
	for (_, a) in enumerate(A):
		if c is None:
			c = a
			l = 0
		if a == c:
			l += 1
		else:
			if not f(B_, c, l):
				return 'NO'
			c = a
			l = 1
	else:
		if not f(B_, c, l):
			return 'NO'
	if B_:
		return 'NO'
	return 'YES'

def main():
	N = read_int()
	for _ in range(N):
		a = read_str()
		b = read_str()
		print(slv(a, b))
main()


t = int(input())
while t:
	s1 = input()
	s2 = input()
	count = 0
	l1 = []
	l2 = []
	prev = ''
	for i in s1:
		if i != prev:
			l1.append((prev, count))
			prev = i
			count = 0
		count += 1
	l1.append((prev, count))
	prev = ''
	count = 0
	for i in s2:
		if i != prev:
			l2.append((prev, count))
			prev = i
			count = 0
		count += 1
	l2.append((prev, count))
	if len(l1) != len(l2):
		print('NO')
	else:
		flag = False
		for i in range(len(l1)):
			if l1[i][0] != l2[i][0]:
				flag = True
				break
			elif l1[i][1] > l2[i][1]:
				flag = True
				break
		if flag:
			print('NO')
		else:
			print('YES')
	t -= 1


for _ in range(int(input())):
	s1 = str(input())
	s2 = str(input())
	i = 0
	j = 0
	flag = 1
	while i < len(s1) and j < len(s2):
		if s1[i] == s2[j]:
			i += 1
			j += 1
		else:
			if i == 0:
				flag = 0
				break
			i -= 1
			if s1[i] == s2[j]:
				i += 1
				j += 1
			else:
				flag = 0
				break
	while j < len(s2):
		if s2[j] != s1[-1]:
			flag = 0
		j += 1
	if (i != len(s1) or j != len(s2)) and flag == 1:
		flag = 0
	if flag == 0:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def cnt(s):
	l = [[s[0], 1]]
	for c in s[1:]:
		if l[-1][0] == c:
			l[-1][1] += 1
		else:
			l.append([c, 1])
	return l

def cmp(sc, tc):
	if len(tc) != len(sc):
		return False
	for i in range(len(tc)):
		if tc[i][0] != sc[i][0] or tc[i][1] < sc[i][1]:
			return False
	return True
for _ in range(int(input())):
	(s, t) = (input().strip(), input().strip())
	(sc, tc) = (cnt(s), cnt(t))
	print('YES' if cmp(sc, tc) else 'NO')


for k in range(int(input())):
	str1 = input()
	str2 = input()
	i = 0
	j = 0
	n1 = len(str1)
	n2 = len(str2)
	flag = True
	while i < n1:
		cur = str1[i]
		tot = 0
		while str1[i] == cur and i < n1:
			tot += 1
			i += 1
			if i == n1:
				break
		tot2 = 0
		if j < n2:
			while cur == str2[j] and j < n2:
				j += 1
				tot2 += 1
				if j == n2:
					break
		if tot > tot2:
			flag = False
	if flag == True and j == n2:
		print('YES')
	else:
		print('NO')


import sys
import bisect
t = int(input())
for _ in range(t):
	s = input()
	s1 = input()
	ptr = 0
	ptr1 = 0
	yes = 1
	(m1, m2, ch) = (len(s), len(s1), s[0])
	while True:
		cnt = 0
		while ptr < m1 and ch == s[ptr]:
			cnt += 1
			ptr += 1
		cnt1 = 0
		while ptr1 < m2 and ch == s1[ptr1]:
			ptr1 += 1
			cnt1 += 1
		if cnt1 < cnt:
			yes = 0
			break
		if ptr >= m1 and ptr1 >= m2:
			break
		if ptr == m1 and ptr1 != m2:
			yes = 0
			break
		if ptr < m1:
			ch = s[ptr]
	if yes:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout

def input():
	return stdin.readline().strip()
MOD = 1000000007
for t in range(int(input())):
	b = input()
	a = input()
	if len(b) > len(a):
		print('NO')
		continue
	count = 1
	x = []
	for i in range(1, len(b)):
		if b[i] == b[i - 1]:
			count += 1
		else:
			x.append([b[i - 1], count])
			count = 1
	x.append((b[-1], count))
	count = 1
	y = []
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			count += 1
		else:
			y.append([a[i - 1], count])
			count = 1
	y.append((a[-1], count))
	if len(x) != len(y):
		print('NO')
		continue
	flag = True
	for i in range(len(x)):
		if x[i][0] != y[i][0] or x[i][1] > y[i][1]:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


def forward(s, p, len):
	cnt = 1
	while p < len - 1 and s[p] == s[p + 1]:
		p += 1
		cnt += 1
	return cnt

def judge(s1, s2):
	len_s1 = len(s1)
	len_s2 = len(s2)
	p1 = p2 = 0
	while p1 < len_s1 and p2 < len_s2:
		if s1[p1] == s2[p2]:
			con_s1 = forward(s1, p1, len_s1)
			con_s2 = forward(s2, p2, len_s2)
			if con_s1 > con_s2:
				print('NO')
				return
			else:
				p1 += con_s1
				p2 += con_s2
		else:
			print('NO')
			return
	if p1 != len_s1 or p2 != len_s2:
		print('NO')
		return
	print('YES')
n = int(input())
for index in range(n):
	s1 = input()
	s2 = input()
	judge(s1, s2)


n = int(input())
for i in range(n):
	s = list(input())
	s.append(0)
	dan = []
	counter = 1
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			dan.append((s[i - 1], counter))
			counter = 1
		else:
			counter += 1
	t = list(input())
	t.append(0)
	j = 0
	lena = len(dan)
	counter = 1
	for i in range(1, len(t)):
		if t[i] != t[i - 1]:
			if j >= lena:
				print('NO')
				break
			if t[i - 1] == dan[j][0] and counter >= dan[j][1]:
				j += 1
				counter = 1
			else:
				print('NO')
				break
		else:
			counter += 1
	else:
		if j == lena:
			print('YES')
		else:
			print('NO')


n = int(input().strip())
while n > 0:
	s = input()
	t = input()
	ls = [(s[0], 1)]
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			ls[-1] = (s[i], ls[-1][1] + 1)
		else:
			ls.append((s[i], 1))
	vs = [(t[0], 1)]
	c = 0
	flag = 1
	for i in range(1, len(t)):
		if t[i] == t[i - 1]:
			vs[-1] = (t[i], vs[-1][1] + 1)
		elif c < len(ls):
			if ls[c][0] == vs[c][0] and ls[c][1] <= vs[c][1]:
				vs.append((t[i], 1))
				c += 1
			else:
				flag = 0
				break
		else:
			flag = 0
			break
	if flag == 1 and ls[-1][0] == vs[-1][0] and (ls[-1][1] <= vs[-1][1]) and (len(vs) == len(ls)):
		print('YES')
	else:
		print('NO')
	n -= 1


t = int(input())
for test in range(t):
	s = input()
	t = input()
	arr_s = []
	arr_t = []
	prev = '1'
	for i in s:
		if i == prev:
			arr_s[-1][1] += 1
		else:
			arr_s.append([i, 1])
			prev = i
	prev = '1'
	for i in t:
		if i == prev:
			arr_t[-1][1] += 1
		else:
			arr_t.append([i, 1])
			prev = i
	ans = 'YES'
	if len(arr_s) == len(arr_t):
		for i in range(len(arr_s)):
			if arr_s[i][0] == arr_t[i][0] and arr_s[i][1] <= arr_t[i][1]:
				continue
			else:
				ans = 'NO'
	else:
		ans = 'NO'
	print(ans)


def koto(s):
	li = []
	for i in range(len(s)):
		if len(li) != 0:
			if s[i] != li[-1]:
				li.append(s[i])
		else:
			li.append(s[i])
	return ''.join(li)

def mod(L, k):
	val = L[k]
	cn = 0
	for i in range(k, len(L)):
		if L[i] == val:
			cn += 1
		else:
			break
	return cn

def abrar(L):
	li = []
	i = 0
	while i < len(L):
		ab = mod(L, i)
		li.append(ab)
		i = i + ab
	return li

def mn(L, M):
	a = abrar(L)
	b = abrar(M)
	cn = 0
	if len(a) == len(b):
		for i in range(len(a)):
			if a[i] <= b[i]:
				cn += 1
	if len(a) != len(b):
		return 0
	if cn == len(a):
		return 1
n = int(input())
for i in range(n):
	s = input()
	t = input()
	ss = koto(s)
	tt = koto(t)
	if ss == tt and mn(s, t) == 1:
		print('YES')
	else:
		print('NO')


N = int(input())
for i in range(N):
	w1 = input() + '+'
	w2 = input()
	pre = '.'
	cur = 0
	for ch in w2:
		if ch == w1[cur]:
			pre = w1[cur]
			cur += 1
		elif ch != pre:
			print('NO')
			break
	else:
		if cur > len(w1) - 2:
			print('YES')
		else:
			print('NO')


import sys
sys.setrecursionlimit(1000000)

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self):
		return sys.stdin.readline().split()

	def next_ints(self):
		return [int(x) for x in sys.stdin.readline().split()]

	def next_int(self):
		return int(self.next())

	def solve(self):
		t = self.next_int()
		for _ in range(t):
			a = self.next()
			b = self.next()
			print('YES' if self.test(a, b) else 'NO')

	def test(self, a, b):
		i = 0
		for c in a:
			while i < len(b) and b[i] != c:
				if i > 0 and b[i] == b[i - 1]:
					i += 1
				else:
					return False
			if i >= len(b):
				return False
			i += 1
		while i < len(b):
			if b[i] != b[i - 1]:
				return False
			i += 1
		return True
Main().solve()


n = int(input())
for i in range(n):
	s = input()
	t = input()
	j = 0
	k = 0
	v = s[0]
	while j < len(s) and k < len(t):
		if s[j] == t[k]:
			v = s[j]
			j = j + 1
			k = k + 1
		elif t[k] == v:
			k = k + 1
		else:
			break
	while k < len(t):
		if t[k] != v:
			j = 0
		k = k + 1
	if j < len(s):
		print('NO')
	else:
		print('YES')


import sys
n = int(input())
for _ in range(n):
	s = sys.stdin.readline().split('\n')[0]
	t = sys.stdin.readline().split('\n')[0]
	ss = '$'
	c = 1
	if s[0] != t[0] or len(s) > len(t):
		print('NO')
	else:
		ss = s[0]
		tt = t[0]
		i = 1
		j = 1
		while i <= len(s) and j < len(t):
			if i == len(s) or s[i] != t[j]:
				if t[j] == ss[-1]:
					tt += t[j]
					j += 1
				else:
					c = 0
					break
			else:
				ss += s[i]
				tt += t[j]
				i += 1
				j += 1
		if j != len(t) or i != len(s):
			c = 0
		if c:
			print('YES')
		else:
			print('NO')


t = int(input())
for x in range(t):
	have = input()
	need = input()
	lh = []
	ln = []
	letter = have[0]
	count = 0
	for i in have:
		if letter == i:
			count += 1
		else:
			lh.append((letter, count))
			letter = i
			count = 1
	lh.append((letter, count))
	letter = need[0]
	count = 0
	for i in need:
		if letter == i:
			count += 1
		else:
			ln.append((letter, count))
			letter = i
			count = 1
	ln.append((letter, count))
	if len(lh) == len(ln):
		for i in range(len(lh)):
			n = lh.pop()
			p = ln.pop()
			ppp = False
			if n[0] == p[0]:
				if n[1] <= p[1]:
					pass
				else:
					ppp = True
					print('NO')
					break
			else:
				ppp = True
				print('NO')
				break
		if not ppp:
			print('YES')
	else:
		print('NO')


T = int(input())
test = 0
while test < T:
	str1 = input()
	str2 = input()
	cur = ''
	idx1 = 0
	idx2 = 0
	no_answer = 0
	while idx1 < len(str1):
		if str1[idx1] != cur:
			cur = str1[idx1]
			c = 1
		if idx1 < len(str1) - 1 and str1[idx1 + 1] == cur:
			idx1 = idx1 + 1
			c += 1
			continue
		d = 0
		if idx2 >= len(str2):
			print('NO')
			no_answer = 1
			break
		while idx2 < len(str2):
			if str2[idx2] != cur:
				if d < c:
					print('NO')
					no_answer = 1
					break
				else:
					break
			else:
				d += 1
				idx2 += 1
		if d < c and no_answer == 0:
			print('NO')
			no_answer = 1
		if no_answer == 1:
			break
		idx1 += 1
	if idx2 < len(str2) and no_answer == 0:
		no_answer = 1
		print('NO')
	if no_answer == 0:
		print('YES')
	test += 1


def tolis(ch):
	L = []
	s = ''
	for e in ch:
		if e in s:
			s += e
		else:
			L.append(s)
			s = e
	L.append(s)
	return L[1:]

def plycar(ch1, ch2):
	L1 = tolis(ch1)
	L2 = tolis(ch2)
	if len(L1) != len(L2):
		print('NO')
	else:
		for i in range(len(L1)):
			if L1[i][0] != L2[i][0]:
				print('NO')
				return
		for i in range(len(L1)):
			if len(L2[i]) < len(L1[i]):
				print('NO')
				return
		print('YES')
		return
n = int(input())
DATA = []
for i in range(n):
	ch1 = input()
	ch2 = input()
	DATA.append((ch1, ch2))
for (x, y) in DATA:
	plycar(x, y)


n = int(input())

def solve(a, b):

	def map_(s):
		t = []
		last = ''
		cur = 0
		for c in s:
			if c == last:
				cur += 1
			else:
				t.append([c, cur])
				cur = 1
				last = c
		t.append([c, cur])
		return t
	a = map_(a)
	b = map_(b)
	if len(a) != len(b):
		return False
	for i in range(len(a)):
		if a[i][0] != b[i][0]:
			return False
		if a[i][1] > b[i][1]:
			return False
	return True
for _ in range(n):
	a = input()
	b = input()
	print('YES' if solve(a, b) else 'NO')


def check(pred, real):
	lp = len(pred)
	lr = len(real)
	ind_p = 0
	ind_r = 0
	count_p = 0
	count_r = 0
	char_p = None
	char_r = None
	while ind_p < lp:
		if pred[ind_p] != char_p:
			if char_p != char_r or count_p > count_r:
				return 'NO'
			count_p = 1
			char_p = pred[ind_p]
			char_r = real[ind_r]
			count_r = 1
			while ind_r + 1 < lr and char_r == real[ind_r + 1]:
				count_r += 1
				ind_r += 1
			ind_r += 1
		else:
			count_p += 1
		ind_p += 1
	if ind_r != lr:
		return 'NO'
	return 'YES'
n = int(input())
for _ in range(n):
	pred = input()
	real = input()
	print(check(pred + ' ', real + ' '))


import sys
for i in range(int(input())):
	a = sys.stdin.readline()
	b = sys.stdin.readline()
	t1 = a[0]
	t2 = b[0]
	i = 0
	j = 0
	cur1 = a[0]
	cur2 = b[0]
	c1 = 0
	c2 = 0
	temp1 = [a[0], 0]
	temp2 = [b[0], 0]
	ans = 'NO'
	if len(b) < len(a):
		ans = 'NO'
	else:
		while 1:
			while i < len(a):
				if cur1 != a[i]:
					temp1[1] = c1
					c1 = 0
					cur1 = a[i]
					break
				else:
					c1 += 1
					i += 1
					if i == len(a):
						temp1[1] = c1
			while j < len(b):
				if cur2 != b[j]:
					temp2[1] = c2
					c2 = 0
					cur2 = b[j]
					break
				else:
					c2 += 1
					j += 1
					if j == len(b):
						temp2[1] = c2
			if temp1[0] == temp2[0] and temp1[1] <= temp2[1]:
				ans = 'YES'
			else:
				ans = 'NO'
				break
			if i > len(a) - 1 and j > len(b) - 1:
				break
			temp1[0] = cur1
			temp2[0] = cur2
	sys.stdout.write(ans + '\n')


def checker(p1, p2):
	length = len(p1)
	p2l = len(p2) - 1
	i = 0
	identical = 0
	j1 = 0
	for j in p2:
		if j not in p1:
			return -1
	while i <= length - 1:
		if i != length - 1 and p1[i] == p1[i + 1]:
			identical += 1
			i += 1
			continue
		init = j1
		while j1 < p2l and p2[j1] == p2[j1 + 1]:
			j1 += 1
		j1 += 1
		if p1[i - identical:i + 1] not in p2[init:j1]:
			return -1
		identical = 0
		i += 1
	if p2l > j1 - 1:
		return -1
	return 1
pairs = int(input())
while pairs > 0:
	(p1, p2) = (input(), input())
	if checker(p1, p2) == 1:
		print('YES')
	else:
		print('NO')
	pairs -= 1


T = int(input())
t = 0
while t < T:
	s1 = input()
	s2 = input()
	j = 0
	flag = True
	for i in range(len(s1)):
		if j < len(s2) and s1[i] == s2[j]:
			if i < len(s1) - 1 and s1[i] != s1[i + 1]:
				while j < len(s2) and s1[i] == s2[j]:
					j += 1
			else:
				j += 1
		else:
			flag = False
			break
	while j < len(s2):
		if s1[len(s1) - 1] != s2[j]:
			flag = False
			break
		else:
			j += 1
	if flag:
		print('YES')
	else:
		print('NO')
	t += 1


import sys
for _ in range(int(input())):
	s = sys.stdin.readline()
	t = sys.stdin.readline()
	ss = []
	group = [s[0]]
	if len(s) == 1:
		ss.append(''.join(group))
	for i in range(1, len(s)):
		if group[0] != s[i]:
			ss.append(''.join(group))
			group = [s[i]]
		else:
			group.append(s[i])
		if i == len(s) - 1:
			ss.append(''.join(group))
	tt = []
	group = [t[0]]
	if len(t) == 1:
		tt.append(''.join(group))
	for i in range(1, len(t)):
		if group[0] != t[i]:
			tt.append(''.join(group))
			group = [t[i]]
		else:
			group.append(t[i])
		if i == len(t) - 1:
			tt.append(''.join(group))
	if len(ss) != len(tt):
		sys.stdout.write('NO\n')
	else:
		for i in range(len(ss)):
			if ss[i][0] != tt[i][0] or len(ss[i]) > len(tt[i]):
				sys.stdout.write('NO\n')
				break
		else:
			sys.stdout.write('YES\n')


def freq_array(s, a, b):
	n = len(s)
	i = 0
	while i < n:
		ll = 1
		while i < n - 1 and s[i] == s[i + 1]:
			ll += 1
			i += 1
		a.append(ll)
		b.append(s[i])
		i += 1
for i in range(int(input())):
	given = input()
	test = input()
	n = len(given)
	n1 = len(test)
	a = []
	b = []
	(c, d) = ([], [])
	freq_array(given, a, b)
	freq_array(test, c, d)
	nn = len(b)
	ns = len(d)
	if nn != ns:
		print('NO')
	else:
		odd = 0
		for j in range(nn):
			if b[j] != d[j] or a[j] > c[j]:
				odd += 1
		if odd > 0:
			print('NO')
		else:
			print('YES')


a = int(input())
for x in range(a):
	str1 = input()
	str2 = input()
	lam = {}
	if len(str2) < len(str1):
		print('NO')
	elif len(str2) == len(str1):
		if str1 == str2:
			print('YES')
		else:
			print('NO')
	else:
		lam = []
		x = 0
		y = 0
		flag = 5
		while 6 == 6:
			if x >= len(str1):
				break
			if y >= len(str2):
				break
			if str1[x] == str2[y]:
				lam.append(str1[x])
				x += 1
				y += 1
			else:
				if lam == list():
					flag = 6
					break
				if str2[y] == lam[-1]:
					y += 1
				else:
					flag = 6
					break
		if flag == 6:
			print('NO')
		elif y == len(str2) and x != len(str1):
			print('NO')
		elif y == len(str2):
			print('YES')
		else:
			flag = 5
			for it in str2[y:]:
				if it == lam[-1]:
					pass
				else:
					flag = 6
					break
			if flag == 6:
				print('NO')
			else:
				print('YES')


n = int(input())
for idx in range(n):
	s1 = str(input())
	s2 = str(input())
	(i, j) = (0, 0)
	while i < len(s1) and j < len(s2):
		if i >= len(s1) or j >= len(s2):
			break
		if s1[i] != s2[j] and i > 0:
			if s1[i - 1] != s2[j]:
				i = 0
				j = len(s2) * 2
				break
			else:
				j = j + 1
		if i >= len(s1) or j >= len(s2):
			break
		if s1[i] != s2[j] and i == 0:
			break
		if i >= len(s1) or j >= len(s2):
			break
		if s1[i] == s2[j]:
			i = i + 1
			j = j + 1
	if i < len(s1):
		print('NO')
		continue
	while j < len(s2) and s2[j] == s1[len(s1) - 1]:
		j = j + 1
	if i == len(s1) and j == len(s2):
		print('YES')
	else:
		print('NO')


def ch(s1, s2):
	l = []
	last = ''
	for i in range(len(s1)):
		if last == s1[i]:
			l[-1] = (last, l[-1][1] + 1)
		else:
			l.append((s1[i], 1))
		last = s1[i]
	l2 = []
	last = ''
	for i in range(len(s2)):
		if last == s2[i]:
			l2[-1] = (last, l2[-1][1] + 1)
		else:
			l2.append((s2[i], 1))
		last = s2[i]
	if len(l) != len(l2):
		return False
	for i in range(len(l)):
		if l[i][0] == l2[i][0] and l[i][1] <= l2[i][1]:
			continue
		return False
	return True
n = int(input())
for _ in range(n):
	s = input()
	st = input()
	if ch(s, st):
		print('YES')
	else:
		print('NO')


n = int(input())
for w in range(n):
	s = input()
	t = input()
	ls = len(s)
	lt = len(t)
	i = 0
	j = 0
	flag = 0
	while i < ls and j < lt:
		if s[i] == t[j]:
			i += 1
			j += 1
		elif i > 0 and s[i - 1] == t[j]:
			j += 1
		else:
			flag = 1
			break
	if flag == 1:
		print('NO')
	elif i == ls:
		if j == lt:
			print('YES')
		else:
			flag1 = 0
			for k in range(j, lt):
				if t[k] != s[-1]:
					flag1 = 1
					break
			if flag1 == 1:
				print('NO')
			else:
				print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	arr_s = []
	cnt = 1
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			cnt += 1
		else:
			arr_s.append((s[i], cnt + 1))
			cnt = 0
	arr_s.append((s[-1], cnt + 1))
	arr_t = []
	cnt = 1
	for i in range(len(t) - 1):
		if t[i] == t[i + 1]:
			cnt += 1
		else:
			arr_t.append((t[i], cnt + 1))
			cnt = 0
	arr_t.append((t[-1], cnt + 1))
	if len(arr_s) != len(arr_t):
		print('NO')
	else:
		flag = False
		for i in range(len(arr_s)):
			if arr_s[i][0] != arr_t[i][0] or arr_s[i][1] > arr_t[i][1]:
				flag = True
				break
		if flag:
			print('NO')
		else:
			print('YES')


from itertools import groupby
for _ in range(int(input())):
	s = [''.join(g) for (_, g) in groupby(input())]
	t = [''.join(g) for (_, g) in groupby(input())]
	if len(s) == len(t) and all((g1 in g2 for (g1, g2) in zip(s, t))):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	t = input()
	j = 0
	i = 0
	if len(t) < len(s):
		print('NO')
		continue
	while i < len(s):
		f = True
		cu = s[i]
		cou = 1
		i += 1
		while i < len(s) and s[i] == cu:
			cou += 1
			i += 1
		while cou > 0:
			if j >= len(t) or t[j] != cu:
				f = False
				break
			else:
				cou -= 1
				j += 1
		if not f:
			break
		while j < len(t) and t[j] == cu:
			j += 1
	if f and j == len(t):
		print('YES')
	else:
		print('NO')


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 checklet(i, t, l):
	if i >= len(w2):
		return -1
	counter = 0
	ii = i
	while ii < len(w2) and w2[ii] == l:
		counter += 1
		ii += 1
	if counter < t:
		return -1
	else:
		return ii
c = cinn()
n = c.cin()
for i in range(n):
	w1 = c.cin(str)
	w2 = c.cin(str)
	minil = []
	el = w1[0]
	t1 = (w1[0], 1)
	for i in range(1, len(w1)):
		if w1[i] == el:
			t1 = (w1[i], t1[1] + 1)
		else:
			minil.append(t1)
			el = w1[i]
			t1 = (w1[i], 1)
	minil.append(t1)
	k = 0
	for ll in minil:
		if k == -1:
			break
		k = checklet(k, ll[1], ll[0])
		if k == -1:
			break
	if k == len(w2):
		print('YES')
	else:
		print('NO')


def f():
	a = input()
	i = 0
	p = a[i]
	l = []
	while i < len(a):
		temp = 1
		t = [p]
		i += 1
		while i < len(a):
			if a[i] != p:
				p = a[i]
				break
			p = a[i]
			t.append(p)
			i += 1
			if i == len(a):
				temp = 0
				break
		l.append(t)
		if temp == 0:
			break
	a = input()
	i = 0
	p = a[i]
	l1 = []
	while i < len(a):
		temp = 1
		t = [p]
		i += 1
		while i < len(a):
			if a[i] != p:
				p = a[i]
				break
			p = a[i]
			t.append(p)
			i += 1
			if i == len(a):
				temp = 0
				break
		l1.append(t)
		if temp == 0:
			break
	if len(l) != len(l1):
		return 0
	for i in range(0, len(l)):
		if l[i][0] != l1[i][0] or len(l[i]) > len(l1[i]):
			return 0
	return 1
for i in range(int(input())):
	if f():
		print('YES')
	else:
		print('NO')


def check_possible(original, typed):
	j = 0
	original_passed = False
	for char in typed:
		if char == original[j]:
			if j < len(original) - 1:
				j += 1
			else:
				original_passed = True
		elif j != 0 and char == original[j - 1] and (not original_passed):
			pass
		else:
			return 'NO'
	else:
		if original_passed:
			return 'YES'
		else:
			return 'NO'
n = int(input())
for _ in range(n):
	original1 = input()
	typed1 = input()
	print(check_possible(original1, typed1))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq

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

def stringListIn():
	return [x for x in stdin.readline().split()]

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

def stringIn():
	return stdin.readline().strip()
n = intIn()
for i in range(n):
	s = stringIn()
	t = stringIn()
	if len(t) < len(s) or t[0] != s[0]:
		print('NO')
	else:
		i = 0
		j = 0
		(lt, ls) = (len(t), len(s))
		while j < lt and i < ls:
			if s[i] == t[j]:
				prev = s[i]
				i += 1
				j += 1
			elif t[j] == prev:
				j += 1
			else:
				break
		if i != ls:
			print('NO')
		else:
			f = 1
			while j < lt:
				if t[j] != s[-1]:
					f = 0
					break
				j += 1
			if f:
				print('YES')
			else:
				print('NO')


import sys
read = lambda : sys.stdin.readline().strip()
for t in range(int(input())):
	(a, b) = (read(), read())
	(A, B) = ([], [])
	for i in a:
		if not A:
			A.append((1, i))
		else:
			(cnt, char) = A[-1]
			if char == i:
				A[-1] = (cnt + 1, char)
			else:
				A.append((1, i))
	for i in b:
		if not B:
			B.append((1, i))
		else:
			(cnt, char) = B[-1]
			if char == i:
				B[-1] = (cnt + 1, char)
			else:
				B.append((1, i))
	if len(A) != len(B):
		sys.stdout.write('NO\n')
	else:
		flag = True
		for (i, j) in zip(A, B):
			if j[0] < i[0] or i[1] != j[1]:
				sys.stdout.write('NO\n')
				flag = False
				break
		if flag:
			sys.stdout.write('YES\n')


n = int(input())
for l in range(n):
	x = input()
	y = input()
	(x1, y1, x2, y2, x3, y3) = ([], [], 1, 1, [], [])
	lol = 1
	x1.append(x[0])
	y1.append(y[0])
	for i in range(1, len(x)):
		if x[i] == x[i - 1]:
			x2 += 1
		else:
			x3.append(x2)
			x1.append(x[i])
			x2 = 1
	x3.append(x2)
	for i in range(1, len(y)):
		if y[i] == y[i - 1]:
			y2 += 1
		else:
			y3.append(y2)
			y1.append(y[i])
			y2 = 1
	y3.append(y2)
	if len(x1) != len(y1):
		print('NO')
		lol = 0
	else:
		for i in range(len(x1)):
			if x1[i] == y1[i]:
				if x3[i] > y3[i]:
					print('NO')
					lol = 0
					break
			else:
				print('NO')
				lol = 0
				break
		if lol:
			print('YES')


n = int(input())
for _ in range(n):
	s1 = input() + '?'
	s2 = input() + '?'
	(a1, a2, b1, b2, i, j) = (1, 1, s1[0], s2[0], 0, 0)
	f = 0
	while 1:
		if b1 != b2:
			print('NO')
			f = 1
			break
		else:
			if b1 == '?':
				break
			while 1:
				i += 1
				if s1[i] == b1:
					a1 += 1
				else:
					break
			while 1:
				j += 1
				if s2[j] == b2:
					a2 += 1
				else:
					break
			if a1 <= a2:
				b1 = s1[i]
				b2 = s2[j]
				a1 = 1
				a2 = 1
			else:
				print('NO')
				f = 1
				break
	print('YES') if f == 0 else 1


n = int(input())
for i in range(n):
	first = input()
	second = input()
	index_f = 0
	index_s = 0
	f = True
	if len(first) <= len(second):
		while index_f != len(first):
			if index_f != len(first) - 1 and index_s != len(second) - 1:
				if first[index_f] == second[index_s] and first[index_f] != first[index_f + 1] and (second[index_s] == second[index_s + 1]):
					index_s += 1
				elif first[index_f] != second[index_s]:
					f = False
					break
				else:
					index_f += 1
					index_s += 1
			elif index_s == len(second) - 1 and index_f != len(first) - 1:
				f = False
				break
			elif index_f == len(first) - 1 and index_s != len(second) - 1:
				while index_s != len(second):
					if second[index_s] == first[index_f]:
						index_s += 1
					else:
						f = False
						break
				index_f += 1
			elif first[index_f] == second[index_s]:
				break
			else:
				f = False
				break
		if f:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from collections import defaultdict
n = int(input())
ans = []
for _ in range(n):
	a = input()
	b = input()
	flag = 0
	count1 = []
	count2 = []
	l = [a[0], 1]
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			l[1] += 1
		else:
			count1.append(l)
			l = [a[i], 1]
	count1.append(l)
	l = [b[0], 1]
	for i in range(1, len(b)):
		if b[i] == b[i - 1]:
			l[1] += 1
		else:
			count2.append(l)
			l = [b[i], 1]
	count2.append(l)
	if len(count1) != len(count2):
		flag = 1
	else:
		for i in range(len(count1)):
			if count1[i][0] != count2[i][0] or count1[i][1] > count2[i][1]:
				flag = 1
				break
	if flag == 1:
		print('NO')
	else:
		print('YES')


from itertools import groupby
for i in range(int(input())):
	C = True
	A = [''.join(y) for (_, y) in groupby(input())]
	B = [''.join(y) for (_, y) in groupby(input())]
	for i in range(len(A)):
		if A[i] in B[i] and len(A) == len(B):
			continue
		else:
			C = False
			break
	print('YES' if C == True else 'NO')


import sys
import math
input = sys.stdin.readline
n = int(input())
for i in range(n):
	s = input()
	t = input()
	sc = list(s[0])
	tc = list(t[0])
	scount = [1]
	tcount = [1]
	for i in range(1, len(s)):
		if s[i] == sc[-1]:
			scount[-1] += 1
		else:
			sc.append(s[i])
			scount.append(1)
	for i in range(1, len(t)):
		if t[i] == tc[-1]:
			tcount[-1] += 1
		else:
			tc.append(t[i])
			tcount.append(1)
	if sc == tc:
		flag = True
		for i in range(len(scount)):
			if scount[i] > tcount[i]:
				print('NO')
				flag = False
				break
		if flag:
			print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	s1 = input()
	a = []
	for j in range(len(s)):
		if j != 0 and s[j] == s[j - 1]:
			a[-1][1] += 1
			continue
		a.append([s[j], 1])
	d = True
	b = []
	for j in range(len(s1)):
		if j != 0 and s1[j] == s1[j - 1]:
			b[-1][1] += 1
			continue
		b.append([s1[j], 1])
	if len(a) != len(b):
		print('NO')
		continue
	for j in range(len(a)):
		if a[j][0] != b[j][0] or b[j][1] < a[j][1]:
			print('NO')
			d = False
			break
	if d:
		print('YES')


def solve(s):
	res = []
	i = 0
	while i < len(s):
		j = i
		while j < len(s) and s[i] == s[j]:
			j += 1
		res.append((s[i], j - i))
		i = j
	return res
t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	r1 = solve(s1)
	r2 = solve(s2)
	if len(r1) != len(r2):
		print('NO')
		continue
	for i in range(len(r1)):
		if r1[i][0] != r2[i][0] or r2[i][1] < r1[i][1]:
			print('NO')
			break
	else:
		print('YES')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	cnts = {}
	start = ''
	i = 0
	ind = 0
	while i < len(s):
		if s[i] == start:
			cnts[ind][1] += 1
		else:
			ind = i
			cnts[ind] = [s[i], 1]
		start = s[i]
		i += 1
	cntt = {}
	start = ''
	i = 0
	ind = 0
	while i < len(t):
		if t[i] == start:
			cntt[ind][1] += 1
		else:
			ind = i
			cntt[ind] = [t[i], 1]
		start = t[i]
		i += 1
	(cnts, cntt) = (list(cnts.values()), list(cntt.values()))
	if len(cnts) != len(cntt):
		print('NO')
	else:
		for i in range(len(cnts)):
			if cnts[i][0] != cntt[i][0] or cnts[i][1] > cntt[i][1]:
				print('NO')
				break
		else:
			print('YES')


def main():
	t = int(input())
	for _ in range(t):
		string1 = input()
		string2 = input()
		i = 0
		j = 0
		NO = 0
		while i < len(string1):
			if string1[i] == string2[j]:
				prev = string1[i]
				j += 1
				i += 1
				curr = 0
				if i < len(string1):
					curr = string1[i]
				else:
					break
			else:
				NO = 1
				break
			while j < len(string2) and string2[j] == prev and (curr != 0) and (curr != prev):
				j += 1
			if j >= len(string2):
				NO = 1
				break
		while j < len(string2):
			if string1[i - 1] != string2[j]:
				NO = 1
				break
			j += 1
		if NO == 1:
			print('NO')
		else:
			print('YES')
main()


for _ in range(int(input())):
	a = input()
	p = input()
	f = i = j = g = h = 0
	la = len(a) - 1
	lp = len(p) - 1
	while True:
		x = i
		y = 0
		while a[i] == a[x]:
			y += 1
			if i < la:
				i += 1
			else:
				g = 1
				break
		z = 0
		while p[j] == a[x]:
			z += 1
			if j < lp:
				j += 1
			else:
				h = 1
				break
		if z < y or (g and (not h)) or (not g and h):
			f = 1
			break
		elif g or h:
			break
	print(['YES', 'NO'][f])


def email(s, t):
	x = '#'
	k = 0
	for i in t:
		if i == s[k]:
			x = s[k]
			k += 1
		elif i != x:
			return 'NO'
	return 'YES' if k == len(s) - 1 else 'NO'
for _ in range(int(input())):
	s = input() + '1'
	t = input()
	print(email(s, t))


for _ in range(int(input())):
	a = list(input())
	b = list(input())
	if len(b) < len(a):
		print('NO')
	else:
		i = 0
		j = 0
		f = 0
		se = ''
		while i < len(a) and j < len(b):
			s = a[i]
			i += 1
			while i < len(a) and s[0] == a[i]:
				s += a[i]
				i += 1
			if b[j] == s[0]:
				se = b[j]
				j += 1
				while j < len(b) and se[0] == b[j]:
					se += b[j]
					j += 1
				if len(s) > len(se):
					f = 1
					print('NO')
					break
			else:
				f = 1
				print('NO')
				break
		if f == 0 and j < len(b):
			while j < len(b) and se[0] == b[j]:
				j += 1
			if j < len(b):
				f = 1
				print('NO')
		if f == 0 and i == len(a):
			print('YES')
		if f == 0 and i < len(a):
			print('NO')


def separate(s):
	a = []
	prev = s[0]
	temp = s[0]
	for i in range(1, len(s)):
		if s[i] == prev:
			temp += s[i]
		else:
			prev = s[i]
			a.append(temp)
			temp = s[i]
	a.append(temp)
	return a
t = int(input())
for _ in range(t):
	s = input()
	t = input()
	a = separate(s)
	b = separate(t)
	if len(a) != len(b):
		print('NO')
	else:
		for i in range(len(a)):
			if not (a[i][0] == b[i][0] and len(a[i]) <= len(b[i])):
				print('NO')
				break
		else:
			print('YES')


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):
	print(' '.join(map(str, l)))
n = read_int()
for i in range(n):
	broken = 0
	actual = read_string()
	garbled = read_string()
	actual_group = []
	j = 0
	counter = 1
	while j < len(actual) - 1:
		if actual[j] == actual[j + 1]:
			j += 1
			counter += 1
		else:
			actual_group.append((actual[j], counter))
			j += 1
			counter = 1
	actual_group.append((actual[j], counter))
	garbled_group = []
	j = 0
	counter = 1
	while j < len(garbled) - 1:
		if garbled[j] == garbled[j + 1]:
			j += 1
			counter += 1
		else:
			garbled_group.append((garbled[j], counter))
			j += 1
			counter = 1
	garbled_group.append((garbled[j], counter))
	if len(actual_group) != len(garbled_group):
		print('NO')
		continue
	for j in range(len(actual_group)):
		if actual_group[j][0] != garbled_group[j][0] or actual_group[j][1] > garbled_group[j][1]:
			broken = 1
			break
	if broken:
		print('NO')
	else:
		print('YES')


n = int(input())
while n > 0:
	s = input()
	t = input()
	reps = [[s[0], 1]]
	rept = [[t[0], 1]]
	for i in range(1, len(s)):
		if s[i] == reps[-1][0]:
			reps[-1][1] += 1
		else:
			reps.append([s[i], 1])
	for i in range(1, len(t)):
		if t[i] == rept[-1][0]:
			rept[-1][1] += 1
		else:
			rept.append([t[i], 1])
	if len(reps) != len(rept):
		print('NO')
	else:
		flag = 0
		for i in range(0, len(reps)):
			if reps[i][0] != rept[i][0] or reps[i][1] > rept[i][1]:
				print('NO')
				flag = 1
				break
		if flag == 0:
			print('YES')
	n -= 1


for _ in range(int(input())):
	a = input()
	b = input()
	c = []
	k = 0
	g = b[0]
	d = []
	for i in b:
		if i == g:
			k += 1
		else:
			c.append(g)
			d.append(k)
			g = i
			k = 0
	c.append(g)
	d.append(k)
	g = a[0]
	k = 0
	c1 = []
	d1 = []
	for i in a:
		if i == g:
			k += 1
		else:
			c1.append(g)
			d1.append(k)
			g = i
			k = 0
	c1.append(g)
	d1.append(k)
	if len(c1) != len(c):
		print('NO')
	else:
		f = 0
		for i in range(len(c1)):
			if c1[i] == c[i] and d[i] >= d1[i]:
				continue
			else:
				f = 1
				print('NO')
				break
		if f == 0:
			print('YES')


for _ in range(int(input())):
	p = input()
	q = input()
	k = 0
	f = 0
	if p[0] != q[0]:
		print('NO')
	else:
		for i in range(len(q)):
			if p[k] == q[i]:
				k += 1
				if k == len(p):
					f = 1
					if (len(q) - i) * p[k - 1] == q[i:]:
						print('YES')
					else:
						print('NO')
					break
			if k > 0 and q[i] != p[k - 1]:
				f = 1
				print('NO')
				break
		if f == 0:
			print('NO')


from sys import stdin, stdout
n = int(stdin.readline())

def parse(s):
	ans = []
	prev = None
	count = 0
	for c in s:
		if prev is None:
			prev = c
		elif prev != c:
			ans.append((prev, count))
			prev = c
			count = 0
		count += 1
	ans.append((prev, count))
	return ans

def do(p1, p2):
	if len(p1) != len(p2):
		stdout.write('NO\n')
		return
	for i in range(len(p1)):
		(c1, ct1) = p1[i]
		(c2, ct2) = p2[i]
		if c1 != c2 or ct2 < ct1:
			stdout.write('NO\n')
			return
	stdout.write('YES\n')
for i in range(n):
	s1 = stdin.readline().strip()
	s2 = stdin.readline().strip()
	p1 = parse(s1)
	p2 = parse(s2)
	do(p1, p2)


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, OrderedDict, deque
from functools import reduce
from operator import mul
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().strip('\n')
grid = lambda r: [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')
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip('\n') + '0'
	t = input().strip('\n') + '0'
	arr = []
	d = defaultdict(int)
	for i in range(len(s)):
		d[s[i]] += 1
		if len(d) > 1:
			for i in d:
				arr.append([i, d[i]])
				d.pop(i)
				break
	arr2 = []
	d = defaultdict(int)
	for i in range(len(t)):
		d[t[i]] += 1
		if len(d) > 1:
			for i in d:
				arr2.append([i, d[i]])
				d.pop(i)
				break
	if len(arr) == len(arr2):
		ans = 'YES'
		for i in range(len(arr)):
			if arr[i][0] == arr2[i][0] and arr[i][1] <= arr2[i][1]:
				pass
			else:
				ans = 'NO'
				break
		print(ans)
	else:
		print('NO')
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


def ok_vardi(orig_s, t):
	l1 = len(orig_s)
	l2 = len(t)
	prev = '*'
	ind1 = 0
	ind2 = 0
	while ind1 < l1:
		if ind2 == l2:
			return False
		if orig_s[ind1] == t[ind2]:
			prev = orig_s[ind1]
			ind1 += 1
			ind2 += 1
		elif t[ind2] == prev:
			ind2 += 1
		else:
			return False
	while ind2 < l2:
		if t[ind2] != prev:
			return False
		ind2 += 1
	if ind1 != l1:
		return False
	return True
n = int(input())
for i in range(n):
	s = input()
	t = input()
	if ok_vardi(s, t):
		print('YES')
	else:
		print('NO')


n = int(input())
for _ in range(n):
	scorrect = input()
	sreal = input()
	if len(scorrect) > len(sreal):
		print('NO')
		continue
	ic = 0
	ir = 0
	f = 1
	while ic < len(scorrect) and ir < len(sreal):
		current = scorrect[ic]
		if sreal[ir] != current:
			if ir > 0 and sreal[ir] == sreal[ir - 1]:
				while ir < len(sreal) and sreal[ir] == sreal[ir - 1]:
					ir += 1
			else:
				f = 0
				break
		else:
			ir += 1
			ic += 1
	if ic < len(scorrect) and ir == len(sreal):
		print('NO')
		continue
	last = scorrect[-1]
	while ir < len(sreal):
		if sreal[ir] != last:
			f = 0
			break
		ir += 1
	if f == 1:
		print('YES')
	else:
		print('NO')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
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 main():
	n = I()
	aa = [[S(), S()] for _ in range(n)]

	def ff(s):
		c = 1
		t = s[0]
		r = []
		for i in range(1, len(s)):
			si = s[i]
			if si == t:
				c += 1
			else:
				r.append((t, c))
				t = si
				c = 1
		r.append((t, c))
		return r
	r = []
	for (s, t) in aa:
		a = ff(s)
		b = ff(t)
		if len(a) != len(b):
			r.append('NO')
			continue
		f = True
		for (si, ti) in zip(a, b):
			if si[0] != ti[0] or ti[1] < si[1]:
				f = False
				break
		if f:
			r.append('YES')
		else:
			r.append('NO')
	return JA(r, '\n')
print(main())


import sys
from itertools import groupby

def V(arr):
	count = 1
	v = []
	for i in range(len(arr)):
		if i < len(arr) - 1:
			if arr[i] == arr[i + 1]:
				count += 1
				continue
		v.append([count, arr[i]])
		count = 1
	return v
input = sys.stdin.readline
n = int(input())
for x in range(n):
	a = input().strip('\n')
	b = input().strip('\n')
	a = V(a)
	b = V(b)
	if len(a) != len(b):
		print('NO')
		continue
	ans = True
	for i in range(len(a)):
		if a[i][1] == b[i][1] and a[i][0] <= b[i][0]:
			continue
		ans = False
		break
	if ans:
		print('YES')
	else:
		print('NO')


n = int(input())
for tee in range(n):
	s = input()
	t = input()
	if len(s) > len(t):
		print('NO')
		continue
	if len(s) == len(t):
		if s == t:
			print('YES')
		else:
			print('NO')
		continue
	arr = []
	i = 0
	pre = None
	cc = 0
	while i < len(s):
		if pre == None:
			pre = s[i]
			cc = 1
		elif pre == s[i]:
			cc += 1
		else:
			arr.append([pre, cc])
			pre = s[i]
			cc = 1
		i += 1
	arr.append([pre, cc])
	brr = []
	i = 0
	pre = None
	cc = 0
	while i < len(t):
		if pre == None:
			pre = t[i]
			cc = 1
		elif pre == t[i]:
			cc += 1
		else:
			brr.append([pre, cc])
			pre = t[i]
			cc = 1
		i += 1
	brr.append([pre, cc])
	if len(brr) != len(arr):
		print('NO')
	else:
		check = True
		for i in range(len(arr)):
			if arr[i][0] != brr[i][0] or arr[i][1] > brr[i][1]:
				check = False
				break
		if not check:
			print('NO')
		else:
			print('YES')


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	s = input()
	t = input()
	if len(s) > len(t):
		print('NO')
		continue
	j = 0
	flag = False
	for i in range(len(s)):
		while True:
			if t[j] == s[i]:
				j += 1
				break
			elif t[j] == t[j - 1] and j > 0:
				j += 1
				continue
			flag = True
			break
		if flag:
			print('NO')
			break
	else:
		for i in range(j, len(t)):
			if t[i] == s[-1]:
				continue
			print('NO')
			break
		else:
			print('YES')


for _ in range(int(input().strip())):
	s = list(input().strip())
	t = list(input().strip())
	(s_subs, t_subs) = ([], [])
	curr_sub = [s[0]]
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			s_subs.append(curr_sub)
			curr_sub = []
		curr_sub.append(s[i])
	s_subs.append(curr_sub)
	curr_sub = [t[0]]
	for i in range(1, len(t)):
		if t[i] != t[i - 1]:
			t_subs.append(curr_sub)
			curr_sub = []
		curr_sub.append(t[i])
	t_subs.append(curr_sub)
	if len(s_subs) != len(t_subs):
		print('NO')
	else:
		flag = False
		for i in range(len(s_subs)):
			if s_subs[i][0] == t_subs[i][0] and len(s_subs[i]) <= len(t_subs[i]):
				continue
			else:
				flag = True
				break
		if flag:
			print('NO')
		else:
			print('YES')


n = int(input())
for _ in range(0, n):
	a = input()
	b = input()
	la = len(a)
	lb = len(b)
	a = a + '0'
	pos = 0
	for i in range(0, lb):
		if a[pos] == b[i] and pos < la:
			pos += 1
		elif b[i - 1] != b[i] or i == 0:
			pos = -1
			break
	print('YES' if pos == la else 'NO')


def encodeLine(line):
	eLine = []
	try:
		for i in line:
			index = len(eLine)
			if index == 0:
				eLine.append([i, 1])
			elif eLine[index - 1][0] == i:
				eLine[index - 1][1] += 1
			else:
				eLine.append([i, 1])
	except:
		print(eLine, index)
	return eLine
noOfPairs = int(input())
pairs = []
for i in range(noOfPairs):
	original = input()
	broken = input()
	pairs.append([original, broken])
for i in range(noOfPairs):
	pair = pairs[i]
	eOriginalLine = encodeLine(pair[0])
	eBrokenLine = encodeLine(pair[1])
	if len(eOriginalLine) != len(eBrokenLine):
		print('NO')
		continue
	else:
		possible = True
		for j in range(len(eOriginalLine)):
			if eOriginalLine[j][0] != eBrokenLine[j][0] or eOriginalLine[j][1] > eBrokenLine[j][1]:
				possible = False
				break
		if possible is True:
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
	t = input().rstrip()
	s = input().rstrip()
	s += '$'
	t += '$'
	i = 0
	p = None
	flag = True
	for c in t:
		if i >= len(s):
			flag = False
			break
		if c == s[i]:
			i += 1
			p = c
		else:
			if p != s[i]:
				flag = False
				break
			while i < len(s) and p == s[i]:
				i += 1
			if c != s[i]:
				flag = False
				break
			else:
				i += 1
				p = c
	if i != len(s):
		flag = False
	print('YES' if flag else 'NO')


def get_letter_list(s):
	list = []
	list.append([s[0], 1])
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			list[-1][1] += 1
		else:
			list.append([s[i], 1])
	return list

def check(arr1, arr2):
	if len(arr1) != len(arr2):
		return False
	else:
		for i in range(len(arr1)):
			if arr1[i][0] != arr2[i][0] or (arr1[i][1] > arr2[i][1] and arr1[i][0] == arr2[i][0]):
				return False
		return True
n = int(input())
ans = []
for i in range(n):
	word_predict = input()
	word = input()
	if check(get_letter_list(word_predict), get_letter_list(word)):
		ans.append('YES')
	else:
		ans.append('NO')
for i in range(len(ans)):
	print(ans[i])


for i in range(int(input())):
	a = input()
	b = input()
	x = 0
	y = 1
	s1 = []
	s2 = []
	while x < len(a) - 1:
		if a[x] == a[x + 1]:
			y += 1
		else:
			s1.append(y)
			s2.append(a[x])
			y = 1
		x += 1
	if a[x] == a[x - 1]:
		s1.append(y)
		s2.append(a[x])
	else:
		s1.append(1)
		s2.append(a[x])
	x = 0
	y = 1
	s3 = []
	s4 = []
	while x < len(b) - 1:
		if b[x] == b[x + 1]:
			y += 1
		else:
			s3.append(y)
			s4.append(b[x])
			y = 1
		x += 1
	if b[x] == b[x - 1]:
		s3.append(y)
		s4.append(b[x])
	else:
		s3.append(1)
		s4.append(b[x])
	if len(s1) != len(s3):
		print('NO')
	else:
		ans = 'YES'
		for i in range(len(s1)):
			if s3[i] < s1[i] or s4[i] != s2[i]:
				ans = 'NO'
				break
		print(ans)


from collections import deque
ans = ['YES', 'NO']
n = int(input())
for i in range(n):
	k = 0
	s = list(input().strip())
	t = list(input().strip())
	ss = []
	tt = []
	pre = s[0]
	c = 0
	for i in s:
		if i == pre:
			c += 1
		else:
			ss.append((pre, c))
			pre = i
			c = 1
	ss.append((pre, c))
	pre = t[0]
	c = 0
	for i in t:
		if i == pre:
			c += 1
		else:
			tt.append((pre, c))
			pre = i
			c = 1
	tt.append((pre, c))
	if len(ss) != len(tt):
		k = 1
	else:
		for (x, y) in zip(ss, tt):
			if x[1] <= y[1] and x[0] == y[0]:
				pass
			else:
				k = 1
	print(ans[k])


for _ in ' ' * int(input()):
	a = input()
	b = input()
	ans = True
	i = 0
	i1 = len(a)
	j = 0
	j1 = len(b)
	if j1 < i1:
		print('NO')
		continue
	while i < i1 and j < j1:
		if a[i] != b[j]:
			ans = False
			break
		else:
			k = a[i]
			f = f1 = 0
			while i < i1:
				if k == a[i]:
					i += 1
					f += 1
				else:
					break
			while j < j1:
				if k == b[j]:
					j += 1
					f1 += 1
				else:
					break
			if f > f1:
				ans = False
				break
	if i == i1 and j == j1 and ans:
		print('YES')
	else:
		print('NO')


n = int(input())
for _ in range(n):
	s = input()
	t = input()
	j = 0
	l = s[0]
	s1 = []
	t1 = []
	flag1 = True
	for i in s:
		if l == i:
			j += 1
		else:
			s1.append([l, j])
			l = i
			j = 1
	s1.append([l, j])
	l = t[0]
	j = 0
	for i in t:
		if l == i:
			j += 1
		else:
			t1.append([l, j])
			l = i
			j = 1
	t1.append([l, j])
	if len(s1) != len(t1):
		flag1 = False
	else:
		for i in range(len(s1)):
			if not (s1[i][0] == t1[i][0] and s1[i][1] <= t1[i][1]):
				flag1 = False
				break
	if flag1:
		print('YES')
	else:
		print('NO')


import os
import sys
from math import *
from io import BytesIO, IOBase

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

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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	a = input()
	b = input()
	flag = 0
	p = 0
	m = 0
	while m < len(a):
		k = m
		count = 0
		countb = 0
		while a[k] == a[m]:
			count += 1
			k += 1
			if k == len(a):
				break
		if p < len(b):
			while b[p] == a[m]:
				countb += 1
				p += 1
				if p == len(b):
					break
		m = m + count
		if countb < count or (m == len(a) and p != len(b)):
			flag = 1
			break
	if flag == 1 or a[-1] != b[-1]:
		print('NO')
	else:
		print('YES')


import collections
for t in range(int(input())):
	a = input()
	b = input()
	if len(b) < len(a):
		print('NO')
	else:
		ans = 'YES'
		(i, j) = (0, 0)
		while i < len(a):
			cnt1 = 1
			while i + 1 < len(a) and a[i] == a[i + 1]:
				cnt1 += 1
				i += 1
			cnt2 = 0
			while j < len(b) and b[j] == a[i]:
				cnt2 += 1
				j += 1
			if cnt1 > cnt2:
				ans = 'NO'
				break
			i += 1
		print(ans if i == len(a) and j == len(b) else 'NO')


t = int(input())
for i in range(t):
	a = input()
	b = input()
	ret = 1
	i = 0
	j = 0
	while j < len(b):
		if i < len(a) and b[j] == a[i]:
			i = i + 1
			j = j + 1
		elif j > 0 and b[j] == b[j - 1]:
			j = j + 1
		else:
			ret = 0
			break
	if i < len(a):
		ret = 0
	if ret:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for i in range(int(input())):
	a = input()
	b = input()
	if len(a) > len(b) or set(a) != set(b):
		print('NO')
		continue
	a2 = [None] * len(b)
	a3 = [0] * len(b)
	b2 = [None] * len(b)
	b3 = [0] * len(b)
	t = None
	j = -1
	for x in a:
		if x != t:
			j += 1
			a2[j] = x
			a3[j] += 1
		else:
			a3[j] += 1
		t = x
	t = None
	j = -1
	for x in b:
		if x != t:
			j += 1
			b2[j] = x
			b3[j] += 1
		else:
			b3[j] += 1
		t = x
	if a2 == b2:
		t = sum([x > y for (x, y) in zip(a3, b3)])
		if t == 0:
			print('YES')
			continue
	print('NO')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	l = len(t)
	if s[0] != t[0]:
		print('NO')
	else:
		index = 1
		for j in range(1, len(s)):
			exists = False
			while index < l:
				if s[j] == t[index]:
					index += 1
					exists = True
					break
				elif t[index] == s[j - 1]:
					index += 1
				else:
					break
			if not exists:
				print('NO')
				break
		else:
			if index < l:
				if t[index:] == s[-1] * (l - index):
					print('YES')
				else:
					print('NO')
			else:
				print('YES')


for _ in range(int(input())):
	s = input()
	t = input()
	d = []
	i = 0
	c = 1
	co = []
	for x in range(len(s) - 1):
		if s[x] == s[x + 1]:
			c += 1
		else:
			d.append(s[x])
			co.append(c)
			c = 1
			i += 1
	d.append(s[-1])
	co.append(c)
	i += 1
	d1 = []
	i1 = 0
	c1 = 1
	co1 = []
	for x in range(len(t) - 1):
		if t[x] == t[x + 1]:
			c1 += 1
		else:
			d1.append(t[x])
			co1.append(c1)
			c1 = 1
			i1 += 1
	d1.append(t[-1])
	co1.append(c1)
	i1 += 1
	if i != i1:
		print('NO')
	else:
		for i in range(i1):
			if d[i] != d1[i] or co[i] > co1[i]:
				print('NO')
				break
		else:
			print('YES')


n = int(input())
for i in range(n):
	s = input() + ' '
	t = input() + ' '
	s1 = []
	t1 = []
	tmp = 1
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			s1 += [(s[i], tmp)]
			tmp = 1
		else:
			tmp += 1
	tmp = 1
	for i in range(len(t) - 1):
		if t[i] != t[i + 1]:
			t1 += [(t[i], tmp)]
			tmp = 1
		else:
			tmp += 1
	if len(s1) == len(t1) and all([s1[i][1] <= t1[i][1] and s1[i][0] == t1[i][0] for i in range(len(t1))]):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	flag = 0
	buffr = 0
	cnt = len(b)
	for i in range(len(a)):
		j = buffr
		found = 0
		while j < len(b):
			cnt -= 1
			if a[i] != b[j] and (not found):
				flag = 1
				break
			elif a[i] == b[j]:
				found = 1
				if i + 1 < len(a) and a[i] == a[i + 1]:
					buffr = j + 1
					break
			else:
				buffr = j
				cnt += 1
				break
			j += 1
		if not found:
			flag = 1
	print('YES' if not flag and cnt <= 0 else 'NO')


for e in range(int(input())):
	(s, t) = (input(), input())
	u = 0
	j = 0
	f = 1
	while u < len(s) and j < len(t):
		if s[u] == t[j]:
			u += 1
			j += 1
		elif u and s[u - 1] == t[j]:
			j += 1
		else:
			f = 0
			break
	if f and u == len(s) and (j == len(t) or {s[-1]} == set(t[j:])):
		print('YES')
	else:
		print('NO')


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


n = int(input())
for i in range(n):
	s = input()
	s_ = input()
	if len(s_) < len(s):
		print('NO')
	elif s_ == s:
		print('YES')
	else:
		i = 0
		j = 0
		bad = False
		while i < len(s) and j < len(s_):
			if s[i] != s_[j]:
				bad = True
				break
			c = s[i]
			i += 1
			j += 1
			while j < len(s_) and s_[j] == c and (i == len(s) or s_[j] != s[i]):
				j += 1
		if i != len(s) or j != len(s_) or bad:
			print('NO')
		else:
			print('YES')


for numb in range(int(input())):
	t = True
	fword = input()
	sword = input()
	last = None
	last2 = sword[0]
	w1 = {fword[0]: 1}
	w2 = {sword[0]: 1}
	jbegin = 0
	for symb in fword:
		if symb == last:
			w1 = {symb: w1[symb] + 1}
		elif last != None:
			w2 = {sword[jbegin]: 0}
			for j in range(jbegin, len(sword)):
				symb2 = sword[j]
				if symb2 == last2:
					w2 = {symb2: w2[symb2] + 1}
				else:
					last2 = symb2
					jbegin = j
					break
			if (w1 == {}) != (w2 == {}):
				t = False
				print('NO')
				break
			elif w1 == {}:
				pass
			else:
				(k1, v1) = w1.popitem()
				(k2, v2) = w2.popitem()
				if k1 == k2 and v1 <= v2:
					pass
				else:
					print('NO')
					t = False
					break
				w1 = {symb: 1}
		last = symb
	else:
		w2 = {sword[jbegin]: 0}
		for j in range(jbegin, len(sword)):
			symb2 = sword[j]
			if symb2 == last2:
				w2 = {symb2: w2[symb2] + 1}
			else:
				t = False
				break
		if (w1 == {}) != (w2 == {}):
			print('NO')
		elif w1 == {}:
			print('YES')
		else:
			(k1, v1) = w1.popitem()
			(k2, v2) = w2.popitem()
			if k1 == k2 and v1 <= v2 and t:
				print('YES')
			else:
				print('NO')


for u in range(int(input())):
	s = input()
	r = input()
	(n, m) = (len(s), len(r))
	s += '3'
	c = 0
	for i in range(m):
		if s[c] == r[i] and c < n:
			c += 1
		elif r[i] != r[i - 1] or i == 0:
			c = c - 1
			break
	if c == n:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	word = input()
	wlength = len(word)
	typed = input()
	tlength = len(typed)
	index = 0
	flag = True
	for (i, letter) in enumerate(word):
		if index >= tlength:
			flag = False
			break
		if letter == typed[index]:
			index += 1
			if i + 1 == wlength or word[i + 1] != letter:
				while index < tlength and typed[index] == letter:
					index += 1
		else:
			flag = False
			break
	if not flag or index != tlength:
		print('NO')
	else:
		print('YES')


def rle(s):
	last = ''
	count = 0
	runs = []
	counts = []
	for c in s + '\x00':
		if c != last:
			if last:
				runs.append(last)
				counts.append(count)
			last = c
			count = 1
		else:
			count += 1
	return (runs, counts)
for _ in range(int(input())):
	(r1, c1) = rle(input())
	(r2, c2) = rle(input())
	print('YES' if r1 == r2 and all((x <= y for (x, y) in zip(c1, c2))) else 'NO')


def get():
	s = input()
	p = []
	(c, x) = (s[0], 0)
	for i in s:
		if i == c:
			x += 1
		else:
			p.append([c, x])
			c = i
			x = 1
	p.append([c, x])
	return p

def check():
	(s, t) = (get(), get())
	if len(s) != len(t):
		return 'NO'
	for i in range(len(s)):
		if s[i][0] != t[i][0] or s[i][1] > t[i][1]:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	print(check())


n = int(input())
for _ in range(n):
	s = list(input())
	t = list(input())
	c = []
	l = []
	for i in range(len(s)):
		if i == 0:
			c.append([s[i], 1])
		elif s[i - 1] == s[i]:
			c[-1][-1] += 1
		else:
			c.append([s[i], 1])
	for i in range(len(t)):
		if i == 0:
			l.append([t[i], 1])
		elif t[i - 1] == t[i]:
			l[-1][-1] += 1
		else:
			l.append([t[i], 1])
	z = 0
	if len(c) == len(l):
		for i in range(len(c)):
			if c[i][0] != l[i][0] or c[i][1] > l[i][1]:
				z += 1
				break
		if z == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


def solve():
	i = list(input())
	o = list(input())
	li = len(i) - 1
	lo = len(o) - 1
	while True:
		if li == -1 and lo == -1:
			return 'YES'
		if li == -1 and lo != -1:
			return 'NO'
		if li != -1 and lo == -1:
			return 'NO'
		if i[li] == o[lo]:
			t = i[li]
			p1 = 0
			p2 = 0
			while li >= 0 and i[li] == t:
				i.pop(li)
				p1 += 1
				li -= 1
			while lo >= 0 and o[lo] == t:
				o.pop(lo)
				p2 += 1
				lo -= 1
			if p2 < p1:
				return 'NO'
		else:
			return 'NO'
tc = int(input())
result = ''
for _ in range(tc):
	result += solve() + '\n'
print(result)


from bisect import *
from collections import *
from itertools import *
import functools
import sys
from math import *
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 flush():
	return sys.stdout.flush()
n = int(input())
for _ in range(n):
	s = input()
	t = input()
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		elif i > 0 and t[j] == s[i - 1]:
			j += 1
		else:
			break
	if j < len(t) and i > 0:
		while j < len(t) and t[j] == s[i - 1]:
			j += 1
	if i == len(s) and j == len(t):
		print('YES')
	else:
		print('NO')


inp = input()
n = int(inp)
while n > 0:
	str1 = input()
	str2 = input()
	len1 = len(str1)
	len2 = len(str2)
	flag = True
	str3 = ''
	str4 = ''
	for ch in str1:
		if not str3.endswith(ch):
			str3 += ch
	for ch in str2:
		if not str4.endswith(ch):
			str4 += ch
	if str3 != str4 or len1 > len2:
		flag = False
	i = 0
	j = 0
	while i < len1 and flag:
		if j >= len2:
			flag = False
		while flag and str1[i] != str2[j]:
			j += 1
			if j >= len2:
				flag = False
		i += 1
		j += 1
	if flag:
		print('YES')
	else:
		print('NO')
	n -= 1


for _ in range(int(input())):
	a = list(input())
	b = list(input())
	while a and b:
		if a[-1] != b[-1]:
			print('NO')
			break
		else:
			(x, y) = (0, 0)
			c = a[-1]
			while a and a[-1] == c:
				a.pop()
				x += 1
			while b and b[-1] == c:
				b.pop()
				y += 1
			if x > y:
				print('NO')
				break
	else:
		print('NO' if a or b else 'YES')


import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
	A = input().strip()
	B = input().strip()
	AA = []
	AA.append([A[0], 1])
	for i in range(1, len(A)):
		if A[i] == A[i - 1]:
			AA[-1][1] += 1
		else:
			AA.append([A[i], 1])
	BB = []
	BB.append([B[0], 1])
	for i in range(1, len(B)):
		if B[i] == B[i - 1]:
			BB[-1][1] += 1
		else:
			BB.append([B[i], 1])
	if len(AA) != len(BB):
		print('NO')
	else:
		for i in range(len(AA)):
			if AA[i][0] == BB[i][0] and AA[i][1] <= BB[i][1]:
				continue
			else:
				print('NO')
				break
		else:
			print('YES')


def main():
	for _ in range(int(input())):
		s = input()
		t = input()
		after = [(s[0], 1)]
		for i in range(1, len(s)):
			if s[i] == after[-1][0]:
				after[-1] = (after[-1][0], after[-1][1] + 1)
			else:
				after.append((s[i], 1))
		ter = [(t[0], 1)]
		for i in range(1, len(t)):
			if t[i] == ter[-1][0]:
				ter[-1] = (ter[-1][0], ter[-1][1] + 1)
			else:
				ter.append((t[i], 1))
		if len(after) != len(ter):
			print('NO')
		else:
			fucked = False
			for i in range(len(ter)):
				if after[i][0] != ter[i][0] or after[i][1] > ter[i][1]:
					print('NO')
					fucked = True
					break
			if not fucked:
				print('YES')
main()


n = int(input())
for _ in range(n):
	s = input()
	t = input()
	count = []
	i = 0
	while i < len(t):
		c = t[i]
		a = [c, 1]
		i += 1
		while i < len(t) and t[i] == c:
			a[1] += 1
			i += 1
		count.append(a)
	i = 0
	j = 0
	ans = True
	if s[i] != t[j]:
		ans = False
		print('NO')
		continue
	while i < len(s):
		if s[i] == count[j][0] and count[j][1] > 0:
			i += 1
			count[j][1] -= 1
		elif j + 1 < len(count) and count[j + 1][0] == s[i]:
			j += 1
			count[j][1] -= 1
			i += 1
		else:
			ans = False
			break
	if j < len(count) - 1:
		ans = False
	print('YES' if ans else 'NO')


from collections import Counter
n = int(input())
for _ in range(n):
	s = str(input())
	t = str(input())
	sl = len(s)
	tl = len(t)
	s = s + '0'
	i = 0
	for j in range(tl):
		if s[i] == t[j]:
			i += 1
		elif t[j] != t[j - 1] or j == 0:
			i = -1
			break
	if i == sl:
		print('YES')
	else:
		print('NO')


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
for _ in range(n):
	s1 = si()
	s2 = si()
	i = 1
	j = 1
	fg = 0
	while i < len(s1) and j < len(s2):
		if s1[i] == s2[j]:
			i += 1
			j += 1
		elif s2[j] == s1[i - 1]:
			j += 1
		else:
			fg = 1
			print('NO')
			break
	if s1[0] != s2[0] and fg != 1:
		fg = 1
		print('NO')
	if len(s1) > len(s2) and fg == 0:
		print('NO')
		fg = 1
	while j < len(s2) and fg != 1:
		if s2[j] != s1[i - 1]:
			fg = 1
			print('NO')
			break
		j += 1
	if i == len(s1) and j == len(s2) and (fg != 1):
		print('YES')
	elif fg != 1:
		print('NO')


N = int(input())
for n in range(N):
	s = input()
	j = 0
	t = input()
	prev = ''
	wrong = False
	for c in t:
		if j < len(s) and c == s[j]:
			prev = s[j]
			j += 1
			continue
		if c == prev:
			continue
		else:
			wrong = True
			break
	if wrong or j < len(s):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	t = input()
	n = len(s)
	m = len(t)
	i = j = 0
	ans = 'YES'
	while i < n:
		p = 1
		cnt = 0
		while i < n - 1 and s[i] == s[i + 1]:
			p += 1
			i += 1
		while j < m and t[j] == s[i]:
			cnt += 1
			j += 1
		if cnt < p:
			ans = 'NO'
			break
		i += 1
	if ans != 'NO':
		while j < m:
			if t[j] not in s[i:]:
				ans = 'NO'
				break
			j += 1
	print(ans)


from sys import stdin, stdout
input = stdin.readline
n = int(input())
for _ in range(n):
	a = input()
	b = input()
	a = a[:len(a) - 1]
	b = b[:len(b) - 1]
	a = list(a)
	b = list(b)
	x = a[-1]
	fl = 0
	while a or b:
		if len(a) > 0 and len(b) > 0 and (a[-1] == b[-1]):
			x = a.pop()
			b.pop()
		elif len(b) > 0 and b[-1] == x:
			b.pop()
		else:
			fl = 1
			break
	if len(a) == len(b) == 0:
		stdout.write('YES' + '\n')
	else:
		stdout.write('NO' + '\n')


from sys import stdin

def solve():
	results = []
	for _ in range(int(stdin.readline())):
		s1 = stdin.readline().strip()
		s2 = stdin.readline().strip()
		n1 = len(s1)
		n2 = len(s2)
		if n2 < n1 or set(s1) != set(s2):
			results.append('NO')
			continue
		(i, j) = (0, 0)
		ans = 'YES'
		flag = 0
		while i < n1 and j < n2:
			if s1[i] != s2[j]:
				ans = 'NO'
				break
			while i < n1 - 1 and j < n2 and (s1[i] == s1[i + 1]):
				if s1[i] != s2[j]:
					ans = 'NO'
					flag = 1
					break
				i += 1
				j += 1
			if flag:
				break
			if (i < n1 and j < n2) and s1[i] != s2[j]:
				ans = 'NO'
				break
			while j < n2 - 1 and s2[j] == s2[j + 1]:
				j += 1
			i += 1
			j += 1
		if i != n1 or j != n2:
			ans = 'NO'
		results.append(ans)
	print('\n'.join(results))
solve()


for _ in range(int(input())):
	a = list(str(input()))
	b = list(str(input()))
	first = []
	second = []
	pnt1 = 0
	pnt2 = 0
	for i in range(len(a)):
		if a[pnt2] != a[pnt1]:
			first.append(a[pnt1:pnt2])
			pnt1 = int(pnt2)
		pnt2 += 1
	first.append(a[pnt1:pnt2])
	(pnt1, pnt2) = (0, 0)
	for i in range(len(b)):
		if b[pnt2] != b[pnt1]:
			second.append(b[pnt1:pnt2])
			pnt1 = int(pnt2)
		pnt2 += 1
	second.append(b[pnt1:pnt2])
	if len(first) != len(second):
		print('NO')
	else:
		ok = True
		for i in range(len(first)):
			if first[i][0] != second[i][0] or len(second[i]) < len(first[i]):
				ok = False
				break
		if ok:
			print('YES')
		else:
			print('NO')


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

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

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

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

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

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

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

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

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

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

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

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

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True

def solve(a, n):
	i = 1
	ml = []
	c = 1
	while i < n:
		if a[i] == a[i - 1]:
			c += 1
		else:
			ml.append((a[i - 1], c))
			c = 0
		i += 1
	ml.append((a[-1], c))
	return ml
for _ in range(int(inp())):
	a = inp()
	b = inp()
	n = len(a)
	m = len(b)
	ml1 = solve(a, n)
	ml2 = solve(b, m)
	(n, m) = (len(ml1), len(ml2))
	flg = True
	if n != m:
		print('NO')
		continue
	for i in range(n):
		if ml1[i][0] != ml2[i][0] or ml1[i][1] > ml2[i][1]:
			flg = False
			break
	print('YES' if flg else 'NO')


for _ in range(int(input())):
	First = input()
	Second = input()
	x = 0
	Prev = First[0]
	i = 0
	flag = 0
	if len(Second) < len(First):
		print('NO')
		continue
	while i != len(Second):
		if x >= len(First):
			while i != len(Second):
				if Second[i] == Prev:
					i += 1
				else:
					print('NO')
					flag = 1
					break
			break
		if Second[i] == First[x]:
			Prev = First[x]
			x += 1
			i += 1
			continue
		elif Second[i] == Prev:
			i += 1
		else:
			print('NO')
			flag = 1
			break
	if not flag and x == len(First):
		print('YES')
	elif not flag:
		print('NO')


n = int(input())
for i in range(n):
	a = input()
	b = input()
	if len(b) < len(a):
		print('NO')
		continue
	ans1 = []
	c = 1
	for i in range(len(a) - 1):
		if a[i] != a[i + 1]:
			ans1.append([a[i], c])
			c = 1
		else:
			c = c + 1
	ans1.append([a[-1], c])
	ans2 = []
	c = 1
	for i in range(len(b) - 1):
		if b[i] != b[i + 1]:
			ans2.append([b[i], c])
			c = 1
		else:
			c = c + 1
	ans2.append([b[-1], c])
	if len(ans1) != len(ans2):
		print('NO')
		continue
	c = 0
	for i in range(len(ans1)):
		if ans1[i][0] == ans2[i][0] and ans1[i][1] <= ans2[i][1]:
			c = c + 1
	if c == len(ans1):
		print('YES')
	else:
		print('NO')


for k in range(int(input())):
	s1 = input()
	s2 = input()
	c = 0
	lf = len(s1)
	ls = len(s2)
	s1 += '0'
	for i in range(ls):
		if s1[c] == s2[i] and c < lf:
			c += 1
		elif s2[i - 1] != s2[i] or i == 0:
			c -= 1
			break
	if c == lf:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	t = input()
	m = max(len(s), len(t))
	j = count = 1
	k = 0
	c = [[0]] * m
	c[0] = [s[0], 1]
	while j < len(s):
		if s[j] == s[j - 1]:
			c[k][1] += 1
		else:
			k += 1
			c[k] = [s[j], 1]
			count += 1
		j += 1
	d = [[0]] * m
	j = count1 = 1
	k = 0
	d[0] = [t[0], 1]
	while j < len(t):
		if t[j] == t[j - 1]:
			d[k][1] += 1
		else:
			k += 1
			d[k] = [t[j], 1]
			count1 += 1
		j += 1
	count = max(count, count1)
	j = 0
	while j < count:
		if c[j][0] == d[j][0] and c[j][0] != 0:
			if c[j][1] > d[j][1]:
				break
		else:
			break
		j = j + 1
	if j == count:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	a = input()
	b = input()
	di = [[a[0], 1]]
	for i in a[1:]:
		if di[-1][0] == i:
			di[-1][1] += 1
		else:
			di.append([i, 1])
	di2 = [[b[0], 1]]
	for i in b[1:]:
		if di2[-1][0] == i:
			di2[-1][1] += 1
		else:
			di2.append([i, 1])
	if len(di) != len(di2):
		print('NO')
		continue
	f = 0
	for i in range(len(di)):
		if di[i][0] == di2[i][0] and di[i][1] <= di2[i][1]:
			continue
		f = 1
		break
	if f:
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(n):
	r = input()
	s = input()
	if len(r) > len(s):
		print('NO')
		continue
	r1 = []
	s1 = []
	rc = []
	sc = []
	f = 0
	j = 1
	r1.append(r[0])
	while j < len(r):
		c = 1
		while j < len(r) and r[j] == r[j - 1]:
			j += 1
			c += 1
		rc.append(c)
		if j >= len(r):
			break
		r1.append(r[j])
		j += 1
	if len(r) > 1 and r[-1] != r[-2]:
		rc.append(1)
	j = 1
	s1.append(s[0])
	while j < len(s):
		c = 1
		while j < len(s) and s[j] == s[j - 1]:
			j += 1
			c += 1
		sc.append(c)
		if j >= len(s):
			break
		s1.append(s[j])
		j += 1
	if len(s) > 1 and s[-1] != s[-2]:
		sc.append(1)
	if r1 != s1:
		print('NO')
		continue
	else:
		for j in range(len(rc)):
			if sc[j] >= rc[j]:
				continue
			else:
				f = 1
				break
		if f == 1:
			print('NO')
		else:
			print('YES')


n = int(input())
for _ in range(n):
	(a, b) = (input(), input())
	groupa = []
	groupb = []
	c = None
	for i in range(len(a)):
		if a[i] != c:
			groupa.append([a[i], 0])
			c = a[i]
		groupa[-1][1] += 1
	c = None
	for i in range(len(b)):
		if b[i] != c:
			groupb.append([b[i], 0])
			c = b[i]
		groupb[-1][1] += 1
	if len(groupa) != len(groupb):
		print('NO')
		continue
	else:
		f = False
		for i in range(len(groupa)):
			if groupa[i][0] != groupb[i][0] or groupb[i][1] < groupa[i][1]:
				print('NO')
				f = True
				break
		if not f:
			print('YES')


def getTuplesArray(w):
	letterBeginIndex = 0
	array = []
	while letterBeginIndex < len(w):
		letter = w[letterBeginIndex]
		count = 1
		letterLastIndex = letterBeginIndex
		nextLetterIndex = letterLastIndex + 1
		while nextLetterIndex < len(w) and w[nextLetterIndex] == letter:
			count += 1
			nextLetterIndex += 1
		letterBeginIndex = nextLetterIndex
		array.append((letter, count))
	return array

def isGood(w1, w2):
	tuples1 = getTuplesArray(w1)
	tuples2 = getTuplesArray(w2)
	if len(tuples1) != len(tuples2):
		return 'NO'
	for i in range(0, len(tuples1)):
		if tuples1[i][0] != tuples2[i][0] or tuples1[i][1] > tuples2[i][1]:
			return 'NO'
	return 'YES'
wordsNumber = int(input())
answers = []
for i in range(0, wordsNumber):
	firstWord = input()
	secondWord = input()
	result = isGood(firstWord, secondWord)
	answers.append(result)
[print(answer) for answer in answers]


import itertools
n = int(input())
is_possible = True
for i in range(n):
	is_possible = True
	(s, t) = (input(), input())
	if len(s) > len(t):
		print('NO')
	else:
		(group_s, group_t) = ([], [])
		for i in s:
			if len(group_s) == 0:
				group_s.append([i])
			elif group_s[-1][0] == i:
				group_s[-1].append(i)
			elif group_s[-1][0] != i:
				group_s.append([i])
		for i in t:
			if len(group_t) == 0:
				group_t.append([i])
			elif group_t[-1][0] == i:
				group_t[-1].append(i)
			elif group_t[-1][0] != i:
				group_t.append([i])
		if len(group_s) != len(group_t):
			print('NO')
		else:
			for i in range(len(group_s)):
				if len(group_s[i]) > len(group_t[i]):
					is_possible = False
					break
				if group_s[i][0] != group_t[i][0]:
					is_possible = False
					break
			if is_possible:
				print('YES')
			else:
				print('NO')


def meth(s1, s2):
	a1 = ''
	a2 = ''
	for x in s1:
		if a1 == '':
			a1 += x
		elif len(a1) > 0 and x != a1[-1]:
			a1 += x
	for x in s2:
		if a2 == '':
			a2 += x
		elif len(a2) > 0 and x != a2[-1]:
			a2 += x
	if a1 == a2:
		return True
	return False
n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	a1 = []
	a2 = []
	val = ''
	c = 0
	fl = 0
	for x in s1:
		if fl == 0:
			val = x
			c += 1
			fl += 1
		elif x == val:
			c += 1
		else:
			a1.append(c)
			c = 1
			val = x
	if c != 0:
		a1.append(c)
	val = ''
	c = 0
	fl = 0
	for x in s2:
		if fl == 0:
			val = x
			c += 1
			fl += 1
		elif x == val:
			c += 1
		else:
			a2.append(c)
			c = 1
			val = x
	if c != 0:
		a2.append(c)
	if not meth(s1, s2):
		print('NO')
	else:
		fl = 0
		for i1 in range(len(a1)):
			if a1[i1] > a2[i1]:
				print('NO')
				fl = 1
				break
		if fl == 0:
			print('YES')


import sys
input = iter(sys.stdin.read().splitlines()).__next__
n = int(input())

def prep(s):
	S = []
	lc = None
	count = 0
	for c in s:
		if c != lc and count:
			S.append((lc, count))
			count = 0
		count += 1
		lc = c
	if count:
		S.append((lc, count))
	return S
for _ in range(n):
	t = input()
	s = input()
	T = prep(t)
	S = prep(s)
	if len(T) == len(S):
		for i in range(len(T)):
			if T[i][0] != S[i][0] or T[i][1] > S[i][1]:
				break
		else:
			print('YES')
			continue
		print('NO')
	else:
		print('NO')


N = int(input())
for _ in range(N):
	A = input()
	B = input()
	Max = max(len(A), len(B))
	S1 = []
	count = 1
	Temp = A[0]
	for val in A[1:]:
		if val == Temp:
			count += 1
		else:
			S1.append([Temp, count])
			count = 1
			Temp = val
	S1.append([Temp, count])
	Temp = B[0]
	count = 1
	S2 = []
	for val in B[1:]:
		if val == Temp:
			count += 1
		else:
			S2.append([Temp, count])
			count = 1
			Temp = val
	S2.append([Temp, count])
	if len(S1) != len(S2):
		print('NO')
	else:
		Bool = False
		for (a, b) in zip(S1, S2):
			if a[0] == b[0] and a[1] <= b[1]:
				pass
			else:
				Bool = True
				break
		if Bool == False:
			print('YES')
		else:
			print('NO')


n = int(input())
for i in range(n):
	x = []
	y = []
	a = input()
	b = input()
	x.append([a[0], 1])
	y.append([b[0], 1])
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			x[-1][1] += 1
		else:
			x.append([a[i], 1])
	for i in range(1, len(b)):
		if b[i] == b[i - 1]:
			y[-1][1] += 1
		else:
			y.append([b[i], 1])
	ans = 'YES'
	if len(x) != len(y):
		ans = 'NO'
	else:
		for i in range(len(x)):
			if x[i][0] != y[i][0] or x[i][1] > y[i][1]:
				ans = 'NO'
	print(ans)


tcase = int(input())
while tcase > 0:
	tcase -= 1
	a = input()
	b = input()
	(result_a, result_b) = ('', '')
	(l_a, l_b, ctr) = ([], [], 0)
	c = a[0]
	for i in a:
		if i == c:
			ctr += 1
		elif i != c:
			result_a += c
			l_a.append(ctr)
			ctr = 1
			c = i
	l_a.append(ctr)
	result_a += a[len(a) - 1]
	(c, ctr) = (b[0], 0)
	for i in b:
		if i == c:
			ctr += 1
		elif i != c:
			result_b += c
			l_b.append(ctr)
			ctr = 1
			c = i
	l_b.append(ctr)
	result_b += b[len(b) - 1]
	result = False
	if len(l_a) == len(l_b) and result_a == result_b:
		i = 0
		result = True
		while i < len(result_a):
			if l_a[i] > l_b[i]:
				result = False
				break
			i += 1
	if result:
		print('YES')
	else:
		print('NO')


import collections
for _ in range(int(input())):
	s1 = list(input())
	s2 = list(input())
	res = True
	while s1 and s2:
		s = s1[-1]
		(x, y) = (0, 0)
		while s1 and s1[-1] == s:
			s1.pop()
			x += 1
		while s2 and s2[-1] == s:
			s2.pop()
			y += 1
		if x > y:
			res = False
	print('YES' if res and len(s1) == 0 and (len(s2) == 0) else 'NO')


n = int(input())
for i in range(n):
	a1 = input()
	a2 = input()
	i = 0
	j = 0
	f = 0
	la1 = len(a1)
	la2 = len(a2)
	a1 += '0'
	a2 += '0'
	a1m = []
	a2m = []
	for i in range(la1):
		if a1[i] == a1[i - 1]:
			a1m[-1] += 1
		else:
			a1m.append(a1[i])
			a1m.append(1)
	for i in range(la2):
		if a2[i] == a2[i - 1]:
			a2m[-1] += 1
		else:
			a2m.append(a2[i])
			a2m.append(1)
	if len(a1m) != len(a2m):
		print('NO')
	else:
		f = 0
		for i in range(len(a1m) // 2):
			if a1m[2 * i] != a2m[2 * i]:
				f = 1
				break
			if int(a1m[2 * i + 1]) > int(a2m[2 * i + 1]):
				f = 1
				break
		print('YES' if f == 0 else 'NO')


for t in range(int(input())):
	(First, Second, i, j) = (input(), input(), 0, 0)
	(S1, S2, First, Second, Res) = (len(First), len(Second), First, Second, True)
	if S2 < S1:
		print('NO')
		continue
	while i < S1 and j < S2:
		(C1, C2, Check) = (0, 0, First[i])
		while i < S1 and First[i] == Check:
			C1 += 1
			i += 1
		while j < S2 and Second[j] == Check:
			C2 += 1
			j += 1
		if C1 > C2:
			Res = False
			break
	print('YES' if Res and j == S2 and (i == S1) else 'NO')


n = int(input())
res = []
for i in range(n):
	src = input()
	dest = input()
	current_char = None
	cnt = 0
	dest_idx = 0
	no = False
	for c in src:
		if current_char == None:
			current_char = c
			cnt = 1
		elif current_char == c:
			cnt += 1
		else:
			for j in range(cnt):
				if dest_idx + j < len(dest) and dest[dest_idx + j] == current_char:
					continue
				else:
					no = True
					break
			if no:
				break
			dest_idx += cnt
			while dest_idx < len(dest) and dest[dest_idx] == current_char:
				dest_idx += 1
			current_char = c
			cnt = 1
	if no:
		res.append('NO')
		continue
	for j in range(cnt):
		if dest_idx + j < len(dest) and dest[dest_idx + j] == current_char:
			continue
		else:
			no = True
			break
	dest_idx += cnt
	while dest_idx < len(dest) and dest[dest_idx] == current_char:
		dest_idx += 1
	if no or dest_idx < len(dest):
		res.append('NO')
	else:
		res.append('YES')
for r in res:
	print(r)


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	elif p == 3:
		return list(input())
	else:
		return int(input())

class DisjointSet:

	def __init__(self, n):
		self.parent = [i for i in range(1, n + 1)]
		self.rank = [0] * (n + 1)

	def find_set(self, x):
		if self.parent[x] == x:
			return x
		else:
			self.parent[x] = self.find_set(self.parent[x])
			return self.parent[x]

	def union(self, x, y):
		set_x = self.find_set(x)
		set_y = self.find_set(y)
		if set_x != set_y:
			if self.rank[x]:
				pass

def graph(n, m, edg=False):
	edges = []
	visited = [0] * n
	g = [list() for _ in range(n + 1)]
	for i in range(m):
		(u, v) = f(1)
		g[u].append(v)
		g[v].append(u)
		if edg:
			edges.append((u, v))
	if edg:
		return (g, visited, edg)
	else:
		return (g, visited)

def bfs(g, visited):
	queue = [1]
	visited[1] = 1
	for u in queue:
		for v in g[u]:
			if visited[v] == 0:
				queue.append(v)
			visited[v] = 1

def dfs(u, g, visited):
	visited[u] = 1
	for v in g[u]:
		if visited[v] == 0:
			dfs(v, g, visited)
n = f()
for i in range(n):
	s = input()
	t = input()
	a = []
	b = []
	count = 1
	sm = ''
	for i in range(len(s) - 1):
		sm = s[i]
		if s[i] == s[i + 1]:
			count += 1
		else:
			a.append((sm, count))
			count = 1
	if count == 1:
		a.append((s[-1], 1))
	else:
		a.append((sm, count))
	count = 1
	for i in range(len(t) - 1):
		sm = t[i]
		if t[i] == t[i + 1]:
			count += 1
		else:
			b.append((sm, count))
			count = 1
	if count == 1:
		b.append((t[-1], 1))
	else:
		b.append((sm, count))
	if len(a) != len(b):
		print('NO')
	else:
		st = True
		for i in range(len(a)):
			if a[i][0] == b[i][0]:
				if a[i][1] > b[i][1]:
					st = False
					break
			else:
				st = False
				break
		if st:
			print('YES')
		else:
			print('NO')


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

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

def IS():
	return input()

def IM():
	return map(int, input().split())
t = I()
for i in range(t):
	s1 = IS()
	s2 = IS()
	f = 1
	if len(s1) > len(s2):
		print('NO')
		continue
	if len(s1) == len(s2):
		print('YES' if s1 == s2 else 'NO')
		continue
	grps1 = []
	grps2 = []
	i = 0
	n = len(s1)
	m = len(s2)
	while i < n:
		curr = s1[i]
		c = 0
		while i < n and s1[i] == curr:
			c += 1
			i += 1
		grps1.append([curr, c])
	i = 0
	while i < m:
		curr = s2[i]
		c = 0
		while i < m and s2[i] == curr:
			c += 1
			i += 1
		grps2.append([curr, c])
	if len(grps1) != len(grps2):
		print('NO')
		continue
	f = 1
	for i in range(len(grps1)):
		if grps1[i][0] != grps2[i][0] or grps1[i][1] > grps2[i][1]:
			f = 0
	print('YES' if f else 'NO')


def is_same(message, letters):
	(message, letters) = (count(message), count(letters))
	if len(message) != len(letters):
		return False
	else:
		for (item1, item2) in zip(message, letters):
			if item1[0] != item2[0] or item1[1] > item2[1]:
				return False
		return True

def count(string):
	l = []
	i = 0
	while i < len(string):
		counter = 0
		current_char = string[i]
		while current_char == string[i]:
			counter += 1
			i += 1
			if i == len(string):
				break
		l.append((current_char, counter))
	return l
n = int(input())
while n > 0:
	(message, letters) = (input(), input())
	print('YES' if is_same(message, letters) else 'NO')
	n -= 1


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

def rints():
	return list(map(int, input().split()))
from itertools import groupby, zip_longest
n = rint()
for _ in range(n):
	a = input()
	b = input()
	p = True
	for (g1, g2) in zip_longest(groupby(a), groupby(b)):
		if g1 is None or g2 is None:
			p = False
			break
		(k1, v1) = g1
		(k2, v2) = g2
		if k1 != k2 or len(list(v1)) > len(list(v2)):
			p = False
			break
	print('YES' if p else 'NO')


def check(a, b):
	z = True
	(i, j) = (0, 0)
	(n, m, z) = (len(a), len(b), True)
	while i < n and j < m and z:
		if a[i] == b[j]:
			rem = a[i]
			i += 1
			j += 1
		else:
			if i == 0:
				return False
			if b[j] == rem:
				x = True
				while j < m and x:
					if b[j] == rem:
						j += 1
					else:
						x = False
			else:
				z = False
	if i != n:
		return False
	while j < m and z:
		if b[j] == a[n - 1]:
			j += 1
		else:
			z = False
	return z
n = int(input())
for i in range(n):
	a = list(input())
	b = list(input())
	if check(a, b):
		print('YES')
	else:
		print('NO')


from itertools import groupby
for i in range(int(input())):
	s = list((''.join(g) for (_, g) in groupby(input())))
	t = list((''.join(g) for (_, g) in groupby(input())))
	if len(s) == len(t) and all((x in y for (x, y) in zip(s, t))):
		print('YES')
	else:
		print('NO')


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]
	n = len(s)
	m = len(t)
	f = 1
	(i, j) = (0, 0)
	while i < n and j < m:
		x = s[i]
		y = t[j]
		c1 = 0
		c2 = 0
		while i < n and s[i] == x:
			c1 += 1
			i += 1
		while j < m and t[j] == y:
			c2 += 1
			j += 1
		if c2 < c1 or x != y:
			f = 0
			break
	if f == 0 or i < n or j < m:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
n = int(input())
word = [input() for i in range(2 * n)]
for i in range(n):
	word0 = word[i * 2]
	word1 = word[i * 2 + 1]
	li0 = [[word0[0], 1]]
	li1 = [[word1[0], 1]]
	for i in range(1, len(word0)):
		if li0[-1][0] == word0[i]:
			li0[-1][1] += 1
		else:
			li0.append([word0[i], 1])
	for i in range(1, len(word1)):
		if li1[-1][0] == word1[i]:
			li1[-1][1] += 1
		else:
			li1.append([word1[i], 1])
	for i in range(len(li0)):
		if li0[i][0] == li1[i][0] and li0[i][1] <= li1[i][1]:
			continue
		else:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(0, t):
	s = input()
	a = input()
	p = len(s)
	for b in range(0, 1):
		if s[0] == a[0]:
			count = 1
			j = 1
			flag = 0
			for i in range(1, len(a)):
				if j < p and a[i] == s[j]:
					count += 1
					j += 1
				elif a[i] == s[j - 1]:
					pass
				else:
					flag = 1
					break
			if flag == 1:
				print('NO')
			elif count == p:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	if len(t) < len(s):
		print('NO')
	else:
		l = []
		l1 = []
		flag = -1
		for i in range(len(t) - 1):
			if t[i] == t[i + 1]:
				l1.append(t[i])
				flag = 1
			else:
				l1.append(t[i])
				l.append(l1)
				l1 = []
				flag = 0
		if flag == 1:
			l1.append(t[-1])
			l.append(l1)
		else:
			l.append([t[-1]])
		for i in range(len(l)):
			l[i] = ''.join(l[i])
		d = []
		d1 = []
		flag = -1
		for i in range(len(s) - 1):
			if s[i] == s[i + 1]:
				d1.append(s[i])
				flag = 1
			else:
				d1.append(s[i])
				d.append(d1)
				d1 = []
				flag = 0
		if flag == 1:
			d1.append(s[-1])
			d.append(d1)
		else:
			d.append([s[-1]])
		for i in range(len(d)):
			d[i] = ''.join(d[i])
		if len(d) != len(l):
			print('NO')
		else:
			flag = 0
			for i in range(len(d)):
				if d[i][0] != l[i][0] or len(d[i]) > len(l[i]):
					flag = 1
					break
			if flag == 1:
				print('NO')
			else:
				print('YES')


n = int(input())
for i in range(n):
	ans = True
	s = input()
	t = input()
	r1 = 0
	r2 = 0
	while r1 < len(s) and r2 < len(t):
		if s[r1] != t[r2]:
			ans = False
			break
		p1 = r1
		p2 = r2
		while p1 < len(s) and s[p1] == s[r1]:
			p1 += 1
		while p2 < len(t) and t[p2] == t[r2]:
			p2 += 1
		if p1 - r1 > p2 - r2:
			ans = False
			break
		r1 = p1
		r2 = p2
	if ans and r1 == len(s) and (r2 == len(t)) and (len(s) <= len(t)):
		print('YES')
	else:
		print('NO')


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')
for t in range(int(input())):
	a = input()
	b = input()
	a += '0'
	b += '0'
	temp = ''
	(gpa, gpb) = ([], [])
	cnt = 0
	for i in range(len(a) - 1):
		cnt += 1
		if a[i] != a[i + 1]:
			gpa.append((a[i], cnt))
			cnt = 0
	for i in range(len(b) - 1):
		cnt += 1
		if b[i] != b[i + 1]:
			gpb.append((b[i], cnt))
			cnt = 0
	lena = len(gpa)
	lenb = len(gpb)
	flag = lena == lenb
	if flag == 1:
		for i in range(lena):
			if gpa[i][0] != gpb[i][0] or gpa[i][1] > gpb[i][1]:
				flag = 0
	print('YES' if flag == 1 else 'NO')


t = int(input())
for zzz in range(t):
	s1 = input()
	s2 = input()
	pos1 = 0
	pos2 = 0
	prev1 = 0
	prev2 = 0
	while pos1 < len(s1):
		let1 = s1[pos1]
		while pos1 < len(s1) and s1[pos1] == let1:
			pos1 += 1
		while pos2 < len(s2) and s2[pos2] == let1:
			pos2 += 1
		if pos1 - prev1 > pos2 - prev2:
			print('NO')
			break
		prev1 = pos1
		prev2 = pos2
	else:
		if pos1 == len(s1) and pos2 == len(s2):
			print('YES')
		else:
			print('NO')


def good(s, t):
	n = len(s)
	pt = 0
	pt1 = 0
	m = len(t)
	if n > m:
		return False
	while pt1 < m:
		c = t[pt1]
		ct = 0
		while pt1 < m and t[pt1] == c:
			ct = ct + 1
			pt1 = pt1 + 1
		if pt >= n:
			return False
		if s[pt] != c:
			return False
		ct2 = 0
		while s[pt] == c:
			ct2 = ct2 + 1
			pt = pt + 1
			if pt >= n:
				break
		if ct < ct2:
			return False
	if pt != n:
		return False
	return True

def main():
	n = int(input())
	for i in range(n):
		s = input()
		t = input()
		if good(s, t):
			print('YES')
		else:
			print('NO')
main()


import sys
for _ in range(int(input())):
	word = sys.stdin.readline().strip()
	word2 = sys.stdin.readline().strip()
	prev = word[0]
	cnt = 0
	dat2 = []
	for l in word2:
		if l == prev:
			cnt += 1
		else:
			dat2.append((prev, cnt))
			prev = l
			cnt = 1
	dat2.append((prev, cnt))
	prev = word2[0]
	cnt = 0
	dat = []
	for l in word:
		if l == prev:
			cnt += 1
		else:
			dat.append((prev, cnt))
			prev = l
			cnt = 1
	dat.append((prev, cnt))
	ln = len(dat)
	if ln != len(dat2):
		print('NO')
	else:
		good = True
		for i in range(ln):
			if dat[i][0] != dat2[i][0] or dat[i][1] > dat2[i][1]:
				good = False
				break
		if good:
			print('YES')
		else:
			print('NO')


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

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

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 2750132
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(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
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	s = input()
	t = input()
	if len(t) < len(s):
		print('NO')
		return
	indx_s = indx_t = 0
	while indx_s < len(s) and indx_t < len(t):
		if s[indx_s] != t[indx_t]:
			print('NO')
			return
		i = indx_s + 1
		count_s = 1
		while i < len(s) and s[indx_s] == s[i]:
			i += 1
			count_s += 1
		indx_s = i
		i = indx_t + 1
		count_t = 1
		while i < len(t) and t[indx_t] == t[i]:
			count_t += 1
			i += 1
		indx_t = i
		if count_t < count_s:
			print('NO')
			return
	if indx_t == len(t) and indx_s < len(s) or (indx_s == len(s) and indx_t < len(t)):
		print('NO')
		return
	print('YES')
t = 1
t = int(input())
for _ in range(t):
	solve()


n = int(input())
out = []
for i in range(n):
	s1 = input()
	s2 = input()
	if len(s2) < len(s1):
		out.append('NO')
		continue
	(i1, i2) = (0, 0)
	while True:
		if i2 == len(s2):
			out.append('NO' if i1 < len(s1) else 'YES')
			break
		c1 = s1[i1] if i1 < len(s1) else '_'
		c2 = s2[i2] if i2 < len(s2) else '_'
		if c1 == c2:
			i1 += 1
			i2 += 1
		elif i1 == 0:
			out.append('NO')
			break
		elif c2 != s1[i1 - 1]:
			out.append('NO')
			break
		else:
			i1 -= 1
for i in range(n):
	print(out[i])


from math import *
for _ in range(int(input())):
	s = input()
	t = input()
	flg = 0
	i = 0
	indx = 0
	while i < len(s) and indx < len(t):
		j = i
		tmp = 0
		while j < len(s) and s[j] == s[i]:
			tmp += 1
			j += 1
		h = indx
		tmp2 = 0
		while h < len(t) and t[h] == t[indx]:
			tmp2 += 1
			h += 1
		if s[i] != t[indx] or tmp > tmp2:
			flg = 1
			break
		i = j
		indx = h
	if i != len(s) or indx != len(t):
		flg = 1
	if flg:
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	k = 0
	for j in range(len(s2)):
		if j and k < len(s1) - 1 and (s1[k + 1] == s2[j]):
			k += 1
		elif s1[k] != s2[j]:
			print('NO')
			break
	else:
		print('YES' if k == len(s1) - 1 else 'NO')


t = int(input())
for i in range(t):
	st = input()
	co = input()
	j = 0
	past = st[j]
	count = 0
	temp = True
	for i in co:
		if j != len(st):
			if i == st[j]:
				count = count + 1
				past = st[j]
				j = j + 1
			elif i == past:
				continue
			else:
				temp = False
				break
		elif i == past:
			continue
		else:
			temp = False
	if temp and len(st) == count:
		print('YES')
	else:
		print('NO')


n = int(input())
for k in range(n):
	s = input()
	t = input()
	(z, x) = (len(t), len(s))
	s += '~'
	(i, j) = (0, 0)
	while i < x and j < z and (s[i] == t[j]):
		if s[i] == s[i + 1]:
			i += 1
			j += 1
			continue
		while j < z and s[i] == t[j]:
			j += 1
		i += 1
	if i == x and j == z:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	t = input()
	s1 = []
	t1 = []
	if len(set(s)) == 1:
		s1 = [s]
	else:
		s2 = ''
		for i in range(len(s)):
			if s2 == '':
				s2 += s[i]
			elif s[i] != s2[-1]:
				s1.append(s2)
				s2 = s[i]
			else:
				s2 += s[i]
		if s2 != '':
			s1.append(s2)
	if len(set(t)) == 1:
		t1 = [t]
	else:
		s2 = ''
		for i in range(len(t)):
			if s2 == '':
				s2 += t[i]
			elif t[i] != s2[-1]:
				t1.append(s2)
				s2 = t[i]
			else:
				s2 += t[i]
		if s2 != '':
			t1.append(s2)
	if len(s1) != len(t1):
		print('NO')
	else:
		f = True
		for i in range(len(s1)):
			if s1[i][0] != t1[i][0]:
				print('NO')
				f = False
				break
			if len(s1[i]) > len(t1[i]):
				print('NO')
				f = False
				break
		if f:
			print('YES')


n = int(input())
for _ in range(n):
	ina = inb = 0
	a = input() + ' '
	wa = []
	a1 = b1 = ''
	k = 0
	for i in range(len(a)):
		if i == 0 or a[i - 1] == a[i]:
			k += 1
		else:
			wa.append(k)
			k = 0
			a1 += a[i - 1]
	b = input() + ' '
	wb = []
	k = 0
	for i in range(len(b)):
		if i == 0 or b[i - 1] == b[i]:
			k += 1
		else:
			wb.append(k)
			k = 0
			b1 += b[i - 1]
	if a1 == b1:
		f = 0
		for j in range(len(wa)):
			if wa[j] > wb[j]:
				print('NO')
				f = 1
				break
		if not f:
			print('YES')
	else:
		print('NO')


import sys
n = int(input())
lines = sys.stdin.readlines()
for i in range(n):

	def cnt(line):
		l1 = []
		for l in line:
			if l1 and l1[-1][0] == l:
				l1[-1][1] += 1
			else:
				l1.append([l, 1])
		return l1
	c1 = cnt(lines[i * 2].strip())
	c2 = cnt(lines[i * 2 + 1].strip())
	if len(c1) != len(c2):
		print('NO')
	else:
		good = True
		for p in zip(c1, c2):
			if p[0][0] != p[1][0] or p[0][1] > p[1][1]:
				good = False
				break
		if good:
			print('YES')
		else:
			print('NO')


def processString(mstr):
	c_old = mstr[0]
	count = 0
	res = []
	for c in mstr:
		if c_old != c:
			res.append((c_old, count))
			c_old = c
			count = 1
		else:
			count += 1
	res.append((c_old, count))
	return res
t = int(input())
while t > 0:
	a = input()
	A = processString(a)
	b = input()
	B = processString(b)
	if len(A) != len(B):
		print('NO')
	else:
		flag = False
		for i in range(0, len(A)):
			if A[i][0] != B[i][0] or A[i][1] > B[i][1]:
				flag = True
				break
		if flag:
			print('NO')
		else:
			print('YES')
	t -= 1


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	(l1, l2) = ([], [])
	counter = 1
	for j in range(len(s1) - 1):
		if s1[j] == s1[j + 1]:
			counter += 1
		else:
			l1.append([s1[j], counter])
			counter = 1
	l1.append([s1[-1], counter])
	counter = 1
	for j in range(len(s2) - 1):
		if s2[j] == s2[j + 1]:
			counter += 1
		else:
			l2.append([s2[j], counter])
			counter = 1
	l2.append([s2[-1], counter])
	if len(l1) != len(l2):
		print('NO')
	else:
		for j in range(len(l1)):
			if l1[j][0] == l2[j][0]:
				if l1[j][1] <= l2[j][1]:
					pass
				else:
					print('NO')
					break
			else:
				print('NO')
				break
		else:
			print('YES')


n = int(input())
res = ''
for f in range(n):
	s1 = str(input())
	s2 = str(input())
	a = []
	amass = []
	a1 = 0
	b = []
	bmass = []
	b1 = 0
	k = 0
	q = 0
	v = s1[0]
	w = s2[0]
	for i in range(len(s1)):
		if v != s1[i]:
			a.append(k)
			amass.append(s1[i - 1])
			a1 += 1
			k = 1
			v = s1[i]
		else:
			k += 1
	a.append(k)
	amass.append(s1[len(s1) - 1])
	a1 += 1
	for i in range(len(s2)):
		if w != s2[i]:
			b.append(q)
			bmass.append(s2[i - 1])
			b1 += 1
			q = 1
			w = s2[i]
		else:
			q += 1
	b.append(q)
	bmass.append(s2[len(s2) - 1])
	b1 += 1
	err = 0
	if a1 != b1:
		err -= 1000010
		res += 'NO\n'
	else:
		for i in range(a1):
			if a[i] > b[i] or amass[i] != bmass[i]:
				err += 1
	if err == 0:
		res += 'YES\n'
	elif err > 0:
		res += 'NO\n'
print(res)


import sys
input = sys.stdin.readline
qq = int(input())
for _ in range(qq):
	ans = True
	s = input()
	t = input()
	n = len(s)
	m = len(t)
	(p, q) = (0, 0)
	curp = s[0]
	curq = t[0]
	cntp = 0
	cntq = 0
	while p < n and q < m:
		curp = s[p]
		curq = t[q]
		cntp = cntq = 0
		if curp != curq:
			ans = False
			break
		while p < n:
			if s[p] == curp:
				cntp += 1
				p += 1
			else:
				break
		while q < m:
			if t[q] == curq:
				cntq += 1
				q += 1
			else:
				break
		if cntq >= cntp:
			continue
		else:
			ans = False
			break
	if ans and p == n and (q == m):
		print('YES')
	else:
		print('NO')


p = int(input())
while p:
	p = p - 1
	s = input()
	t = input()
	i = 0
	j = 0
	while j < len(t):
		if i < len(s) and s[i] == t[j]:
			i = i + 1
			j = j + 1
		elif j != 0 and t[j] == t[j - 1]:
			j = j + 1
		else:
			break
	if i == len(s) and j == len(t):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input() + '0'
	t = input()
	c = 0
	x = '*'
	for i in t:
		if i == s[c]:
			x = s[c]
			c += 1
		elif i != x:
			print('NO')
			break
	else:
		if c == len(s) - 1:
			print('YES')
		else:
			print('NO')


def letters(s):
	ans = []
	cur = s[0]
	ca = 0
	for c in s:
		if c != cur:
			ans.append((cur, ca))
			cur = c
			ca = 1
		else:
			ca += 1
	ans.append((cur, ca))
	return ans

def can(s, t):
	ls = letters(s)
	lt = letters(t)
	if len(ls) != len(lt):
		return False
	for (a, b) in zip(ls, lt):
		if a[0] != b[0]:
			return False
		if a[1] > b[1]:
			return False
	return True
n = int(input())
for i in range(n):
	s = input()
	t = input()
	if can(s, t):
		print('YES')
	else:
		print('NO')


import sys

def full_match(s, t):
	if len(s) > len(t):
		return False
	i = j = 0
	while j < len(t):
		if i < len(s) and j < len(t) and (s[i] == t[j]):
			i += 1
			j += 1
		elif j > 0 and t[j] == t[j - 1]:
			j += 1
		else:
			return False
	return i == len(s) and j == len(t)
ans = []
for _ in range(int(input())):
	(s, t) = (next(sys.stdin).strip() for _ in '**')
	ans.append(('NO', 'YES')[full_match(s, t)])
print('\n'.join(ans))


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	for _ in range(int(input())):
		s1 = input()
		s2 = input()
		l1 = [0]
		l2 = [0]
		flag = 1
		for i in range(len(s1)):
			if s1[i] != s1[l1[-1]]:
				l1.append(i)
		for i in range(len(s2)):
			if s2[i] != s2[l2[-1]]:
				l2.append(i)
		if len(l1) == len(l2):
			l1.append(len(s1))
			l2.append(len(s2))
			for i in range(1, len(l1)):
				if s1[l1[i - 1]] != s2[l2[i - 1]] or l1[i] - l1[i - 1] > l2[i] - l2[i - 1]:
					flag = 0
					break
		else:
			flag = 0
		if flag:
			print('YES')
		else:
			print('NO')
main()