{"trustable":false,"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\u003e \n \u003cspan\u003eJong\u003c/span\u003e \n \u003cspan\u003eHyok\u003c/span\u003e loves strings. One day he gives a problem to his friend you. He writes down n strings Pi in front of you, and asks m questions. For \n \u003cspan\u003ei-th\u003c/span\u003e question, there is a string \n \u003cspan\u003eQi\u003c/span\u003e. We called strange set(s) \u003d {(i, j) | s occurs in Pi and j is the position of its last character in the current \n \u003cspan\u003eoccurence\u003c/span\u003e}. And for \n \u003cspan\u003eith\u003c/span\u003e question, you must answer the number of different strings t which satisfies strange set(\n \u003cspan\u003eQi\u003c/span\u003e) \u003d strange set(t) and t is a \n \u003cspan\u003esubstring\u003c/span\u003e of at least one of the given n strings.\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e First line contains T, a number of test cases.\u003cbr\u003e \u003cbr\u003e For each test cases, there two numbers n, m and then there are n strings Pi and m strings \u003cspan\u003eQj\u003c/span\u003e.(i \u003d 1…n, j \u003d 1…m)\u003cbr\u003e \u003cbr\u003e \u003cbr\u003e 1 \u0026lt;\u003d T \u0026lt;\u003d 10\u003cbr\u003e 1 \u0026lt;\u003d n \u0026lt;\u003d 100000\u003cbr\u003e 1 \u0026lt;\u003d m\u0026lt;\u003d 500000\u003cbr\u003e 1 \u0026lt;\u003d|Pi|\u0026lt;\u003d100000\u003cbr\u003e 1 \u0026lt;\u003d|\u003cspan\u003eQi\u003c/span\u003e|\u0026lt;\u003d100000\u003cbr\u003e $\\sum_{i\u003d1}^{n} |P_i|\\\u003cspan\u003eleq\u003c/span\u003e 100000$\u003cbr\u003e File size is less than 3.5 megabytes.\u003cbr\u003e \u0026nbsp;\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e For each test case, first line contains a line “Case #x:”, x is the number of the case.\u003cbr\u003e \u003cbr\u003e For each question, you should print one integer in one line.\u003cbr\u003e \u0026nbsp;\u003c/p\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e\r\n1\r\n2 2\r\n\u003cspan\u003eaba\u003c/span\u003e\r\n\u003cspan\u003eab\u003c/span\u003e\r\na\r\n\u003cspan\u003eab\u003c/span\u003e\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e\r\nCase #1:\r\n1\r\n2\r\n\r\n\r\n \r\n \u003ci\u003e \u003c/i\u003e\u003c/pre\u003e"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cpre\u003e\r\n\u003c/pre\u003e \n\u003cdiv\u003e \n \u003cpre\u003e\r\n\t\u003c/pre\u003e \n \u003cdiv\u003e \n \u003cpre\u003e\r\n\t\t\u003c/pre\u003e \n \u003c/div\u003e strange set(“a”) \u003d{(1, 1), (1, 3), (2, 1)}. strange set(\n \u003cspan\u003e“ab”\u003c/span\u003e) \u003d{(1, 2), (2, 2)}. strange set(“b”) \u003d{(1, 2), (2, 2)}.\n\u003c/div\u003e"}}]}