"""
NTC here
"""
from sys import stdin
# import threading
# setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(stdin.readline())
def lin(): return list(map(int, stdin.readline().split()))

# range = xrange
# input = raw_input

md=10**9+7

def main():
    t=iin()
    while t:
        t-=1
        x=iin()
        s=list(input())
        l=len(s)
        ans=l
        i=0
        while i<x:
            i+=1
            ch=int(s[i-1])
            ans=(i+ch*(ans-i))%md 
            if l>=x:continue
            incr=l
            ss=[]
            for _ in range(ch):
                for j in range(i,l):
                    if incr<ans and incr<x:
                        ss.append(s[j])
                        incr+=1
                    else:
                        break
            l=incr
            for k in ss:s.append(k)
            #print(ans, l, s)
        print(ans%md)




        
main()
#threading.Thread(target=main).start()
