Given two strings, determine if they share a common substring.  A substring may be as small as one character.  

Example 

$s1=\text{'and'}$ 

$s2=\text{'art'}$  

These share the common substring $\class{ML__boldsymbol}{\boldsymbol{a}}$.  

$\textbf{s1}=\textbf{'be'}$ 

$s2=\text{'cat'}$  

These do not share a substring.  

Function Description

Complete the function twoStrings in the editor below.    

twoStrings has the following parameter(s):  

string s1:  a string
string s2:  another string    

Returns  

string: either YES or NO

Input Format

The first line contains a single integer $\boldsymbol{p}$, the number of test cases.     

The following $\boldsymbol{p}$ pairs of lines are as follows:

The first line contains string $\mbox{s1}$.
The second line contains string $\mbox{s2}$.

Constraints

$\mbox{s1}$ and $\mbox{s2}$ consist of characters in the range ascii[a-z].
$1\leq p\leq10$
$1\leq|s1|,|s2|\leq10^5$

Output Format

For each pair of strings, return YES or NO.

Sample Input
2
hello
world
hi
world

Sample Output
YES
NO

Explanation

We have $p=2$ pairs to check:

$s1=\text{"hello"}$, $s2=\text{"world"}$. The substrings $\text{"o"}$ and $\text{"l"}$  are common to both strings.  
$a=\textsf{hi}$, $b=\text{"world"}$. $\mbox{s1}$ and $\mbox{s2}$ share no common substrings.

Difficulty: EASY
Tags: String algorithms

Starter code:

Solutions:
a = int(input())
for i in range(a):
	i = input()
	j = input()
	setx = set([a for a in i])
	sety = set([y for y in j])
	if setx.intersection(sety) == set():
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s1 = set(input())
	s2 = set(input())
	if s1.intersection(s2):
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	(A, B) = (input(), input())
	(A, B) = (min(A, B), max(A, B))
	found = False
	for ch in A:
		if ch in B:
			found = True
			break
	print('YES' if found else 'NO')


n = int(input().strip())
for x in range(0, n):
	word1 = input().strip()
	word2 = input().strip()
	word1Set = set(word1)
	word2Set = set(word2)
	if word1Set.intersection(word2Set):
		print('YES')
	else:
		print('NO')


iteration = int(input())
for i in range(iteration):
	boolean = False
	str1 = input()
	str2 = input()
	for j in str1:
		if j in str2:
			print('YES')
			boolean = True
			break
	if boolean == False:
		print('NO')


t = int(input())
for i in range(0, t):
	a = list(input())
	b = list(input())
	if bool(set(a) & set(b)):
		print('YES')
	else:
		print('NO')


def wordsearch(wordlist):
	for l in set(wordlist[0]):
		if l in wordlist[1]:
			return 'YES'
	return 'NO'
cases = input()
for i in range(int(cases)):
	wordlist = []
	wordlist.append(set(input()))
	wordlist.append(set(input()))
	out = wordsearch(wordlist)
	print(out)


import re
t = int(input())
strings = []
for i in range(t * 2):
	strings.append(input())
i = 0
while i < len(strings):
	a = strings[i]
	b = strings[i + 1]
	a = '[' + a + ']'
	b = '[' + b + ']'
	if len(a) <= len(b):
		if re.search(a, b):
			print('YES')
		else:
			print('NO')
	elif re.search(b, a):
		print('YES')
	else:
		print('NO')
	i = i + 2


t = int(input())
k = 0
while t:
	k = 0
	s = input()
	p = input()
	for i in s:
		if i in p:
			k = 1
			break
		if k == 1:
			break
	if k == 1:
		print('YES')
	else:
		print('NO')
	t = t - 1


(T, final) = (int(input('')), [])
for i in range(T):
	temp = []
	(a, b) = (input(''), input(''))
	for let in a:
		if let in b:
			temp.append('YES')
		else:
			temp.append('NO')
	if 'YES' in temp:
		final.append('YES')
	else:
		final.append('NO')
for i in final:
	print(i)


n = int(input())
for i in range(n):
	find = False
	m1 = input()
	m2 = input()
	for j in range(len(m1)):
		if m1[j] in m2:
			find = True
			break
	if find:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	t -= 1
	s1 = input()
	s2 = input()
	for i in range(1, len(s1), 1):
		if s1[i] in s2:
			print('YES')
			break
		if i == len(s1) - 1:
			print('NO')
			break


