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 $a_1, a_2, \dots, a_7$ ($a_i = 0$ or $a_i = 1$):  $a_1=1$ if and only if there are classes for guest students on Sundays;  $a_2=1$ if and only if there are classes for guest students on Mondays;  ...   $a_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 $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.


-----Input-----

The 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. 

Each 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 = 0$ or $a_i = 1$) where $a_i=1$ if and only if classes for guest students are held on the $i$-th day of a week.


-----Output-----

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.


-----Example-----
Input
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

Output
8
233333332
1



-----Note-----

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.

Difficulty: MEDIUM

Solutions:
t = int(input())
for u in range(t):
	k = int(input())
	a = list(map(int, input().split()))
	per = a.count(1)
	breaks = []
	b = a + a
	curr = 1
	ind = b.index(1) + 1
	for i in range(7):
		if b[ind] == 0:
			curr += 1
			ind += 1
		else:
			breaks.append(curr)
			curr = 1
			ind += 1
	z = k % per
	if z == 0:
		print(7 * (k // per) - max(breaks) + 1)
	elif z == 1:
		print(7 * (k // per) + 1)
	else:
		brea = breaks + breaks
		sums = [sum(brea[:z - 1])]
		for i in range(per - 1):
			sums.append(sums[-1] + brea[z + i - 1] - brea[i])
		print(7 * (k // per) + 1 + min(sums))


from sys import stdin
for _ in range(int(stdin.readline())):
	K = int(stdin.readline())
	lst = [*map(int, stdin.readline().split())]
	(ans, item) = ([], 0)
	for (i, x) in enumerate(lst):
		if x == 1:
			ans.append(i)
			item += 1
	res = 100000000000000000000000
	for (i, x) in enumerate(ans):
		k = K
		elem = 0
		if k <= item - i:
			elem = ans[i + k - 1] - x + 1
		else:
			elem += 7 - x
			k -= item - i
			elem += k // item * 7
			k = k % item
			if k == 0:
				elem -= 7 - ans[-1] - 1
			else:
				elem += ans[k - 1] + 1
		res = min(res, elem)
	print(res)


def main():
	count = int(input())
	for x in range(count):
		lessons = int(input())
		arr = input().split()
		tot = 0
		for y in arr:
			if y == '1':
				tot += 1
		if lessons % tot == 0:
			a = lessons // tot - 1
			b = tot
		else:
			a = lessons // tot
			b = lessons % tot
		store = 7
		for y in range(7):
			test = 0
			for z in range(7):
				if arr[(y + z) % 7] == '1':
					test += 1
				if test == b:
					break
			store = min(store, z + 1)
		print(a * 7 + store)
main()


for _ in range(int(input())):
	k = int(input())
	a = tuple(map(int, input().split()))
	cnt = sum(a)
	(weeks, k) = divmod(k - 1, cnt)
	ans = 1 << 32
	for i in range(7):
		x = 0
		for j in range(7):
			x += a[(i + j) % 7]
			if x == k + 1:
				ans = min(ans, j + 1)
				break
	print(7 * weeks + ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	orga = list(map(int, input().split()))
	mini = pow(10, 8) * 7 + 1
	for i in range(7):
		a = orga[i:] + orga[0:i]
		one = a.count(1)
		weeks = n // one
		days = weeks * 7
		rem = n % one
		if rem == 0:
			days -= 7
			rem = one
		extday = 0
		for i in a:
			if rem == 0:
				break
			extday += 1
			if i == 1:
				rem -= 1
		mini = min(mini, days + extday)
	print(mini)


import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())
t = nu()
for it in range(t):
	k = nu()
	a = li()
	s = sum(a)
	zz = []
	for i in range(7):
		pp = 0
		cc = k
		for j in range(i, 7):
			pp += 1
			cc -= a[j]
			if cc == 0:
				break
		if cc == 0:
			zz.append(pp)
			continue
		kl = cc % s
		if kl == 0:
			nm = cc // s - 1
		else:
			nm = cc // s
		cc = cc - nm * s
		nm = nm * 7
		pp += nm
		for j in range(0, 7):
			if cc == 0:
				break
			pp += 1
			cc -= a[j]
		zz.append(pp)
	print(min(zz))


t = int(input())
for i in range(t):
	k = int(input())
	a = list(map(int, input().split()))
	wd = sum(a)
	rem = k % wd
	q = k // wd
	if rem == 0:
		rem = wd
		q = max(0, q - 1)
	ma = 10
	for i in range(7):
		ls = 0
		for j in range(i, i + 7):
			ls += a[j % 7]
			if ls >= rem:
				ma = min(ma, j - i + 1)
				break
	print(q * 7 + ma)


t = int(input())
for i in range(t):
	k = int(input())
	week = [int(x) for x in input().split()]
	i = 1
	need = {}
	happy = sun = 0
	answer = 10 ** 100
	for item in week:
		if item == 1:
			happy += 1
			need[happy] = i
		i += 1
	week.reverse()
	for item in week:
		if item == 0:
			sun += 1
		else:
			break
	week.reverse()
	need[0] = 0
	i = happy
	for item in week:
		if item == 1:
			counter = 8 - need[happy - i + 1] + (k - i) // happy * 7 + need[(k - i) % happy]
			if (k - i) % happy == 0:
				counter -= sun
			answer = min(answer, counter)
			i -= 1
	print(answer)


from collections import *
import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(rint()):
		(n, a) = (rint(), deque(rints()))
		(su, ans) = (sum(a), float('inf'))
		(days, mod) = divmod(n, su)
		if mod == 0:
			days -= 1
			mod = su
		for i in range(7):
			tem = 0
			for (j, k) in enumerate(a, 1):
				if k == 1:
					tem += 1
					if tem == mod:
						ans = min(ans, days * 7 + j)
						break
			a.rotate(-1)
		print(ans)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
BUFSIZE = 8192
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
main()


import sys
n = int(sys.stdin.readline())
for i in range(n):
	lessons = int(sys.stdin.readline())
	tmpSchedule = str(sys.stdin.readline()).split()
	ans = -1
	for j in range(7):
		schedule = [tmpSchedule[k % 7] for k in range(j, j + 7)]
		worked = []
		for i in range(len(schedule)):
			if schedule[i] == '1':
				worked.append(i + 1)
		atWeek = schedule.count('1')
		tmpAns = (lessons - 1) // atWeek * 7
		tmp = lessons % atWeek - 1
		if tmp < 0:
			tmp = len(worked) - 1
		tmpAns += worked[tmp] - worked[0] + 1
		if tmpAns < ans or ans == -1:
			ans = tmpAns
	print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		k = ri()
		a = ria()
		n1 = a.count(1)
		currdays = 7 * max(0, int(k / n1) - 1)
		kleft = k - max(0, n1 * (int(k / n1) - 1))
		da = 3 * a
		mi1 = 100
		mi2 = 100
		for i in range(7):
			c = 0
			if a[i] == 1:
				for j in range(i, 21):
					if da[j] == 1:
						c += 1
						if c == kleft:
							if currdays == 0:
								mi1 = min(mi1, j - i + 1)
							else:
								mi2 = min(mi2, max(0, j - i + 1))
		print(min(mi1, mi2) + currdays)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()