# 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():

# 	# s1 = [0]*((2*(10**6))+1)
# 	t,=I()
# 	for t1 in range(t):
# 		x, = I()
# 		s1 	= str(input()).rstrip('\n')
# 		# for i in range(len(s2)):
# 		# 	s1[i] = int(s2[i])
# 		l = 0
# 		count = 0
# 		count1 = len(s1)
# 		count1%=((10**9)+7)
# 		for i in range(x):
# 			k = int(s1[i])
# 			count1-=1
# 			count1%=((10**9)+7)
# 			if count1>x:	
# 				count1*=k
# 				count1%=((10**9)+7)
# 			else:
# 				l1 = len(s1)
# 				for j in range(k-1):
# 					for l in range(i+1,l1):
# 						s1+=s1[l]
# 				count1*=k
# 				count1%=((10**9)+7)
# 		count1+=x
# 		count1%=((10**9)+7)
# 		print(count1)

# main()


import sys
 
input = sys.stdin.readline
 
mod = 10 ** 9 + 7
t = int(input())
for _ in range(t):
    x = int(input())
    s = input().rstrip('\n')
 
    X = []
    for i, si in enumerate(s):
        if i == x:
            break
        X.append(int(s[i]))
    ans = len(s)
    for i in range(x):
        ans = (ans + (ans - i - 1) * (X[i] - 1)) % mod
        if len(X) < x:
            if X[i] == 1:
                continue
            X_ = X[i + 1:]
            for j in range(X[i] - 1):
                if len(X) < x:
                    X.extend(X_)
    print(ans)