t=int(input())
for i in range(t):
    x=int(input())
    y=input()
    s=[]
    for j in y:
        s.append(j)
    l=0
    res=len(s)
    while(l!=x):
        if len(s)<x:
            le=len(s)
            for p in range(int(s[l])-1):
                for j in range(l + 1, le):
                    s.append(s[j])
        res=(res+(res-l-1)*(int(s[l])-1))%(10**9+7)
        l+=1
    print(res%(10**9+7))