def check(A, B):
	dict = {}
	for l in A:
		dict[l] = 1
	for l in B:
		if dict.get(l, 0) == 1:
			return 'YES'
	return 'NO'
for i in range(int(input())):
	(A, B) = (input(), input())
	print(check(A, B))


n = int(input())
for i in range(n):
	str1 = input()
	str2 = input()
	if set(str1).intersection(set(str2)):
		print('YES')
	else:
		print('NO')


def compare(str1, str2):
	str1 = set(str1)
	str2 = set(str2)
	res = str1 & str2
	return len(res) > 0 and 'YES' or 'NO'
t = int(input())
for i in range(t):
	s1 = input()
	s2 = input()
	print(compare(s1, s2))


def isSubStr(a, b):
	for x in a:
		if x in b:
			return 'YES'
	return 'NO'
anz = int(input())
for i in range(anz):
	a = input()
	b = input()
	print(isSubStr(a, b))


def have_common_substr(a, b):
	counta = [0 for _ in range(26)]
	countb = [0 for _ in range(26)]
	for (s1, s2) in zip(a, b):
		(i, j) = (97 - ord(s1), 97 - ord(s2))
		counta[i] += 1
		countb[j] += 1
		if counta[i] != 0 and countb[i] != 0 or (counta[j] != 0 and countb[j] != 0):
			return True
	return False
t = int(input())
for _ in range(t):
	a = input()
	b = input()
	print('YES' if have_common_substr(a, b) else 'NO')


t = int(input())
for _ in range(t):
	(a, b) = (input(), set(input()))
	if any([i for i in a if i in b]):
		print('YES')
	else:
		print('NO')


def check_common(a, b):
	f1 = [0] * 150
	f2 = [0] * 150
	for i in range(0, len(a)):
		f1[ord(a[i])] += 1
	for j in range(0, len(b)):
		f2[ord(b[j])] += 1
	for k in range(97, 122):
		if f1[k] > 0 and f2[k] > 0:
			return 'YES'
	return 'NO'
t = int(input())
while t > 0:
	a = input()
	b = input()
	print(check_common(a, b))
	t -= 1


T = int(input())
for _ in range(T):
	string1_set = set(input())
	string2_set = set(input())
	exists = False
	for char in string1_set:
		if char in string2_set:
			exists = True
			break
	if exists:
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	a = input()
	b = input()
	counter = 0
	for d in a:
		if d in b:
			counter += 1
	if counter:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	list3 = list()
	str1 = input()
	str2 = input()
	list1 = set(str1)
	list2 = set(str2)
	ln1 = len(list1)
	ln2 = len(list2)
	for item in list1:
		list3.append(item)
	for item in list2:
		list3.append(item)
	list4 = set(list3)
	ln3 = len(list4)
	if ln1 + ln2 == ln3:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	result = False
	A = set(list(input()))
	B = set(list(input()))
	if len(A & B) > 0:
		print('YES')
	else:
		print('NO')


numTests = int(input())
for test in range(numTests):
	A = input()
	B = input()
	if 0 == len(set(A).intersection(set(B))):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	s1 = input()
	s2 = input()
	freq1 = [0 for j in range(26)]
	freq2 = [0 for j in range(26)]
	for j in range(len(s1)):
		freq1[ord(s1[j]) - 97] += 1
	for j in range(len(s2)):
		freq2[ord(s2[j]) - 97] += 1
	flag = 0
	for j in range(26):
		if freq1[j] * freq2[j] != 0:
			flag = 1
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


T = int(input())
for i in range(T):
	s1 = input()
	s2 = input()
	if len(s2) < len(s1):
		temp = s2
		s2 = s1
		s1 = temp
	answer = 'NO'
	for ch in s1:
		if s2.find(ch) != -1:
			answer = 'YES'
			break
	print(answer)


T = int(input())
for _ in range(T):
	a = set(input())
	b = set(input())
	c = a & b
	if len(c):
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(T):
	a = input()
	b = input()
	if len(a) > len(b):
		(a, b) = (b, a)
	dict = {}
	for c in a:
		g = dict.get(c, False)
		if not g:
			dict[c] = True
	found = False
	for c in b:
		found = dict.get(c, False)
		if found:
			break
	if found:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = set(input())
	b = set(input())
	print({False: 'NO', True: 'YES'}[len(a.intersection(b)) > 0])


