#1374
Unrated
Guest Student
시간 제한
2s
메모리 제한
512MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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,,a7a_1, a_2, \dots, a_7 (ai=0a_i = 0 or ai=1a_i = 1):

  • a1=1a_1=1 if and only if there are classes for guest students on Sundays;
  • a2=1a_2=1 if and only if there are classes for guest students on Mondays;
  • a7=1a_7=1 if and only if there are classes for guest students on Saturdays.

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 kk 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 kk days as a guest student.

입력

The first line of the input contains integer tt (1t100001 \le t \le 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 kk (1k1081 \le k \le 10^8) — the required number of days to study as a guest student. The second line contains exactly seven integers a1,a2,,a7a_1, a_2, \dots, a_7 (ai=0a_i = 0 or ai=1a_i = 1) where ai=1a_i=1 if and only if classes for guest students are held on the ii-th day of a week.

출력

Print tt lines, the ii-th line should contain the answer for the ii-th test case — the length of the shortest continuous period of days you need to stay to study exactly kk days as a guest student.

예제 입력 1

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

예제 출력 1

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 88 days in the capital of Berland.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.