{"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\"\u003eDota as a popular computer game has serval years. Lots of Dota fans know that the equipment in the game is very important. To get a excellent equipment may be pass many processes. Look the picture, you may see that in order to get the finally one must get the other two first. But this two may be can not get directly.\u003cbr\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/dda83ee9a47124b13718e0192ea339a0?v\u003d1714197844\"\u003e\u003cbr\u003e \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/339012418e75d982d689d128861fcc15?v\u003d1714197844\"\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/155698995552f284e5abf9e3011da7ba?v\u003d1714197844\"\u003e\u003cbr\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/e2806d15caa0302df778e149b8ba7bc4?v\u003d1714197844\"\u003e\u003cbr\u003e \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/339012418e75d982d689d128861fcc15?v\u003d1714197844\"\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/de5f436d06bcffc867f15a709fd05965?v\u003d1714197844\"\u003e\u003cbr\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/675a5af15be8df8c0a1c7549f11cfb48?v\u003d1714197844\"\u003e\u003cbr\u003e\u003cbr\u003e\u003cbr\u003e \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/339012418e75d982d689d128861fcc15?v\u003d1714197844\"\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/ee634a0230445cb5c86395ed53ab7735?v\u003d1714197844\"\u003e \u003cbr\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/52e058ea016d8ee2a6be4420de4347cc?v\u003d1714197844\"\u003e \u003cbr\u003eNow give the primary equipments which you can buy it by money directly in the shop.\u003cbr\u003eAnd the numbers of equipments you already have.\u003cbr\u003eYou also know all the formulas how to get a new better equipment by primary equipments.\u003cbr\u003eLast give the numbers of equipments you want, tell us how much extra money you need. \u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input contains multiple test cases.\u003cbr\u003eFirst part a integer n1 expressing the numbers of primary equipments you can buy in the shop.\u003cbr\u003eNext n1 lines, each line form as S V,S is the name of equipment and V meaning you should cost V money to buy one equipments S.\u003cbr\u003eSecond part a integer n2 expressing the numbers of kinds equipments you have.\u003cbr\u003eNext n2 lines, each line form as S,M, meaning the numbers of equipment S you have is M.\u003cbr\u003eThird part a integer n3 expressing the numbers of formulas.\u003cbr\u003eNext n3 lines, each line have a character \u0027\u003d\u0027, The left is the equipments you should use to get the right equipment. For example A + B + C \u003d D, In order to get a D, you must use A,B,C,D.each one.\u003cbr\u003eLast part a integer n4, expressing n4 kinds of equipments you need.\u003cbr\u003eThan n4 lines, each line form as S,M. Meaning the numbers of equipment S you need is M.\u003cbr\u003e\u003cbr\u003eYou may sure the total kinds of equipment will not larger than 100. And the lengths of equipment name will less than 50.(a chinese words made up of two character )\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Output the extra money you need to achieve goal."}},{"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\u003e4\r\n欢欣之刃 100\r\n敏捷之靴 20\r\n半兽人之斧 100\r\n力量腰带 50\r\n2\r\n散华 1\r\n力量腰带 2\r\n3\r\n欢欣之刃 + 敏捷之靴 \u003d 散华\r\n半兽人之斧 + 力量腰带 \u003d 夜叉\r\n散华 + 夜叉 \u003d 散夜对剑\r\n1\r\n散夜对剑 2\r\n\r\n5\r\n鹰角弓 3200\r\n短棍 1100\r\n攻击之爪 950\r\n阔剑 1200\r\n恶魔刀锋 2600\r\n0\r\n3\r\n鹰角弓 + 短棍 \u003d 蝴蝶\r\n攻击之爪 + 阔剑 \u003d 水晶剑\r\n水晶剑 + 恶魔刀锋 \u003d 大炮\r\n2\r\n蝴蝶 1\r\n大炮 1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e320\r\n9050\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}