{"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\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eBerland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country.\u003c/p\u003e\u003cp\u003eBerland State University works every day of the week, but classes for guest students are held on the following schedule. You know the sequence of seven integers $$$a_1, a_2, \\dots, a_7$$$ ($$$a_i \u003d 0$$$ or $$$a_i \u003d 1$$$):\u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$a_1\u003d1$$$ if and only if there are classes for guest students on Sundays; \u003c/li\u003e\u003cli\u003e $$$a_2\u003d1$$$ if and only if there are classes for guest students on Mondays; \u003c/li\u003e\u003cli\u003e ... \u003c/li\u003e\u003cli\u003e $$$a_7\u003d1$$$ if and only if there are classes for guest students on Saturdays. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe classes for guest students are held in at least one day of a week.\u003c/p\u003e\u003cp\u003eYou want to visit the capital of Berland and spend the minimum number of days in it to study $$$k$$$ days as a guest student in Berland State University. Write a program to find the length of the shortest continuous period of days to stay in the capital to study exactly $$$k$$$ days as a guest student.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of the input contains integer $$$t$$$ ($$$1 \\le t \\le 10\\,000$$$) — the number of test cases to process. For each test case independently solve the problem and print the answer. \u003c/p\u003e\u003cp\u003eEach test case consists of two lines. The first of them contains integer $$$k$$$ ($$$1 \\le k \\le 10^8$$$) — the required number of days to study as a guest student. The second line contains exactly seven integers $$$a_1, a_2, \\dots, a_7$$$ ($$$a_i \u003d 0$$$ or $$$a_i \u003d 1$$$) where $$$a_i\u003d1$$$ if and only if classes for guest students are held on the $$$i$$$-th day of a week.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint $$$t$$$ lines, the $$$i$$$-th line should contain the answer for the $$$i$$$-th test case — the length of the shortest continuous period of days you need to stay to study exactly $$$k$$$ days as a guest student.\u003c/p\u003e"}},{"title":"Examples","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\n2\n0 1 0 0 0 0 0\n100000000\n1 0 0 0 1 0 1\n1\n1 0 0 0 0 0 0\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e8\n233333332\n1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first test case you must arrive to the capital of Berland on Monday, have classes on this day, spend a week until next Monday and have classes on the next Monday. In total you need to spend $$$8$$$ days in the capital of Berland.\u003c/p\u003e"}}]}