import sys
cases = int(sys.stdin.readline().strip())
for case in range(0, cases):
	a = set(sys.stdin.readline().strip())
	b = set(sys.stdin.readline().strip())
	exists = False
	for i in a:
		for j in b:
			if i == j:
				exists = True
				break
	if exists:
		print('YES')
	else:
		print('NO')


tests = int(input())
for _ in range(tests):
	word_a = input()
	word_b = input()
	a = set(word_a)
	b = set(word_b)
	if len(a & b) > 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	ans = 'NO'
	a = input()
	b = input()
	for c in a:
		if c in b:
			ans = 'YES'
			break
	print(ans)


def has_common(a, b):
	return len(set(a) & set(b)) > 0
t = int(input())
for _ in range(t):
	(a, b) = (input() for _ in range(2))
	print('YES' if has_common(a, b) else 'NO')


testcases = int(input())
for test in range(testcases):
	word1 = input()
	word2 = input()
	no = True
	for letter in word1:
		if letter in word2:
			print('YES')
			no = False
			break
	if no:
		print('NO')


ncase = int(input())

def r():
	iscommonsubstr = False
	str1 = input()
	str2 = input()
	for c in str1:
		if c in str2:
			iscommonsubstr = True
			break
	if iscommonsubstr:
		print('YES')
	else:
		print('NO')
for i in range(ncase):
	r()


tCases = int(input(''))
for i in range(tCases):
	a = input('')
	b = input('')
	works = False
	for letter in a:
		if letter in b:
			works = True
	if works:
		print('YES')
	else:
		print('NO')


def common(a, b):
	L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	for c in L:
		if c in a and c in b:
			return 'YES'
	return 'NO'
t = int(input())
for t in range(t):
	a = input()
	b = input()
	print(common(a, b))


__author__ = 'leo'
tests = int(input())
for i in range(tests):
	s1 = input()
	s2 = input()
	for i in s1:
		if i in s2:
			print('YES')
			break
	else:
		print('NO')


def twostrings(x, y):
	for i in x:
		if i in y:
			return 'YES'
	return 'NO'
a = int(input())
for i in range(a):
	b = str(input())
	c = str(input())
	print(twostrings(b, c))


T = int(input())
for _ in range(T):
	w1 = set(input())
	w2 = set(input())
	if len(w1.intersection(w2)) > 0:
		print('YES')
	else:
		print('NO')


def commonSubstring(first, second):
	firstLetters = {}
	for aLetter in first:
		firstLetters[aLetter] = True
	for aLetter in second:
		if aLetter in firstLetters:
			return 'YES'
	return 'NO'
inputlength = int(input().strip())
for i in range(0, inputlength):
	first = input()
	second = input()
	print(commonSubstring(first, second))


__author__ = 'nolanemirot'

def findTwoStrings(s1, s2):
	dic = []
	for n in s1:
		if n not in dic:
			dic.append(n)
	for s in s2:
		if s in dic:
			return 'YES'
	return 'NO'
nbTestCase = int(input())
for i in range(0, nbTestCase):
	s1 = input()
	s2 = input()
	print(findTwoStrings(s1, s2))


def check(string1, string2):
	for j in string1:
		if j in string2:
			return 'YES'
	return 'NO'
t = int(input())
for i in range(t):
	string1 = input()
	string2 = input()
	print(check(string1, string2))


t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	flags = 128 * [0]
	for u in s1:
		flags[ord(u)] += 1
	yes_flag = False
	for v in s2:
		if flags[ord(v)]:
			yes_flag = True
			break
	if yes_flag:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	a = input()
	b = input()
	result = False
	for l in a:
		if l in b:
			result = True
			break
	print('YES' if result else 'NO')


def commonSubstring(word1, word2):
	count1 = {c: 0 for c in 'abcdefghijklmnopqrstuvwxyz'}
	count2 = {c: 0 for c in 'abcdefghijklmnopqrstuvwxyz'}
	for c in word1:
		count1[c] += 1
	for c in word2:
		count2[c] += 1
	for (c1, c2) in zip(count1, count2):
		if count1[c1] > 0 and count2[c2] > 0:
			return True
	return False
numTestCases = int(input())
for i in range(numTestCases):
	word1 = str(input())
	word2 = str(input())
	if commonSubstring(word1, word2):
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	A = input()
	B = input()
	if set(A) & set(B):
		print('YES')
	else:
		print('NO')


