C. Song
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Lívia is the captain of a spaceship that was attacked by space pirates, and, as a last resort for survival, she had to eject herself from the ship.

Now, Lívia finds herself floating aimlessly through space, and the only things she has with her are her cellphone and a pair of headphones. Luckily, she managed to send an SOS before leaving the ship and knows that, although it may take a few days, help is on the way. To pass the time, she decided to listen to some songs by her favorite artist, Saylor Twift.

Lívia created her own musical notation for the melodies she listens to. She considers that a song contains at most 26 distinct musical notes, and, when listening to a melody, she represents each musical note by one of the letters of the Latin alphabet (from "a" to "z"). Therefore, a melody is represented by a sequence of letters.

Additionally, Lívia wrote down $$$N$$$ pairs of notes $$$(u, v)$$$ to represent that note $$$v$$$ sounds good after note $$$u$$$. Now, she wants to compile a playlist with all of Saylor Twift's beautiful songs, so she asked for your help. Lívia considers beautiful only the melodies where, for every note played (except the first), it sounds good after the previous note.

Lívia emphasizes that a certain note $$$v$$$ sounding good after note $$$u$$$ does not mean that note $$$u$$$ would also sound good after note $$$v$$$. Given a melody by Saylor Twift, determine whether Lívia will consider it beautiful or not.

Input

The first line of the input contains a string $$$S$$$ $$$(1 \le |S| \le 10^5)$$$, representing Saylor Twift's song.

The second line contains an integer $$$N$$$ $$$(0 \le N \le 676)$$$, the number of pairs of musical notes that sound good together.

Each of the next $$$N$$$ lines contains two Latin alphabet letters, $$$u$$$ and $$$v$$$, representing that note $$$u$$$ sounds good before note $$$v$$$.

Output

The output must contain "SIM" if Lívia will consider the melody beautiful, or "NAO" if she will not.

Examples
Input
abac
3
a b
b a
a c
Output
SIM
Input
abac
3
a b
c a
b a
Output
NAO
Input
taylorswift
10
l o
a y
y l
i f
o r
r s
s w
w i
t a
f t
Output
SIM
Input
cde
2
c d
c e
Output
NAO