ttt = int(input())
mod = 10**9 + 7
s = "#"*(10**6 + 1500)
s=list(s)
for bo in range(ttt):
    x=int(input())
    st=input()
    s[1:len(st)+1]=list(st)
    siz=len(st)
    p = 0
    while siz < x:
        p += 1
        whe = siz
        for de4d in range(int(s[p])-1):
            for k in range(p+1,whe+1):
                siz += 1
                s[siz] = s[k]
                if (siz>x):
                    break
            if (siz>x):
                break
        if (siz>x):
            break
    ans = len(st)
    for i in range(1,x+1):
        ans = i + (ans-i)*int(s[i])
        ans = ans%mod
    print(ans)