T = int(input())
for x in range(0, T):
	first = input()
	second = input()
	result = 'NO'
	temp = []
	for i in first:
		if i in temp:
			pass
		else:
			temp[len(temp) + 1:] = [i]
	for i in second:
		if i in temp:
			result = 'YES'
			break
	print(result)


__author__ = 'Bohdan'
N = int(input())
for tests in range(N):
	a = input()
	b = input()
	alph_a = [0 for i in range(26)]
	alph_b = [0 for i in range(26)]
	for i in range(len(a)):
		alph_a[ord(a[i]) - ord('a')] += 1
	for i in range(len(b)):
		alph_b[ord(b[i]) - ord('a')] += 1
	flag = False
	for i in range(26):
		if alph_a[i] != 0 and alph_b[i] != 0:
			flag = True
	if flag:
		print('YES')
	else:
		print('NO')


def commonLetter(s1, s2):
	tab = [0] * 26
	for c in s1.lower():
		tab[ord(c) - ord('a')] += 1
	for c in s2.lower():
		if tab[ord(c) - ord('a')] != 0:
			return 'YES'
	return 'NO'

def main():
	T = int(input())
	for x in range(T):
		s1 = input()
		s2 = input()
		print(commonLetter(s1, s2))
main()


for _ in range(int(input().strip())):
	s1 = input().strip()
	s2 = input().strip()
	print('YES' if len(set(s1).intersection(s2)) else 'NO')


n = int(input())
for i in range(0, n):
	a = input()
	b = input()
	length = len(a) if len(a) < len(b) else len(b)
	message = 'NO'
	for j in range(0, length):
		if a[j] in b:
			message = 'YES'
			break
	print(message)


T = int(input())
for i in range(0, T):
	A = input()
	B = input()
	result = 'NO'
	for ch in A:
		if ch in B:
			result = 'YES'
	print(result)


for t in range(int(input())):
	(a, b) = (set(input()), set(input()))
	ans = False
	for i in a:
		if i in b:
			ans = True
			break
	print('YES' if ans else 'NO')


for x in range(int(input())):
	a = input()
	b = input()
	t = [0] * 26
	p = [0] * 26
	flag = 0
	for i in a:
		t[ord(i) - 97] += 1
	for i in b:
		p[ord(i) - 97] += 1
	i = 0
	while i < 26:
		if t[i] > 0 and p[i] > 0:
			flag = 1
			break
		i += 1
	if flag == 1:
		print('YES')
	else:
		print('NO')


T = int(input())
Ns = [[input(), input()] for t in range(0, T)]
for N in Ns:
	found = False
	for c in N[0]:
		if c in N[1]:
			print('YES')
			found = True
			break
	if found == False:
		print('NO')


a = int(input())
b = 0
while b < a:
	str1 = input()
	str2 = input()
	res = 'NO'
	for c in range(0, len(str1)):
		if str2.find(str1[c:c + 1]) >= 0:
			res = 'YES'
	b += 1
	print(res)


t = int(input())
while t > 0:
	t -= 1
	a = input()
	b = input()
	flag = 0
	for i in a:
		if i in b:
			flag = 1
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	found = 'NO'
	for c in a:
		if c in b:
			found = 'YES'
	print(found)


__author__ = 'user'
T = int(input())
for t in range(T):
	a = input().strip()
	b = input().strip()
	res = False
	for c in a:
		if c in b:
			res = True
	if res:
		print('YES')
	else:
		print('NO')


T = int(input())
for test in range(T):
	a = list(str(input()))
	b = list(str(input()))
	if set(a) & set(b):
		print('YES')
	else:
		print('NO')


for _ in range(0, int(input())):
	print('YES' if len(set(input()).intersection(set(input()))) > 1 else 'NO')


import sys
data = sys.stdin.readlines()

def test(first, second):
	b_letters = [i for i in first.strip('\n') if i in second.strip('\n')]
	if b_letters:
		return 'YES'
	return 'NO'

def pairwise(it):
	return zip(it[::2], it[1::2])
data.pop(0)
for x in pairwise(data):
	print(test(x[0], x[1]))


def has_substring(str_a, str_b):
	for letter in str_a:
		if letter in str_b:
			return 'YES'
	return 'NO'
test_cases = int(input())
for i in range(test_cases):
	a = input()
	b = input()
	print(has_substring(a, b))


cases = int(input())
answers = []
for i in range(0, cases):
	string1 = input()
	string2 = input()
	set = {i for i in string1}
	for j in string2:
		if set.issuperset(j):
			answers.append('YES')
			break
	if len(answers) < i + 1:
		answers.append('NO')
