import sys
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
mod = 10**9+7
for _ in range(t):
    x = int(input())
    s = list(map(int, list(input())))
    ans = len(s)
    cnt = ans
    flg = True
    for i in range(x):
        ans += (s[i]-1)*(ans-i-1)
        if len(s) > x:
            flg = False
        if flg:
            l = len(s)
            for j in range((l-i-1)*(s[i]-1)):
                s.append(s[i+1+j%(l-i-1)])
                cnt += 1
                if cnt>x:
                    break
        ans %= mod
    print(ans)