xsquare-and-two-strings-1

Xsquare loves to play with strings a lot. Today, he has two strings S1 and S2 both consisting of lower case alphabets. Xsquare listed all subsequences of string S1 on a paper and all subsequences of string S2 on a separate paper. Xsquare wants to know whether there exists a string which is listed on both the papers.

Xsquare thinks that this task is pretty boring and handed it to you. Please accomplish this task on his behalf.

 Input 
First line of input contains a single integer T denoting the number of test cases. Each test case consists of two lines. First line of each test case contains a string denoting string S1. Next line of each test case contains a string denoting string S2.

Output
For each test case, Print Yes if both papers contain a common string otherwise Print No.

Constraints
1 ≤ T ≤ 10^5

1 ≤ |S1| ≤ 10^5

1 ≤ |S2| ≤ 10^5

Sum of |S1| over all test case does not exceed 5*10^5

Sum of |S2| over all test case does not exceed 5*10^5

SAMPLE INPUT
2
phackerekarthj
jhakckerearthp
hello
buy


SAMPLE OUTPUT
Yes
No

Explanation

Testcase 1 : There is a common subsequence of letters between S1 and S2. For ex: "hackerearth" is subsequence of S1 and S2 both.
Testcase 2 : There is no common subsequence of letters between S1 and S2.

Difficulty: EASY
Tags: Fundamentals

Ad-hoc

Starter code:

Solutions:
test = eval(input())
for i in range(test):
	s1 = input()
	s2 = input()
	for j in s1:
		if j in s2:
			print("Yes")
			break
	else:
		print("No")


import sys
t=int(input())
while(t>0):
	s1=input()
	s2=input()
	for i in range(len(s1)):
		if s1[i] in s2:
			print("Yes")
			break
	else:
		print("No")
	t=t-1
	


t=eval(input(''))
cnt=0

while t>cnt:
	s1=list(input(''))
	s2=list(input(''))
	if len(set(s1).intersection(s2))==0:
		print("No")
	else:
		print("Yes")
	t-=1



n = eval(input())
for i in range(n):
	t = 0
	a = input()
	b = input()
	d = {x : a.count(x) for x in ('abcdefghijklmnopqrstuvwxyz')}
	for s in b:
		if d[s] > 0:
			print("Yes")
			t = 1
			break
	if(t == 0):
		print("No")



n = int(input())
for _ in range(n):
	storageA = input()
	storageB = input()
	storageA = set(storageA)
	storageB = set(storageB)
	if storageA.intersection(storageB):
		print("Yes")
	else:
		print("No")


for i in range(eval(input())):
	a = input()
	b = input()
	if len(set(a).intersection(b))>0:
		print('Yes')
	else:
		print('No')


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
import bisect
i = input()
for k in range(int(i)):
	a=input()
	b=input()
	c=sorted(a)
	d=sorted(b)
	for i in c:
		k=bisect.bisect(d, i)
		if d[k-1]==i:
			print("Yes")
			break
	else:
		print("No")
		


t =int(input(""));
res = [];

for i in range(0,t):
	str1 = input("");
	str2 =input("");
	flag =0;
	arr = [0 for i in range(0,26)];
	for i in range(0,len(str1)):
			arr[ord(str1[i])-97]+=1;
	for i in range(0,len(str2)):
		if(arr[ord(str2[i])-97]):
			flag = 1;
			break;
	if(flag):
		res.append("Yes");
	else:
		res.append("No");

for i in res:
	print(i);


for _ in range(eval(input())):
	a=list(input())
	b=list(input())
	flag = 0
	for i in ['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']:
		if str(i) in a and str(i) in b:
			flag = 1
			break
	if flag: print('Yes')
	else: print('No')




for i in range(eval(input())):
	a=input()
	b=input()
	s=a
	s1=""
	for m in range(0,len(b)):
		if(b[m] not in s1):
			s1+=b[m]
	for j in range(0,len(b)):
		if(b[j] not in s):
			s+=b[j]
	
	if(len(s)==len(a)+len(s1)):
		print('No')
	else:
		print('Yes')


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
TestCase = int(eval(input()))
for _ in range(TestCase):
	Str1 = input()
	Str2 = input()
	
	Dict = {char : Str1.count(char) for char in 'abcdefghijklmnopqrstuvwxyz'}
	Ans = True
	t = 0
	for char in Str2:
		if Dict[char] > 0:
			print("Yes")
			t = 1
			break

	if t == 0:
		print("No")


from difflib import SequenceMatcher
t=eval(input())
while t:
	t=t-1
	a=input().replace(" ","")
	b=input().replace(" ","")    
	j=0
	for x in a:
		if x in b:
			print('Yes')
			j=1
			break
	if(j==0):
		print('No')


T = int(input())
for t in range(T):
	s1 = input()
	s2 = input()
	s1 = list(set(s1))
	s2 = list(set(s2))
	s =[]
	p=[]
	res= False
	if len(s1) < len(s2):
		s = s1
		p=s2
	else:
		s= s2
		p = s1
	for x in s:
		if x in p:
			res=True
			break
	if res:
		print('Yes')
	else:
		print('No')


#!/usr/local/bin/python

import sys
from itertools import combinations

total_test_cases= int(sys.stdin.readline())
for _ in range(total_test_cases):
	found = False
	string_one = sys.stdin.readline().strip()
	string_two = sys.stdin.readline().strip()
	for i in string_two:
		if i in string_one:
			print("Yes")
			found = True
			break
	if found == False:
		print("No")