Read problems statements in Mandarin Chinese and Russian as well. 

Chef wants to implement wildcard pattern matching supporting only the wildcard '?'. The wildcard character '?' can be substituted by any single lower case English letter for matching. He has two strings X and Y of equal length, made up of lower case letters and the character '?'. He wants to know whether the strings X and Y can be matched or not.

------ Input ------ 

The first line of input contain an integer T denoting the number of test cases. Each test case consists of two lines, the first line contains the string X and the second contains the string Y.

------ Output ------ 

For each test case, output a single line with the word Yes if the strings can be matched, otherwise output No.

------ Constraints ------ 

$1 ≤ T ≤ 50$
$Both X and Y have equal length and the length is between 1 and 10.$
$Both X and Y consist of lower case letters and the character '?'.$

----- Sample Input 1 ------ 
2

s?or?

sco??

stor?

sco??
----- Sample Output 1 ------ 
Yes

No
----- explanation 1 ------ 
Test case $1$: One of the possible ways to match both the strings is $\texttt{score}$. This can be done by:
- Replace $1^{st}$ and $2^{nd}$ $\texttt{?}$ of string $X$ by characters $\texttt{c}$ and $\texttt{e}$ respectively.
- Replace $1^{st}$ and $2^{nd}$ $\texttt{?}$ of string $Y$ by characters $\texttt{r}$ and $\texttt{e}$ respectively. 

Test case $2$: There exists no way to fill the $\texttt{?}$ such that the strings become equal. Thus, the answer is No.

Difficulty: EASY
Tags: Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
for _ in range(int(input())):
	x = input()
	y = input()
	flag = 1
	for i in range(len(x)):
		if x[i] != '?' and y[i] != '?':
			if x[i] != y[i]:
				flag = 0
				break
	if flag == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	x = input()
	y = input()
	for (chr_x, chr_y) in zip(x, y):
		if chr_x != chr_y and chr_x != '?' and (chr_y != '?'):
			print('No')
			break
	else:
		print('Yes')


t = int(input())
for i in range(1, t + 1):
	x = input()
	y = input()
	s = 0
	for j in range(0, len(x)):
		if x[j] == y[j] or x[j] == '?' or y[j] == '?':
			continue
		else:
			s += 1
	if s != 0:
		print('No')
	else:
		print('Yes')


n = int(input())
for i in range(n):
	x = input()
	y = input()
	s = 0
	for i in range(len(x)):
		if x[i] != '?' and y[i] != '?':
			if x[i] != y[i]:
				s += 1
				break
	if s == 1:
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	num = 0
	x = input()
	y = input()
	leng = len(x)
	for j in range(leng):
		if x[j] != '?' and y[j] != '?':
			if x[j] != y[j]:
				num += 1
	if num == 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	s = input()
	q = input()
	ans = 'Yes'
	for i in range(len(s)):
		if s[i] != q[i]:
			if s[i] == '?' or q[i] == '?':
				ans = 'Yes'
			else:
				ans = 'No'
				break
	print(ans)


t = int(input())
for i in range(t):
	x = input()
	y = input()
	flag = True
	for i in range(len(x)):
		if x[i] != y[i]:
			if x[i] != '?' and y[i] != '?':
				flag = False
				break
	if flag:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	x1 = input()
	x2 = input()
	for i in range(len(x1)):
		if x1[i] != x2[i] and x1[i] != '?' and (x2[i] != '?'):
			print('No')
			break
	else:
		print('Yes')


for _ in range(int(input())):
	str_x = input()
	str_y = input()
	for i in range(len(str_x)):
		if str_x[i] != str_y[i] and (str_y[i] == '?' or str_x[i] == '?'):
			continue
		elif str_x[i] == str_y[i]:
			continue
		else:
			print('No')
			break
	else:
		print('Yes')


for _ in range(int(input())):
	t = input()
	a = input()
	t = list(t)
	a = list(a)
	for i in range(len(t)):
		if t[i] != a[i]:
			if t[i] == '?':
				t[i] = a[i]
			if a[i] == '?':
				a[i] = t[i]
	print(('No', 'Yes')[t == a])


