for _ in range(int(input())):
    x=int(input())
    s=list(map(int, input()))
    ans=len(s)
    l=1
    while l<=x:
        ans=((ans-l)*s[l-1]+l)%1000000007
        for _ in range(s[l-1]-1):
            if len(s)<x:
                s+=s[l:]
            else:
                break
        l+=1
    print(ans)
    