{"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 Now Coach Pang is preparing for the Graduate Record Examinations as George did in 2011. At each day, Coach Pang can:\u003cbr\u003e \u003cb\u003e\"+w\"\u003c/b\u003e: learn a word w\u003cbr\u003e \u003cb\u003e\"?p\"\u003c/b\u003e: read a paragraph p, and count the number of learnt words. Formally speaking, count the number of substrings of p which is a learnt words.\u003cbr\u003e Given the records of N days, help Coach Pang to find the count. For convenience, the characters occured in the words and paragraphs are only \u00270\u0027 and \u00271\u0027.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":" The first line of the input file contains an integer T, which denotes the number of test cases. T test cases follow.\u003cbr\u003e The first line of each test case contains an integer N (1 \u0026lt;\u003d N \u0026lt;\u003d 10\u003csup\u003e5\u003c/sup\u003e), which is the number of days. Each of the following N lines contains either \"+w\" or \"?p\". Both p and w are 01-string in this problem.\u003cbr\u003e Note that the input file has been encrypted. For each string occured, let L be the result of last \"?\" operation. The string given to you has been shifted L times (the shifted version of string s\u003csub\u003e1\u003c/sub\u003es\u003csub\u003e2\u003c/sub\u003e ... s\u003csub\u003ek\u003c/sub\u003e is s\u003csub\u003ek\u003c/sub\u003es\u003csub\u003e1\u003c/sub\u003es\u003csub\u003e2\u003c/sub\u003e ... s\u003csub\u003ek-1\u003c/sub\u003e). You should decrypt the string to the original one before you process it. Note that L equals to 0 at the beginning of each test case.\u003cbr\u003e The test data guarantees that for each test case, total length of the words does not exceed 10\u003csup\u003e5\u003c/sup\u003e and total length of the paragraphs does not exceed 5 * 10\u003csup\u003e6\u003c/sup\u003e."}},{"title":"Output","value":{"format":"HTML","content":" For each test case, first output a line \"Case #x:\", where x is the case number (starting from 1).\u003cbr\u003e And for each \"?\" operation, output a line containing the result."}},{"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\n3\r\n+01\r\n+01\r\n?01001\r\n3\r\n+01\r\n?010\r\n?011\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1:\r\n2\r\nCase #2:\r\n1\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}