Chef likes strings a lot but he likes palindromic strings more. Today, Chef has two strings A and B, each consisting of lower case alphabets.

Chef is eager to know whether it is possible to choose some non empty strings s1 and s2 where s1 is a substring of A, s2 is a substring of B such that s1 + s2 is a palindromic string. Here '+' denotes the concatenation between the strings.
Note:
A string is a palindromic string if it can be read same both forward as well as backward. To know more about palindromes click here.

-----Input-----
- First line of input contains a single integer T denoting the number of test cases.
- For each test case:
	
- First line contains the string A
- Second line contains the string B.

-----Output-----
For each test case, Print "Yes" (without quotes) if it possible to choose such strings s1 & s2. Print "No" (without quotes) otherwise.


-----Constraints-----
- 1 ≤ T ≤ 10 
- 1 ≤ |A|, |B| ≤ 1000 

-----Subtasks-----
-  Subtask 1: 1 ≤ |A|, |B| ≤ 10 : ( 40 pts )
-  Subtask 2: 1 ≤ |A|, |B| ≤ 1000 : ( 60 pts )

-----Example-----Input
3
abc
abc
a
b
abba
baab

Output
Yes
No
Yes

-----Explanation-----
- Test 1: One possible way of choosing s1 & s2 is s1 = "ab", s2 = "a" such that s1 + s2 i.e "aba" is a palindrome.
- Test 2: There is no possible way to choose s1 & s2 such that s1 + s2 is a palindrome.
- Test 3: You can figure it out yourself.

Source: codechef | Difficulty: EASY
Tags: String algorithms

Constructive algorithms

Data structures

Ad-hoc


Solutions:
for _ in range(int(input())):
	a = input()
	b = input()
	f = 0
	for i in a:
		for j in b:
			if i == j:
				print('Yes')
				f = 1
				break
		if f == 1:
			break
	if f == 0:
		print('No')


for k in range(int(input())):
	a = input()
	b = input()
	flag = 0
	for i in a:
		for j in b:
			if i == j:
				print('Yes')
				flag = 1
				break
			if flag == 1:
				break
		if flag == 1:
			break
	if flag == 0:
		print('No')


for _ in range(int(input())):
	a = input()
	b = input()
	ans = 'No'
	for i in range(len(a)):
		if a[i] in b:
			ans = 'Yes'
			break
	print(ans)


n = int(input())
for i in range(n):
	a = input()
	b = input()
	c = 0
	for i in a:
		if i in b:
			c = 1
			print('Yes')
			break
	if c == 0:
		print('No')


def main():
	T = int(input())
	for _ in range(T):
		A = input()
		B = input()
		flag = False
		for i in range(len(A)):
			for j in range(len(B)):
				if A[i] == B[j]:
					flag = True
					break
			if flag:
				break
		print('Yes' if flag else 'No')
main()


T = int(input())
for i in range(T):
	A = input()
	B = input()
	flag = 0
	for i in A:
		if i in B:
			flag = 1
			break
	if flag == 0:
		print('No')
	else:
		print('Yes')


t = int(input())
for tc in range(t):
	n = input()
	s = input()
	a = set(n)
	b = set(s)
	c = 0
	for j in a:
		if j in b:
			c += 1
	if c >= 1:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	s1 = input()
	s2 = input()
	c = 0
	for i in s1:
		for j in s2:
			if i == j:
				c += 1
	if c > 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for n in range(t):
	a = str(input())
	b = str(input())
	count = 0
	for i in a:
		for j in b:
			if i == j:
				count += 1
	if count > 0:
		print('Yes')
	else:
		print('No')


