{"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\u003e给定一个长度为$$$n$$$的由小写英文字母组成的字符串$$$s$$$。这个字符串可以用来构建其他字符串。每个字母的成本在另一个长度为$$$n$$$的由数字组成的字符串$$$c$$$中给出,其中使用字母$$$s_i$$$的成本是$$$c_i$$$个硬币。\u003c/p\u003e\u003cp\u003e此外,还给定另一个长度为$$$m$$$的由\u003cspan class\u003d\"tex-font-style-bf\"\u003e唯一\u003c/span\u003e小写英文字母组成的字符串$$$p$$$。你的任务是找到使用$$$s$$$的字母构建字符串$$$p$$$的最小成本。你能做到吗?\u003c/p\u003e"}},{"title":"输入","value":{"format":"HTML","content":"\u003cp\u003e第一行包含一个整数$$$T$$$($$$1 \\le T \\le 500$$$),表示测试用例的数量。\u003c/p\u003e\u003cp\u003e每个测试用例的第一行包含两个整数$$$n$$$和$$$m$$$($$$1 \\le n \\le 10^3,\\,1 \\le m \\le 26$$$),其中$$$n$$$是字符串$$$s$$$和$$$c$$$的长度,$$$m$$$是字符串$$$p$$$的长度。\u003c/p\u003e\u003cp\u003e接下来有$$$3$$$行,每行包含一个字符串,分别给出字符串$$$s$$$、$$$c$$$和$$$p$$$。字符串$$$s$$$和$$$p$$$只包含小写英文字母,而字符串$$$c$$$只包含数字。另外,字符串$$$p$$$由\u003cspan class\u003d\"tex-font-style-bf\"\u003e唯一\u003c/span\u003e的字母组成。\u003c/p\u003e"}},{"title":"输出","value":{"format":"HTML","content":"\u003cp\u003e对于每个测试用例,输出一行,包含使用字符串$$$s$$$的字母构建字符串$$$p$$$的最小成本。如果无法使用字符串$$$s$$$构建字符串$$$p$$$,则输出$$$-1$$$。\u003c/p\u003e"}},{"title":"示例 1","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\n4 2\nabcd\n1234\nac\n4 4\nabcd\n1234\nabec\n5 3\nabcba\n24513\nacb\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\n-1\n8\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"注意","value":{"format":"HTML","content":"\u003cp\u003e在第一个测试用例中,你需要使用字符串$$$s$$$的$$$1^{st}$$$和$$$3^{rd}$$$字母来构建字符串$$$p$$$。因此,总成本是$$$1 + 3 \u003d 4$$$。\u003c/p\u003e\u003cp\u003e在第二个测试用例中,你无法使用$$$s$$$构建字符串$$$p$$$,因为$$$p$$$中的字母\u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003ee\u003c/span\u003e\u0027不存在于$$$s$$$中。因此,答案是$$$-1$$$。\u003c/p\u003e\u003cp\u003e在第三个测试用例中,最佳方法是使用字符串$$$s$$$的$$$1^{st}$$$、$$$3^{rd}$$$和$$$4^{th}$$$字母来构建$$$p$$$。因此,总成本是$$$2 + 5 + 1 \u003d 8$$$。\u003c/p\u003e"}}]}