시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 6 2 2 40.000%

문제

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 puzzle are: MARGARITA, ALEMA, BARBECUE, TROPICAL, SUPREMA, LOUISIANA, CHEESEHAM, EUROPA, HAVAIANA, CAMPONESA.

  0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0 Q W S P I L A A T I R A G R A M Y K E I
1 A G T R C L Q A X L P O I J L F V B U Q
2 T Q T K A Z X V M R W A L E M A P K C W
3 L I E A C N K A Z X K P O T P I Z C E O
4 F G K L S T C B T R O P I C A L B L B C
5 J E W H J E E W S M L P O E K O R O R A
6 L U P Q W R N J O A A G J K M U S J A E
7 K R Q E I O L O A O Q P R T V I L C B Z
8 Q O P U C A J S P P O U T M T S L P S F
9 L P O U Y T R F G M M L K I U I S X S W
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).

입력

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 L input lines, each one of size C characters, contain the word puzzle. Then at last the W words are input one per 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.

예제 입력

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

예제 출력

0 15 G
2 11 C
7 18 A
4 8 C
16 13 B
4 15 E
10 3 D
5 1 E
19 7 C
11 11 H

힌트

단어가 여러 번 퍼즐판에 등장할 때, 이 경우에는

  1. 행 위치가 더 작거나,
  2. 행 위치가 같으면 열 위치가 더 작거나,
  3. 행과 열 위치가 같으면 방향이 작은(A~H까지의 방향이 있다면 A가 가장 작습니다)

위치를 출력해야 합니다.