a = int(input())
while a:
	a = a - 1
	b = input()
	c = input()
	p = []
	for i in c:
		if i not in p:
			p.append(i)
	f = 0
	for i in b:
		if i not in p:
			continue
		else:
			f = 1
			break
	if f == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	(s1, s2) = (input(), input())
	for i in s1:
		if i in s2:
			print('Yes')
			break
	else:
		print('No')


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	a1 = set(a)
	b1 = set(b)
	if a1.intersection(b1):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	b = input()
	for x in input():
		if x in b:
			print('Yes')
			break
	else:
		print('No')


for _ in range(int(input())):
	A = list(input())
	B = list(input())
	AS = set(A)
	BS = set(B)
	if len(AS) > 1 or len(BS) > 1:
		flag = False
		for ele in AS:
			for ele1 in BS:
				if ele == ele1:
					flag = True
		if flag:
			print('Yes')
		else:
			print('No')
	else:
		print('No')


n = int(input(' '))
maxcount = 0
while n >= 1:
	a = input()
	b = input()
	flag = 0
	for i in a:
		if i in b:
			print('Yes')
			flag = 1
			break
	if flag == 0:
		print('No')
	n -= 1


for i in range(int(input())):
	a = input()
	b = input()
	(x, y) = (set(a), set(b))
	c = 0
	for i in x:
		if i in y:
			c += 1
	print('Yes' if c >= 1 else 'No')


n = int(input())
for i in range(n):
	a = input()
	b = input()
	s = a + b
	o = 0
	fc = [0] * 26
	r = 0
	for i in a:
		l = a.count(i)
		m = b.count(i)
		if l >= 1 and m >= 1:
			print('Yes')
			r = 1
			break
	if r == 0:
		print('No')


for tc in range(int(input())):
	s1 = set(input())
	s2 = input()
	poss = False
	for ele in s2:
		if ele in s1:
			poss = True
			break
	if poss:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	s1 = set(input())
	s2 = set(input())
	if len(s1 & s2):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	f = 0
	for i in s2:
		if i in s1:
			f = 1
			break
	if f == 1:
		print('Yes')
	else:
		print('No')


tc = int(input())
for _ in range(tc):
	a = input()
	b = input()
	n1 = len(a)
	n2 = len(b)
	gorb = False
	if n1 <= n2:
		for i in a:
			if i in b:
				gorb = True
				break
	else:
		for i in b:
			if i in a:
				gorb = True
				break
	print('Yes' if gorb else 'No')


t = int(input())
for i in range(t):
	s1 = input()
	s2 = input()
	(x, y) = (set(s1), set(s2))
	c = 0
	for i in x:
		if i in y:
			c += 1
	if c >= 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	x = set(input())
	y = set(input())
	if len(x & y):
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	s1 = input()
	s2 = input()
	check = False
	for i in s1:
		if s2.count(i) >= 1:
			print('Yes')
			check = True
			break
	if check != True:
		print('No')


for _ in range(int(input())):
	a = input()
	b = input()
	f = 0
	for x in a:
		if x in b:
			f = 1
			break
	if f:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	a = input()
	b = input()
	flag = False
	for item in a:
		if item in b:
			flag = True
	if flag == True:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	s = sorted(input())
	s1 = sorted(input())
	count = 0
	for i in s:
		if i in s1:
			count += 1
	if count > 0:
		print('Yes')
	else:
		print('No')


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


for _ in range(int(input())):
	a = input()
	b = input()
	pal = False
	for i in a:
		if i in b:
			print('Yes')
			pal = True
			break
	if not pal:
		print('No')


def solve(s1, s2):
	for i in s2:
		if i in s1:
			return 'Yes'
	return 'No'
for _ in range(int(input())):
	s1 = set(input())
	s2 = set(input())
	print(solve(s1, s2))


