{"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\"\u003eLong long time ago, there is a magic continent far far away.\u003cbr\u003eThere are N types of magic crystals that contain ancient magic powers. Each of the type of magic crystal has its own price for one piece in the market. As the most powerful magician, Mr. Panda could synthesize some types of crystals by collecting some amount of other types of crystals. He could also create some types of crystals by using some number of his magic powers.\u003cbr\u003eNow, Mr Panda can create any number of crystals as he wish by using no more than M magic powers. He want to know the maximum amount of money he can make by sell all the crytals he creates and synthesizes.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input gives the number of test cases, T. T test cases follow.\u003cbr\u003eEach test case starts with 3 positive intergers, M, N and K represent the amount of magic powers Mr. Panda had, the number of crystal types on the magic continent and the number of crystal synthesis equations.\u003cbr\u003eThen N lines follows, each of them starts with one 0 or 1 which indicates whehter Mr. Panda could create this type of crystal.\u003cbr\u003eIf the $i^{th}$ line starts with 0, which means Mr. Panda couldn’t create crystal type i. Then there is one integer $p_i$ in this line which is the price for each piece of crystal type i.\u003cbr\u003eIf the $i^{th}$ line starts with 1, which means Mr. Panda could create crystal type i. Then there are two positive integers $c_i$ and $p_i$ in this line, the first is the amout of magic power cost when creates one piece of crystal type i, and the second is is the price for each piece of crystal type i.\u003cbr\u003eThe following K lines each start with two interger $x_i$ and $y_i$ , which means for synthesizing one piece of crystal type $x_i$ , $y_i$ rules should be satisfied. Then there are $y_i$ pair of positive intergers $u_j$ and $v_j$ means for one piece of $x^{th}_{i}$ type cristal, we have to collect $v_i$ piece of crystal type $u_i$. Only when all the rules of $u_i$ and $v_i$ are satisfied, Mr. Panda could synthesize one piece $x^{th}_{i}$ type cristal.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the maximum amout of money Mr. Panda could make.\u003cbr\u003e\u003ch2\u003elimits\u003c/h2\u003e\u003cbr\u003e$\\bullet 1 ≤ T ≤ 100.$\u003cbr\u003e$\\bullet 1 ≤ M ≤ 10000.$\u003cbr\u003e$\\bullet 1 ≤ N ≤ 200.$\u003cbr\u003e$\\bullet 1 ≤ K ≤ 200.$\u003cbr\u003e$\\bullet 1 ≤ x_i, u_j ≤ N.$\u003cbr\u003e$\\bullet for each crystal synthesis equation, all uj are different.$\u003cbr\u003e$\\bullet 1 ≤ v_j ≤ 100.$\u003cbr\u003e$\\bullet 1 ≤ c_i , p_i ≤ 10000.$\u003cbr\u003e\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\u003e2\r\n100 3 2\r\n0 20\r\n1 15 10\r\n1 2 1\r\n1 2 2 1 3 1\r\n2 1 3 2\r\n100 3 2\r\n1 3 1\r\n1 4 1\r\n0 10\r\n3 1 1 3\r\n3 1 2 2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1: 330\r\nCase #2: 121\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}