t = int(input())
for tc in range(t):
	x = input()
	y = input()
	c = 0
	for j in range(len(x)):
		if x[j] == y[j]:
			c += 1
		elif x[j] == '?' or y[j] == '?':
			c += 1
	if c == len(y):
		print('Yes')
	else:
		print('No')


t = int(input())
for ni in range(t):
	x = input()
	y = input()
	no = 0
	for i in range(len(x)):
		if x[i] == y[i] or (x[i] != y[i] and x[i] == '?' or y[i] == '?'):
			continue
		else:
			no = 1
			print('No')
			break
	if no == 0:
		print('Yes')


t = int(input())
for i in range(t):
	x = input()
	y = input()
	c = 0
	for j in range(len(x)):
		if x[j] == y[j]:
			c += 1
		elif x[j] == '?' or y[j] == '?':
			c += 1
		elif x[j] == '?' and y[j] == '?':
			c += 1
		else:
			pass
	if c == len(x):
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	a = input()
	b = input()
	c = 'Yes'
	for i in range(len(a)):
		if a[i] != b[i] and a[i] != '?' and (b[i] != '?'):
			c = 'No'
			break
		else:
			c = 'Yes'
	print(c)
	t -= 1


t = int(input())
for i in range(t):
	x = input()
	y = input()
	count = 0
	a = len(x)
	b = len(y)
	j = 0
	k = 0
	while j != a and k != b:
		if x[j] == y[k] or x[j] == '?' or y[k] == '?':
			count += 1
			j += 1
			k += 1
		else:
			j += 1
			k += 1
	if count == a:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	a = str(input())
	t = str(input())
	ans = 'Yes'
	for i in range(len(a)):
		if a[i] != t[i] and a[i] != '?' and (t[i] != '?'):
			ans = 'No'
			break
	print(ans)


t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	flag = 0
	for i in range(len(s1)):
		if not (s1[i] == s2[i] or s1[i] == '?' or s2[i] == '?'):
			flag += 1
	if flag > 0:
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	first = input()
	second = input()
	l = len(first)
	ex = 0
	for i in range(l):
		if first[i] == '?' or second[i] == '?':
			continue
		if first[i] == second[i]:
			continue
		ex = 1
		break
	if ex == 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	x = str(input())
	y = str(input())
	for i in range(len(x)):
		if x[i] != y[i] and x[i] != '?' and (y[i] != '?'):
			print('No')
			break
	else:
		print('Yes')


for _ in range(int(input())):
	s = input()
	s1 = input()
	for i in range(len(s)):
		if s[i] != s1[i] and s[i] != '?' and (s1[i] != '?'):
			print('No')
			break
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	x = input()
	y = input()
	b = True
	for i in range(len(x)):
		if x[i] == '?' or y[i] == '?':
			pass
		elif x[i] != y[i]:
			b = False
	if b:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	a = input()
	b = input()
	f = True
	for i in range(len(a)):
		if a[i] != '?' and b[i] != '?':
			if a[i] != b[i]:
				f = False
				break
	print('Yes' if f else 'No')


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	flag = 0
	for i in range(len(s1)):
		if s1[i] == s2[i] or (s1[i] == '?' and s2[i].isalpha()) or (s1[i].isalpha() and s2[i] == '?'):
			flag = 1
		else:
			flag = 0
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	x = input()
	y = input()
	for i in range(len(x)):
		if x[i] == '?' or y[i] == '?':
			continue
		elif x[i] != y[i]:
			print('No')
			break
	else:
		print('Yes')


for _ in range(int(input())):
	x = input()
	y = input()
	for (i, j) in zip(x, y):
		if i == '?' or j == '?':
			continue
		elif i == j:
			continue
		else:
			print('No')
			break
	else:
		print('Yes')


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	for i in range(len(s1)):
		if s1[i] == '?' or s2[i] == '?':
			continue
		elif s1[i] != s2[i]:
			print('No')
			break
	else:
		print('Yes')


for _ in range(int(input())):
	a = input()
	b = input()
	l = []
	for i in range(len(a)):
		if a[i] != b[i]:
			l.extend([a[i], b[i]])
			if '?' not in l:
				print('No')
				break
			else:
				l.clear()
	if not l:
		print('Yes')