T = int(input())
for i in range(T):
	A = input().lower()
	B = input().lower()
	P1 = set(A)
	P2 = set(B)
	c = 0
	for j in P1:
		if j in P2:
			c += 1
	if c >= 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	d = input()
	e = input()
	f = 0
	for k in d:
		for l in e:
			if k == l:
				f = 1
				break
	if f == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	a = input()
	b = input()
	c = 0
	for i in a:
		if i in b:
			c = 1
			break
		else:
			continue
	if c == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for x in range(t):
	a = input()
	b = input()
	flag = False
	for i in a:
		if i in b:
			flag = True
			break
	if flag:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	s1 = input()
	s2 = input()
	flag = 0
	for i in range(len(s1)):
		for j in range(len(s2)):
			if s1[i] == s2[j]:
				flag = 1
				break
		if flag == 1:
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	a = input()
	b = input()
	s1 = set(a)
	s2 = set(b)
	f = 0
	for i in s1:
		if i in s2:
			print('Yes')
			f = 1
			break
	if f == 0:
		print('No')


t = int(input())
for i in range(t):
	s1 = set(input())
	s2 = set(input())
	count = 0
	for ele in s1:
		if ele in s2:
			count += 1
	if count > 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	str1 = input()
	str2 = input()
	res = 'No'
	for i in str1:
		if i in str2:
			res = 'Yes'
			break
	print(res)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	c = False
	for j in a:
		if j in b:
			c = True
			break
	if c:
		print('Yes')
	else:
		print('No')


t = int(input())
for z in range(t):
	a = input()
	b = input()
	s1 = set(a)
	s2 = set(b)
	if s1 & s2:
		print('Yes')
	else:
		print('No')


import sys

def iinput():
	return int(input())
for _ in range(iinput()):
	s1 = set(input())
	s2 = set(input())
	if len(s1 & s2):
		print('Yes')
	else:
		print('No')


T = int(input())
for i in range(T):
	A = input()
	B = input()
	count = 0
	for j in A:
		if j in B:
			count += 1
	if count > 0:
		print('Yes')
	else:
		print('No')


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


t = int(input())
while t:
	A = input()
	B = input()
	f = False
	for i in A:
		if i in B:
			f = True
			break
	if f == True:
		print('Yes')
	else:
		print('No')
	t = t - 1


for i in range(int(input())):
	a = input()
	b = input()
	for i in a:
		if i in b:
			print('Yes')
			break
	else:
		print('No')


def solve(A, B):
	flag = False
	for i in range(len(A)):
		if A[i] in B:
			flag = True
			print('Yes')
			break
	if flag == False:
		print('No')
for _ in range(int(input())):
	a = input()
	b = input()
	solve(a, b)


for _ in range(int(input())):
	a = set(input())
	b = set(input())
	print('Yes' if len(a & b) > 0 else 'No')


T = int(input())
for cases in range(T):
	A = input()
	B = input()
	duplicate_Strings = [s for s in A if s in B]
	if len(duplicate_Strings) > 0:
		print('Yes')
	else:
		print('No')


def solve(a, b):
	for i in a:
		for j in b:
			if i == j:
				return 1
	return 0
t = int(input())
for _ in range(0, t):
	a = input()
	b = input()
	if solve(a, b):
		print('Yes')
	else:
		print('No')


x = int(input())
i = []
for mk in range(0, x):
	ik = str(input())
	ire = str(input())
	ytr = [ik, ire]
	i.append(ytr)
for jk in i:
	up = jk[0]
	idx = jk[1]
	loft = 0
	for ip in up:
		if ip in idx:
			print('Yes')
			loft = 1
			break
	if loft != 1:
		print('No')


for t in range(int(input())):
	s1 = set(input())
	s2 = set(input())
	flag = False
	for key in s1:
		if key in s2:
			flag = True
			break
	if flag:
		print('Yes')
	else:
		print('No')


from collections import Counter
t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	j = 1
	f = 0
	for i in range(len(s1)):
		subs = s1[i:j]
		j += 1
		if subs in s2:
			print('Yes')
			f = 1
			break
	if f == 0:
		print('No')


for i in range(int(input())):
	a = input()
	b = input()
	t = False
	for i in a:
		if i in b:
			t = True
	if t:
		print('Yes')
	else:
		print('No')


