|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||6||6||6||100.000%|
Berland 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.
Berland 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 a1, a2, . . . , a7 (ai = 0 or ai = 1):
The classes for guest students are held in at least one day of a week.
You 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.
The first line of the input contains integer t (1 ≤ t ≤ 10 000) — the number of test cases to process. For each test case independently solve the problem and print the answer.
Each test case consists of two lines. The first of them contains integer k (1 ≤ k ≤ 108) — the required number of days to study as a guest student. The second line contains exactly seven integers a1, a2, . . . , a7 (ai = 0 or ai = 1) where ai = 1 if and only if classes for guest students are held on the i-th day of a week.
Print 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.
3 2 0 1 0 0 0 0 0 100000000 1 0 0 0 1 0 1 1 1 0 0 0 0 0 0
8 233333332 1
In 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.