import time
import sys

MOD = 1e9 + 7
# f = open('test.txt', 'w+')
# f.write("1\n333047\n")
# f.write('1'*300 + '2' + '1'*20 + '2')
# f.seek(0)

f = sys.stdin
t1 = time.time()
for t in range(int(f.readline())):
    x, s = int(f.readline().rstrip()), f.readline().rstrip()
    i = 0
    while len(s) < x:
        i += 1
        s += s[i:] * (int(s[i - 1])-1)
    answer = len(s)
    while i < x:
        i += 1
        answer = (answer + (answer - i) * (int(s[i - 1]) - 1)) % MOD
    print(int(answer))
# print("--- %s seconds ---" % (time.time() - t1))