for _ in range(int(input())):
	i = input()
	j = input()
	ans = 'Yes'
	for val in range(len(i)):
		if i[val] != j[val] and i[val] != '?' and (j[val] != '?'):
			ans = 'No'
			break
	print(ans)


for i in range(int(input())):
	s = input()
	c = input()
	count = 0
	a = 0
	for j in range(len(s)):
		if s[j] == c[j] and s[j] != '?' and (c[j] != '?'):
			count = count + 1
		elif s[j] == '?' and c[j] == '?':
			count = count + 1
		elif s[j] == '?' and c[j] != '?':
			count = count + 1
		elif s[j] != '?' and c[j] == '?':
			count = count + 1
	if count == len(s):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	x = input()
	y = input()
	ans = 'Yes'
	for i in range(len(x)):
		if x[i] != y[i] and x[i] != '?' and (y[i] != '?'):
			ans = 'No'
			break
	print(ans)


for _ in range(int(input())):
	X = input()
	Y = input()
	if len(X) != len(Y) or len(X) < 1 or len(X) > 10:
		print('No')
	else:
		c = 0
		for i in range(0, len(X)):
			if X[i].isalpha() and Y[i].isalpha() and (X[i] != Y[i]):
				print('No')
				break
			else:
				c = c + 1
				continue
		if c == len(X):
			print('Yes')


T = int(input())
for _ in range(T):
	x = input()
	y = input()
	f = 0
	for i in range(len(x)):
		if x[i] == '?' or y[i] == '?':
			f = 1
		elif x[i] == y[i]:
			f = 1
		else:
			f = 0
			break
	if f == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	x = input()
	y = input()
	l1 = list(x)
	l2 = list(y)
	c = 0
	d = 0
	for i in range(len(x)):
		if x[i].isalpha() and y[i].isalpha():
			c += 1
			if x[i] == y[i]:
				d += 1
	if c == d:
		print('Yes')
	else:
		print('No')


T = int(input())
for i in range(T):
	x = input()
	y = input()
	count = 0
	for i in range(len(x)):
		if x[i] != y[i]:
			if x[i] != '?' and y[i] != '?':
				count += 1
	if count == 0:
		print('Yes')
	else:
		print('No')


T = int(input())
for _ in range(T):
	X = input()
	Y = input()
	res = 'Yes'
	for i in range(len(X)):
		if X[i] == Y[i]:
			continue
		elif X[i] == '?' or Y[i] == '?':
			continue
		else:
			res = 'No'
			break
	print(res)


T = int(input())
x = range(T)
for i in x:
	a = input()
	b = input()
	if len(a) != len(b):
		print('No')
	else:
		c = list(a)
		d = list(b)
		e = 0
		f = 0
		for j in range(len(a)):
			if a[j].isalpha() and b[j].isalpha():
				e += 1
				if a[j] == b[j]:
					f += 1
		if e == f:
			print('Yes')
		else:
			print('No')


for i in range(int(input())):
	s1 = str(input())
	s2 = str(input())
	a = 1
	for i in range(len(s1)):
		if s1[i] == s2[i] or s1[i] == '?' or s2[i] == '?':
			continue
		else:
			print('No')
			a = 0
			break
	if a:
		print('Yes')


def check(a, b):
	count = 0
	if len(a) == len(b):
		for i in range(len(a)):
			if a[i] != b[i] and a[i] != '?' and (b[i] != '?'):
				print('No')
				break
			else:
				count += 1
		if count == len(a):
			print('Yes')
	else:
		print('No')
t = int(input())
while t > 0:
	x = input()
	y = input()
	check(x, y)
	t = t - 1


testCases = int(input())
for tc in range(testCases):
	s1 = str(input())
	s2 = str(input())
	flag = 1
	for (i, j) in zip(s1, s2):
		if i != j:
			if i != '?' and j != '?':
				flag = 0
				break
	if flag == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for ii in range(t):
	s1 = input()
	s2 = input()
	l1 = len(s1)
	l2 = len(s2)
	flag = 0
	if l1 == l2:
		for i in range(l1):
			if s1[i] == s2[i] or s1[i] == '?' or s2[i] == '?':
				continue
			else:
				flag = -3
				break
		if flag == 0:
			print('Yes')
		else:
			print('No')
	else:
		print('No')


