M = 1000000007
t = int(input())
while t:
    t += -1
    x = int(input())
    s = input()
    i = 0
    while len(s) < x:
        s += s[i + 1: ] * (int(s[i]) - 1)
        i += 1
    n = len(s)
    for j in range(i, x):
        tmp = n - (j + 1)
        n = j + 1 + tmp * (int(s[j]))
        n = n % M
    print(n % M)