def main():
	MOD = int(1e9 + 7)
	n = int(input())
	string = str(input())
	i = 0
	while len(string)<n:
		temp = int(string[i])
		string = string + string[i+1:]*(temp-1)
		i+=1
	ans = len(string)
	if(i<n):
		while i<n:
			temp = int(string[i])
			ans += ((temp-1)*(ans-i-1))
			ans = ans%MOD
			i+=1
	print(ans)
	return
def test():
    t = int(input())
    while(t):
        main()
        t-=1
    return
test()
# main()