for _ in range(int(input())):
    x = int(input())
    s = list(input())
    l = 0
    ans = len(s)
    while(l<x):
        if(ans>=x):
            break
        temp = len(s)
        ans+=(int(s[l])-1)*(temp-l-1)
        for i in range(int(s[l])-1):
            if(len(s)>x):
                break
            for j in range(l+1,temp):
                s.append(s[j])
                if(len(s)>x):
                    break
        l+=1
    while(l<x):
        temp = ans
        ans+=(int(s[l])-1)*(temp-l-1)
        ans = ans%(10**9+7)
        l+=1
    print(ans)