import sys
 
 
reader = (line.rstrip() for line in sys.stdin)
 
t = int(next(reader))
modulo = 10 ** 9 + 7
for _ in range(t):
    x = int(next(reader))
    s = [int(i) for i in next(reader)]
    l = 0
    total = len(s)
    while l < x:
        l += 1
        k = s[l-1]
        if len(s) < x:
            n = len(s)
            for _ in range(k - 1):
                s.extend(s[l:n])
            total = len(s)
        else:
            total += (k - 1) * (total - l)
            total %= modulo
    print(total)