from sys import stdin

rint = lambda: int(stdin.readline())
rstr = lambda: stdin.readline().strip()
add = lambda a, b: (a + b) % mod
mult = lambda a, b: (a * b) % mod
mod = 10 ** 9 + 7
out = []

for _ in range(int(input())):
    n, s = rint(), list(rstr())
    le = len(s)
    for i in range(n):
        cur = int(s[i]) - 1
        while len(s) < n and cur:
            s += s[i + 1:le]
            cur -= 1

        le = add(le, mult(int(s[i]) - 1, add(le, -(i + 1))))
    print(le)
