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