Module: Linear enumeration


Problem

2 /5


Belvita and bakery sign

Problem

Tomorrow Belvita opens her bakery, but she still hasn't prepared a sign for her establishment. 
Belvita has n sets of tablets in her closet, each of which contains 3 identical tablets containing exactly two lowercase Latin letters.
Belvite doesn't care what the name of her bakery will be, but she wants the final name to contain the substring s, which also consists of two lowercase Latin letters.
Help Belvita see if it's possible to select some of the available tablets and use them to make the name of the bakery so that it contains the required substring.

Input:
The first line contains two lowercase Latin letters - the string s that Belvita wants to see in the name of the bakery.
The second line contains one integer n (1 <= n <= 100) - the number of sets of plaques in the closet.
The next n lines contain two lowercase Latin letters each describing the inscriptions on the tablets in the sets.

Output:
Print "YES" if Belvita can choose several tablets so that the resulting word contains the substring s, and "NO" otherwise.

Examples:
 
Input Output
ya
4
ah
oy
to
ha
YES
hp
2
ht
tp
NO
ah
1
ha
YES

Explanations:
In the first example, you can use the third, second, and first sets by making the word "tooyah" that contains the substring "ya".
In the second example, get the word with the substring "hp" no way.
In the third example, you can use two of the three tablets from the first set, making the word "haha" where there is a substring "ah".