def solve(l,s):
    n = len(s)
    for i in range(l):
        n += (n-i-1)*(int(s[i])-1)
        n %= 7 + 10**9
        if len(s) < l:
            s += s[i+1:]*(int(s[i])-1)
    return n

for _ in range(int(input())):
    l = int(input())
    s = input()
    print(solve(l,s))