```go
package main
import (
"bufio"
"io"
"os"
)
func main() {
data, _ := io.ReadAll(os.Stdin)
pos := 0
next := func() []byte {
n := len(data)
for pos < n && data[pos] <= ' ' {
pos++
}
start := pos
for pos < n && data[pos] > ' ' {
pos++
}
return data[start:pos]
}
s := next()
n := len(s)
pi := make([]int32, n)
if n > 0 {
for i := 1; i < n; i++ {
j := int(pi[i-1])
for j > 0 && s[i] != s[j] {
j = int(pi[j-1])
}
if s[i] == s[j] {
j++
}
pi[i] = int32(j)
}
}
aut := make([]int32, (n+1)*26)
if n > 0 {
for c := 0; c < 26; c++ {
if byte('a'+c) == s[0] {
aut[c] = 1
} else {
aut[c] = 0
}
}
for j := 1; j <= n; j++ {
row := j * 26
base := int(pi[j-1]) * 26
for c := 0; c < 26; c++ {
if j < n && byte('a'+c) == s[j] {
aut[row+c] = int32(j + 1)
} else {
aut[row+c] = aut[base+c]
}
}
}
}
qb := next()
q := 0
for i := 0; i < len(qb); i++ {
q = q*10 + int(qb[i]-'0')
}
w := bufio.NewWriterSize(os.Stdout, 1<<20)
defer w.Flush()
appendInt := func(dst []byte, v int32) []byte {
if v == 0 {
return append(dst, '0')
}
var buf [12]byte
i := len(buf)
x := int(v)
for x > 0 {
i--
buf[i] = byte('0' + (x % 10))
x /= 10
}
return append(dst, buf[i:]...)
}
for ; q > 0; q-- {
t := next()
m := len(t)
ext := make([]int32, m)
var j int32
if n > 0 {
j = pi[n-1]
} else {
j = 0
}
out := make([]byte, 0, m*3)
getPi := func(k int32) int32 {
if int(k) < n {
return pi[k]
}
return ext[int(k)-n]
}
for i := 0; i < m; i++ {
c := int(t[i] - 'a')
for int(j) > n {
if t[int(j)-n] == t[i] {
j++
goto store
}
j = getPi(j - 1)
}
if int(j) == n {
if n > 0 && t[0] == t[i] {
j++
} else {
j = aut[n*26+c]
}
} else {
j = aut[int(j)*26+c]
}
store:
ext[i] = j
out = appendInt(out, j)
if i+1 < m {
out = append(out, ' ')
} else {
out = append(out, '\n')
}
}
w.Write(out)
}
}
```