PROGRAMMING:Guest Student
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):
Boland State University invites people from all over the world as guest students. You can come to the capital of Portland and study with the best teachers in the country. Every day of the world week at Portland State University, but guest students' courses are held according to the following schedule. Do you know the sequence of seven integers A1, A2,..., a7 (AI = 0 or AI = 1)
• a1 = 1 if and only if there are classes for guest students on Sundays;
• a2 = 1 if and only if there are classes for guest students on Mondays;
• . . .
• a7 = 1 if and only if there are classes for guest students on Saturdays.
A1 = 1 if and only if there are guest courses on Sundays· A2 = 1 if and only if there are guest courses on Monday· A7 and 1 if there are classes, visiting students on Saturday
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.
Courses for students are held at least one day a week. You want to visit the capital of Berlin and spend the least number of days there studying K days as a guest student at d National University in Berlin. Write a program to find out the shortest length of consecutive days and stay in the capital to study for exactly k days as guest students.
###Input format:
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.
The first line of input contains the integer t (1 ≤ t ≤ 10000) - the number of test cases to process. Solve the problem independently for each test case and print the answer. Each test case consists of two lines. The first one contains the integer k (1 ≤ K ≤ 108) - as the number of days required for guest students to study. The second line contains exactly seven integers A1, A2,..., a7 (AI = 0 or AI = 1), where AI = 1 if and only if the guest student's course is held on the first day of the week
###Output format:
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.
Print t line, the first line should contain the answer of the first test case - as a guest student, the shortest continuous length of time you need to stay.
###Input example:
Here is a set of inputs. For example:
```in
three
two
0 1 0 0 0 0 0
one hundred million
1 0 0 0 1 0 1
one
1 0 0 0 0 0 0
```
###Output example:
The corresponding output is given here. For example:
```out
eight
two hundred and thirty-three million three hundred and thirty-three thousand three hundred and thirty-two
one
```
answer:If there is no answer, please comment
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):
Boland State University invites people from all over the world as guest students. You can come to the capital of Portland and study with the best teachers in the country. Every day of the world week at Portland State University, but guest students' courses are held according to the following schedule. Do you know the sequence of seven integers A1, A2,..., a7 (AI = 0 or AI = 1)
• a1 = 1 if and only if there are classes for guest students on Sundays;
• a2 = 1 if and only if there are classes for guest students on Mondays;
• . . .
• a7 = 1 if and only if there are classes for guest students on Saturdays.
A1 = 1 if and only if there are guest courses on Sundays· A2 = 1 if and only if there are guest courses on Monday· A7 and 1 if there are classes, visiting students on Saturday
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.
Courses for students are held at least one day a week. You want to visit the capital of Berlin and spend the least number of days there studying K days as a guest student at d National University in Berlin. Write a program to find out the shortest length of consecutive days and stay in the capital to study for exactly k days as guest students.
###Input format:
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.
The first line of input contains the integer t (1 ≤ t ≤ 10000) - the number of test cases to process. Solve the problem independently for each test case and print the answer. Each test case consists of two lines. The first one contains the integer k (1 ≤ K ≤ 108) - as the number of days required for guest students to study. The second line contains exactly seven integers A1, A2,..., a7 (AI = 0 or AI = 1), where AI = 1 if and only if the guest student's course is held on the first day of the week
###Output format:
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.
Print t line, the first line should contain the answer of the first test case - as a guest student, the shortest continuous length of time you need to stay.
###Input example:
Here is a set of inputs. For example:
```in
three
two
0 1 0 0 0 0 0
one hundred million
1 0 0 0 1 0 1
one
1 0 0 0 0 0 0
```
###Output example:
The corresponding output is given here. For example:
```out
eight
two hundred and thirty-three million three hundred and thirty-three thousand three hundred and thirty-two
one
```
answer:If there is no answer, please comment