← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

const MOD int64 = 1000000007

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var x int
		var s string
		fmt.Fscan(in, &x)
		fmt.Fscan(in, &s)

		n := int64(len(s))
		buf := []byte(s)

		for i := 0; i < x; i++ {
			d := int64(buf[i] - '0')
			remaining := (n - int64(i) - 1) % MOD
			add := (remaining * ((d - 1) % MOD)) % MOD
			n = (n + add) % MOD

			if len(buf) < x {
				curLen := len(buf)
				if curLen < i+1 {
					curLen = i + 1
				}
				suf := make([]byte, 0, curLen-(i+1))
				if i+1 < len(buf) {
					suf = append(suf, buf[i+1:]...)
				}
				need := x - len(buf)
				toAppend := make([]byte, 0, need)
				for rep := int64(0); rep < d-1 && len(toAppend) < need; rep++ {
					if len(suf) == 0 {
						break
					}
					if len(suf) <= need-len(toAppend) {
						toAppend = append(toAppend, suf...)
					} else {
						toAppend = append(toAppend, suf[:need-len(toAppend)]...)
					}
				}
				buf = append(buf, toAppend...)
			}
		}

		fmt.Fprintln(out, n%MOD)
	}
}
```