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

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