{"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\"\u003eYou are a rich person, and you think your wallet is too heavy and full now. So you want to give me some money by buying a lovely pusheen sticker which costs $p$ dollars from me. To make your wallet lighter, you decide to pay exactly $p$ dollars by as many coins and/or banknotes as possible.\u003cbr\u003e\u003cbr\u003eFor example, if $p \u003d 17$ and you have two $\\$10$ coins, four $\\$5$ coins, and eight $\\$1$ coins, you will pay it by two $\\$5$ coins and seven $\\$1$ coins. But this task is incredibly hard since you are too rich and the sticker is too expensive and pusheen is too lovely, please write a program to calculate the best solution.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains an integer $T$ indicating the total number of test cases. Each test case is a line with 11 integers $p, c_1, c_5, c_{10}, c_{20}, c_{50}, c_{100}, c_{200}, c_{500}, c_{1000}, c_{2000}$, specifying the price of the pusheen sticker, and the number of coins and banknotes in each denomination. The number $c_i$ means how many coins/banknotes in denominations of $i$ dollars in your wallet.\u003cbr\u003e\u003cbr\u003e$1 \\le T \\le 20000$\u003cbr\u003e$0 \\le p \\le 10^9$\u003cbr\u003e$0 \\le c_i \\le 100000$"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, please output the maximum number of coins and/or banknotes he can pay for exactly $p$ dollars in a line. If you cannot pay for exactly $p$ dollars, please simply output \u0027-1\u0027."}},{"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\u003e3\r\n17 8 4 2 0 0 0 0 0 0 0\r\n100 99 0 0 0 0 0 0 0 0 0\r\n2015 9 8 7 6 5 4 3 2 1 0\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e9\r\n-1\r\n36\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}