Word search

You must solve a word search. ?‘does it seem easy? It is, except for a little detail: we are not only going to allow that the words appear in rows, columns or diagonals, but also that “go round”: when the board ends, the word can “continue” in the opposite side. ?‘Look the following instance: do you find the word “abracadabra”?

z z a z z a z z d z z
r z z b z z c z z a z
z a z z r z z a z z b

A detail: we do not accept that the same letter of the word search corresponds to two or more different letters in the word. For instance, the following word search do not contain the word “abracadabra”; instead, it contains the word “zbzzbz” (in diagonal, not in vertical).

z z z z z z z z z z
a b r a b r a c a d
z z z z z z z z z z

Input

A test data contains various cases, separated by a line in white. Each case starts with three naturals separated by spaces, RR, CC and NN. It is fulfilled that 3F,C1003\leq F, C \leq 100 and 0N1000\leq N \leq 100. Then, RR lines follow with CC lowercase letters each one of them, describing the word search. Finally, NN lines, each one of them contains a non empty word formed by lowercase letters that you must search in the word search.

Output

Return the same board marking all the appearances of each word. Mark it writing with uppercase letters all the letters that are part of one of the words that you searchs. Consider that the same word can appear many times, once or never in the word search. Separe two cases with a line in white.

Score

Author: Omer Giménez

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:25:30.981Z

© Jutge.org, 2006–2026.
https://jutge.org