for i in answers:
	print(i)


for case in range(int(input())):
	(A, B, result, characters) = (input(), input(), 'NO', {})
	for character in A:
		characters[character] = True
	for character in B:
		if character in characters:
			result = 'YES'
	print(result)


no_of_tests = int(input())
for i in range(no_of_tests):
	str_1 = set(input())
	str_2 = set(input())
	if str_1.intersection(str_2):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	A = input()
	B = input()
	La = [int(0) for x in range(26)]
	Lb = [int(0) for x in range(26)]
	for x in A:
		La[ord(x) - 97] = 1
	for x in B:
		Lb[ord(x) - 97] = 1
	for i in range(26):
		if La[i] == 1 and Lb[i] == 1:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for i in range(0, t):
	s1 = input()
	s2 = input()
	s1 = set(s1)
	s2 = set(s2)
	if len(s1.intersection(s2)) == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	u = set([c for c in input()])
	w = set([c for c in input()])
	print('YES' if u.intersection(w) else 'NO')


def common_sub(str1, str2):
	for ltr in str1:
		if ltr in str2:
			return 'YES'
	return 'NO'
cases = input()
for case in range(0, int(cases)):
	inp1 = input()
	inp2 = input()
	answer = common_sub(inp1, inp2)
	print(answer)


t = int(input())
for _ in range(0, t):
	string1 = input()
	string2 = input()
	for letter in string1:
		if letter in string2:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
assert 1 <= t <= 10

def common(a, b):
	encountered = [False] * 26
	for char in a:
		if not encountered[ord(char) - 97]:
			encountered[ord(char) - 97] = True
	for char in b:
		if encountered[ord(char) - 97]:
			return 'YES'
	return 'NO'
for i in range(t):
	a = str(input())
	b = str(input())
	assert 1 <= len(a) <= 10 ** 5 and 1 <= len(b) <= 10 ** 5
	print(common(a, b))


def func():
	d = []
	T = int(input())
	for i in range(0, T):
		vb = input()
		vc = input()
		d = []
		r = False
		for j in vb:
			if j not in d:
				d.append(j)
		for j in vc:
			if j in d:
				r = True
		if r == True:
			print('YES')
		else:
			print('NO')
func()


T = int(input())
for t in range(T):
	a = input()
	b = input()
	if set(a).intersection(b):
		print('YES')
	else:
		print('NO')


def substring(str1, str2):
	for char1 in str1:
		if char1 in str2:
			return 'YES'
	return 'NO'
test = int(input())
for i in range(test):
	print(substring(input(), input()))


from sys import stdin
T = int(stdin.readline().rstrip())
for i in range(0, T):
	s1 = sorted(stdin.readline().rstrip())
	s2 = stdin.readline().rstrip()
	found = False
	if s1[0] in s2:
		found = True
	else:
		for j in range(1, len(s1)):
			if s1[j] != s1[j - 1]:
				if s1[j] in s2:
					found = True
					break
	if found:
		print('YES')
	else:
		print('NO')


n = input()
for i in range(int(n)):
	(a, b) = (input(), input())
	ans = False
	for ch in a:
		if ch in b:
			ans = True
			break
	print('YES' if ans else 'NO')


t = int(input())
for _ in range(t):
	a = set(input().strip())
	b = set(input().strip())
	print('YES' if b.intersection(a) else 'NO')


T = int(input())

def subsequence(A, B):
	for a in set(A):
		if B.find(a) >= 0:
			return 'YES'
	return 'NO'
for _ in range(T):
	A = input()
	B = input()
	print(subsequence(A, B))


def have_substring(A, B):
	counts = [0] * 26
	for c in A:
		counts[ord(c) - ord('a')] += 1
	for c in B:
		if counts[ord(c) - ord('a')] > 0:
			return True
	return False
T = int(input())
for _ in range(T):
	A = input()
	B = input()
	print('YES' if have_substring(A, B) else 'NO')


for n in range(int(input())):
	a = set(input())
	b = set(input())
	x = a.intersection(b)
	if len(x) > 0:
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	k = 0
	A = input()
	B = input()
	for a in A:
		if a in B:
			k = 1
			break
	if k == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	l1 = list(input())
	l2 = list(input())
	checked = [0] * 26
	flag = False
	for c1 in l1:
		if checked[ord(c1) - 97] == 0:
			for j in range(len(l2)):
				if c1 == l2[j]:
					flag = True
					break
		checked[ord(c1) - 97] = 1
		if flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')


