{"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\"\u003e \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;Aliens on planet Pandora also write computer programs like us. Their programs only consist of capital letters (‘A’ to ‘Z’) which they learned from the Earth. On \u003cbr\u003eplanet Pandora, hackers make computer virus, so they also have anti-virus software. Of course they learned virus scanning algorithm from the Earth. Every virus has a pattern string which consists of only capital letters. If a virus’s pattern string is a substring of a program, or the pattern string is a substring of the reverse of that program, they can say the program is infected by that virus. Give you a program and a list of virus pattern strings, please write a program to figure out how many viruses the program is infected by.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are multiple test cases. The first line in the input is an integer T ( T\u0026lt;\u003d 10) indicating the number of test cases.\u003cbr\u003e\u003cbr\u003eFor each test case:\u003cbr\u003e\u003cbr\u003eThe first line is a integer n( 0 \u0026lt; n \u0026lt;\u003d 250) indicating the number of virus pattern strings.\u003cbr\u003e\u003cbr\u003eThen n lines follows, each represents a virus pattern string. Every pattern string stands for a virus. It’s guaranteed that those n pattern strings are all different so there \u003cbr\u003eare n different viruses. The length of pattern string is no more than 1,000 and a pattern string at least consists of one letter.\u003cbr\u003e\u003cbr\u003eThe last line of a test case is the program. The program may be described in a compressed format. A compressed program consists of capital letters and \u003cbr\u003e“compressors”. A “compressor” is in the following format:\u003cbr\u003e\u003cbr\u003e[qx]\u003cbr\u003e\u003cbr\u003eq is a number( 0 \u0026lt; q \u0026lt;\u003d 5,000,000)and x is a capital letter. It means q consecutive letter xs in the original uncompressed program. For example, [6K] means \u003cbr\u003e‘KKKKKK’ in the original program. So, if a compressed program is like:\u003cbr\u003e\u003cbr\u003eAB[2D]E[7K]G\u003cbr\u003e\u003cbr\u003eIt actually is ABDDEKKKKKKKG after decompressed to original format.\u003cbr\u003e\u003cbr\u003eThe length of the program is at least 1 and at most 5,100,000, no matter in the compressed format or after it is decompressed to original format.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print an integer K in a line meaning that the program is infected by K viruses.\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\u003e3\r\n2\r\nAB\r\nDCB\r\nDACB\r\n3\r\nABC\r\nCDE\r\nGHI\r\nABCCDEFIHG\r\n4\r\nABB\r\nACDEE\r\nBBB\r\nFEEE\r\nA[2B]CD[4E]F\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\r\n3\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":"In the second case in the sample input, the reverse of the program is ‘GHIFEDCCBA’, and ‘GHI’ is a substring of the reverse, so the program is infected \u003cbr\u003eby virus ‘GHI’.\u003cbr\u003e"}}]}