{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eYou start with the number \u003cvar\u003e\\(0\\)\u003c/var\u003e and you want to reach the number \u003cvar\u003e\\(N\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003cp\u003eYou can change the number, paying a certain amount of coins, with the following operations:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eMultiply the number by \u003cvar\u003e\\(2\\)\u003c/var\u003e, paying \u003cvar\u003e\\(A\\)\u003c/var\u003e coins.\u003c/li\u003e\r\n\u003cli\u003eMultiply the number by \u003cvar\u003e\\(3\\)\u003c/var\u003e, paying \u003cvar\u003e\\(B\\)\u003c/var\u003e coins.\u003c/li\u003e\r\n\u003cli\u003eMultiply the number by \u003cvar\u003e\\(5\\)\u003c/var\u003e, paying \u003cvar\u003e\\(C\\)\u003c/var\u003e coins.\u003c/li\u003e\r\n\u003cli\u003eIncrease or decrease the number by \u003cvar\u003e\\(1\\)\u003c/var\u003e, paying \u003cvar\u003e\\(D\\)\u003c/var\u003e coins.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eYou can perform these operations in arbitrary order and an arbitrary number of times.\u003c/p\u003e\r\n\u003cp\u003eWhat is the minimum number of coins you need to reach \u003cvar\u003e\\(N\\)\u003c/var\u003e?\u003c/p\u003e\r\n\u003cp\u003e\u003cstrong\u003eYou have to solve \u003cvar\u003e\\(T\\)\u003c/var\u003e testcases.\u003c/strong\u003e\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\le T \\le 10\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\le N \\le 10^{18}\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\le A, B, C, D \\le 10^9\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003eAll numbers \u003cvar\u003e\\(N, A, B, C, D\\)\u003c/var\u003e are integers.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eThe input is given from Standard Input. The first line of the input is\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(T\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003cp\u003eThen, \u003cvar\u003e\\(T\\)\u003c/var\u003e lines follow describing the \u003cvar\u003e\\(T\\)\u003c/var\u003e testcases.\r\nEach of the \u003cvar\u003e\\(T\\)\u003c/var\u003e lines has the format\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(N\\)\u003c/var\u003e \u003cvar\u003e\\(A\\)\u003c/var\u003e \u003cvar\u003e\\(B\\)\u003c/var\u003e \u003cvar\u003e\\(C\\)\u003c/var\u003e \u003cvar\u003e\\(D\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eFor each testcase, print the answer on Standard Output followed by a newline.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 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\u003e5\r\n11 1 2 4 8\r\n11 1 2 2 8\r\n32 10 8 5 4\r\n29384293847243 454353412 332423423 934923490 1\r\n900000000000000000 332423423 454353412 934923490 987654321\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e20\r\n19\r\n26\r\n3821859835\r\n23441258666\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eFor the first testcase, a sequence of moves that achieves the minimum cost of \u003cvar\u003e\\(20\\)\u003c/var\u003e is:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eInitially \u003cvar\u003e\\(x \u003d 0\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(8\\)\u003c/var\u003e to increase by \u003cvar\u003e\\(1\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 1\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(1\\)\u003c/var\u003e to multiply by \u003cvar\u003e\\(2\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 2\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(1\\)\u003c/var\u003e to multiply by \u003cvar\u003e\\(2\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 4\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(2\\)\u003c/var\u003e to multiply by \u003cvar\u003e\\(3\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 12\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(8\\)\u003c/var\u003e to decrease by \u003cvar\u003e\\(1\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 11\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eFor the second testcase, a sequence of moves that achieves the minimum cost of \u003cvar\u003e\\(19\\)\u003c/var\u003e is:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eInitially \u003cvar\u003e\\(x \u003d 0\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(8\\)\u003c/var\u003e to increase by \u003cvar\u003e\\(1\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 1\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(1\\)\u003c/var\u003e to multiply by \u003cvar\u003e\\(2\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 2\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(2\\)\u003c/var\u003e to multiply by \u003cvar\u003e\\(5\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 10\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003cli\u003ePay \u003cvar\u003e\\(8\\)\u003c/var\u003e to increase by \u003cvar\u003e\\(1\\)\u003c/var\u003e (\u003cvar\u003e\\(x \u003d 11\\)\u003c/var\u003e).\u003c/li\u003e\r\n\u003c/ul\u003e\u003c/section\u003e\r\n"}}]}