import sys
mod=10**9+7
t=int(sys.stdin.readline())
for _ in range(t):
    x=int(sys.stdin.readline())
    z=1
    s=[i for i in sys.stdin.readline()][:-1]
    length=len(s)
    for i in range(1,x+1):
        #print(length,'length')
        #print(s,'s')
        if len(s)>=x:
            #print(int(s[i-1]))
            add=((length-i)%mod)*((int(s[i-1])-1)%mod)%mod
            length=(length+add)%mod
        else:
            count=0
            rep=(int(s[i-1])-1)
            start,end=i,len(s)
            for k in range(rep):
                for j in range(start,end):
                    s.append(s[j])
            add=((length-i)%mod)*((int(s[i-1])-1)%mod)%mod
            length=(length+add)%mod
    print(length)
            
