// 1714D. Color with Occurrences
package main

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

type Pair struct {
	w, p, l int
}

var ans []Pair

func substring(st string, start int, sub string) bool {
	for i := 0; i < len(sub); i++ {
		if start+i >= len(st) {
			return false
		}
		if sub[i] != st[start+i] {
			return false
		}
	}
	return true
}
func backtrack(st string, start int, pairs []Pair, so_far []Pair) {
	if start == len(st) {
		if ans == nil || len(so_far) < len(ans) {
			ans = make([]Pair, len(so_far))
			for i := 0; i < len(so_far); i++ {
				ans[i] = so_far[i]
			}
		}
	}
	greatest := Pair{w: -1, l: -1, p: -1}
	for i := 0; i < len(pairs); i++ {
		if pairs[i].p <= start && pairs[i].p+pairs[i].l > start {
			if greatest.w == -1 || greatest.p+greatest.l < pairs[i].p+pairs[i].l {
				greatest = pairs[i]
			}
		}
	}
	if greatest.w != -1 {
		so_far = append(so_far, greatest)
		backtrack(st, greatest.p+greatest.l, pairs, so_far)
		so_far = so_far[:len(so_far)-1]
	}

}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var st string
		fmt.Fscan(reader, &st)
		var n int
		fmt.Fscan(reader, &n)
		s := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &s[i])
		}
		all_pairs := make([]Pair, 0)
		for i := 0; i < len(st); i++ {
			for j := 0; j < n; j++ {
				if substring(st, i, s[j]) {
					all_pairs = append(all_pairs, Pair{w: j, p: i, l: len(s[j])})
				}
			}
		}
		ans = nil
		so_far := make([]Pair, 0)
		backtrack(st, 0, all_pairs, so_far)
		if ans == nil {
			fmt.Println(-1)
		} else {
			fmt.Println(len(ans))
			for i := 0; i < len(ans); i++ {
				fmt.Println(ans[i].w+1, ans[i].p+1)
			}
		}
	}
}

package main

import (
	"fmt"
	"os"
	"sort"
)

var in = os.Stdin
var out = os.Stdout

func qwq() {
	var n int
	var s string
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &n)
	ss := make([]string, n)
	type P struct {
		l, r, id int
	}
	ps := []P{}
	filter := []P{}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ss[i])
		for j := 0; j+len(ss[i])-1 < len(s); j++ {
			if s[j:j+len(ss[i])] == ss[i] {
				ps = append(ps, P{j, j + len(ss[i]) - 1, i + 1})
			}
		}
	}

	sort.Slice(ps, func(i, j int) bool {
		if ps[i].l == ps[j].l {
			return ps[i].r < ps[j].r
		}
		return ps[i].l < ps[j].l
	})

	ans := []P{}
	r := -1
	for i := 0; i < len(ps); i++ {
		for i+1 < len(ps) && ps[i].l == ps[i+1].l {
			i++
		}
		filter = append(filter, ps[i])
	}
	for i := 0; r < len(s)-1 && i < len(filter); {
		id := -1
		imax := r
		for i < len(filter) && filter[i].l <= r+1 {
			if filter[i].r > imax {
				imax = filter[i].r
				id = i
			}
			i++
		}
		if id == -1 {
			fmt.Fprintln(out, -1)
			return
		}
		ans = append(ans, filter[id])
		r = imax
	}
	if len(ans) == 0 || r < len(s)-1 {
		fmt.Fprintln(out, -1)
		return
	}
	fmt.Fprintln(out, len(ans))
	for _, l := range ans {
		fmt.Fprintln(out, l.id, l.l+1)
	}
}

func main() {
	// defer out.Flush()
	q := 1

	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		qwq()
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var c = 0
var qq = 0

func qwq() {
	c++
	var n int
	var s string
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &n)
	ss := make([]string, n)
	type P struct {
		l, r, id int
	}
	ps := []P{}
	filter := []P{}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ss[i])
		for j := 0; j+len(ss[i])-1 < len(s); j++ {
			if s[j:j+len(ss[i])] == ss[i] {
				ps = append(ps, P{j, j + len(ss[i]) - 1, i + 1})
			}
		}
	}
	// if qq == 100 && c == 27 {
	// 	fmt.Fprintln(out, n, s, ss)
	// 	return
	// } else if qq == 100 {

	// 	return
	// }

	sort.Slice(ps, func(i, j int) bool {
		if ps[i].l == ps[j].l {
			return ps[i].r < ps[j].r
		}
		return ps[i].l < ps[j].l
	})
	// fmt.Fprintln(out, ps)

	ans := []P{}
	r := -1
	for i := 0; i < len(ps); i++ {
		for i+1 < len(ps) && ps[i].l == ps[i+1].l {
			i++
		}
		filter = append(filter, ps[i])
	}
	// fmt.Fprintln(out, filter)
	for i := 0; r < len(s)-1 && i < len(filter); {
		id := -1
		imax := r
		for i < len(filter) && filter[i].l <= r+1 {
			if filter[i].r > imax {
				imax = filter[i].r
				id = i
			}
			i++
		}
		if id == -1 {
			fmt.Fprintln(out, -1)
			return
		}
		ans = append(ans, filter[id])
		r = imax
	}
	if len(ans) == 0 || r < len(s)-1 {
		fmt.Fprintln(out, -1)
		return
	}
	fmt.Fprintln(out, len(ans))
	for _, l := range ans {
		fmt.Fprintln(out, l.id, l.l+1)
	}
}

func main() {
	defer out.Flush()
	q := 1

	fmt.Fscan(in, &q)
	qq = q
	for ; q > 0; q-- {
		qwq()
	}

}

package main

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

const (
	N = 1e5 + 5
)

var n, sLen int
var s string
var strs []string
var cnt []int

func check(i int, str string) bool {
	ls := len(str)
	if ls > i {
		return false
	}
	for pos := range str {
		if s[i-ls+pos] != str[pos] {
			return false
		}
	}
	return true
}
func cal(a, b int) int {
	if a == -1 || a > b {
		return b
	}
	return a
}

type line struct {
	l, r, id int
}

func addAns(ans *[]line, l line) bool {
	le := len(*ans)
	if le == 0 || (*ans)[le-1].r < l.r {
		*ans = append(*ans, l)
		return true
	}
	return false
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for o := 0; o < t; o++ {
		fmt.Fscan(in, &s)
		fmt.Fscan(in, &n)
		lines := make([]line, 0)
		sLen = len(s)
		strs = make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &strs[i])
		}
		for i := 1; i <= sLen; i++ {
			for j, v := range strs {
				if check(i, v) {
					lines = append(lines, line{i - len(v) + 1, i, j + 1})
				}
			}
		}
		if len(lines) == 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		sort.Slice(lines, func(i, j int) bool {
			if lines[i].l != lines[j].l {
				return lines[i].l < lines[j].l
			}
			return lines[i].r > lines[j].r
		})
		ans := make([]line, 0)
		last, temp := 0, -1
		i, ls := 0, len(lines)
		for i < ls {
			temp = -1
			for i < ls && lines[i].l <= last+1 {
				if temp == -1 || lines[temp].r < lines[i].r {
					temp = i
				}
				i++
			}
			if temp == -1 {
				break
			}
			flag := addAns(&ans, lines[temp])
			if flag {
				last = lines[temp].r
			}
		}
		flag := last == sLen
		if flag {
			fmt.Fprintln(out, len(ans))
			for _, v := range ans {
				fmt.Fprintln(out, v.id, v.l)
			}
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}

package main

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

const (
	N = 1e5 + 5
)

var n, sLen int
var s string
var strs []string
var cnt []int

func check(i int, str string) bool {
	ls := len(str)
	if ls > i {
		return false
	}
	for pos := range str {
		if s[i-ls+pos] != str[pos] {
			return false
		}
	}
	return true
}
func cal(a, b int) int {
	if a == -1 || a > b {
		return b
	}
	return a
}

type line struct {
	l, r, id int
}