a = int(input())
for i in range(1, a + 1):
	m = input()
	n = input()
	is_true = False
	for j in m:
		if j in n:
			is_true = True
			break
	if is_true:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	A = input()
	B = input()
	for i in A:
		if i in B:
			print('Yes')
			break
		else:
			continue
	else:
		print('No')


t = int(input())
for i in range(t):
	a = input()
	b = input()
	a = set(a)
	b = set(b)
	c = 0
	for j in a:
		if j in b:
			c += 1
	if c > 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	s1 = sorted(input())
	s2 = sorted(input())
	cnt = 0
	for i in s1:
		if i in s2:
			cnt = 1
	print(['Yes', 'No'][cnt == 0])


def if_pal_sub(A, B):
	if set(A) & set(B):
		return 'Yes'
	else:
		return 'No'
for _ in range(int(input())):
	A = input()
	B = input()
	print(if_pal_sub(A, B))


t = int(input())
for i in range(t):
	flag = 0
	a = input()
	b = input()
	a1 = [0] * 26
	b1 = [0] * 26
	for i in a:
		ind = ord(i) - 97
		a1[ind] += 1
	for i in b:
		ind = ord(i) - 97
		b1[ind] += 1
	for i in range(26):
		if a1[i] > 0 and b1[i] > 0:
			flag = 1
			break
	if flag == 0:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	a = str(input())
	b = str(input())
	k = 0
	for i in a:
		for j in b:
			if i == j:
				k += 1
	if k > 0:
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0:
	a = input()
	b = input()
	flag = False
	for i in a:
		for j in b:
			if i == j:
				print('Yes')
				flag = True
				break
		if flag:
			break
	else:
		print('No')
	t -= 1


n = int(input())
for i in range(n):
	s1 = input()
	s2 = input()
	for j in s1:
		if j in s2:
			print('Yes')
			break
	else:
		print('No')


def palinSubStr(A, B):
	for i in range(len(A)):
		if A[i] in B:
			return 'Yes'
	return 'No'
for _ in range(int(input())):
	A = input()
	B = input()
	print(palinSubStr(A, B))


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	v = 0
	for i in s1:
		if i in s2:
			v += 1
	if v != 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	A = input()
	B = input()
	for e in list(A):
		if e in B:
			print('Yes')
			break
	else:
		print('No')


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	flag = 0
	for k in range(len(s1)):
		if s1[k] in s2:
			flag = 1
			break
	if flag == 0:
		print('No')
	else:
		print('Yes')


t = int(input())
while t > 0:
	a = input()
	b = input()
	is_boolean = False
	for i in range(len(a)):
		if a[i] in b:
			is_boolean = True
			break
	if is_boolean:
		print('Yes')
	else:
		print('No')
	t -= 1


def solve(s1, s2):
	for i in s1:
		for j in s2:
			if i == j:
				return 'Yes'
	return 'No'
t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	print(solve(s1, s2))


t = int(input())
while t:
	t = t - 1
	a = input()
	b = input()
	f = 0
	for i in a:
		if i in b:
			f = 1
			break
	if f == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	ct = 0
	for i in a:
		if i in b:
			ct = 1
			break
	if ct == 0:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	A = input()
	B = set(input())
	flag = 0
	for i in range(len(A)):
		if A[i] in B:
			flag = 1
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	a = input()
	b = input()
	flag = True
	for i in a:
		if i in b:
			print('Yes')
			flag = False
			break
	if flag:
		print('No')


for t in range(int(input())):
	a = str(input())
	b = str(input())
	for i in range(len(a)):
		if a[i] in b:
			print('Yes')
			break
	else:
		print('No')


for _ in range(int(input())):
	a = input()
	b = input()
	i = 0
	for x in a:
		if x in b:
			print('Yes')
			i = 1
			break
	if i == 0:
		print('No')