n = int(input())
import math

def getdb(s, x):
    l = 1
    newS = s
    while len(newS) <= x:
        newS = newS[0:l] + newS[l - 1] * newS[l:]
        l += 1
    return newS

for i in range(n):
    x = int(input())
    s = [int(x) for x in input()]
    
    dbli = getdb(s,x)
    print(*dbli)
    tot = len(s)
    l = 1
    while l <= x:
        tot = l + dbli[l - 1]*(tot - l)
        if math.log(tot) > 9.01:
            tot %= (10**9 + 7)
        l += 1
        
    print(tot % (10**9 + 7))