def main():
    TT = int(input())
    for _ in range(TT):
        x = int(input())
        s = [int(c) for c in input().strip()]
        ans = len(s)

        for l in range(0, x):
            ans += (ans - l - 1) * (s[l] - 1)
            ans %= 1000000007

            end = len(s)
            for _ in range(1, s[l]):
                if len(s) > x + 1:
                    break
                for c in range(l + 1, end):
                    if len(s) > x + 1:
                        break
                    s.append(s[c])

        print(ans)

if __name__ == '__main__':
    main()