def zip_sorted(a,b): return zip(*sorted(zip(a,b)))[0],zip(*sorted(zip(a,b)))[1]
def gcd(a,b): return math.gcd(a,b)
def lcm(a,b): return ((a*b)//math.gcd(a,b))
def ncr(n,r): return math.comb(n,r)
def npr(n,r): return (math.factorial(n)//math.factorial(n-r))
def decimal_to_binary(n): return bin(n).replace("0b", "")
def binary_to_decimal(s): return int(s,2)

import sys, os.path
import math
from collections import defaultdict,deque

input = sys.stdin.readline

I = lambda : list(map(int,input().split()))
S = lambda : list(map(str,input()))

def main():

	t,=I()
	for t1 in range(t):
		x, = I()
		s 	= S()[:-1]
		if len(set(s))==1:
			k = int(s[0])
			for i in range(x):
				count1-=1
				count1%=((10**9)+7)
				count1*=k
				count1%=((10**9)+7)
			count1 = count1+x
			count1%=((10**9)+7)
			print(count1)		

		else:

			l = 0
			count = 0
			count1 = len(s)
			count1%=((10**9)+7)
			s1 = ''.join(s)
			for i in range(x):
				k = int(s1[0])
				count1-=1
				count1%=((10**9)+7)
				s1  = s1[1:]
				if count1>x:	
					count1*=k
					count1%=((10**9)+7)
				else:
					s1+=(s1[:]*(k-1))
					count1*=k
					count1%=((10**9)+7)
			count1 = count1+x
			count1%=((10**9)+7)
			print(count1)

main()
