{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\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 type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eThe letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.\u003c/p\u003e\u003cp\u003eLetters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.\u003c/p\u003e\u003cp\u003eThere are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount.\u003c/p\u003e\u003cul\u003e \u003cli\u003e For example, for $$$s$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003earrayhead\u003c/span\u003e\" and $$$t_i$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003earya\u003c/span\u003e\" $$$5$$$ letters have to be bought (\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003earray\u003c/span\u003ehead\u003c/span\u003e\"). \u003c/li\u003e\u003cli\u003e For example, for $$$s$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003earrayhead\u003c/span\u003e\" and $$$t_i$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003eharry\u003c/span\u003e\" $$$6$$$ letters have to be bought (\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003earrayh\u003c/span\u003eead\u003c/span\u003e\"). \u003c/li\u003e\u003cli\u003e For example, for $$$s$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003earrayhead\u003c/span\u003e\" and $$$t_i$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003eray\u003c/span\u003e\" $$$5$$$ letters have to be bought (\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003earray\u003c/span\u003ehead\u003c/span\u003e\"). \u003c/li\u003e\u003cli\u003e For example, for $$$s$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003earrayhead\u003c/span\u003e\" and $$$t_i$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003er\u003c/span\u003e\" $$$2$$$ letters have to be bought (\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003ear\u003c/span\u003erayhead\u003c/span\u003e\"). \u003c/li\u003e\u003cli\u003e For example, for $$$s$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003earrayhead\u003c/span\u003e\" and $$$t_i$$$\u003d\"\u003cspan class\u003d\"tex-font-style-tt\"\u003eareahydra\u003c/span\u003e\" all $$$9$$$ letters have to be bought (\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003earrayhead\u003c/span\u003e\u003c/span\u003e\"). \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIt is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.\u003c/p\u003e\u003cp\u003eNote that the values for friends are independent, friends are only estimating them but not actually buying the letters.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) — the length of showcase string $$$s$$$.\u003c/p\u003e\u003cp\u003eThe second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters.\u003c/p\u003e\u003cp\u003eThe third line contains one integer $$$m$$$ ($$$1 \\le m \\le 5 \\cdot 10^4$$$) — the number of friends.\u003c/p\u003e\u003cp\u003eThe $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \\le |t_i| \\le 2 \\cdot 10^5$$$) — the name of the $$$i$$$-th friend.\u003c/p\u003e\u003cp\u003eIt is guaranteed that $$$\\sum \\limits_{i\u003d1}^m |t_i| \\le 2 \\cdot 10^5$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount.\u003c/p\u003e\u003cp\u003eIt is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.\u003c/p\u003e"}},{"title":"Examples","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\u003e9\narrayhead\n5\narya\nharry\nray\nr\nareahydra\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\n6\n5\n2\n9\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}