```go
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func getTransition(d string, v byte, V_edge string) (bool, string, byte) {
lenD := len(d)
lenV := len(V_edge)
minLen := lenD
if lenV < minLen {
minLen = lenV
}
for i := 0; i < minLen; i++ {
if d[i] != V_edge[i] {
return false, "", 0
}
}
if lenD < lenV {
if V_edge[lenD] != v {
return false, "", 0
}
new_d := V_edge[lenD+1:]
if len(new_d) == 0 {
return true, "", 0
}
return true, new_d, 1
} else {
new_d := d[lenV:] + string([]byte{v})
return true, new_d, 0
}
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
buf := make([]byte, 10*1024*1024)
scanner.Buffer(buf, 10*1024*1024)
nextInt := func() int {
scanner.Scan()
res, _ := strconv.Atoi(scanner.Text())
return res
}
if !scanner.Scan() {
return
}
n, _ := strconv.Atoi(scanner.Text())
m := nextInt()
edges := make(map[byte]map[byte]string)
for i := 1; i <= n; i++ {
edges[byte(i)] = make(map[byte]string)
}
for i := 0; i < m; i++ {
u := byte(nextInt())
v := byte(nextInt())
k := nextInt()
vision := make([]byte, k)
for j := 0; j < k; j++ {
vision[j] = byte(nextInt())
}
edges[u][v] = string(vision)
}
maxLen := 2 * n
MOD := 1000000007
type State struct {
u byte
t byte
d string
}
current := make(map[State]int)
for i := 1; i <= n; i++ {
s := State{u: byte(i), t: 0, d: string([]byte{byte(i)})}
current[s] = 1
}
var firstValidPath []int
parents := make([]map[State]State, maxLen+1)
for i := 0; i <= maxLen; i++ {
parents[i] = make(map[State]State)
}
ansE2 := make([]int, maxLen+1)
for step := 1; step <= maxLen; step++ {
nextMap := make(map[State]int)
for state, count := range current {
if state.t == 1 {
v := state.d[0]
if V_edge, exists := edges[state.u][v]; exists {
new_d := state.d[1:] + V_edge
if step+len(new_d) <= maxLen {
new_t := byte(1)
if len(new_d) == 0 {
new_t = 0
}
ns := State{u: v, t: new_t, d: new_d}
nextMap[ns] = (nextMap[ns] + count) % MOD
if firstValidPath == nil {
if _, exists := parents[step][ns]; !exists {
parents[step][ns] = state
}
}
}
}
} else {
for v, V_edge := range edges[state.u] {
ok, new_d, new_t := getTransition(state.d, v, V_edge)
if ok {
if new_t == 1 && step+len(new_d) > maxLen {
continue
}
ns := State{u: v, t: new_t, d: new_d}
nextMap[ns] = (nextMap[ns] + count) % MOD
if firstValidPath == nil {
if _, exists := parents[step][ns]; !exists {
parents[step][ns] = state
}
}
}
}
}
}
current = nextMap
for state, count := range current {
if state.t == 0 && state.d == "" {
ansE2[step] = (ansE2[step] + count) % MOD
if firstValidPath == nil {
path := make([]int, step+1)
currState := state
for s := step; s >= 0; s-- {
path[s] = int(currState.u)
if s > 0 {
currState = parents[s][currState]
}
}
firstValidPath = path
}
}
}
}
if firstValidPath == nil {
fmt.Println(0)
} else {
fmt.Println(len(firstValidPath))
for i, x := range firstValidPath {
if i > 0 {
fmt.Print(" ")
}
fmt.Print(x)
}
fmt.Println()
}
for step := 1; step <= maxLen; step++ {
fmt.Println(ansE2[step])
}
}
```