Word Puzzles

Word puzzles are usually simple and very entertaining for all ages. They are so entertaining that Pizza- Hut company started using table covers with word puzzles printed on them, possibly with the intent to minimise their client’s perception of any possible delay in bringing them their order. Even though word puzzles may be entertaining to solve by hand, they may become boring when they get very large. Computers do not yet get bored in solving tasks, therefore we thought you could devise a program to speedup (hopefully!) solution finding in such puzzles. The following figure illustrates the PizzaHut puzzle. The names of the pizzas to be found in the puz- zle are: MARGARITA, ALEMA, BARBECUE, TROPICAL, SUPREMA, LOUISIANA, CHEESE- HAM, EUROPA, HAVAIANA, CAMPONESA. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 0QWSPILAATIRAGRAMYKEI 1AGTRCLQAXLPOIJLFVBUQ 2TQTKAZXVMRWALEMAPKCW 3LIEACNKAZXKPOTPIZCEO 4FGKLSTCBTROPICALBLBC 5JEWHJEEWSMLPOEKORORA 6LUPQWRNJOAAGJKMUSJAE 7KRQEIOLOAOQPRTVILCBZ 8QOPUCAJSPPOUTMTSLPSF 9LPOUYTRFGMMLKIUISXSW 10 W A H C P O I Y T G A K L M N A H B V A 11 E I A K H P L B G S M C L O G N G J M L 12 L D T I K E N V C S W Q A Z U A O E A L 13 H O P L P G E J K M N U T I I O R M N C 14 L O I U F T G S Q A C A X M O P B E I O 15 Q O A S D H O P E P N B U Y U Y O B X B 16 I O N I A E L O J H S W A S M O U T R K 17 H P O I Y T J P L N A Q W D R I B I T G 18 L P O I N U Y M R T E M P T M L M N B O 19 P A F C O P L H A V A I A N A L B P F S Your task is to produce a program that given the word puzzle and words to be found in the puzzle, determines, for each word, the position of the first letter and its orientation in the puzzle. You can assume that the left upper corner of the puzzle is the origin, (0, 0). Furthemore, the orientation of the word is marked clockwise starting with letter A for north (note: there are 8 possible directions in total). Input The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. The first line of input consists of three positive numbers, the number of lines, 0 < L ≤ 1000, the number of columns, 0 < C ≤ 1000, and the number of words to be found, 0 < W ≤ 1000. The following

2/3 L input lines, each one of size C characters, contain the word puzzle. Then at last the W words are input one per line. Output For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. Your program should output, for each word (using the same order as the words were input) a triplet defining the coordinates, line and column, where the first letter of the word appears, followed by a letter indicating the orientation of the word according to the rules define above. Each value in the triplet must be separated by one space only. Sample Input 1 20 20 10 QWSPILAATIRAGRAMYKEI AGTRCLQAXLPOIJLFVBUQ TQTKAZXVMRWALEMAPKCW LIEACNKAZXKPOTPIZCEO FGKLSTCBTROPICALBLBC JEWHJEEWSMLPOEKORORA LUPQWRNJOAAGJKMUSJAE KRQEIOLOAOQPRTVILCBZ QOPUCAJSPPOUTMTSLPSF LPOUYTRFGMMLKIUISXSW WAHCPOIYTGAKLMNAHBVA EIAKHPLBGSMCLOGNGJML LDTIKENVCSWQAZUAOEAL HOPLPGEJKMNUTIIORMNC LOIUFTGSQACAXMOPBEIO QOASDHOPEPNBUYUYOBXB IONIAELOJHSWASMOUTRK HPOIYTJPLNAQWDRIBITG LPOINUYMRTEMPTMLMNBO PAFCOPLHAVAIANALBPFS MARGARITA ALEMA BARBECUE TROPICAL SUPREMA LOUISIANA CHEESEHAM EUROPA HAVAIANA CAMPONESA Sample Output 0 15 G

3/3 2 11 C 7 18 A 48C 16 13 B 4 15 E 10 3 D 51E 19 7 C 11 11 H