for i in range(int(input())):
    x = int(input())
    s = input()
    ans = len(s)
    a = x
    for j in range(1,x+1):
        if s[j-1] == '1':
            pass
        elif s[j-1] == '2':
            ans += (ans-j)
            ans %= (10**9+7)
            s = s + s[j:]
        elif s[j-1] == '3':
            ans += 2*(ans-j)
            ans %= (10**9+7)
            s = s + 2*s[j:]
        if len(s) > x:
            a = j
            break
    for k in range(a+1,x+1):
        if s[k-1] == '1':
            pass
        elif s[k-1] == '2':
            ans += (ans-k)
            ans %= (10**9+7)
        elif s[k-1] == '3':
            ans += 2*(ans-k)
            ans %= (10**9+7)
    ans %= (10**9+7)
    print(ans)
    