{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eIsabella and Steve are very good friends, and they often write letters to each other. They exchange funny experiences, talk about people around, share their feelings and write about almost everything through the letters. When the letters are delivered, they are quite afraid that some other people(maybe their parents) would peek. So they encrypted the letter, and only they know how to decrypt it. This guarantees their privacy.\u003cbr\u003eThe encrypted message is an N * N matrix, and each grid contains a character.\u003cbr\u003eSteve uses a special mask to work as a key. The mask is N * N(where N is an even number) matrix with N*N/4 holes of size 1 * 1 on it.\u003cbr\u003eThe decrypt process consist of the following steps:\u003cbr\u003e1. Put the mask on the encrypted message matrix\u003cbr\u003e2. Write down the characters you can see through the holes, from top to down, then from left to right.\u003cbr\u003e3. Rotate the mask by 90 degrees clockwise.\u003cbr\u003e4. Go to step 2, unless you have wrote down all the N*N characters in the message matrix.\u003cbr\u003e5. Erase all the redundant white spaces in the message.\u003cbr\u003eFor example, you got a message shown in figure 1, and you have a mask looks like figure 2. The decryption process is shown in figure 3, and finally you may get a message \"good morning\".\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/c142baf751f259247f62a8be8353ee37?v\u003d1715147971\"\u003e\u003c/center\u003e \u003cbr\u003eYou can assume that the mask is always carefully chosen that each character in the encrypted message will appear exactly once during decryption.\u003cbr\u003e However, in the first step of decryption, there are several ways to put the mask on the message matrix, because the mask can be rotated (but not flipped). So you may get different results such as \"od morning go\" (as showed in figure 4), and you may also get other messages like \"orning good m\", \"ng good morni\".\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/9b0ab5d9853716369be33448cfda534a?v\u003d1715147971\"\u003e\u003c/center\u003e \u003cbr\u003eSteve didn\u0027t know which direction of the mask should be chosen at the beginning, but after he tried all possibilities, he found that the message \"good morning\" is the only one he wanted because he couldn\u0027t recognize some words in the other messages. So he will always consider the message he can understand the correct one. Whether he can understand a message depends whether he knows all the words in the message. If there are more than one ways to decrypt the message into an understandable one, he will choose the lexicographically smallest one. The way to compare two messages is to compare the words of two messages one by one, and the first pair of different words in the two messages will determine the lexicographic order of them.\u003cbr\u003eIsabella sends letters to Steve almost every day. As decrypting Isabella\u0027s message takes a lot of time, and Steve can wait no longer to know the content of the message, he asked you for help. Now you are given the message he received, the mask, and the list of words he already knew, can you write a program to help him decrypt it?\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains an integer T(1 \u0026lt;\u003d T \u0026lt;\u003d 100), indicating the number of test cases.\u003cbr\u003eEach test case contains several lines.\u003cbr\u003eThe first line contains an even integer N(2 \u0026lt;\u003d N \u0026lt;\u003d 50), indicating the size of the matrix.\u003cbr\u003eThe following N lines each contains exactly N characters, reresenting the message matrix. The message only contains lowercase letters and periods(\u0027.\u0027), where periods represent the white spaces.\u003cbr\u003eYou can assume the matrix contains at least one letter.\u003cbr\u003eThe followingN lines each containsN characters, representing the mask matrix. The asterisk(\u0027*\u0027) represents a hole, and period(\u0027.\u0027) otherwise. The next line contains an integer M(1 \u0026lt;\u003d M \u0026lt;\u003d 100), the number of words he knew.\u003cbr\u003eThen the following M lines each contains a string represents a word. The words only contain lowercase letters, and its length will not exceed 20.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case in the input, print one line: \"Case #X: Y\", where X is the test case number (starting with 1) and Y is Isabella\u0027s message.\u003cbr\u003eIf Steve cannot understand the message, just print the Y as \"FAIL TO DECRYPT\"."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n4\r\no.do\r\n.ng.\r\ngrmn\r\no.i.\r\n.*..\r\n*.*.\r\n....\r\n*...\r\n2\r\ngood\r\nmorning\r\n4\r\n..lf\r\neoyv\r\noeou\r\nvrer\r\n..*.\r\n.*..\r\n....\r\n*.*.\r\n5\r\ni\r\nyou\r\nthe\r\nlove\r\nforever\r\n4\r\n.sle\r\ns.c.\r\ne.fs\r\n..uu\r\n*...\r\n.*..\r\n...*\r\n..*.\r\n1\r\nsuccessful\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1: good morning\r\nCase #2: love you forever\r\nCase #3: FAIL TO DECRYPT\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}