#Bhargey Mehta (Junior)
#DA-IICT, Gandhinagar
import sys, math
MOD = 10**9+7
#sys.stdin = open('input.txt', 'r')

for _ in range(int(input())):
    x = int(input())
    s = list(map(int, list(input())))
    ans = len(s)
    
    l, lens = 1, len(s)
    s = s + [0]*(x-len(s))
    for l in range(1, x+1):
        for i in range(lens, min((lens-l)*s[l-1]+l, len(s))):
            s[i] = s[l+i-lens]

        lens = min((lens-l)*s[l-1]+l, len(s))
        if lens == len(s):
            break

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