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