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.
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.
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.
ya
4
ah
oy
to
ha
YES
hp
2
ht
tp
NO
ah
1
ha
YES
bb
4
ba
ab
aa
bb
YES
bc
4
ca
ba
bb
cc
YES
ba
4
cd
ad
cc
cb
YES
pg
4
zl
xs
di
xn
NO
bn
100
df
yb
ze
ml
yr
of
nw
fm
dw
lv
zr
hu
zt
lw
ld
mo
xz
tp
mr
ou
me
px
vp
es
xi
nr
bx
qc
gm
js
kn
tw
rq
kz
uc
vc
qr
ab
na
ro
ya
qy
gu
vk
qk
gs
yq
op
hw
rj
eo
lz
bh
kr
kb
ma
rd
za
uf
hq
mc
mn
ti
wn
sh
ax
si
nd
tz
du
fj
kl
ws
ow
nf
vr
ye
zc
iw
fv
kv
oo
sm
bc
rs
au
uz
uv
gh
su
jn
dz
rl
wj
bk
zl
as
ms
it
wu
YES
bb
1
aa
NO
qm
25
qw
we
er
rt
ty
yu
ui
io
op
pa
as
sd
df
fg
gh
hj
jk
kl
lz
zx
xc
cv
vb
bn
nm
NO
mq
25
qw
we
er
rt
ty
yu
ui
io
op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1
hi
YES
ag
1
ag
YES
th
1
th
YES
sb
1
sb
YES
hp
1
hp
YES
ah
1
ah
YES
ta
1
ta
YES
tb
1
tb
YES
ab
5
ca
da
ea
fa
ka
NO
ac
1
ac
YES
ha
2
ha
zz
YES
ok
1
ok
YES
bc
1
bc
YES
az
1
zz
NO
ab
2
ba
tt
YES
ah
2
ap
hp
NO
sh
1
sh
YES
az
1
by
NO
as
1
as
YES
ab
2
ab
cd
YES
ab
2
xa
za
NO
ab
2
et
ab
YES
ab
1
aa
NO
ab
2
ab
de
YES
ah
2
ba
ha
YES
ha
3
dd
cc
ha
YES
oo
1
ox
NO
ab
2
ax
bx
NO
ww
4
uw
ow
po
ko
NO
ay
1
ay
YES
yo
1
yo
YES
ba
1
ba
YES
qw
1
qw
YES
la
1
la
YES
ab
2
bb
bc
NO
aa
2
ab
ac
NO
ah
2
bb
ha
YES
ya
42
ab
ac
ad
ae
af
ag
ah
ai
ak
aj
ba
bc
bd
be
bf
bg
bh
bi
bk
bj
cb
ca
cd
ce
cf
cg
ch
ci
ck
cj
db
dc
da
de
df
dg
dh
di
dk
dj
ef
ek
NO
ab
3
ab
xx
yy
YES
ab
2
ab
cc
YES
sa
2
xx
as
YES
ma
1
ma
YES
ba
1
bb
NO
bc
1
ab
NO
fa
1
fa
YES
ap
1
ap
YES
ab
1
bb
NO
bk
1
bk
YES
xy
2
xy
aa
YES
ab
2
za
bz
YES
s=input()
n=int(input())
f=e=''
for i in range(n):
    t=input()
    if t==s:exit(print('YES'))
    f+=t[0]
    e+=t[1]
    if s[0] in e and s[1] in f:exit(print('YES'))
print('NO')