#
#   Bad python template TM
#
#       Zeyu, 2019
#

from sys import stdin, stdout, setrecursionlimit

input = stdin.readline
flush = stdout.flush

# setrecursionlimit(1000000)

############################################################

OUT = []


def write(item, sep=""):
    if type(item) is int or type(item) is long:
        OUT.append(str(item))
    elif type(item) is float:
        OUT.append("%.9f" % item)
    elif type(item) is list or type(item) is tuple:
        if len(item) == 0:
            OUT.append(" ")
        elif type(item[0]) is int:
            OUT.append(sep.join(map(str, item)))
        else:
            OUT.append(sep.join(item))
    else:
        OUT.append(item)


def PRINT(sep="\n"):
    print(sep.join(OUT))


GI = lambda: int(input())
GS = lambda: input().rstrip()

gi = lambda: list(map(int, input().split()))
gs = lambda: input().split()

digits = lambda i: list(map(int, str(i)))

############################################################
mod = pow(10, 9) + 7
t = GI()
for _ in xrange(t):
    x = GI()
    s = GS()
    arr = [0] * x
    for i, j in enumerate(map(int, s)):
        if i >= len(arr):
            break
        arr[i] = j
    tot = p = len(s)
    outside = 0
    for i in xrange(x):
        cur = arr[i] - 1
        lim = tot
        j = i + 1
        while cur and p < x and j < lim:
            arr[p] = arr[j]
            tot += 1
            p += 1
            j += 1
            if j == lim:
                cur -= 1
                j = i + 1
        if p >= x and cur > 0:
            rem = lim - j + (cur - 1) * (lim - i - 1)
            tot = (tot + rem) % mod
    print tot