for _ in range(int(input())):
    n=int(input())
    a=[0]*n
    tmp=input()
    ans=last=len(tmp)
    for i,x in enumerate(tmp):
        if i==n:
            last=n
            break
        a[i]=int(x)
    
    
    for i in range(n):
        ans=(ans-i-1)*a[i]+i+1
        ans%=(10**9+7)
        k=last
        for _ in range(a[i]-1):
            for j in range(i+1,last):
                if k==n:
                    break
                a[k]=a[j]
                k+=1
        last=k
    
    print(ans%(10**9+7))
    #print()