for _ in range(input()):
    x = input()
    s = raw_input()
    t = map(int, s)
    real_len = len(s)
    idx = 0
    while 1:
        idx += 1
        k = t[idx - 1]
        if k != 1:
            k -= 1
            right_len = real_len - idx
            real_len = (real_len + right_len * k) % 1000000007

            length = len(t)
            for i in range(k):
                if len(t) < x:
                    t += t[idx: length]
                else:
                    break
        else:
            add_len = 0
        if idx == x:
            print real_len
            break