{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\r\n\tGiven a \u003ci\u003em\u003c/i\u003e by \u003ci\u003en\u003c/i\u003e grid of letters, ( \u003cimg align\u003d\"MIDDLE\" alt\u003d\"$1 \\leq m,n \\leq 20$\" border\u003d\"0\" height\u003d\"30\" src\u003d\"http://uva.onlinejudge.org/external/100/10010img2.gif\" width\u003d\"111\" /\u003e), and a list of words, find the location in the grid at which the word can be found. A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid \u003cu\u003e\u003cspan style\u003d\"font-family:comic sans ms,cursive;\"\u003eregardless of case\u003c/span\u003e\u003c/u\u003e (i.e. upper and lower case letters are to be treated as the same). The matching can be done in any of the eight directions either horizontally, vertically or diagonally through the grid.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e\r\n\t\u003cb\u003eThe 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.\u003c/b\u003e\u003c/p\u003e\r\n\u003cp\u003e\r\n\tThe input begins with a pair of integers,\u0026nbsp;\u003ci\u003em\u003c/i\u003e\u0026nbsp;followed by\u0026nbsp;\u003ci\u003en\u003c/i\u003e,\u0026nbsp;\u003cimg align\u003d\"MIDDLE\" alt\u003d\"$1 \\leq\r\nm,n \\leq 50$\" border\u003d\"0\" height\u003d\"30\" src\u003d\"http://uva.onlinejudge.org/external/100/10010img2.gif\" width\u003d\"111\" /\u003e\u0026nbsp;in decimal notation on a single line. The next\u0026nbsp;\u003ci\u003em\u003c/i\u003e\u0026nbsp;lines contain\u0026nbsp;\u003ci\u003en\u003c/i\u003e\u0026nbsp;letters each; this is the grid of letters in which the words of the list must be found. The letters in the grid may be in upper or lower case. Following the grid of letters, another integer\u0026nbsp;\u003ci\u003ek\u003c/i\u003e\u0026nbsp;appears on a line by itself (\u0026nbsp;\u003cimg align\u003d\"MIDDLE\" alt\u003d\"$1 \\leq k \\leq 20$\" border\u003d\"0\" height\u003d\"32\" src\u003d\"http://uva.onlinejudge.org/external/100/10010img3.gif\" width\u003d\"87\" /\u003e). The next\u0026nbsp;\u003ci\u003ek\u003c/i\u003e\u0026nbsp;lines of input contain the list of words to search for, one word per line. These words may contain upper and lower case letters only (no spaces, hyphens or other non-alphabetic characters).\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e\r\n\t\u003cb\u003eThe outputs of two consecutive cases will be separated by a blank line.\u0026nbsp;\u003c/b\u003e\u003c/p\u003e\r\n\u003cp\u003e\r\n\tFor each word in the word list, a pair of integers representing the location of the corresponding word in the grid must be output. The integers must be separated by a single space. The first integer is the line in the grid where the first letter of the given word can be found (1 represents the topmost line in the grid, and\u0026nbsp;\u003ci\u003em\u003c/i\u003e\u0026nbsp;represents the bottommost line). The second integer is the column in the grid where the first letter of the given word can be found (1 represents the leftmost column in the grid, and\u0026nbsp;\u003ci\u003en\u003c/i\u003e\u0026nbsp;represents the rightmost column in the grid). If a word can be found more than once in the grid, then the location which is output should correspond to the uppermost\u0026nbsp;\u003cspan data-scayt_word\u003d\"occurence\" data-scaytid\u003d\"10\"\u003eoccurence\u003c/span\u003e\u0026nbsp;of the word (i.e. the\u0026nbsp;\u003cspan data-scayt_word\u003d\"occurence\" data-scaytid\u003d\"11\"\u003eoccurence\u003c/span\u003e\u0026nbsp;which places the first letter of the word closest to the top of the grid). If two or more words are uppermost, the output should correspond to the leftmost of these\u0026nbsp;\u003cspan data-scayt_word\u003d\"occurences\" data-scaytid\u003d\"12\"\u003eoccurences\u003c/span\u003e. All words can be found at least once in the grid.\u003c/p\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e\r\n1\r\n\r\n8 11\r\n\u003cspan data-scayt_word\u003d\"abcDEFGhigg\" data-scaytid\u003d\"1\"\u003eabcDEFGhigg\u003c/span\u003e\r\n\u003cspan data-scayt_word\u003d\"hEbkWalDork\" data-scaytid\u003d\"2\"\u003ehEbkWalDork\u003c/span\u003e\r\n\u003cspan data-scayt_word\u003d\"FtyAwaldORm\" data-scaytid\u003d\"3\"\u003eFtyAwaldORm\u003c/span\u003e\r\n\u003cspan data-scayt_word\u003d\"FtsimrLqsrc\" data-scaytid\u003d\"4\"\u003eFtsimrLqsrc\u003c/span\u003e\r\n\u003cspan data-scayt_word\u003d\"byoArBeDeyv\" data-scaytid\u003d\"5\"\u003ebyoArBeDeyv\u003c/span\u003e\r\n\u003cspan data-scayt_word\u003d\"Klcbqwikomk\" data-scaytid\u003d\"6\"\u003eKlcbqwikomk\u003c/span\u003e\r\n\u003cspan data-scayt_word\u003d\"strEBGadhrb\" data-scaytid\u003d\"7\"\u003estrEBGadhrb\u003c/span\u003e\r\n\u003cspan data-scayt_word\u003d\"yUiqlxcnBjf\" data-scaytid\u003d\"8\"\u003eyUiqlxcnBjf\u003c/span\u003e\r\n4\r\nWaldorf\r\nBambi\r\nBetty\r\n\u003cspan data-scayt_word\u003d\"Dagbert\" data-scaytid\u003d\"9\"\u003eDagbert\u003c/span\u003e\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e\r\n2 5\r\n2 3\r\n1 2\r\n7 8\r\n\u003c/pre\u003e"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cp\u003e\r\n\tPay attention to the key phases in the problem.\u003c/p\u003e"}}]}