import sys
input=sys.stdin.readline
t=int(input())
co=0
mod=10**9+7
for _ in range(t):
    x=int(input())
    arr=list(map(int,input().strip()))
    note=arr[:]
    ans=len(note)
    
    for i in range(x):
        ans=(ans-(i+1))*(note[i])+(i+1)
        if(ans<0):
            ans+=mod
        #print(ans)
        ans=ans%mod
        
        temp=[]
        for j in range(note[i]-1):
            if(len(note)+len(temp)<x):
                temp+=note[i+1:]
            else:
                break
        #print(temp)
        #print(note) 
        note+=temp
    
    print(ans%mod)
                    
                    
                     
                        
                
            
        
    
   