As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.

Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.


-----Input-----

The first line contains two lowercase English letters — the password on the phone.

The second line contains single integer n (1 ≤ n ≤ 100) — the number of words Kashtanka knows.

The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.


-----Output-----

Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.

You can print each letter in arbitrary case (upper or lower).


-----Examples-----
Input
ya
4
ah
oy
to
ha

Output
YES

Input
hp
2
ht
tp

Output
NO

Input
ah
1
ha

Output
YES



-----Note-----

In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".

In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.

In the third example the string "hahahaha" contains "ah" as a substring.

Difficulty: competition

Starter code:

Solutions:
s = input()
n = int(input())
a = [input() for i in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] == s or a[i][1] + a[j][0] == s:
            print("YES")
            return
print("NO")


pas = input()
count = int(input())
words = [input() for i in range(count)]

if pas in words:
    print("YES")
else:
    f1 = False
    f2 = False
    for word in words:
        if pas[0] == word[1]:
            f1 = True
        if pas[1] == word[0]:
            f2 = True
    if f1 and f2:
        print("YES")
    else:
        print("NO")


3

s = input()
n = int(input())
l = [input() for i in range(n)]

ans = False

if s in l:
    ans = True
else:
    for i in range(n):
        for j in range(n):
            if (l[i] + l[j])[1:3] == s:
                ans = True

if ans:
    print("YES")
else:
    print("NO")


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 main():
    s = S()
    n = I()
    a = [S() for _ in range(n)]
    if (s in a) or (s[0] in [x[1] for x in a] and s[1] in [x[0] for x in a]):
        return 'YES'

    return 'NO'


print(main())






want = input()
n = int(input())
l = [input() for _ in range(n)]
works = False
if want in l:
	works = True
for i in range(n):
	for j in range(n):
		if want in l[i] + l[j]:
			works = True

print("YES" if works else "NO")

p = input().strip()
a = [input().strip() for i in range(int(input()))]
b = [(ai[1]+aj[0]) for ai in a for aj in a]
print('YES' if p in a+b else 'NO')

p = input()
n = int(input())
c = False
w = [input() for i in range(n)]
for i in range(n):
    for j in range(n):
        if (w[i][0]==p[1] and w[j][1]==p[0]):
            c = True
            break
print({True:"YES",False:"NO"}[c or p in w])


t = input()
n = int(input())

ok = [0, 0]
for i in range(n):
    w = input()
    if w == t:
        ok = [1, 1]
    if w[1] == t[0]:
        ok[0] = 1
    if w[0] == t[1]:
        ok[1] = 1

if ok == [1, 1]:
    print("YES")
else:
    print("NO")


s = input()
sec = []
fir = []
n = int(input())
for i in range(n):
	s1 = input()
	sec.append(s1[1])
	fir.append(s1[0])
	if s1 == s:
		print('YES')
		break
else:
	if s[0] in sec and s[1] in fir:
		print('YES')
	else:
		print('NO')

def __starting_point():
	password = input()
	n = int(input())
	lasts = set()
	firsts = set()
	attempts = set()
	for _ in range(n):
		attempt = input()
		attempts.add(attempt)
		firsts.add(attempt[0])
		lasts.add(attempt[1])
	
	if password in attempts or (password[0] in lasts and password[1] in firsts):
		print("YES")
	else:
		print("NO")
__starting_point()

from sys import stdin, stdout

pwd = stdin.readline().rstrip()
n = int(stdin.readline().rstrip())
words = []
for _ in range(n):
    words.append(stdin.readline().rstrip())
    
if pwd in words:
    print('YES')
else:
    possible1 = False
    possible2 = False
    for word in words:
        if word[0]==pwd[1]:
            possible1=True
        if word[1]==pwd[0]:
            possible2=True
    if possible1 and possible2:
        print('YES')
    else:
        print('NO')


p=str(input())
s=[]
e=[]
ip=[]
for i in range(int(input())):
    temp=str(input())
    ip.append(temp)
    s.append(temp[0])
    e.append(temp[1])
b=0
if p in ip:
    b=1
else:
    if p[0] in e and p[1] in s:
        b=1
if b==1:
    print('YES')
else:
    print('NO')


s = input()
n = int(input())
data = []
for i in range(n):
    data.append(input())
mark = 0
for i in range(n):
    for j in range(n):
        if s in (data[i] + data[j]):
            mark = 1
            
if mark:
    print("YES")
else:
    print("NO")

pas = input()
n = int(input())
l_letters = set()
r_letters = set()
ans = False
for i in range(n):
    j = input()
    l_letters.add(j[0])
    r_letters.add(j[1])
    if j == pas:
        ans = True
    if j[0] == pas[1]:
        if pas[0] in r_letters:
            ans = True
    if j[1] == pas[0]:
        if pas[1] in l_letters:
            ans = True
if ans:
    print("YES")
else:
    print("NO")


st = input()
arr = []
for _ in range(int(input())):
    arr.append(input())

firf = False
secf = False
flag = True
for sbst in arr:
    if sbst == st:
        print('YES')
        flag = False
        break
    if sbst[1] == st[0]:
        firf = True
    if sbst[0] == st[1]:
        secf = True

    if firf and secf:
        print('YES')
        flag = False
        break

if flag:
    print ('NO')


s=input()
n=int(input())
l=[]
for u in range(n):
	l.append(input())

flag=0
for i in range(n):
	for j in range(n):
		if((l[i]+l[j]).count(s) >=1):
			flag=1
			break
	if(flag):
		break
if(flag):
	print("YES")
else:
	print("NO")

def check(password,n,a):
	for i in range(n):
		if (password[0] == a[i][1]):
			for j in range(n):
				if (password[1] == a[j][0]):
					return True

	if (password in a):
		return True

	return False

password = input()
n = int(input())
a = []
for i in range(n):
	a.append(input())

if (check(password,n,a)):
	print('YES')
else:
	print('NO')




def solution():
	w = input().strip()
	n = int(input())
	words = []
	for i in range(n):
		words.append(input().strip())

	for i in range(n):
		if words[i] == w:
			return True
		for j in range(n):
			if words[i][1]+words[j][0] == w:
				return True
	
	return False


print('YES' if solution() else 'NO')

s=input()
n=int(input())
a=[input() for i in range(n)]
for x in a:
	for y in a:
		if s in x+y:
			print('YES')
			return

print('NO')



password = input()
n = int(input())
a = []
for i in range(n):
	a.append(input())
b = []
for w in a:
	for w2 in a:
		b.append((w+w2)[:2])
		b.append((w+w2)[1:3])
		b.append((w+w2)[2:])

if password in b:
	print("YES")
else:
	print("NO")

s = input()
n = int(input())
a = [input() for i in range(n)]
for i in a:
    for j in a:
        if s in i + j:
            print('YES')
            return
print('NO')


def main():
    pwd = input()
    n = int(input())
    f_l = False
    s_l = False
    for _ in range(n):
        b = input()
        if b == pwd:
            print('YES')
            return
        if pwd[1] == b[0]:
            f_l = True
        if pwd[0] == b[1]:
            s_l = True
    if f_l and s_l:
        print('YES')
    else:
        print('NO')


def __starting_point():
    main()

__starting_point()