func addAns(ans *[]line, l line) bool {
	le := len(*ans)
	if le == 0 || (*ans)[le-1].r < l.r {
		*ans = append(*ans, l)
		return true
	}
	return false
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for o := 0; o < t; o++ {
		fmt.Fscan(in, &s)
		fmt.Fscan(in, &n)
		lines := make([]line, 0)
		sLen = len(s)
		strs = make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &strs[i])
		}
		for i := 1; i <= sLen; i++ {
			for j, v := range strs {
				if check(i, v) {
					lines = append(lines, line{i - len(v) + 1, i, j + 1})
				}
			}
		}
		if len(lines) == 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		sort.Slice(lines, func(i, j int) bool {
			if lines[i].l != lines[j].l {
				return lines[i].l < lines[j].l
			}
			return lines[i].r > lines[j].r
		})
		//fmt.Fprintln(out, lines)
		ans := make([]line, 0)
		last, temp := 0, -1
		i, ls := 0, len(lines)
		for i < ls {
			temp = -1
			for i < ls && lines[i].l <= last+1 {
				if temp == -1 || lines[temp].r < lines[i].r {
					temp = i
				}
				i++
			}
			if temp == -1 {
				break
			}
			flag := addAns(&ans, lines[temp])
			if flag {
				last = lines[temp].r
			}
		}
		cnt = make([]int, sLen+2)
		for _, v := range ans {
			cnt[v.l]++
			cnt[v.r+1]--
		}
		flag := last == sLen
		//fmt.Fprintln(out, ans)
		if flag {
			fmt.Fprintln(out, len(ans))
			for _, v := range ans {
				fmt.Fprintln(out, v.id, v.l)
			}
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}

package main

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

const (
	N = 1e5 + 5
)

var n, sLen int
var s string
var strs []string
var cnt []int

func check(i int, str string) bool {
	ls := len(str)
	if ls > i {
		return false
	}
	for pos := range str {
		if s[i-ls+pos] != str[pos] {
			return false
		}
	}
	return true
}
func cal(a, b int) int {
	if a == -1 || a > b {
		return b
	}
	return a
}

type line struct {
	l, r, id int
}