cases = int(input())
from collections import Counter
for case in range(cases):
	cnt1 = Counter(input())
	cnt2 = Counter(input())
	if len(cnt1.keys() & cnt2.keys()) == 0:
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(n):
	ans = 'NO'
	string1 = input()
	string2 = input()
	if len(string1) > len(string2):
		(string1, string2) = (string2, string1)
	for ch in set(list(string1)):
		if ch in set(list(string2)):
			ans = 'YES'
			break
	print(ans)


from collections import Counter
n = int(input())
for i in range(n):
	w1 = Counter(input())
	w2 = Counter(input())
	found = False
	for key in w1:
		if key in w2:
			print('YES')
			found = True
			break
	if not found:
		print('NO')


t = int(input())
for i in range(t):
	s1 = input()
	s2 = input()
	flag = 0
	for i in s1:
		if i in s2:
			flag = 1
	for j in s2:
		if j in s1:
			flag = 1
	if flag == 1:
		print('YES')
	else:
		print('NO')


def is_common_substring(A, B):
	count = 0
	for chr in A:
		if chr in B:
			count += 1
	if count > 0:
		return True
	return False
t = int(input())
for case in range(t):
	A = input()
	B = input()
	if is_common_substring(A, B):
		print('YES')
	else:
		print('NO')


cases = int(input())
answers = []
for i in range(cases):
	s1 = input()
	s2 = input()
	flag = False
	for i in s1:
		if i in s2:
			flag = True
			answers.append('YES')
			break
	if flag == False:
		answers.append('NO')
for i in answers:
	print(i)


for i in range(int(input())):
	w = set(input())
	w2 = set(input())
	print('YES') if len(w.intersection(w2)) > 0 else print('NO')


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	charA = set(list(a))
	charB = set(list(b))
	if charA.intersection(charB):
		print('YES')
	else:
		print('NO')


def isThereCommonSubstring(a, b):
	a_dict = {}
	for a_itr in a:
		a_dict[a_itr] = True
	for b_itr in b:
		if b_itr in a_dict:
			return True
	return False
count = int(input())
for i in range(count):
	a = input()
	b = input()
	if isThereCommonSubstring(a, b):
		print('YES')
	else:
		print('NO')


num_tests = int(input())
all_results = []
for _ in range(num_tests):
	s1 = set(list(input()))
	s2 = set(list(input()))
	if s1.intersection(s2) == set():
		all_results.append('NO')
	else:
		all_results.append('YES')
for result in all_results:
	print(result)


t = int(input())
for tests in range(t):
	a = input()
	b = input()
	a = set(a)
	b = set(b)
	if len(a.intersection(b)) == 0:
		print('NO')
	else:
		print('YES')


def main():
	testcases = range(int(input()))
	for testcase in testcases:
		if common_substring(input(), input()):
			print('YES')
		else:
			print('NO')

def common_substring(string1, string2):
	firsttab = set()
	secondtab = set()
	firstindex = 0
	secondindex = 0
	while not firsttab & secondtab:
		if firstindex < len(string1):
			firsttab.add(string1[firstindex])
		if secondindex < len(string2):
			secondtab.add(string2[secondindex])
		if firstindex >= len(string1) and secondindex >= len(string2):
			break
		firstindex += 1
		secondindex += 1
	if firsttab & secondtab:
		return True
	return False
main()


dataSet = int(input())
first = []
second = []
for i in range(0, dataSet):
	first.append(input())
	second.append(input())
	count = 0
	for letter in first[i]:
		if letter in second[i]:
			count += 1
	if count > 0:
		print('YES')
	else:
		print('NO')


def two_string(a, b):
	if len(set(a) & set(b)):
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	first = input()
	second = input()
	two_string(first, second)


ncases = int(input())
for _ in range(ncases):
	s1 = input()
	s2 = input()
	print('YES' if set(s1) & set(s2) else 'NO')


size = int(input())
for each in range(size):
	yes = 0
	inpa = input()
	inpb = input()
	if len(inpa) < len(inpb):
		for each in inpa:
			if each in inpb:
				yes = 1
				print('YES')
				break
	else:
		for each in inpb:
			if each in inpa:
				yes = 1
				print('YES')
				break
	if yes == 0:
		print('NO')