from sys import stdin


def fast2():
    import os, sys, atexit
    from cStringIO import StringIO as BytesIO
    # range = xrange
    sys.stdout = BytesIO()
    atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
    return BytesIO(os.read(0, os.fstat(0).st_size)).readline


input = fast2()
rint = lambda: int(input())
rstr = lambda: input().strip()
add = lambda a, b: (a + b) % mod
mult = lambda a, b: (a * b) % mod
mod = 10 ** 9 + 7
out = []

for _ in range(int(input())):
    n, s = rint(), list(rstr())
    le = len(s)
    for i in range(n):
        cur = int(s[i]) - 1
        while len(s) < n and cur:
            s += s[i + 1:le]
            cur -= 1

        le = add(le, mult(int(s[i]) - 1, add(le, -(i + 1))))

    out.append(le)
print('\n'.join(map(str, out)))
