for _ in range(input()):
    x = input()
    s = map(int, raw_input())
    ans=len(s)
    l = 1
    while l<=x:
        k = s[l - 1]
        ans = ((ans - l) * k + l) % 1000000007
        r = len(s)
        for i in range(k - 1):
            if len(s) < x:
                s += s[l: r]
            else:
                break
        l += 1
    print ans