mod = int(1e9+7)

t = int(input())

for _ in range(t):
    x = int(input())
    s = map(int,raw_input())
    arr = [0]*(x+5)
    l1 = len(s)
    arr[:l1] = s
    flag = True
    for i in range(x):
        l = i+1
        ad = (l1-l+mod)%mod
        for j in range(arr[l-1]-1):
            if l1 <= x+1 and flag:
                arr[l1:min(x+1,l1+ad)] = arr[l:min(x+1,l1+ad)-l1+l]
            else:
                flag = False
            l1 = (l1+ad)%mod
    print l1