for _ in range(int(input())):
	a = input()
	b = input()
	flag = 1
	for i in range(len(a)):
		if a[i] != b[i] and a[i] != '?' and (b[i] != '?'):
			flag = 0
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')


def matchStr(X, Y):
	N = len(X)
	questionMark = []
	for i in range(N):
		if X[i] == '?':
			questionMark.append(i)
	for j in range(N):
		if Y[j] == '?' and j not in questionMark:
			questionMark.append(j)
	for k in range(N):
		if k not in questionMark and X[k] != Y[k]:
			return 'No'
	return 'Yes'
for _ in range(int(input())):
	X = input()
	Y = input()
	print(matchStr(X, Y))


for _ in range(int(input())):
	a = input()
	b = input()
	i = 0
	for x in range(len(a)):
		if a[x] == '?' or b[x] == '?':
			pass
		elif a[x] != b[x]:
			print('No')
			i = 1
			break
	if i == 0:
		print('Yes')


for cases in range(int(input())):
	string1 = input()
	string2 = input()
	for i in range(len(string1)):
		if string1[i] != '?' and string2[i] != '?':
			if string1[i] == string2[i]:
				continue
			else:
				print('No')
				break
	else:
		print('Yes')


for i in range(int(input())):
	x = input()
	y = input()
	c = 0
	for i in range(len(x)):
		if x[i] == '?' or y[i] == '?':
			c += 1
		elif x[i] == y[i]:
			c += 1
	if c == len(x):
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	a = input()
	b = input()
	if len(a) == len(b) and len(a) >= 1 and (len(a) <= 10):
		for i in range(len(a)):
			if (a[i] != '?' and b[i] != '?') and a[i] != b[i]:
				print('No')
				break
		else:
			print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	a = list(input())
	b = list(input())
	count = 0
	for i in range(len(a)):
		if (a[i] == '?' or b[i] == '?') or a[i] == b[i]:
			count += 1
	if count == len(a):
		print('Yes')
	else:
		print('No')


for tc in range(int(input())):
	st1 = input()
	st2 = input()
	poss = True
	n1 = len(st1)
	for i in range(n1):
		if st1[i] == '?' or st2[i] == '?':
			continue
		elif st1[i] != st2[i]:
			poss = False
	print('Yes' if poss else 'No')


for _ in range(int(input())):
	x = input()
	y = input()
	flag = True
	for i in range(len(x)):
		if x[i] != y[i]:
			if x[i] == '?' or y[i] == '?':
				continue
			else:
				flag = False
				print('No')
				break
	if flag:
		print('Yes')


t = int(input())
res = []
for i in range(t):
	lix = list(input())
	liy = list(input())
	ans = True
	for k in range(len(lix)):
		if lix[k] != liy[k]:
			if lix[k] == '?' or liy[k] == '?':
				ans = True
			else:
				ans = False
				break
	if ans:
		res.append('Yes')
	else:
		res.append('No')
print('\n'.join(res))


q = int(input())
while q > 0:
	a = list(input())
	b = list(input())
	l = len(a)
	flag = 1
	for i in range(l):
		if a[i] == b[i] or a[i] == '?' or b[i] == '?':
			continue
		else:
			flag = 0
			break
	if flag == 0:
		print('No')
	else:
		print('Yes')
	q = q - 1


def check(str, str1):
	for i in range(len(str)):
		if str[i] == str1[i] or str[i] == '?' or str1[i] == '?':
			continue
		else:
			return 'No'
	return 'Yes'
t = int(input())
for i in range(t):
	str = input()
	str1 = input()
	print(check(str, str1))


t = int(input())

def ans():
	ans = 'Yes'
	x = input()
	y = input()
	for i in range(len(x)):
		if x[i] != y[i] and x[i] != '?' and (y[i] != '?'):
			ans = 'No'
			break
	print(ans)
for i in range(t):
	ans()


for _ in range(int(input())):
	a = input()
	b = input()
	n = len(a)
	for i in range(n):
		if a[i].isalpha() and b[i].isalpha():
			if a[i] != b[i]:
				print('No')
				break
	else:
		print('Yes')