for _ in range(int(input())):
    x=int(input())
    a=input()
    l=len(a)
    a=[i for i in a]
    ans=l
    p=0
    m=10**9+7
    while ans<x:
        for j in range(int(a[p])-1):
            for i in range(p+1,ans):
                a.append(a[i])
        ans+=(int(a[p])-1)*((ans-p-1+m)%m)
        p+=1
    for j in range(p,x):
        ans+=(int(a[j])-1)*((ans-j-1+m)%m)
        ans%=m
    print(ans)
        
        