There is a war situation. The enemy have devised an intelligent algorithm to encrypt messages. Now the defense division have intercepted several messages and got some clues. But they are stuck in the middle of nowhere. They don't know how to move ahead to further decode the messages sent. They need your help as they believe that you are the only one who is capable enough to break this code.
They have shared the following details with you. Can you help them break the codes:
Now it is highly possible that you happen to find more than one possibilities for H then in that case you must select the one possibility in which it starts before other possibilities. Even after doing this, still you might have more than one possibilities. In that case you should select the one that ends before than others.
But it is also possible in some cases that you may not even find a single possibility for H. Then you consider it as a goof.
Remember these messages may be nonsensical to you but the defense division may get very important information from it. Help the defense division for glory. May the force be with you.
Input:
First line contains code C which would be a string with only lowercase characters.
Second line contains two integers m and Q suggesting offset for Caesar cipher and number of queries. (There can be different messages with different properties for same code, so just to make sure about that defense division has came up with these Q queries.)
The next Q lines will contain Q queries.
Each Query will contain 5 space separated integers k, a, b, A, B (Not Kabab :P). These variable names have same meaning as described in question.
Output:
For each query,
1. If you can find such H then you need to output one line with 2 space separated integers l and r denoting the start and end position of H in code.
2. If you can't find such H then output one line with word "GOOF".
Constraints:
Example Input:
dppm
1 3
1 1 3 0 3
1 2 3 0 3
1 3 3 0 3
Example Output:
0 0
1 2
GOOF
Author: Suparshva Mehta
After deciphering "dppm" for caesar code of offset 1, code becomes "cool" (really?) by performing the left shift in characters by offset 1.
For Query 1:
H must satisfy:
Exactly 1 different characters.
Permissible lengths: 1,2 or 3.
H must be substring of C'[0-3].
Hence, "c","o","oo","l" are possibilities of H. Hence H="c".i.e. output = 0 0
For Query 3:
H must satisfy:
Exactly 1 different characters.
Permissible lengths:3.
H must be substring of C'[0-3].
There is no such H possible. Hence it is a goof.i.e. output = GOOF