{"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\"\u003eFor the hope of a forever love, Steven is planning to send a ring to Jane with a romantic string engraved on. The string\u0027s length should not exceed N. The careful Steven knows Jane so deeply that he knows her favorite words, such as \"love\", \"forever\". Also, he knows the value of each word. The higher value a word has the more joy Jane will get when see it.\u003cbr\u003eThe weight of a word is defined as its appeared times in the romantic string multiply by its value, while the weight of the romantic string is defined as the sum of all words\u0027 weight. You should output the string making its weight maximal. \u003cbr\u003e\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. Each test case starts with a line consisting of two integers: N, M, indicating the string\u0027s length and the number of Jane\u0027s favorite words. Each of the following M lines consists of a favorite word Si. The last line of each test case consists of M integers, while the i-th number indicates the value of Si.\u003cbr\u003eTechnical Specification\u003cbr\u003e\u003cbr\u003e1. T ≤ 15\u003cbr\u003e2. 0 \u0026lt; N ≤ 50, 0 \u0026lt; M ≤ 100.\u003cbr\u003e3. The length of each word is less than 11 and bigger than 0.\u003cbr\u003e4. 1 ≤ Hi ≤ 100. \u003cbr\u003e5. All the words in the input are different.\u003cbr\u003e6. All the words just consist of \u0027a\u0027 - \u0027z\u0027.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output the string to engrave on a single line.\u003cbr\u003eIf there\u0027s more than one possible answer, first output the shortest one. If there are still multiple solutions, output the smallest in lexicographically order.\u003cbr\u003e\u003cbr\u003eThe answer may be an empty string. \u003cbr\u003e"}},{"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\u003e2\r\n7 2\r\nlove\r\never\r\n5 5\r\n5 1\r\nab\r\n5\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003elovever\r\nabab\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eSample 1: weight(love) \u003d 5, weight(ever) \u003d 5, so weight(lovever) \u003d 5 + 5 \u003d 10\u003cbr\u003eSample 2: weight(ab) \u003d 2 * 5 \u003d 10, so weight(abab) \u003d 10 \u003cbr\u003e"}}]}