t = int(input())
ans = []
arr = [None] * (10 ** 6)
cur = 0
MOD = 10 ** 9 + 7

for _ in range(t):
    x, s = int(input()), list(map(int, str(input())))
    max_p = cur + x

    for i in range(cur, min(max_p, cur + len(s))):
        arr[i] = s[i - cur]

    def copy(start, length, times):
        b = start + length
        for i in range(times):
            for j in range(length):
                if b >= max_p: return
                arr[b] = arr[start + j]
                b += 1

    val = len(s)
    cnt = 1
    while x:
        if arr[max_p - 1] is None and arr[cur] > 1:
            copy(cur + 1, val - cnt, arr[cur] - 1)
        val = (cnt + (val - cnt) * arr[cur]) % MOD
        cnt += 1
        cur += 1
        x -= 1

    ans.append(val)

for a in ans:
    print(a)