for _ in range(input()):
    x = input()
    s = raw_input()
    t = [0] * x
    real_len = length = len(s)
    for i in range(min(length, x)):
        t[i] = int(s[i]) - 1
    idx = 0
    while 1:
        idx += 1
        k = t[idx - 1]
        if k != 0:
            right_len = real_len - idx
            add_len = max(min(right_len * k, x - length), 0)
            real_len = (real_len + right_len * k) % 1000000007
        else:
            add_len = 0
        if idx == x:
            print real_len
            break
        for i in range(add_len):
            t[length + i] = t[idx + i]
        length += add_len
