{"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\"\u003eJong Hyok 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 i-th question, there is a string Qi. We called strange set(s) \u003d {(i, j) | s occurs in Pi and j is the position of its last character in the current occurence}. And for ith question, you must answer the number of different strings t which satisfies strange set(Qi) \u003d strange set(t) and t is a substring of at least one of the given n strings.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"First line contains T, a number of test cases.\u003cbr\u003e\u003cbr\u003eFor each test cases, there two numbers n, m and then there are n strings Pi and m strings Qj.(i \u003d 1…n, j \u003d 1…m)\u003cbr\u003e\u003cbr\u003e\u003cbr\u003e1 \u0026lt;\u003d T \u0026lt;\u003d 10\u003cbr\u003e1 \u0026lt;\u003d n \u0026lt;\u003d 100000\u003cbr\u003e1 \u0026lt;\u003d m\u0026lt;\u003d 500000\u003cbr\u003e1 \u0026lt;\u003d|Pi|\u0026lt;\u003d100000\u003cbr\u003e1 \u0026lt;\u003d|Qi|\u0026lt;\u003d100000\u003cbr\u003e $\\sum_{i\u003d1}^{n} |P_i|\\leq 100000$\u003cbr\u003eFile size is less than 3.5 megabytes.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, first line contains a line “Case #x:”, x is the number of the case.\u003cbr\u003e\u003cbr\u003eFor each question, you should print one integer in one line.\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\u003e1\r\n2 2\r\naba\r\nab\r\na\r\nab\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1:\r\n1\r\n2\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\u003estrange set(“a”) \u003d{(1, 1), (1, 3), (2, 1)}.\u003cbr\u003estrange set(“ab”) \u003d{(1, 2), (2, 2)}.\u003cbr\u003estrange set(“b”) \u003d{(1, 2), (2, 2)}.\u003cbr\u003e"}}]}