{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"There are $K$ magical pens (numbered $1$ through $K$). You are given strings $P_1, P_2, \\ldots, P_K$ (each of which consists of characters from **\u0027a\u0027, \u0027b\u0027, ..., \u0027t\u0027**) ; for each valid $i$, the $i$-th pen can only write letters from the string $P_i$.\r\n\r\nYou want to write a word $S$ of length $N$. All the characters of $S$ are between **\u0027a\u0027** and **\u0027t\u0027** inclusive. This string must be written from left to right. To write it, you pick up some pen and start writing; after you\u0027ve written some prefix of $S$, you can put down that pen, pick up another pen, continue writing $S$ from the point where you put down the previous pen, later pick up another pen (any pen) and continue writing $S$ with that pen, and so on until you write the whole string $S$. You may pick up each pen any number of times, including zero.\r\n\r\nYou have to find a way of writing the word $S$ such that the number of times you change the pen (put down the pen you\u0027re currently writing with and pick up another) is the smallest possible. If there are multiple solutions, you may find any one. It is guaranteed that it is possible to write $S$ with the given pens.\r\n\r\n### Input\r\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\r\n- The first line of each test case contains two space-separated integers $N$ and $K$.\r\n- The second line contains a single string $S$.\r\n- For each valid $i$, the $i$-th of the next $K$ lines contains a single string $P_i$.\r\n\r\n### Output\r\nFor each test case, print a single line containing $N$ space-separated integers. For each valid $i$, the $i$-th of these integers should be the number of the pen with which you want to write the $i$-th character of $S$.\r\n\r\nYour output will be considered correct if each character can be written with the pen you want to write it with and the number of times you have to change the pen you are writing with is minimum possible.\r\n\r\n### Constraints\r\n- $1 \\le T \\le 10$\r\n- $1 \\le N \\le 10^6$\r\n- $1 \\le K \\le 10^5$\r\n- $S, P_1, P_2, \\ldots, P_K$ contain only characters **\u0027a\u0027, \u0027b\u0027, ..., \u0027t\u0027**\r\n- $1 \\le |P_i| \\le 20$ for each valid $i$\r\n- For each valid $i$, all characters of $P_i$ are pairwise distinct\r\n- The sum of lengths of all the strings on the input does not exceed $2 \\cdot 10^6$\r\n\r\n### Example Input\r\n```\r\n3\r\n4 2\r\nabcd\r\nab\r\ncd\r\n4 2\r\nbaab\r\nab\r\nca\r\n4 2\r\nacaa\r\nab\r\ncd\r\n```\r\n\r\n### Example Output\r\n```\r\n1 1 2 2\r\n1 1 1 1\r\n1 2 1 1\r\n```\r\n\r\n### Explanation\r\n**Example case 1:** You can write the first two characters with the first pen and the next two characters with the second pen. This means you have to change the pen once (from pen $1$ to pen $2$).\r\n\r\n**Example case 2:** You can write the whole string $S$ with the first pen, so you never have to change the pen you are writing with.\r\n\r\n**Example case 3:** You can write the first character with the first pen, the second character with the second pen and then the last two characters again with the first pen. Thus, you have to change the pen twice (from pen $1$ to pen $2$ and then from pen $2$ to pen $1$).\r\n"}}]}