def fastio():
	import sys
	from io import StringIO 
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from collections import defaultdict as dd

t, = I()
while t:
	t -= 1
	x, = I()
	s = list(input())
	n = len(s)
	cur = len(s)
	for i in range(1, x+1):
		k = int(s[i-1])
		if k >= 2 and n <= x:
			for j in range(1, k):
				for ii in range(i, n):
					s.append(s[ii])
					n += 1
					if n > x:
						break
				if n > x:
					break
		cur = (i + ((cur - i)*k)%MOD)
		# print(cur)
	print(cur)