func addAns(ans *[]line, l line) bool {
	le := len(*ans)
	if le == 0 || (*ans)[le-1].r < l.r {
		*ans = append(*ans, l)
		return true
	}
	return false
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for o := 0; o < t; o++ {
		fmt.Fscan(in, &s)
		fmt.Fscan(in, &n)
		lines := make([]line, 0)
		sLen = len(s)
		strs = make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &strs[i])
		}
		for i := 1; i <= sLen; i++ {
			for j, v := range strs {
				if check(i, v) {
					lines = append(lines, line{i - len(v) + 1, i, j + 1})
				}
			}
		}
		if len(lines) == 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		sort.Slice(lines, func(i, j int) bool {
			if lines[i].l != lines[j].l {
				return lines[i].l < lines[j].l
			}
			return lines[i].r > lines[j].r
		})
		//fmt.Fprintln(out, lines)
		ans := make([]line, 0)
		last, temp := 0, -1
		i, ls := 0, len(lines)
		for i < ls {
			temp = -1
			for i < ls && lines[i].l <= last+1 {
				if temp == -1 || lines[temp].r < lines[i].r {
					temp = i
				}
				i++
			}
			if temp == -1 {
				break
			}
			flag := addAns(&ans, lines[temp])
			if flag {
				last = lines[temp].r
			}
		}
		cnt = make([]int, sLen+2)
		for _, v := range ans {
			cnt[v.l]++
			cnt[v.r+1]--
		}
		flag := true
		for i := 1; i <= sLen; i++ {
			cnt[i] += cnt[i-1]
			if cnt[i] == 0 {
				flag = false
			}
		}
		//fmt.Fprintln(out, ans)
		if flag {
			fmt.Fprintln(out, len(ans))
			for _, v := range ans {
				fmt.Fprintln(out, v.id, v.l)
			}
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

type Node struct {
	id         int
	start, end int
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func exec() {
	var t string
	fmt.Scan(&t)
	var n int
	fmt.Scan(&n)

	var s = make([]string, n)
	var records = make([]*Node, 0, 100)

	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
		for j := 0; j < len(t)-len(s[i])+1; j++ {
			var check = true
			for h := j; h < j+len(s[i]); h++ {
				if t[h] != s[i][h-j] {
					check = false
					break
				}
			}
			if check {
				records = append(records, &Node{i, j, j + len(s[i])})
			}
		}
	}
	// fmt.Println("test", t, s)

	sort.Slice(records, func(i, j int) bool {
		if records[i].start == records[j].start {
			return records[i].end > records[j].end
		}
		return records[i].start < records[j].start
	})
	// for i := range records {
	// 	fmt.Println("records", records[i].id, records[i].start, records[i].end)
	// }
	var ret = make([]*Node, 0)

	var prev = 0
	var cur = 0
	for cur < len(records) {
		// fmt.Println(cur, ret)
		if prev < records[cur].start {
			fmt.Println(-1)
			return
		}
		ret = append(ret, records[cur])

		if records[cur].end == len(t) {
			break
		}
		var j = cur
		var m, max = j, records[j].end

		for j < len(records) && records[j].start <= records[cur].end {
			if max < records[j].end {
				m = j
				max = records[j].end
			}
			j += 1
		}
		if max == records[cur].end {
			fmt.Println(-1)
			return
		}
		prev = records[cur].end
		cur = m
	}
	if len(ret) == 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(len(ret))
	for i := 0; i < len(ret); i++ {
		fmt.Println(ret[i].id+1, ret[i].start+1)
	}
}

func main() {
	var T int
	fmt.Scan(&T)
	for it := 0; it < T; it++ {
		exec()
	}
}

package main

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

var (
	in = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

const (
	oo = 26072000
)

func ReadInt() int {
	var i int
	fmt.Fscan(in, &i)
	return i
}

func ReadString() string{
	var s string
	fmt.Fscan(in, &s)
	return s
}

func main(){
	defer out.Flush()

	testCases := ReadInt()

	for ; testCases > 0; testCases-- {
		text := ReadString()

		lt := len(text)
		n := ReadInt()

		cache := make(map[string]int)

		for i := 1; i <= n; i++ {
			s := ReadString()
			cache[s] = i
		}

		dp := make([]int, lt + 1)
		traceBack := make([]int, lt + 1)
		traceColor := make([]int, lt + 1)

		for i := 1; i <= lt; i++ {
			dp[i] = oo
			for start := max(1, i-9); start <= i; start++ {
				for end := i; end <= min(lt, start + 9); end++ {
					index, found := cache[text[start-1:end]]
					if found && dp[i] > dp[start - 1] + 1 {
						dp[i] = dp[start - 1] + 1
						traceBack[i] = start
						traceColor[i] = index
					}
				}
			}
		}

		if dp[lt] == oo {
			dp[lt] = -1
		}

		fmt.Fprintln(out, dp[lt])

		if dp[lt] != -1 {
			for lt > 0 {
				fmt.Fprintln(out, traceColor[lt], traceBack[lt])
				lt = traceBack[lt] - 1
			}
		}
	}
}

func min(u, v int) int {
	if u > v {
		u = v
	}

	return u
}

func max(u, v int) int {
	if u < v {
		u = v
	}

	return u
}

package main

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

func solve(t string, n int, s []string) (int, []int, []int) {
    m := 0
    w := []int{}
    p := []int{}

    index := 0
    for m != -1 && index < len(t) {
        index_nxt := index
        var w_nxt, p_nxt int
        for i := 0; i < n; i++ {
            for j := 0; j <= index && j + len(s[i]) <= len(t); j++ {
                all_equal := true
                for k := 0; k < len(s[i]); k++ {
                    if t[j+k] != s[i][k] {
                        all_equal = false
                    }
                }
                if all_equal {
                    if j + len(s[i]) > index_nxt {
                        index_nxt = j + len(s[i])
                        w_nxt = i+1
                        p_nxt = j+1
                    }
                }
            }
        }

        if index_nxt == index {
            m = -1
            w = []int{}
            p = []int{}
        } else {
            m++
            w = append(w, w_nxt)
            p = append(p, p_nxt)
            index = index_nxt
        }
    }
    return m, w, p
}

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

    var q int
    fmt.Fscan(in, &q)
    for i := 0; i < q; i++ {
        var t string
        var n int
        fmt.Fscan(in, &t)
        fmt.Fscan(in, &n)
        s := make([]string, n)
        for j := 0; j < n; j++ {
            fmt.Fscan(in, &s[j])
        }

        m, w, p := solve(t, n, s)
        if m == -1 {
            fmt.Fprintln(out, m)
        } else {
            fmt.Fprintln(out, m)
            for j := 0; j < m; j++ {
                fmt.Fprintln(out, strconv.Itoa(w[j]) + " " + strconv.Itoa(p[j]))
            }
        }
    }
}

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

	in = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func subString(a string, pos, leng int) (result string) {

	if pos + leng > len(a) {

		return result
	}
	for i := pos; i < pos + leng; i++ {

		result = result + string(a[i])
	}
	return result
}

func checkEqual(a, b string) bool {

	if len(a) != len(b) {

		return false
	}
	for i := 0; i < len(a); i++ {

		if a[i] != b[i] {

			return false
		}
	}
	return true
}

type Node struct {

	w, p, leng int
}

func findString(t string, a []string, ans *([]Node), pos int) {

	var add = false
	for i := 0; i < len(a); i++ {

		var tpos = subString(t, pos, len(a[i]))
		if checkEqual(tpos, a[i]) {

			if add {

				if len(a[i]) + pos >= (*ans)[len(*ans) - 1].leng && len(a[i]) + pos <= len(t) {

					(*ans)[len(*ans) - 1].w = i + 1
					(*ans)[len(*ans) - 1].leng = len(a[i]) + pos
				}
			} else if len(a[i]) + pos <= len(t) {

				*ans = append(*ans, Node{

					w: i + 1,
					p: pos + 1,
					leng: len(a[i]) + pos,
				})
				add = true
			}
		}
	}
}

func main() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)
	for i := 0; i < T; i++ {

		var (

			t string
			n int
			a []string
			ans []Node
			nans []Node
			fans []Node
		)

		fmt.Fscan(in, &t, &n)
		for j := 0; j < n; j++ {

			var x string
			fmt.Fscan(in, &x)
			a = append(a, x)
		}

		for j := 0; j < len(t); j++ {

			findString(t, a, &ans, j)
		}

		// fmt.Fprintln(out, ans)
		if len(ans) == 0 || (len(ans) > 0 && ans[0].p != 1) {

			fmt.Fprintln(out, -1)
			continue
		}

		nans = append(nans, ans[0])
		var pos, ok = 1, false
		for j := 1; j < len(t); j++ {

			if nans[len(nans) - 1].leng > j {

				nans = append(nans, nans[len(nans) - 1])
			} else {

				nans = append(nans, Node{})
			}
			if pos < len(ans) && j + 1 == ans[pos].p {

				if ans[pos].leng > nans[len(nans) - 1].leng {

					nans[len(nans) - 1] = ans[pos]
				}
				pos += 1
			}
			if nans[len(nans) - 1].leng == 0 {

				ok = true
				break;
			}
		}
		if nans[len(nans) - 1].leng != len(t) || ok {

			fmt.Fprintln(out, -1)
			continue
		}
		// fmt.Fprintln(out, nans)
		fans = append(fans, nans[0])
		for {

			if fans[len(fans) - 1].leng == len(t) {

				break
			}
			fans = append(fans, nans[fans[len(fans) - 1].leng])
		}

		fmt.Fprintln(out, len(fans))
		for _, val := range fans {

			fmt.Fprintln(out, val.w, val.p)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var memo = [105][105]int{}

func dp(i int, canSkipTill int, text *string, snip *[]string) int {
	if i >= len(*text) {
		return 0
	}

	if memo[i][canSkipTill] != -1 {
		return memo[i][canSkipTill]
	}

	ans := int(1e9)
	if i < canSkipTill {
		ans = Min(ans, dp(i+1, canSkipTill, text, snip))
	}
	// go over each snip and try to add it
	for a := 0; a < len(*snip); a++ {
		if i+len((*snip)[a]) > len(*text) {
			continue
		}
		// try to match
		canMatch := true
		for j := 0; j < len((*snip)[a]); j++ {
			canMatch = canMatch && (*snip)[a][j] == (*text)[i+j]
		}
		if canMatch {
			got := dp(i+1, i+len((*snip)[a]), text, snip)
			ans = Min(ans, 1+got)
		}
	}
	memo[i][canSkipTill] = ans
	return ans
}

var reconstruction [][2]int

func reconstruct(i int, canSkipTill int, text *string, snip *[]string) {
	if i >= len(*text) {
		return
	}

	ans := dp(i, canSkipTill, text, snip)
	if i < canSkipTill && ans == dp(i+1, canSkipTill, text, snip) {
		reconstruct(i+1, canSkipTill, text, snip)
		return
	}
	// go over each snip and try to add it
	for a := 0; a < len(*snip); a++ {
		if i+len((*snip)[a]) > len(*text) {
			continue
		}
		// try to match
		canMatch := true
		for j := 0; j < len((*snip)[a]); j++ {
			canMatch = canMatch && (*snip)[a][j] == (*text)[i+j]
		}
		if canMatch {
			got := dp(i+1, i+len((*snip)[a]), text, snip)
			if ans == 1+got {
				reconstruction = append(reconstruction, [2]int{a + 1, i + 1})
				reconstruct(i+1, i+len((*snip)[a]), text, snip)
				return
			}
		}
	}
}

func cp() {
	text := readLine()
	M := readInt()
	snip := make([]string, M)
	for i := range snip {
		snip[i] = readLine()
	}

	for i := 0; i <= len(text); i++ {
		for j := 0; j <= len(text); j++ {
			memo[i][j] = -1
		}
	}
	ans := dp(0, 0, &text, &snip)
	if ans >= int(1e9) {
		ans = -1
	}
	reconstruction = make([][2]int, 0)
	reconstruct(0, 0, &text, &snip)

	fmt.Println(ans)
	for _, action := range reconstruction {
		fmt.Println(action[0], action[1])
	}
}

func main() {
	t := 1
	t = readInt()
	for ; t > 0; t-- {
		cp()
	}
}

func init() {
}

func Max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

var IN *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	nStr, _ := IN.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLine() string {
	line, _ := IN.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	return line
}

func readLineNumbs() []string {
	line, _ := IN.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt() []int {
	numbs := readLineNumbs()
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64() []int64 {
	numbs := readLineNumbs()
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

func isExist(uStr *string, uStart int, vStr *string, vStart, length int) bool {
	for i := 0; i < length; i++ {
		if (*uStr)[uStart+i] != (*vStr)[vStart+i] {
			return false
		}
	}
	return true
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var q, n, u, v, k int
	var str, tmp string
	var dp [105][105]int
	var nex, nexIndex, pre, preIndex, frL, frR, colorIndex, colorStartPosition [105][105]int
	var nsum, psum [105]int
	fmt.Fscan(in, &q)
	for ; q != 0; q-- {
		fmt.Fscan(in, &str)
		strLen := len(str)
		for i := 1; i <= strLen; i++ {
			nsum[i], psum[i] = 0, 0
			for j := 1; j <= strLen; j++ {
				dp[i][j] = -1
				frL[i][j] = -1
				frR[i][j] = -1
				colorIndex[i][j] = -1
				colorStartPosition[i][j] = -1
			}
		}
		fmt.Fscan(in, &n)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &tmp)
			sLen := len(tmp)
			for j := 1; j+sLen-1 <= strLen; j++ {
				if isExist(&str, j-1, &tmp, 0, sLen) {
					st, ed := j, j+sLen-1
					dp[st][ed] = 1
					frL[st][ed], frR[st][ed] = 0, 0
					colorIndex[st][ed], colorStartPosition[st][ed] = i, j
					pre[ed][psum[ed]], nex[st][nsum[st]] = st, ed
					preIndex[ed][psum[ed]], nexIndex[st][nsum[st]] = i, i
					psum[ed]++
					nsum[st]++
				}
			}
		}
		for i := 1; i < strLen; i++ {
			for st, ed := 1, i; ed < strLen; st, ed = st+1, ed+1 {
				if dp[st][ed] == -1 {
					continue
				}
				for j := st - 1; j <= ed+1; j++ {
					if j < 1 || j > strLen {
						continue
					}
					if psum[j] != 0 {
						for k = 0; k < psum[j]; k++ {
							u, v = pre[j][k], ed
							if u < st && (dp[u][v] == -1 || dp[u][v] > dp[st][ed]+1) {
								dp[u][v] = dp[st][ed] + 1
								colorIndex[u][v], colorStartPosition[u][v] = preIndex[j][k], u
								frL[u][v], frR[u][v] = st, ed
							}
						}
					}
					if nsum[j] != 0 {
						for k = 0; k < nsum[j]; k++ {
							u, v = st, nex[j][k]
							if ed < v && (dp[u][v] == -1 || dp[u][v] > dp[st][ed]+1) {
								dp[u][v] = dp[st][ed] + 1
								colorIndex[u][v], colorStartPosition[u][v] = nexIndex[j][k], j
								frL[u][v], frR[u][v] = st, ed
							}
						}
					}
				}
			}
		}
		fmt.Fprintln(out, dp[1][strLen])
		if dp[1][strLen] != -1 {
			u, v = 1, strLen
			for ; u != 0 && v != 0; u, v = frL[u][v], frR[u][v] {
				fmt.Fprintln(out, colorIndex[u][v], colorStartPosition[u][v])
			}
		}
	}
}

package main

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

var (
  in = bufio.NewReader(os.Stdin)
  out = bufio.NewWriter(os.Stdout)
)
func scan(a ...any) {
  fmt.Fscan(in, a...)
}
func printf(f string, a ...any) {
  fmt.Fprintf(out, f, a...)
}

func match(x string, y string) bool {
  if len(x) != len(y) { return false }
  for i := 0; i < len(x); i++ {
    if x[i] != y[i] { return false }
  }
  return true
}
func min(x int, y int) int {
  if x < y { return x }
  return y
}
func solve() {
  var s string
  scan(&s)
  var n int
  scan(&n)
  words := make([]string, n)
  for i := 0; i < n; i++ { scan(&words[i]) }

  dp := make([]int, len(s) + 1)
  pos := make([]int, len(s) + 1)
  best_str := make([]int, len(s) + 1)
  dp[0] = 0
  for i := 1; i <= len(s); i++ {
    var mx int = 0
    for j, p := range words {
      if i >= len(p) && match(p, s[i - len(p):i]) {
        if len(p) > mx {
          mx = len(p)
          best_str[i] = j
        }
      }
    }
    var mn_dp int = 1000000;
    for j := 1; j <= min(i, mx); j++ {
      if mn_dp > dp[i - j] {
        mn_dp = dp[i - j]
        pos[i] = i - j
      }
    }

    dp[i] = mn_dp + 1
  }

  if dp[len(s)] >= 1000000 {
    printf("-1\n")
    return
  }
  printf("%d\n", dp[len(s)])
  cur := len(s)
  for cur > 0 {
    printf("%d %d\n", best_str[cur] + 1, cur - len(words[best_str[cur]]) + 1)
    cur = pos[cur]
  }
}

func main() {
  defer out.Flush()
  var q int
  scan(&q)
  for i := 0; i < q; i++ {
    solve()
  }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var q int
	fmt.Fscan(in, &q)
	for q > 0 {
		q--
		var t string
		fmt.Fscan(in, &t)
		var n int
		fmt.Fscan(in, &n)
		a := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		b := make([]byte, len(t)+5)
		for i := 0; i < len(t); i++ {
			b[i+1] = t[i]
		}
		f := make([]int, len(t)+5)
		dp := make([][][2]int, len(t)+5)
		f[0] = 0
		for i := 1; i < len(f); i++ {
			f[i] = int(1e9)
		}
		for i := 1; i <= len(t); i++ {
			mi := 999999
			index := -1
			tar := -1
			for j, s := range a {
				if len(s) > i+1 || s != string(b[i+1-len(s):i+1]) {
					continue
				}
				for k := i - 1; k >= i-len(s); k-- {
					if mi > f[k] {
						index = k
						mi = f[k]
						tar = j
					}
				}
			}
			if mi != 999999 {
				f[i] = f[index] + 1
				dp[i] = append(dp[index], [2]int{tar + 1, i - len(a[tar]) + 1})
			}
		}
		if len(dp[len(t)]) != 0 {
			fmt.Fprintln(out, len(dp[len(t)]))
			for _, v := range dp[len(t)] {
				fmt.Fprintln(out, v[0], v[1])
			}
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var t string
		var n int
		fmt.Fscan(r, &t, &n)
		s := make([]string, n)
		for i := range s {
			fmt.Fscan(r, &s[i])
		}
		w1, w2 := do(n, t, s)
		fmt.Fprintln(w, w1)
		for _, v := range w2 {
			fmt.Fprintln(w, v[0], v[1])
		}
	}
}

func do(n int, t string, s []string) (int, [][2]int) {
	a := make([]int, len(t))
	for i := range t {
		a[i] = -1
		for j := range s {
			if strings.Index(t[i:], s[j]) == 0 {
				if a[i] < 0 || len(s[a[i]]) < len(s[j]) {
					a[i] = j
				}
			}
		}
	}
	r := [][2]int{}
	k := 0
	nextk := 0
	nexti := -1
	for i := 0; i < len(t); i++ {
		if i <= k {
			if a[i] >= 0 && i+len(s[a[i]]) > nextk {
				nextk = i + len(s[a[i]])
				nexti = i
			}
		}
		if nextk <= i {
			return -1, nil
		}
		if i == k {
			r = append(r, [2]int{a[nexti] + 1, nexti + 1})
			k = nextk
		}
	}
	return len(r), r
}

package main

import (
	"bufio"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

type pair struct {
	a, b, where int
}

type pairs []pair

func (a pairs) Len() int {
	return len(a)
}

func (a pairs) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a pairs) Less(i, j int) bool {
	return a[i].a < a[j].a
}

type result struct {
	w, p int
}

func solve() {
	p := gets()
	n := get()
	var a []pair
	for i := 0; i < n; i++ {
		s := gets()
		j := -1
		offset := 0
		for {
			t := strings.Index(p[offset:], s)
			if t == -1 {
				break
			}
			j = offset + t
			a = append(a, pair{j, j + len(s), i})
			offset = j + 1
		}
	}

	sort.Sort(pairs(a))

	i := 0
	j := -1
	best := -1
	var k int
	for k = 0; k < len(a) && a[k].a == 0; k++ {
		if a[k].b > j {
			j = a[k].b
			best = k
		}
	}
	if j == -1 {
		putsln("-1")
		return
	}
	res := []result{{a[best].where, a[best].a}}

	i = j
	for i < len(p) {
		j = -1
		for k < len(a) && a[k].a <= i {
			if a[k].b > j {
				j = a[k].b
				best = k
			}
			k++
		}
		if j == -1 {
			putsln("-1")
			return
		}
		res = append(res, result{a[best].where, a[best].a})
		i = j
	}

	putln(len(res))
	for _, v := range res {
		put(v.w + 1)
		space()
		putln(v.p + 1)
	}
}

const (
	once       = false
	maxBufSize = 10_000_000
	YES        = "YES"
	NO         = "NO"
)

var (
	splitFunc = bufio.ScanWords //bufio.SplitFunc(nil)
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	if splitFunc != nil {
		in.Split(splitFunc)
	}
	if maxBufSize > 0 {
		in.Buffer(make([]byte, maxBufSize), maxBufSize)
	}

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	for t := get(); t > 0; t-- {
		solve()
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func line() {
	putc('\n')
}

func space() {
	putc(' ')
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts(YES)
	line()
}

func no() {
	puts(NO)
	line()
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

type IntTp interface {
	int | int64
}

type Tp interface {
	IntTp | float64
}

func abs[T IntTp](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func fabs(x float64) float64 {
	return math.Abs(x)
}

func max1[T Tp](x T, y T) T {
	if x > y {
		return x
	}
	return y
}

func max[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = max1(r, x)
	}
	return r
}

func maxa[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] <= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func min1[T Tp](x T, y T) T {
	if x < y {
		return x
	}
	return y
}

func min[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = min1(r, x)
	}
	return r
}

func mina[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] >= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func L(i int) int64 {
	return int64(i)
}

func F(i int) float64 {
	return float64(i)
}

func ints(n int, val int) (a []int) {
	a = make([]int, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func int64s(n int, val int64) (a []int64) {
	a = make([]int64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func floats(n int, val float64) (a []float64) {
	a = make([]float64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

const heapBase = 4

func children(i int) (int, int) {
	start := heapBase * i
	return start + 1, start + (1 + heapBase)
}

func parent(i int) int {
	return (i - 1) / heapBase
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func readLine() string {
	s, err := f.ReadString('\n')
	if err != nil {
		panic(err)
	}
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return s
}

func readInts(n int) []int {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	arr := make([]int, n)
	for k, a := range as {
		x, _ := strconv.ParseInt(a, 10, 64)
		arr[k] = int(x)
	}
	return arr
}

var f = bufio.NewReader(os.Stdin)

func main() {
	var t, n int

	l1 := readInts(1)
	t = l1[0]

	for i := 0; i < t; i++ {
		s := readLine()
		n = readInts(1)[0]
		ss := make([]string, n)
		for j := 0; j < n; j++ {
			ss[j] = readLine()
		}
		dp := make([]int, len(s)+1)
		w := make([]int, len(s)+1)
		next := make([]int, len(s)+1)
		dp[len(s)] = 0
		for k := len(s) - 1; k >= 0; k-- {
			dp[k] = -1
			for j := 0; j < n; j++ {
				if strings.HasPrefix(s[k:], ss[j]) {
					for jj := k + 1; jj < k+1+len(ss[j]); jj++ {
						if dp[jj] != -1 && (dp[k] == -1 || dp[k] > 1+dp[jj]) {
							w[k] = j + 1
							next[k] = jj
							dp[k] = 1 + dp[jj]
						}
					}
				}
			}
		}
		fmt.Println(dp[0])
		if dp[0] != -1 {
			for c := 0; c < len(s); c = next[c] {
				fmt.Println(w[c], c+1)
			}
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var c = 0
var qq = 0

func qwq() {
	c++
	var n int
	var s string
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &n)
	ss := make([]string, n)
	type P struct {
		l, r, id int
	}
	ps := []P{}
	filter := []P{}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ss[i])
		for j := 0; j+len(ss[i])-1 < len(s); j++ {
			if s[j:j+len(ss[i])] == ss[i] {
				ps = append(ps, P{j, j + len(ss[i]) - 1, i + 1})
			}
		}
	}
	if qq == 100 && c == 27 {
		fmt.Fprintln(out, n, s, ss)
		return
	} else if qq == 100 {

		return
	}

	sort.Slice(ps, func(i, j int) bool {
		return ps[i].l < ps[j].l
	})

	ans := []P{}
	r := -1
	for i := 0; i < len(ps); i++ {
		for i+1 < len(ps) && ps[i].l == ps[i+1].l {
			i++
		}
		filter = append(filter, ps[i])
	}
	// fmt.Fprintln(out, filter)
	for i := 0; r < len(s)-1 && i < len(filter); {
		id := -1
		imax := r
		for i < len(filter) && filter[i].l <= r+1 {
			if filter[i].r > imax {
				imax = filter[i].r
				id = i
			}
			i++
		}
		if id == -1 {
			fmt.Fprintln(out, -1)
			return
		}
		ans = append(ans, filter[id])
		r = imax
	}
	if len(ans) == 0 || r < len(s)-1 {
		fmt.Fprintln(out, -1)
		return
	}
	fmt.Fprintln(out, len(ans))
	for _, l := range ans {
		fmt.Fprintln(out, l.id, l.l+1)
	}
}

func main() {
	defer out.Flush()
	q := 1

	fmt.Fscan(in, &q)
	qq = q
	for ; q > 0; q-- {
		qwq()
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var c = 0
var q = 0

func qwq() {
	c++
	var n int
	var s string
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &n)
	ss := make([]string, n)
	type P struct {
		l, r, id int
	}
	ps := []P{}
	filter := []P{}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ss[i])
		for j := 0; j+len(ss[i])-1 < len(s); j++ {
			if s[j:j+len(ss[i])] == ss[i] {
				ps = append(ps, P{j, j + len(ss[i]) - 1, i + 1})
			}
		}
	}
	if q == 100 && c == 27 {
		fmt.Fprintln(out, n, s, ss)
		return
	} else if q == 100 {

		return
	}

	sort.Slice(ps, func(i, j int) bool {
		return ps[i].l < ps[j].l
	})

	ans := []P{}
	r := -1
	for i := 0; i < len(ps); i++ {
		for i+1 < len(ps) && ps[i].l == ps[i+1].l {
			i++
		}
		filter = append(filter, ps[i])
	}
	// fmt.Fprintln(out, filter)
	for i := 0; r < len(s)-1 && i < len(filter); {
		id := -1
		imax := r
		for i < len(filter) && filter[i].l <= r+1 {
			if filter[i].r > imax {
				imax = filter[i].r
				id = i
			}
			i++
		}
		if id == -1 {
			fmt.Fprintln(out, -1)
			return
		}
		ans = append(ans, filter[id])
		r = imax
	}
	if len(ans) == 0 || r < len(s)-1 {
		fmt.Fprintln(out, -1)
		return
	}
	fmt.Fprintln(out, len(ans))
	for _, l := range ans {
		fmt.Fprintln(out, l.id, l.l+1)
	}
}

func main() {
	defer out.Flush()
	// q := 1
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		qwq()
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func qwq() {
	var n int
	var s string
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &n)
	ss := make([]string, n)
	type P struct {
		l, r, id int
	}
	ps := []P{}
	filter := []P{}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ss[i])
		for j := 0; j+len(ss[i])-1 < len(s); j++ {
			if s[j:j+len(ss[i])] == ss[i] {
				ps = append(ps, P{j, j + len(ss[i]) - 1, i + 1})
			}
		}
	}
	sort.Slice(ps, func(i, j int) bool {
		return ps[i].l < ps[j].l
	})

	ans := []P{}
	r := -1
	for i := 0; i < len(ps); i++ {
		for i+1 < len(ps) && ps[i].l == ps[i+1].l {
			i++
		}
		filter = append(filter, ps[i])
	}
	// fmt.Fprintln(out, filter)
	for i := 0; r < len(s)-1 && i < len(filter); {
		id := -1
		imax := r
		for i < len(filter) && filter[i].l <= r+1 {
			if filter[i].r > imax {
				imax = filter[i].r
				id = i
			}
			i++
		}
		if id == -1 {
			fmt.Fprintln(out, -1)
			return
		}
		ans = append(ans, filter[id])
		r = imax
	}
	if len(ans) == 0 || r < len(s)-1 {
		fmt.Fprintln(out, -1)
		return
	}
	fmt.Fprintln(out, len(ans))
	for _, l := range ans {
		fmt.Fprintln(out, l.id, l.l+1)
	}
}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		qwq()
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func qwq() {
	var n int
	var s string
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &n)
	ss := make([]string, n)
	type P struct {
		l, r, id int
	}
	ps := []P{}
	filter := []P{}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ss[i])
		for j := 0; j+len(ss[i])-1 < len(s); j++ {
			if s[j:j+len(ss[i])] == ss[i] {
				ps = append(ps, P{j, j + len(ss[i]) - 1, i + 1})
			}
		}
	}
	sort.Slice(ps, func(i, j int) bool {
		return ps[i].l < ps[j].l
	})

	ans := []P{}
	r := -1
	for i := 0; i < len(ps); i++ {
		for i+1 < len(ps) && ps[i].l == ps[i+1].l {
			i++
		}
		filter = append(filter, ps[i])
	}
	// fmt.Fprintln(out, filter)
	for i := 0; r < len(s)-1 && i < len(filter); {
		id := -1
		imax := r
		for i < len(filter) && filter[i].l <= r+1 {
			if filter[i].r > imax {
				imax = filter[i].r
				id = i
			}
			i++
		}
		if id == -1 {
			fmt.Fprintln(out, -1)
			return
		}
		ans = append(ans, filter[id])
		r = imax
	}
	if len(ans) == 0 {
		fmt.Fprintln(out, -1)
		return
	}
	fmt.Fprintln(out, len(ans))
	for _, l := range ans {
		fmt.Fprintln(out, l.id, l.l+1)
	}
}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		qwq()
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func qwq() {
	var n int
	var s string
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &n)
	ss := make([]string, n)
	type P struct {
		l, r, id int
	}
	ps := []P{}
	filter := []P{}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ss[i])
		for j := 0; j+len(ss[i])-1 < len(s); j++ {
			if s[j:j+len(ss[i])] == ss[i] {
				ps = append(ps, P{j, j + len(ss[i]) - 1, i + 1})
			}
		}
	}
	sort.Slice(ps, func(i, j int) bool {
		return ps[i].l < ps[j].l
	})

	ans := []P{}
	r := -1
	for i := 0; i < len(ps); i++ {
		for i+1 < len(ps) && ps[i].l == ps[i+1].l {
			i++
		}
		filter = append(filter, ps[i])
	}
	// fmt.Fprintln(out, filter)
	for i := 0; r < len(s)-1 && i < len(filter); {
		id := -1
		imax := r
		for i < len(filter) && ps[i].l <= r+1 {
			if ps[i].r > imax {
				imax = ps[i].r
				id = i
			}
			i++
		}
		if id == -1 {
			fmt.Fprintln(out, -1)
			return
		}
		ans = append(ans, ps[id])
		r = imax
	}
	if len(ans) == 0 {
		fmt.Fprintln(out, -1)
		return
	}
	fmt.Fprintln(out, len(ans))
	for _, l := range ans {
		fmt.Fprintln(out, l.id, l.l+1)
	}
}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		qwq()
	}

}

package main

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

const (
	N = 1e5 + 5
)

var n, sLen int
var s string
var strs []string
var cnt []int

func check(i int, str string) bool {
	ls := len(str)
	if ls > i {
		return false
	}
	for pos := range str {
		if s[i-ls+pos] != str[pos] {
			return false
		}
	}
	return true
}
func cal(a, b int) int {
	if a == -1 || a > b {
		return b
	}
	return a
}

type line struct {
	l, r, id int
}

func addAns(ans *[]line, l line) {
	le := len(*ans)
	if le == 0 || (*ans)[le-1].r < l.r {
		*ans = append(*ans, l)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for o := 0; o < t; o++ {
		fmt.Fscan(in, &s)
		fmt.Fscan(in, &n)
		lines := make([]line, 0)
		sLen = len(s)
		strs = make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &strs[i])
		}
		for i := 1; i <= sLen; i++ {
			for j, v := range strs {
				if check(i, v) {
					lines = append(lines, line{i - len(v) + 1, i, j + 1})
				}
			}
		}
		if len(lines) == 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		sort.Slice(lines, func(i, j int) bool {
			if lines[i].l != lines[j].l {
				return lines[i].l < lines[j].l
			}
			return lines[i].r > lines[j].r
		})
		//fmt.Fprintln(out, lines)
		ans := make([]line, 0)
		last, temp := lines[0], lines[0]
		i, ls := 0, len(lines)
		for i < ls {
			for i < ls && lines[i].l <= last.r+1 {
				if temp.r < lines[i].r {
					temp = lines[i]
				}
				i++
			}
			addAns(&ans, last)
			addAns(&ans, temp)
			if i < ls {
				last = lines[i]
			}
		}
		addAns(&ans, last)
		addAns(&ans, temp)
		cnt = make([]int, sLen+2)
		for _, v := range ans {
			cnt[v.l]++
			cnt[v.r+1]--
		}
		flag := true
		for i := 1; i <= sLen; i++ {
			cnt[i] += cnt[i-1]
			if cnt[i] == 0 {
				flag = false
			}
		}
		//fmt.Fprintln(out, ans)
		if flag {
			fmt.Fprintln(out, len(ans))
			for _, v := range ans {
				fmt.Fprintln(out, v.id, v.l)
			}
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}

package main

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

const (
	N = 1e5 + 5
)

var n, sLen int
var s string
var strs []string
var cnt []int

func check(i int, str string) bool {
	ls := len(str)
	if ls > i {
		return false
	}
	for pos := range str {
		if s[i-ls+pos] != str[pos] {
			return false
		}
	}
	return true
}
func cal(a, b int) int {
	if a == -1 || a > b {
		return b
	}
	return a
}

type line struct {
	l, r, id int
}

func addAns(ans *[]line, l line) {
	le := len(*ans)
	if le == 0 || (*ans)[le-1].r < l.r {
		*ans = append(*ans, l)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for o := 0; o < t; o++ {
		fmt.Fscan(in, &s)
		fmt.Fscan(in, &n)
		lines := make([]line, 0)
		sLen = len(s)
		strs = make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &strs[i])
		}
		for i := 1; i <= sLen; i++ {
			for j, v := range strs {
				if check(i, v) {
					lines = append(lines, line{i - len(v) + 1, i, j + 1})
				}
			}
		}
		if len(lines) == 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		sort.Slice(lines, func(i, j int) bool {
			if lines[i].l != lines[j].l {
				return lines[i].l < lines[j].l
			}
			return lines[i].r > lines[j].r
		})
		//fmt.Fprintln(out, lines)
		ans := make([]line, 0)
		last, temp := lines[0], lines[0]
		for _, v := range lines {
			if v.l > last.r {
				addAns(&ans, last)
				if last.r >= sLen {
					temp = line{-1, -1, -1}
					break
				}
				if v.l == last.r+1 && v.r > temp.r {
					temp = v
				}
				if temp.r > last.r && v.l >= temp.r {
					addAns(&ans, temp)
					temp = v
				}
				last = temp
			} else if v.r > temp.r {
				temp = v
			}
		}
		addAns(&ans, last)
		//fmt.Fprintln(out, ans, temp, last)
		if temp.r > last.r {
			addAns(&ans, temp)
		}
		cnt = make([]int, sLen+2)
		for _, v := range ans {
			cnt[v.l]++
			cnt[v.r+1]--
		}
		flag := true
		for i := 1; i <= sLen; i++ {
			cnt[i] += cnt[i-1]
			if cnt[i] == 0 {
				flag = false
			}
		}
		//fmt.Fprintln(out, ans)
		if flag {
			fmt.Fprintln(out, len(ans))
			for _, v := range ans {
				fmt.Fprintln(out, v.id, v.l)
			}
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

type Node struct {
	id         int
	start, end int
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func exec() {
	var t string
	fmt.Scan(&t)
	var n int
	fmt.Scan(&n)

	var s = make([]string, n)
	var records = make([]*Node, 0, 100)

	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
		for j := 0; j < len(t)-len(s[i])+1; j++ {
			var check = true
			for h := j; h < j+len(s[i]); h++ {
				if t[h] != s[i][h-j] {
					check = false
					break
				}
			}
			if check {
				records = append(records, &Node{i, j, j + len(s[i])})
			}
		}
	}
	// fmt.Println("test", t, s)

	sort.Slice(records, func(i, j int) bool {
		if records[i].start == records[j].start {
			return records[i].end > records[j].end
		}
		return records[i].start < records[j].start
	})
	// for i := range records {
	// 	fmt.Println("records", records[i].id, records[i].start, records[i].end)
	// }
	var ret = make([]*Node, 0)

	var cur = 0
	for cur < len(records) {
		// fmt.Println(cur, ret)
		ret = append(ret, records[cur])

		if records[cur].end == len(t) {
			break
		}
		var j = cur
		var m, max = j, records[j].end

		for j < len(records) && records[j].start <= records[cur].end {
			if max < records[j].end {
				m = j
				max = records[j].end
			}
			j += 1
		}
		if max == records[cur].end {
			fmt.Println(-1)
			return
		}
		cur = m
	}
	if len(ret) == 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(len(ret))
	for i := 0; i < len(ret); i++ {
		fmt.Println(ret[i].id+1, ret[i].start+1)
	}
}

func main() {
	var T int
	fmt.Scan(&T)
	for it := 0; it < T; it++ {
		exec()
	}
}

package main

import (
	"fmt"
	"sort"
)

type Node struct {
	id         int
	start, end int
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func exec() {
	var t string
	fmt.Scan(&t)
	var n int
	fmt.Scan(&n)

	var s = make([]string, n)
	var records = make([]*Node, 0, 100)

	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
		for j := 0; j < len(t)-len(s[i])+1; j++ {
			var check = true
			for h := j; h < j+len(s[i]); h++ {
				if t[h] != s[i][h-j] {
					check = false
					break
				}
			}
			if check {
				records = append(records, &Node{i, j, j + len(s[i])})
			}
		}
	}
	// fmt.Println("test", t, s)

	sort.Slice(records, func(i, j int) bool {
		if records[i].start == records[j].start {
			return records[i].end > records[j].end
		}
		return records[i].start < records[j].start
	})
	for i := range records {
		fmt.Println("records", records[i].id, records[i].start, records[i].end)
	}
	var ret = make([]*Node, 0)

	var cur = 0
	for cur < len(records) {
		// fmt.Println(cur, ret)
		ret = append(ret, records[cur])

		if records[cur].end == len(t) {
			break
		}
		var j = cur
		var m, max = j, records[j].end

		for j < len(records) && records[j].start <= records[cur].end {
			if max < records[j].end {
				m = j
				max = records[j].end
			}
			j += 1
		}
		if max == records[cur].end {
			fmt.Println(-1)
			return
		}
		cur = m
	}
	if len(ret) == 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(len(ret))
	for i := 0; i < len(ret); i++ {
		fmt.Println(ret[i].id+1, ret[i].start+1)
	}
}

func main() {
	var T int
	fmt.Scan(&T)
	for it := 0; it < T; it++ {
		exec()
	}
}

package main

import (
	"fmt"
	"sort"
)

type Node struct {
	id         int
	start, end int
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func exec() {
	var t string
	fmt.Scan(&t)
	var n int
	fmt.Scan(&n)

	var s = make([]string, n)
	var records = make([]*Node, 0, 100)

	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
		for j := 0; j < len(t)-len(s[i])+1; j++ {
			var check = true
			for h := j; h < j+len(s[i]); h++ {
				if t[h] != s[i][h-j] {
					check = false
					break
				}
			}
			if check {
				records = append(records, &Node{i, j, j + len(s)})
			}
		}
	}
	// fmt.Println("test", t, s)

	sort.Slice(records, func(i, j int) bool {
		if records[i].start == records[j].start {
			return records[i].end > records[j].end
		}
		return records[i].start < records[j].start
	})
	// for i := range records {
	// 	fmt.Println("records", records[i].id, records[i].start, records[i].end)
	// }
	var ret = make([]*Node, 0)

	var cur = 0
	for cur < len(records) {
		// fmt.Println(cur, ret)
		ret = append(ret, records[cur])

		if records[cur].end == len(t) {
			break
		}
		var j = cur
		var m, max = j, records[j].end

		for j < len(records) && records[j].start <= records[cur].end {
			if max < records[j].end {
				m = j
				max = records[j].end
			}
			j += 1
		}
		if max == records[cur].end {
			fmt.Println(-1)
			return
		}
		cur = m
	}
	if len(ret) == 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(len(ret))
	for i := 0; i < len(ret); i++ {
		fmt.Println(ret[i].id+1, ret[i].start+1)
	}
}

func main() {
	var T int
	fmt.Scan(&T)
	for it := 0; it < T; it++ {
		exec()
	}
}

package main

import (
	"fmt"
	"sort"
)

type Node struct {
	id         int
	start, end int
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func exec() {
	var t string
	fmt.Scan(&t)
	var n int
	fmt.Scan(&n)

	var s = make([]string, n)
	var records = make([]*Node, 0, 100)

	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
		for j := 0; j < len(t)-len(s[i])+1; j++ {
			var check = true
			for h := j; h < j+len(s[i]); h++ {
				if t[h] != s[i][h-j] {
					check = false
					break
				}
			}
			if check {
				records = append(records, &Node{i, j, j + len(s)})
			}
		}
	}
	// fmt.Println("test", t, s)

	sort.Slice(records, func(i, j int) bool {
		if records[i].start == records[j].start {
			return records[i].end > records[j].end
		}
		return records[i].start < records[j].start
	})
	// for i := range records {
	// 	fmt.Println("records", records[i].id, records[i].start, records[i].end)
	// }
	var ret = make([]*Node, 0)

	var cur = 0
	for cur < len(records) {
		// fmt.Println(cur, ret)
		ret = append(ret, records[cur])

		if records[cur].end == len(t) {
			break
		}
		var j = cur
		var m, max = j, records[j].end

		for j < len(records) && records[j].start <= records[cur].end {
			if max < records[j].end {
				m = j
				max = records[j].end
			}
			j += 1
		}
		if max == records[cur].end {
			fmt.Println(-1)
			return
		}
		cur = m
	}
	if len(ret) == 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(len(ret))
	for i := 0; i < len(ret); i++ {
		fmt.Println(ret[i].id, ret[i].start)
	}
}

func main() {
	var T int
	fmt.Scan(&T)
	for it := 0; it < T; it++ {
		exec()
	}
}

package main

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

var (
	in = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

const (
	oo = 26072000
)

func ReadInt() int {
	var i int
	fmt.Fscan(in, &i)
	return i
}

func ReadString() string{
	var s string
	fmt.Fscan(in, &s)
	return s
}

func main(){
	defer out.Flush()

	testCases := ReadInt()

	for ; testCases > 0; testCases-- {
		text := ReadString()

		lt := len(text)
		n := ReadInt()

		cache := make(map[string]int)

		for i := 1; i <= n; i++ {
			s := ReadString()
			cache[s] = i
		}

		dp := make([]int, lt + 1)
		traceBack := make([]int, lt + 1)

		for i := 1; i <= lt; i++ {
			dp[i] = oo
			for start := max(1, i-9); start <= i; start++ {
				for end := i; end <= min(lt, start + 9); end++ {
					_, found := cache[text[start-1:end]]
					if found && dp[i] > dp[start - 1] + 1 {
						dp[i] = dp[start - 1] + 1
						traceBack[i] = start
					}
				}
			}
		}

		if dp[lt] == oo {
			dp[lt] = -1
		}

		fmt.Fprintln(out, dp[lt])

		if dp[lt] != -1 {
			for lt > 0 {
				index, _ := cache[text[traceBack[lt] - 1 : lt]]

				fmt.Fprintln(out, index, traceBack[lt])
				lt = traceBack[lt] - 1
			}
		}
	}
}

func min(u, v int) int {
	if u > v {
		u = v
	}

	return u
}

func max(u, v int) int {
	if u < v {
		u = v
	}

	return u
}

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

	in = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func subString(a string, pos, leng int) (result string) {

	if pos + leng > len(a) {

		return result
	}
	for i := pos; i < pos + leng; i++ {

		result = result + string(a[i])
	}
	return result
}

func checkEqual(a, b string) bool {

	if len(a) != len(b) {

		return false
	}
	for i := 0; i < len(a); i++ {

		if a[i] != b[i] {

			return false
		}
	}
	return true
}

type Node struct {

	w, p, leng int
}

func findString(t string, a []string, ans *([]Node), pos int) {

	var add = false
	for i := 0; i < len(a); i++ {

		var tpos = subString(t, pos, len(a[i]))
		if checkEqual(tpos, a[i]) {

			if add {

				if len(a[i]) + pos >= (*ans)[len(*ans) - 1].leng && len(a[i]) + pos <= len(t) {

					(*ans)[len(*ans) - 1].w = i + 1
					(*ans)[len(*ans) - 1].leng = len(a[i]) + pos
				}
			} else if len(a[i]) + pos <= len(t) {

				*ans = append(*ans, Node{

					w: i + 1,
					p: pos + 1,
					leng: len(a[i]) + pos,
				})
				add = true
			}
		}
	}
}

func main() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)
	for i := 0; i < T; i++ {

		var (

			t string
			n int
			a []string
			ans []Node
			nans []Node
			fans []Node
		)

		fmt.Fscan(in, &t, &n)
		for j := 0; j < n; j++ {

			var x string
			fmt.Fscan(in, &x)
			a = append(a, x)
		}

		for j := 0; j < len(t); j++ {

			findString(t, a, &ans, j)
		}

		// fmt.Fprintln(out, ans)
		if len(ans) == 0 || (len(ans) > 0 && ans[0].p != 1) {

			fmt.Fprintln(out, -1)
			continue
		}

		nans = append(nans, ans[0])
		var pos, ok = 1, false
		for j := 1; j < len(t); j++ {

			if nans[len(nans) - 1].leng > j {

				nans = append(nans, nans[len(nans) - 1])
			} else {

				nans = append(nans, Node{})
			}
			if pos < len(ans) && j + 1 == ans[pos].p {

				if ans[pos].leng > nans[len(nans) - 1].leng {

					nans[len(nans) - 1] = ans[pos]
				}
				pos += 1
			}
			if nans[len(nans) - 1].leng == 0 {

				ok = true
				break;
			}
		}
		if nans[len(nans) - 1].leng != len(t) || ok {

			fmt.Fprintln(out, "dcm", -1)
			continue
		}
		// fmt.Fprintln(out, nans)
		fans = append(fans, nans[0])
		for {

			if fans[len(fans) - 1].leng == len(t) {

				break
			}
			fans = append(fans, nans[fans[len(fans) - 1].leng])
		}

		fmt.Fprintln(out, len(fans))
		for _, val := range fans {

			fmt.Fprintln(out, val.w, val.p)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var memo = [105][105]int{}

func dp(i int, canSkipTill int, text *string, snip *[]string) int {
	if i >= len(*text) {
		return 0
	}

	if memo[i][canSkipTill] != -1 {
		return memo[i][canSkipTill]
	}

	ans := int(1e9)
	if i < canSkipTill {
		ans = Min(ans, dp(i+1, canSkipTill, text, snip))
	}
	// go over each snip and try to add it
	for a := 0; a < len(*snip); a++ {
		if i+len((*snip)[a]) > len(*text) {
			continue
		}
		// try to match
		canMatch := true
		for j := 0; j < len((*snip)[a]); j++ {
			canMatch = canMatch && (*snip)[a][j] == (*text)[i+j]
		}
		if canMatch {
			got := dp(i+1, i+len((*snip)[a]), text, snip)
			ans = Min(ans, 1+got)
		}
	}
	memo[i][canSkipTill] = ans
	return ans
}

var reconstruction [][2]int

func reconstruct(i int, canSkipTill int, text *string, snip *[]string) {
	if i >= len(*text) {
		return
	}

	ans := dp(i, canSkipTill, text, snip)
	if i < canSkipTill && ans == dp(i+1, canSkipTill, text, snip) {
		reconstruct(i+1, canSkipTill, text, snip)
		return
	}
	// go over each snip and try to add it
	for a := 0; a < len(*snip); a++ {
		if i+len((*snip)[a]) > len(*text) {
			continue
		}
		// try to match
		canMatch := true
		for j := 0; j < len((*snip)[a]); j++ {
			canMatch = canMatch && (*snip)[a][j] == (*text)[i+j]
		}
		if canMatch {
			got := dp(i+1, i+len((*snip)[a]), text, snip)
			if ans == 1+got {
				reconstruction = append(reconstruction, [2]int{a + 1, i + 1})
				reconstruct(i+1, i+len((*snip)[a]), text, snip)
			}
		}
	}
}

func cp() {
	text := readLine()
	M := readInt()
	snip := make([]string, M)
	for i := range snip {
		snip[i] = readLine()
	}

	for i := 0; i <= len(text); i++ {
		for j := 0; j <= len(text); j++ {
			memo[i][j] = -1
		}
	}
	ans := dp(0, 0, &text, &snip)
	if ans >= int(1e9) {
		ans = -1
	}
	reconstruction = make([][2]int, 0)
	reconstruct(0, 0, &text, &snip)

	fmt.Println(ans)
	for _, action := range reconstruction {
		fmt.Println(action[0], action[1])
	}
}

func main() {
	t := 1
	t = readInt()
	for ; t > 0; t-- {
		cp()
	}
}

func init() {
}

func Max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

var IN *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	nStr, _ := IN.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLine() string {
	line, _ := IN.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	return line
}

func readLineNumbs() []string {
	line, _ := IN.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt() []int {
	numbs := readLineNumbs()
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64() []int64 {
	numbs := readLineNumbs()
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

func isExist(uStr *string, uStart int, vStr *string, vStart, length int) bool {
	for i := 0; i < length; i++ {
		if (*uStr)[uStart+i] != (*vStr)[vStart+i] {
			return false
		}
	}
	return true
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var q, n, u, v, k int
	var str, tmp string
	var dp [105][105]int
	var nex, nexIndex, pre, preIndex, frL, frR, colorIndex, colorStartPosition [105][105]int
	var nsum, psum [105]int
	fmt.Fscan(in, &q)
	for ; q != 0; q-- {
		fmt.Fscan(in, &str)
		strLen := len(str)
		for i := 1; i <= strLen; i++ {
			nsum[i], psum[i] = 0, 0
			for j := 1; j <= strLen; j++ {
				dp[i][j] = -1
				frL[i][j] = -1
				frR[i][j] = -1
				colorIndex[i][j] = -1
				colorStartPosition[i][j] = -1
			}
		}
		fmt.Fscan(in, &n)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &tmp)
			sLen := len(tmp)
			for j := 1; j+sLen-1 <= strLen; j++ {
				if isExist(&str, j-1, &tmp, 0, sLen) {
					st, ed := j, j+sLen-1
					dp[st][ed] = 1
					frL[st][ed], frR[st][ed] = 0, 0
					colorIndex[st][ed], colorStartPosition[st][ed] = i, j
					pre[ed][psum[ed]], nex[st][nsum[st]] = st, ed
					preIndex[ed][psum[ed]], nexIndex[st][nsum[st]] = i, i
					psum[ed]++
					nsum[st]++
				}
			}
		}
		for i := 1; i < strLen; i++ {
			for st, ed := 1, i; ed < strLen; st, ed = st+1, ed+1 {
				if dp[st][ed] == -1 {
					continue
				}
				for j := st - 1; j <= ed+1; j++ {
					if j < 1 || j > strLen {
						continue
					}
					if j > 1 && psum[j] != 0 {
						for k = 0; k < psum[j]; k++ {
							u, v = pre[j][k], ed
							if u < st && (dp[u][v] == -1 || dp[u][v] > dp[st][ed]+1) {
								dp[u][v] = dp[st][ed] + 1
								colorIndex[u][v], colorStartPosition[u][v] = preIndex[j][k], u
								frL[u][v], frR[u][v] = st, ed
							}
						}
					}
					if j < strLen && nsum[j] != 0 {
						for k = 0; k < nsum[j]; k++ {
							u, v = st, nex[j][k]
							if ed < v && (dp[u][v] == -1 || dp[u][v] > dp[st][ed]+1) {
								dp[u][v] = dp[st][ed] + 1
								colorIndex[u][v], colorStartPosition[u][v] = nexIndex[j][k], j
								frL[u][v], frR[u][v] = st, ed
							}
						}
					}
				}
			}
		}
		fmt.Fprintln(out, dp[1][strLen])
		if dp[1][strLen] != -1 {
			u, v = 1, strLen
			for ; u != 0 && v != 0; u, v = frL[u][v], frR[u][v] {
				fmt.Fprintln(out, colorIndex[u][v], colorStartPosition[u][v])
			}
		}
	}
}


package main

import "fmt"

func main() {
    var s string
    var cnt [26]int
    fmt.Scan(&s)
    for _, v := range s {
        cnt[v-'a']++
    }
    odd := 0
    for i := 0; i < 26; i++ {
        if cnt[i]%2 == 1 { odd++ }
    }
    if (odd == 0) || (odd%2 == 1) { fmt.Println("First") } else { fmt.Println("Second") }
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var s string
	for I(&s, "\n") == nil {
		solve(s)
	}
}

func solve(s string) {
	in := make([]int, 35)
	for i := 0; i < len(s); i++ {
		in[s[i]-90]++
	}
	sort.Ints(in)
	k := 0
	for i := 0; i < 35; i++ {
		if in[i]%2 == 1 {
			k++
		}
	}
	if k == 0 || k%2 == 1 {
		O("First", "\n")
	} else {
		O("Second", "\n")
	}
}

package main

import (
	"fmt"
)

func main() {
	var x string
	fmt.Scan(&x)

	odds := 0
	var count [26]int
	for _, c := range x {
		count[c-'a']++
	}
	for _, i := range count {
		if i%2 == 1 {
			odds++
		}
	}

	if odds <= 1 || odds%2 == 1 {
		fmt.Println("First")
	} else {
		fmt.Println("Second")
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"regexp"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")

		letter_count_map := make(map[rune]int)
		for i := 0; i < len(s); i++ {
			letter_count_map[rune(s[i])] += 1
		}

		odd_count := 0
		for _, c := range letter_count_map {
			if c%2 != 0 {
				odd_count += 1
			}
		}

		if odd_count == 0 || odd_count%2 != 0 {
			fmt.Println("First")
		} else {
			fmt.Println("Second")
		}
	}
}

package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	counts := make([]int, 26, 26)
	for i := 0; i < len(s); i++ {
		counts[s[i]-'a']++
	}

	odd := 0
	for i := 0; i < 26; i++ {
		if counts[i]%2 != 0 {
			odd++
		}
	}

	if odd == 0 || odd == 1 || odd%2 == 1 {
		fmt.Println("First")
	} else {
		fmt.Println("Second")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var s string
	for I(&s, "\n") == nil {
		solve(s)
	}
}

func solve(s string) {
	in := make([]int, 35)
	for i := 0; i < len(s); i++ {
		in[s[i]-90]++
	}
	sort.Ints(in)
	k := 0
	for i := 0; i < 35; i++ {
		if in[i]%2 == 1 {
			k++
		}
	}
	if k%2 == 1 {
		O("First", "\n")
	} else {
		O("Second", "\n")
	}
}

package main

import (
	"fmt"
)

func isPalindrome(x *string) bool {
	n := len(*x) / 2
	for i := 0; i < n; i++ {
		if (*x)[i] != (*x)[len(*x)-i-1] {
			return false
		}
	}
	return true
}

func main() {
	var x string
	fmt.Scan(&x)

	if isPalindrome(&x) || len(x)&1 == 1 {
		fmt.Println("First")
	} else {
		fmt.Println("Second")
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"regexp"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")

		letter_count_map := make(map[rune]int)
		for i := 0; i < len(s); i++ {
			letter_count_map[rune(s[i])] += 1
		}

		odd_count := 0
		for _, c := range letter_count_map {
			if c%2 != 0 {
				odd_count += 1
			}
		}

		if odd_count%2 != 0 {
			fmt.Println("First")
		} else {
			fmt.Println("Second")
		}
	}
}