import sys
T = int(sys.stdin.readline().strip())
for _ in range(T):
    x = int(sys.stdin.readline().strip())
    s = list(sys.stdin.readline().strip())
    ls = len(s)
    for l in range(x):
        t = ord(s[l]) - ord('0') - 1
        ls = (ls + (ls - l - 1)*t) % ((10**9)+7)
        e = len(s)
        while len(s) <= x and t > 0:
            s += s[l+1:e]
            t -= 1

    print(ls)
