#NPC2015A. Eefun Guessing Words

Eefun Guessing Words

Eefun is currently learning to read. His way of learning  is unique, by trying to make every possible substring from a given string. However, when the string becomes longer, he can no longer remember all the substring. His friends want to test Eefun's skill by asking questions, given a string S, is there any substring that begins with letter X and ends with letter Y? According to Eefun, each substring contains at least 2 letters. As the given string S is pretty big, Eefun need your help to answer his friend's questions

Input

First line of input contain a single string S which was given by his friends.
Second line contain a number N, the number of questions that Eefun's friends ask.
Next N lines each consists of 2 characters, X and Y

Output

For each questions, output a single string "YA" if the substring exists, or "TIDAK" otherwise
(YA means yes and TIDAK means no in Indonesian) 

Example

Input:
HALO
4
H O
L O
A O
O L 
Output:
YA
YA
YA
TIDAK 

Constraints:

  • 'A' ≤ X,Y ≤ 'Z'
  • 1 ≤ |S| ≤ 1.000.000
  • 1 ≤ N ≤ 1.000.000