package main

// Solution for https://codeforces.com/problemset/problem/14/D

import "fmt"

var neighbors [][]int

type pair struct {
	i1, i2 int
}

var cache = make(map[pair]pair)

// Inspects subgraph connected to c2, but not c1.
// Returns the length of the longest path and the
// length of the longest path involving c2.
func longestPath(c1, c2 int) (resultMaxInternal, resultMaxConnected int) {
	if len(neighbors[c2]) == 1 {
		// c2 is only connected to c1.
		return 0, 0
	}
	if v, has := cache[pair{c1, c2}]; has {
		return v.i1, v.i2
	}
	maxInternal := 0
	maxConnected := 0
	nextMaxConnected := 0
	for _, c3 := range neighbors[c2] {
		if c3 == c1 {
			continue
		}
		internal, connected := longestPath(c2, c3)
		connected++
		if internal > maxInternal {
			maxInternal = internal
		}
		if connected > maxConnected {
			nextMaxConnected = maxConnected
			maxConnected = connected
		} else if connected > nextMaxConnected {
			nextMaxConnected = connected
		}
	}
	resultMaxConnected = maxConnected
	resultMaxInternal = maxInternal
	connection := maxConnected + nextMaxConnected
	if connection > resultMaxInternal {
		resultMaxInternal = connection
	}
	cache[pair{c1, c2}] = pair{resultMaxInternal, resultMaxConnected}
	return
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	neighbors = make([][]int, n)
	var edges []pair
	for i := 0; i < n-1; i++ {
		var c1, c2 int
		fmt.Scanf("%d %d\n", &c1, &c2)
		c1--
		c2--
		neighbors[c1] = append(neighbors[c1], c2)
		neighbors[c2] = append(neighbors[c2], c1)
		edges = append(edges, pair{c1, c2})
	}
	maxProduct := 0
	for _, edge := range edges {
		l1, _ := longestPath(edge.i1, edge.i2)
		l2, _ := longestPath(edge.i2, edge.i1)
		product := l1 * l2
		if product > maxProduct {
			maxProduct = product
		}
	}
	fmt.Println(maxProduct)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF14D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, w, ans int
	Fscan(in, &n)
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	d := func(u, no int) (maxD int) {
		var f func(v, fa, d int)
		f = func(v, fa, d int) {
			if d > maxD {
				maxD = d
				u = v
			}
			for _, w := range g[v] {
				if w != fa && w != no {
					f(w, v, d+1)
				}
			}
		}
		maxD = -1
		f(u, -1, 0)
		maxD = -1
		f(u, -1, 0)
		return
	}
	var f func(v, fa int)
	f = func(v, fa int) {
		for _, w := range g[v] {
			if w != fa {
				if s := d(v, w) * d(w, v); s > ans {
					ans = s
				}
				f(w, v)
			}
		}
	}
	f(0, -1)
	Fprint(out, ans)
}

func main() { CF14D(os.Stdin, os.Stdout) }


package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, m, v, w int
	Scan(&n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		Scan(&v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	dis := make([][]int, n)
	for i := range dis {
		d := make([]int, n)
		for j := range d {
			d[j] = -1
		}
		d[i] = 0
		q := []int{i}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			for _, w = range g[v] {
				if d[w] < 0 {
					d[w] = d[v] + 1
					q = append(q, w)
				}
			}
		}
		dis[i] = d
	}
	for i, d := range dis {
		for j, x := range d {
			c := make([]bool, n)
			m := int64(1)
			for k, y := range d {
				if k == i || k == j {
					continue
				}
				if y+dis[j][k] == x {
					if c[y] {
						m = 0
						break
					}
					c[y] = true
				} else {
					c := 0
					for _, w = range g[k] {
						if d[w]+1 == y && dis[j][w]+1 == dis[j][k] {
							c++
						}
					}
					m = m * int64(c) % 998244353
				}
			}
			Print(m, " ")
		}
		Println()
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	var n, m, v, w int
	Scan(&n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		Scan(&v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	dis := make([][]int, n)
	for i := range dis {
		d := make([]int, n)
		for j := range d {
			d[j] = -1
		}
		d[i] = 0
		q := []int{i}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			for _, w = range g[v] {
				if d[w] < 0 {
					d[w] = d[v] + 1
					q = append(q, w)
				}
			}
		}
		dis[i] = d
	}
	for i, d := range dis {
		for j, x := range d {
			c := make([]bool, n)
			m := int64(1)
			for k, y := range d {
				if k == i || k == j {
					continue
				}
				if y+dis[j][k] == x {
					if c[y] {
						m = 0
						break
					}
					c[y] = true
				} else {
					c := 0
					for _, w = range g[k] {
						if d[w]+1 == y && dis[j][w]+1 == dis[j][k] {
							c++
						}
					}
					m = m * int64(c) % 998244353
				}
			}
			Fprint(out, m, " ")
		}
		Fprintln(out)
	}
	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1495D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	dis := make([][]int, n)
	for i := range dis {
		d := make([]int, n)
		for j := range d {
			d[j] = -1
		}
		d[i] = 0
		q := []int{i}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			for _, w = range g[v] {
				if d[w] < 0 {
					d[w] = d[v] + 1
					q = append(q, w)
				}
			}
		}
		dis[i] = d
	}
	for i, d := range dis {
		for j, x := range d {
			c := make([]bool, n)
			m := int64(1)
			for k, y := range d {
				if k == i || k == j {
					continue
				}
				if y+dis[j][k] == x {
					if c[y] {
						m = 0
						break
					}
					c[y] = true
				} else {
					c := 0
					for _, w = range g[k] {
						if d[w]+1 == y && dis[j][w]+1 == dis[j][k] {
							c++
						}
					}
					m = m * int64(c) % 998244353
				}
			}
			Fprint(out, m, " ")
		}
		Fprintln(out)
	}
}

func main() { CF1495D(os.Stdin, os.Stdout) }

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	var n, m, v, w int
	Scan(&n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		Scan(&v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	dis := make([][]int, n)
	for v = range dis {
		d := make([]int, n)
		for i := range d {
			d[i] = -1
		}
		d[v] = 0
		q := []int{v}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			for _, w = range g[v] {
				if d[w] < 0 {
					d[w] = d[v] + 1
					q = append(q, w)
				}
			}
		}
		dis[v] = d
	}
	for i, d := range dis {
		for j, x := range d {
			c := make([]bool, n)
			m := int64(1)
			for k, y := range d {
				if k == i || k == j {
					continue
				}
				if y+dis[j][k] == x {
					if c[y] {
						m = 0
						break
					}
					c[y] = true
				} else {
					c := 0
					for _, w = range g[k] {
						if d[w]+1 == y && dis[j][w]+1 == dis[j][k] {
							c++
						}
					}
					m = m * int64(c) % 998244353
				}
			}
			Fprint(out, m, " ")
		}
		Fprintln(out)
	}
	out.Flush()
}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, k := readTwoNums(reader)
	A := readNNums(reader, n)
	fmt.Println(solve(n, k, A))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MAX_A = 1000000001

// 236411286

func solve(N, K int, A []int) int {

	count := func(parity int, x int) int {
		var j int
		for i := 0; i < N; i++ {
			if j&1 != parity || A[i] <= x {
				j++
			}
		}
		return j
	}

	check := func(x int) bool {
		return count(0, x) >= K || count(1, x) >= K
	}

	var left, right = 1, MAX_A

	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return right
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1370D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, k int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	f := func(c, up int) bool {
		for i := c; i < n; {
			for ; i < n && a[i] > up; i++ {
			}
			if i < n {
				c++
				i++
			}
			if i < n {
				c++
				i++
			}
		}
		return c >= k
	}
	Fprint(out, sort.Search(1e9, func(up int) bool { return f(0, up) || f(1, up) }))
}

func main() { CF1370D(os.Stdin, os.Stdout) }

package main

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

var (
	inn = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 10000000)
	inn.Split(bufio.ScanWords)
	//prep
	n, k := rd(), rd()
	a := make([]int, n)
	for i := range a {
		a[i] = rd()
	}
	l, r := 1, int(1e9)
	check := func(x, cur int) bool {
		var res int
		for _, it := range a {
			if cur == 0 || it <= x {
				res++
				cur ^= 1
			}
		}
		return res >= k
	}
	for l <= r {
		mid := (l + r) / 2
		if check(mid, 0) || check(mid, 1) {
			r = mid - 1
		} else {
			l = mid + 1
		}
	}
	Fprint(out, l)
}

//-------------------template------------------
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func maxll(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	x, _ = strconv.Atoi(string(inn.Bytes()))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	x, _ = strconv.ParseInt(string(inn.Bytes()), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n, k int
	con.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		con.Scan(&a[i])
	}
	hi := 1000000000
	lo := 1
	for hi > lo {
		mid := (hi + lo) / 2
		ok := false
		if !ok {
			j := 0
			for i := 0; i < n && j < k; i++ {
				if j%2 == 0 {
					if a[i] <= mid {
						j++
					}
				} else {
					j++
				}
			}
			ok = j == k
		}
		if !ok {
			j := 0
			for i := 0; i < n && j < k; i++ {
				if j%2 != 0 {
					if a[i] <= mid {
						j++
					}
				} else {
					j++
				}
			}
			ok = j == k
		}
		if ok {
			hi = mid
		} else if lo == mid {
			lo = mid + 1
		} else {
			lo = mid
		}
	}
	con.Println(lo)
	return nil
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, k := readTwoNums(reader)
	A := readNNums(reader, n)
	fmt.Println(solve(n, k, A))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MAX_A = 1000000001

func solve(N, K int, A []int) int {
	count := func(i int, x int) int {
		var cnt int
		for i < N {
			// from index 1, to make sure this arr is the less-half one
			if A[i] <= x {
				j := i
				for j < N && A[j] <= x {
					j++
				}
				cnt += (j - i + 1) / 2
				i = j - 1
			}
			i++
		}
		return cnt
	}

	check := func(x int) bool {
		//find a array of size H that <= x and not consective to each other
		cnt := count(1, x)
		if cnt >= K/2 {
			return true
		}
		if A[0] > x {
			return false
		}
		// consider A[0]
		cnt = count(0, x)
		return cnt >= (K+1)/2
	}

	var left, right = 1, MAX_A

	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return right
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, k := readTwoNums(reader)
	A := readNNums(reader, n)
	fmt.Println(solve(n, k, A))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MAX_A = 1000000001

// 236411286

func solve(N, K int, A []int) int {
	count := func(begin, end int, x int) int {
		var cnt int
		for i := begin; i < end; i++ {
			if A[i] <= x {
				j := i
				for j < N && A[j] <= x {
					j++
				}
				cnt += (j - i + 1) / 2
				i = j - 1
			}
		}
		return cnt
	}

	check := func(x int) bool {
		if K&2 == 0 {
			return count(0, N-1, x) >= K/2 || count(1, N, x) >= K/2
		}
		return count(0, N, x) >= (K+1)/2 || count(1, N-1, x) >= K/2
	}

	var left, right = 1, MAX_A

	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return right
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, k := readTwoNums(reader)
	A := readNNums(reader, n)
	fmt.Println(solve(n, k, A))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MAX_A = 1000000001

// 236411286

func solve(N, K int, A []int) int {
	count := func(begin, end int, x int) int {
		var cnt int
		for i := begin; i < end; i++ {
			if A[i] <= x {
				j := i
				for j < N && A[j] <= x {
					j++
				}
				cnt += (j - i + 1) / 2
				i = j - 1
			}
		}
		return cnt
	}

	check := func(x int) bool {
		cnt := count(0, N, x)
		if K&2 == 0 {
			return cnt >= K/2
		}
		if cnt >= (K+1)/2 {
			return true
		}
		return count(1, N-1, x) >= K/2
	}

	var left, right = 1, MAX_A

	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return right
}


package main

import (
	"bufio"
	"os"
	"fmt"
)
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	var n int
	scanf("%d\n", &n)
	a := make([]int,n)
	for i := 0;i<n;i++ {
		scanf("%d ",&a[i])
	}
	if a[0] != 0 {
		printf("%d\n",1)
	} else {
		flag := true
		r := 0
		c := 0
		b := 0
		for i :=1;i<n;i++ {
			if a[i]>=0  && (a[i]<c-1 || a[i]>b+1) {
				flag = false
				r = i+1
				break
			} else {
				if a[i]<c {
					c = a[i]
				}
				if a[i]>b {
					b= a[i]
				}
			}
		}
		if flag {
			printf("%d\n",-1)
		} else {
			printf("%d\n",r)
		}
	}

}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 100*1024*1024)
	nums := readInts(r, readInt(r))

	max := -1
	for i := 0; i < len(nums); i++ {
		if nums[i] >= 0 && nums[i] <= max + 1 {
			if nums[i] > max {
				max = nums[i]
			}
		} else {
			fmt.Print(i+1)
			return
		}
	}
	fmt.Print(-1)
}

func readString(reader *bufio.Reader, l int) string {
	sTemp := readLine(reader)
	if len(sTemp) < l {
		l = len(sTemp)
	}
	return sTemp[:l]
}

func readInt(reader *bufio.Reader) int {
	tmpInt, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)
	return int(tmpInt)
}

func readInts(reader *bufio.Reader, n int) []int {
	tmpInts := strings.Split(readLine(reader), " ")

	var result []int
	for i := 0; i < n; i++ {
		tmpInt, err := strconv.ParseInt(tmpInts[i], 10, 64)
		checkError(err)
		result = append(result, int(tmpInt))
	}
	return result
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 100*1024*1024)
	nums := readInts(r, readInt(r))

	max := -1
	for i := 0; i < len(nums); i++ {
		if nums[i] >= 0 && nums[i] <= max + 1 {
			if nums[i] > max {
				max = nums[i]
			}
		} else {
			fmt.Print(i+1)
			return
		}
	}
	fmt.Print(-1)
}

func readString(reader *bufio.Reader, l int) string {
	sTemp := readLine(reader)
	if len(sTemp) < l {
		l = len(sTemp)
	}
	return sTemp[:l]
}

func readInt(reader *bufio.Reader) int {
	tmpInt, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)
	return int(tmpInt)
}

func readInts(reader *bufio.Reader, n int) []int {
	l := readLine(reader)
	fmt.Println(l)
	tmpInts := strings.Split(l, " ")

	var result []int
	for i := 0; i < n; i++ {
		tmpInt, err := strconv.ParseInt(tmpInts[i], 10, 64)
		checkError(err)
		result = append(result, int(tmpInt))
	}
	return result
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}


package main

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

var in *bufio.Reader
var out *bufio.Writer

////////////////////////////////////////////////

func solve() {
	s := ReadString()
	n := len(s)

	Print(Abs(int(s[0]) - int(s[n-1])))

	ans := make([]int, 0)
	if s[0] < s[n-1] {
		for i := s[0]; i <= s[n-1]; i++ {
			for j := 0; j < n; j++ {
				if s[j] == i {
					ans = append(ans, j+1)
				}
			}
		}
	} else {
		for i := s[0]; i >= s[n-1]; i-- {
			for j := 0; j < n; j++ {
				if s[j] == i {
					ans = append(ans, j+1)
				}
			}
		}
	}
	Println("", len(ans))
	for _, i := range ans {
		Print(i, " ")
	}
	Println()
}

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

	t := 1
	t = ReadInt()

	for i := 0; i < t; i++ {
		solve()
	}
}

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

func ReadInts(n int) []int {
	a := make([]int, n)
	for i, _ := range a {
		a[i] = ReadInt()
	}
	return a
}

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

func Print(a ...any) {
	fmt.Fprint(out, a...)
}

func Println(a ...any) {
	fmt.Fprintln(out, a...)
}

type IntPair struct {
	x int
	y int
}

func Iota(a []int, start int) {
	for i := 0; i < len(a); i++ {
		a[i] = start
		start++
	}
}

func NextPermutation(a []int) bool {
	n := len(a)
	pos := n - 2
	for ; pos >= 0; pos-- {
		if a[pos] < a[pos+1] {
			break
		}
	}
	if pos == -1 {
		return false
	}
	for i := n - 1; i >= 0; i-- {
		if a[i] > a[pos] {
			a[i], a[pos] = a[pos], a[i]
			Reverse(a[pos+1 : n])
			break
		}
	}
	return true
}

func Reverse(a []int) {
	n := len(a)
	for i := 0; i < n/2; i++ {
		a[i], a[n-i-1] = a[n-i-1], a[i]
	}
}

func RemoveIf(a []int, cond func(int) bool) []int {
	n := len(a)
	pos := 0
	for i := 0; i < n; i++ {
		if !cond(a[i]) {
			a[pos] = a[i]
			pos++
		}
	}
	return a[0:pos]
}

func Min(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func Max(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Abs(x int) int {
	if x < 0 {
		return -x
	} else {
		return x
	}
}

package main

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

func distance(a, b byte) byte {
	if a < b {
		return b - a
	}
	return a - b
}

func printInts(arr []int) {
	buf := bytes.NewBuffer(nil)

	for i, v := range arr {
		if i > 0 {
			fmt.Fprint(buf, " ")
		}
		fmt.Fprint(buf, v)
	}
	fmt.Println(buf.String())
}

func main() {
	var cases int

	fmt.Scanln(&cases)

	buf := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		var str string
		fmt.Fscanln(buf, &str)

		fc := str[0]
		lc := str[len(str)-1]

		m := make([][]int, 256)
		for j := 0; j < len(str); j++ {
			c := str[j]

			m[c] = append(m[c], j+1)
		}

		step := 1
		if fc > lc {
			step = -1
		}

		path := make([]int, 0, len(str))
		for c := fc; c != lc; c += byte(step) {
			path = append(path, m[c]...)
		}
		path = append(path, m[lc]...)

		fmt.Println(distance(fc, lc), len(path))
		printInts(path)
	}

}

package main

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

const N = 3e5
const inf = 1e9

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }

func main() {
	in := os.Stdin
	out := os.Stdout
	// if isLocal() {
	// 	in, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	// }
	iost = NewIost(in, out)
	defer func() {
		iost.Writer.Flush()
	}()
	t := iost.GetNextInt()
	for t > 0 {
		t--
		s := iost.Text()
		n := len(s)
		var a [26][]int
		for i := 0; i < n; i++ {
			a[s[i]-'a'] = append(a[s[i]-'a'], i)
		}
		var x, y byte
		var o []int
		o = append(o, 1)
		if s[0] < s[n-1] {
			x = s[0]
			y = s[n-1]
			for i := x; i <= y; i++ {
				for j := 0; j < len(a[i-'a']); j++ {
					if a[i-'a'][j] != 0 && a[i-'a'][j] != n-1 {
						o = append(o, a[i-'a'][j]+1)
					}
				}
			}
		} else {
			x = s[n-1]
			y = s[0]
			for i := y; i >= x; i-- {
				for j := 0; j < len(a[i-'a']); j++ {
					if a[i-'a'][j] != 0 && a[i-'a'][j] != n-1 {
						o = append(o, a[i-'a'][j]+1)
					}
				}
			}
		}
		o = append(o, n)
		iost.Println(y-x, " ", len(o))
		for i := 0; i < len(o); i++ {
			iost.Print(o[i], " ")
		}
		iost.Println()
	}
}

package main

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

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

func main() {

	defer out.Flush()

	t := 0
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}

	for ; t > 0; t-- {
		s := ""
		if _, err := fmt.Fscan(in, &s); err != nil {
			return
		}
		mp := make(map[uint8][]int)
		for i := 0; i < len(s); i++ {
			mp[s[i]] = append(mp[s[i]], i)
		}
		a, b := s[0], s[len(s)-1]
		count := 0
		if a < b {
			for i := a; i <= b; i++ {
				count += len(mp[i])
			}
			fmt.Fprintln(out, b-a, count)
			for i := a; i <= b; i++ {
				for _, j := range mp[i] {
					fmt.Fprintf(out, "%v ", j+1)
				}
			}
		} else {
			for i := a; i >= b; i-- {
				count += len(mp[i])
			}
			fmt.Fprintln(out, a-b, count)
			for i := a; i >= b; i-- {
				for _, j := range mp[i] {
					fmt.Fprintf(out, "%v ", j+1)
				}
			}
		}
		fmt.Fprintln(out)
	}
}

package main

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

// https://space.bilibili.com/206214
func CF1729C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		pos := [26][]int{}
		for i, b := range s {
			b -= 'a'
			pos[b] = append(pos[b], i+1)
		}
		d := 1
		if s[0] > s[n-1] {
			d = -1
		}
		ans := []int{}
		for i := int(s[0] - 'a'); ; i += d {
			ans = append(ans, pos[i]...)
			if i == int(s[n-1]-'a') {
				break
			}
		}
		Fprintln(out, abs(int(s[0])-int(s[n-1])), len(ans))
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}
func main() { CF1729C(os.Stdin, os.Stdout) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanws(a ...interface{})           { fmt.Fscan(reader, a...) }

func main() {

	defer writer.Flush()
	var tc int
	var s string
	var idx [27][]int
	var ans []int
	var cost int

	scanws(&tc)
	for t := 1; t <= tc; t++ {
		scanws(&s)
		ans = nil
		for i := 0; i <= 26; i++ {
			idx[i] = nil
		}
		n := len(s)
		for i := 0; i < n; i++ {
			a := byte(s[i] - 'a' + 1)
			temp := idx[a]
			temp = append(temp, i+1)
			idx[a] = temp
		}
		var st int = int(s[0] - 'a' + 1)
		var ed int = int(s[n-1] - 'a' + 1)
		if st < ed {
			cost = ed - st
			for ; st <= ed; st++ {
				nn := len(idx[st])
				for j := 0; j < nn; j++ {
					ans = append(ans, idx[st][j])
				}
			}
		} else {
			cost = st - ed
			for ; st >= ed; st-- {
				nn := len(idx[st])
				for j := 0; j < nn; j++ {
					ans = append(ans, idx[st][j])
				}
			}
		}
		nn := len(ans)
		printf("%d %d\n", cost, nn)
		for i := 0; i < nn; i++ {
			if i != 0 {
				printf(" ")
			}
			printf("%d", ans[i])
		}
		printf("\n")
	}

}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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 < T; t++ {
		var s string
		fmt.Fscan(in, &s)

		aa := make([][]int, 26)
		for i, ch := range s {
			aa[ch-'a'] = append(aa[ch-'a'], i)
		}

		a, b := int(s[0]-'a'), int(s[len(s)-1]-'a')
		var c int
		if a > b {
			for i := a; i >= b; i-- {
				c += len(aa[i])
			}
			fmt.Fprintln(out, abs(a-b), c)
			for i := a; i >= b; i-- {
				for _, v := range aa[i] {
					fmt.Fprintf(out, "%d ", v+1)
				}
			}
		} else {
			for i := a; i <= b; i++ {
				c += len(aa[i])
			}

			fmt.Fprintln(out, abs(a-b), c)
			for i := a; i <= b; i++ {
				for _, v := range aa[i] {
					fmt.Fprintf(out, "%d ", v+1)
				}
			}
		}
		fmt.Fprintln(out)
	}
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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 < T; t++ {
		var s string
		fmt.Fscan(in, &s)

		aa := make([][]int, 26)
		for i, ch := range s {
			aa[ch-'a'] = append(aa[ch-'a'], i)
		}

		bb := []int{}
		a, b := int(s[0]-'a'), int(s[len(s)-1]-'a')
		if a > b {
			for i := a; i >= b; i-- {
				for _, v := range aa[i] {
					bb = append(bb, v+1)
				}
			}
		} else {
			for i := a; i <= b; i++ {
				for _, v := range aa[i] {
					bb = append(bb, v+1)
				}
			}
		}

		fmt.Fprintln(out, abs(a-b), len(bb))
		for _, v := range bb {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func index(r rune) int {
	return int(r-'a') + 1
}

type pair struct {
	r rune
	i int
}

func solve() string {
	var s string
	fmt.Fscan(in, &s)
	var runes = []rune(s)
	var l, r = runes[0], runes[len(runes)-1]
	var reverse bool

	if l > r {
		l, r = r, l
		reverse = true
	}

	var res = make([]pair, 0, len(runes))

	for i, x := range runes {
		if x >= l && x <= r {
			res = append(res, pair{r: x, i: i + 1})
		}
	}

	if reverse {
		sort.Slice(res, func(i, j int) bool {
			if res[i].r < res[j].r {
				return false
			}
			return true
		})
	} else {
		sort.Slice(res, func(i, j int) bool {
			if res[i].r < res[j].r {
				return true
			}
			return false
		})
	}

	str1 := fmt.Sprintf("%d %d\n", abs(int(l-r)), len(res))
	var strArr = make([]string, 1, len(res))
	strArr[0] = "1"
	for i := 0; i < len(res); i++ {
		if res[i].i != 1 && res[i].i != len(runes) {
			strArr = append(strArr, strconv.Itoa(res[i].i))
		}
	}
	strArr = append(strArr, strconv.Itoa(len(runes)))

	return str1 + strings.Join(strArr, " ")
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var tests = 1
	Fscan(in, &tests)

	var run_case func()
	run_case = func() {
		var n int
		var ans = []int{}
		//Fscan(in, &n)
		a := make([][]int, 0)

		var ss string
		Fscan(in, &ss)
		s := []byte(ss)
		n = len(s)
		for i := 1; i < n-1; i++ {
			if s[i] <= max(s[0], s[n-1]) && s[i] >= min(s[0], s[n-1]) {
				a = append(a, []int{int(s[i]), i})
			}
		}
		sort.Slice(a, func(i, j int) bool {
			if a[i][0] == a[j][0] {
				return i < j
			}
			if s[0] > s[n-1] {
				return a[i][0] > a[j][0]
			} else {
				return a[i][0] < a[j][0]
			}
		})
		for _, v := range a {
			ans = append(ans, v[1])
		}
		Fprintln(out, abs(s[0], s[n-1]), len(ans)+2)
		Fprint(out, 1, " ")
		for _, v := range ans {
			Fprint(out, v+1)
			Fprint(out, " ")
		}
		Fprint(out, len(s))
		Fprintln(out)
	}

	for i := 0; i < tests; i++ {
		run_case()
	}
}
func max(a, b byte) byte {
	if a > b {
		return a
	}
	return b
}
func min(a, b byte) byte {
	if a < b {
		return a
	}
	return b
}
func abs(a, b byte) byte {
	if a > b {
		return a - b
	}
	return b - a
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 2
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(len(str), " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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"
	"sort"
)

type T struct {
	index int
	value byte
}

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	var s string
	Fscan(in, &t)
	for t > 0 {
		t--
		Fscan(in, &s)
		b := []byte(s)
		a := make([]T, 0)
		if b[0] <= b[len(b)-1] {
			for i := 1; i < len(b)-1; i++ {
				if b[i] >= b[0] && b[i] <= b[len(b)-1] {
					a = append(a, T{i, b[i]})
				}
			}
			sort.Slice(a, func(i, j int) bool {
				return a[i].value < a[j].value
			})
			Fprintln(out, int(b[len(b)-1]-b[0]), len(a)+2)
			result := make([]int, 0)
			result = append(result, 1)
			for i := range a {
				result = append(result, a[i].index+1)
			}
			result = append(result, len(b))
			for i := range result {
				if i != len(result)-1 {
					Fprint(out, result[i], " ")
				} else {
					Fprint(out, result[i], "\n")
				}
			}
		} else {
			for i := 1; i < len(b)-1; i++ {
				if b[i] <= b[0] && b[i] >= b[len(b)-1] {
					a = append(a, T{i, b[i]})
				}
			}
			sort.Slice(a, func(i, j int) bool {
				return a[i].value > a[j].value
			})
			Fprintln(out, b[0]-b[len(b)-1], len(a)+2)
			result := make([]int, 0)
			result = append(result, 1)
			for i := range a {
				result = append(result, a[i].index+1)
			}
			result = append(result, len(b))
			for i := range result {
				if i != len(result)-1 {
					Fprint(out, result[i], " ")
				} else {
					Fprint(out, result[i], "\n")
				}
			}
		}
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	m = 2
	if s > e {
		cost = int(s - e)
		for i := s; i >= e; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		cost = int(e - s)
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		o := fmt.Sprintf("%v", path)
		fmt.Println(o[1 : len(o)-1])
	}
}

package main
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)

	defer out.Flush()

	abs := func(i int) int {
		if (i > 0) {
			return i;
		} else {
			return -i;
		}
	}

	var T int
	for Fscan(in, &T); T > 0; T-- {
		var s string
		Fscan(in, &s)

		n := len(s)
		a := [26][]int{}
		for i, c := range s {
			d := int(c - 'a')
			a[d] = append(a[d], i+1)
		}

		d := 1
		if (s[0] > s[n - 1]) {
			d = -1
		}

		ans := []int{}
		for i := int(s[0]) - 'a'; ; i += d {
			if (i == int(s[n - 1]) - 'a' + d || i == 26 || i == -1) {
				break
			}
			for _, j := range a[i] {
				ans = append(ans, j)
			}
		}
		Fprintln(out, abs(int(s[0]) - int(s[n - 1])), len(ans))
		for _, i := range ans {
			Fprint(out, i, " ")
		}
		Fprintln(out)
	}
}
func main() { solve(os.Stdin, os.Stdout) }

package main
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
func CF1729C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var s string
	Fscan(in, &T)

	for ; T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		a := [26][]int{}
		for i, c := range s {
			d := int(c - 'a')
			a[d] = append(a[d], i+1)
		}
		d := 1
		if (s[0] > s[n - 1]) {
			d = -1
		}
		ans := []int{}
		for i := int(s[0] - 'a'); ; i += d {
			ans = append(ans, a[i]...)
			if (i == int(s[n - 1] - 'a')) {
				break
			}
		}
		al := int(s[0]) - int(s[n - 1])
		if (al < 0) {
			al = -al
		}
		Fprintln(out, al, len(ans))
		for _, h := range ans {
			Fprint(out, h, " ")
		}
		Fprintln(out)
	}
}
func main() { CF1729C(os.Stdin, os.Stdout) }

package main

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

// github.com/EndlessCheng/codeforces-go
func CF981E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	abs := func(x int) int {
		if x < 0 {
			return -x
		} else {
			return x
		}
	}

	var T int
	var s string
	Fscan(in, &T)
	for ; T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		pos := [26][]int{}
		for i, b := range s {
			b -= 'a'
			pos[b] = append(pos[b], i+1)//pos[b].push_back(i+1)
		}
		d := 1
		if s[0] > s[n - 1] {
			d = -1
		}
		ans := []int{}
		for i := int(s[0] - 'a'); ; i += d {
			ans = append(ans, pos[i]...)
			if i == int(s[n - 1] - 'a') {
				break
			}
		}
		Fprintln(out, abs(int(s[0]) - int(s[n - 1])), len(ans))
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

func main() { CF981E(os.Stdin, os.Stdout) }

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m1 := make(Nodes, 0)

		for i := range s {
			m1 = append(m1, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m1[0]
		tail := m1[len(m1)-1]

		m := m1.GetInterval(head.value, tail.value)

		if head.value < tail.value {
			sort.Slice(m, func(a, b int) bool { return m[a].value < m[b].value })
		} else {
			sort.Slice(m, func(a, b int) bool { return m[a].value > m[b].value })
		}

		sid := -1
		for i := 0; i < len(m); i++ {
			if sid < 0 && m[i].value == head.value {
				sid = i
			}
			if m[i] == head {
				m[sid], m[i] = m[i], m[sid]
				break
			}
		}

		eid := -1
		for i := len(m) - 1; i > sid; i-- {
			if eid < 0 && m[i].value == tail.value {
				eid = i
			}
			if m[i] == tail {
				m[eid], m[i] = m[i], m[eid]
			}
		}
		m = m[sid : eid+1]

		sum := 0
		path := make([]int, 0)

		for i := 1; i < len(m); i++ {
			sum += Abs(m[i].value - m[i-1].value)
		}
		for i := range m {
			path = append(path, m[i].id)
		}
		fmt.Fprintln(writer, sum, len(path))
		s = fmt.Sprintf("%v", path)
		s = s[1 : len(s)-1]
		fmt.Fprintln(writer, s)
		Flush()
	}

}

func Abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

func (n Nodes) GetInterval(a, b int) Nodes {
	if a > b {
		return n.GetInterval(b, a)
	}

	m := make(Nodes, 0)
	for i := 0; i < len(n); i++ {
		if a <= n[i].value && n[i].value <= b {
			m = append(m, n[i])
		}
	}
	return m
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 2
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(len(str)-1, " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(len(str)-1, " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 1
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(len(str)-1, " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 1
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(str[len(str)-1], " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 1
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str); j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str); j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 0; j < len(str); j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int           { return len(a.els) }
func (a arr) Less(i, j int) bool { return a.asc == (a.els[i].value < a.els[j].value) }
func (a arr) Swap(i, j int)      { a.els[i], a.els[j] = a.els[j], a.els[i] }

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 0; j < len(str); j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int           { return len(a.els) }
func (a arr) Less(i, j int) bool { return a.asc == (a.els[i].value < a.els[j].value) }
func (a arr) Swap(i, j int)      { a.els[i], a.els[j] = a.els[j], a.els[i] }

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := range str {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index+1, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int           { return len(a.els) }
func (a arr) Less(i, j int) bool { return a.asc == (a.els[i].value < a.els[j].value) }
func (a arr) Swap(i, j int)      { a.els[i], a.els[j] = a.els[j], a.els[i] }

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := range str {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index+1, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] < str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int           { return len(a.els) }
func (a arr) Less(i, j int) bool { return a.asc == (a.els[i].value < a.els[j].value) }
func (a arr) Swap(i, j int)      { a.els[i], a.els[j] = a.els[j], a.els[i] }

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := range str {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] < str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

// https://codeforces.com/contest/1729/problem/C

package main

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

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "abc"

		if str[0] < str[len(str)-1] {
			asc(str)
		} else {
			desc(str)
		}
	}
}

func asc(str string) {
	var firstLetter = str[0]
	var lastLetter = str[len(str)-1]

	var path = BinaryTree{}
	for j := range str {
		if str[j] >= firstLetter && str[j] <= lastLetter {
			path.insert(data{index: j, value: str[j]})
		}
	}

	indices := path.root.indices()
	fmt.Println(lastLetter-firstLetter, len(indices))
	for _, index := range indices {
		fmt.Print(index+1, " ")
	}
	fmt.Println()
}

func desc(str string) {
	var firstLetter = str[0]
	var lastLetter = str[len(str)-1]

	var path = LBinaryTree{}
	for j := range str {
		if str[j] <= firstLetter && str[j] >= lastLetter {
			path.insert(data{index: j, value: str[j]})
		}
	}

	indices := path.root.indices()
	fmt.Println(firstLetter-lastLetter, len(indices))
	for _, index := range indices {
		fmt.Print(index+1, " ")
	}
	fmt.Println()
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

type data struct {
	index int
	value uint8
}

type BinaryTree struct {
	root *BinaryNode
}

func (t *BinaryTree) insert(data data) *BinaryTree {
	if t.root == nil {
		t.root = &BinaryNode{data: data}
	} else {
		t.root.insert(data)
	}
	return t
}

type BinaryNode struct {
	left  *BinaryNode
	right *BinaryNode
	data  data
}

func (n *BinaryNode) insert(data data) {
	if n == nil {
		return
	} else if data.value < n.data.value {
		if n.left == nil {
			n.left = &BinaryNode{data: data}
		} else {
			n.left.insert(data)
		}
	} else {
		if n.right == nil {
			n.right = &BinaryNode{data: data}
		} else {
			n.right.insert(data)
		}
	}
}

func (n *BinaryNode) indices() []int {
	if n == nil {
		return nil
	}
	return append(n.left.indices(), append([]int{n.data.index}, n.right.indices()...)...)
}

type LBinaryTree struct {
	root *LBinaryNode
}

func (t *LBinaryTree) insert(data data) *LBinaryTree {
	if t.root == nil {
		t.root = &LBinaryNode{data: data}
	} else {
		t.root.insert(data)
	}
	return t
}

type LBinaryNode struct {
	left  *BinaryNode
	right *BinaryNode
	data  data
}

func (n *LBinaryNode) insert(data data) {
	if n == nil {
		return
	} else if data.value > n.data.value {
		if n.left == nil {
			n.left = &BinaryNode{data: data}
		} else {
			n.left.insert(data)
		}
	} else {
		if n.right == nil {
			n.right = &BinaryNode{data: data}
		} else {
			n.right.insert(data)
		}
	}
}

func (n *LBinaryNode) indices() []int {
	if n == nil {
		return nil
	}
	return append(n.left.indices(), append([]int{n.data.index}, n.right.indices()...)...)
}

// https://codeforces.com/contest/1729/problem/C

package main

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

func main() {
	t := readInt64()

	for i := 0; i < int(t); i++ {
		str := readString()

		var firstLetter = str[0]
		var lastLetter = str[len(str)-1]

		var cost uint8
		var up bool
		if firstLetter < lastLetter {
			cost = lastLetter - firstLetter
			up = true
		} else {
			cost = firstLetter - lastLetter
			up = false
		}

		var down = !up

		var path = BinaryTree{}
		for j := range str {
			if up && str[j] >= firstLetter && str[j] <= lastLetter ||
				down && str[j] <= firstLetter && str[j] >= lastLetter {

				path.insert(data{index: j, value: str[j]})
			}
		}

		indices := path.root.indices()
		if down {
			for j := range indices {
				if j == len(indices)/2 {
					break
				} else {
					indices[j], indices[len(indices)-1-j] = indices[len(indices)-1-j], indices[j]
				}
			}
		}
		fmt.Println(cost, len(indices))
		for _, index := range indices {
			fmt.Print(index+1, " ")
		}
		fmt.Println()
	}
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readString() 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 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
}

type data struct {
	index int
	value uint8
}

type BinaryNode struct {
	left  *BinaryNode
	right *BinaryNode
	data  data
}

type BinaryTree struct {
	root *BinaryNode
}

func (t *BinaryTree) insert(data data) *BinaryTree {
	if t.root == nil {
		t.root = &BinaryNode{data: data, left: nil, right: nil}
	} else {
		t.root.insert(data)
	}
	return t
}

func (n *BinaryNode) insert(data data) {
	if n == nil {
		return
	} else if data.value <= n.data.value {
		if n.left == nil {
			n.left = &BinaryNode{data: data, left: nil, right: nil}
		} else {
			n.left.insert(data)
		}
	} else {
		if n.right == nil {
			n.right = &BinaryNode{data: data, left: nil, right: nil}
		} else {
			n.right.insert(data)
		}
	}
}

func (n *BinaryNode) indices() []int {
	if n == nil {
		return nil
	}
	return append(n.left.indices(), append([]int{n.data.index}, n.right.indices()...)...)
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	m = 2
	if s > e {
		cost = int(s - e)
		for i := e; i >= s; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		cost = int(e - s)
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	if s > e {
		cost = int(s - e)
		for i := s; i >= e; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		cost = int(e - s)
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	m = 2
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	if s > e {
		cost = int(s - e)
		for i := e; i >= s; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		cost = int(e - s)
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	m = 2
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	cost = int(e - s)
	if cost < 0 {
		cost *= 1
	}
	if s > e {
		for i := e; i >= s; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	m = 2
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}
	if s > e {
		s, e = e, s
	}
	cost = int(e - s)
	m = 2
	for i := s; i <= e; i++ {
		if v, ok := pos[i]; ok {
			m += len(v)
			path = append(path, v...)
		}
	}
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]
	cost = int(s - e)
	if cost < 0 {
		cost *= -1
	}

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}
	if s > e {
		s, e = e, s
	}
	for i := s; i <= e; i++ {
		if v, ok := pos[i]; ok {
			path = append(path, v...)
		}
	}
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)

	defer out.Flush()

	abs := func(i int) int {
		if (i > 0) {
			return i;
		} else {
			return -i;
		}
	}

	var T int
	for Fscan(in, &T); T > 0; T-- {
		var s string
		Fscan(in, &s)

		n := len(s)
		a := [26][]int{}
		for i, c := range s {
			d := int(c - 'a')
			a[d] = append(a[d], i+1)
		}

		d := 1
		if (s[0] > s[n - 1]) {
			d = -1
		}

		ans := []int{}
		for i := int(s[0]) - 'a'; ; i += d {
			if (i == 26 || i == -1) {
				break
			}
			for _, j := range a[i] {
				ans = append(ans, j)
			}
			if (i == int(s[n - 1]) - 'a' + d) {
				break
			}
		}
		Fprintln(out, abs(int(s[0]) - int(s[n - 1])), len(ans))
		for _, i := range ans {
			Fprint(out, i, " ")
		}
		Fprintln(out)
	}
}
func main() { solve(os.Stdin, os.Stdout) }

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m := make(Nodes, 0)

		for i := range s {
			m = append(m, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m[0]
		tail := m[len(m)-1]
		sort.Sort(&m)
		sum := 0
		path := make(Path, 0)

		for i, a, b := 1, false, false; i < len(m)+1; i++ {
			if m[i-1] == tail {
				b = true
			}
			if m[i-1] == head {
				a = true
			}
			if a && b {
				path = append(path, m[i-1].id)
				break
			}
			v1, v2 := m[i].value, m[i-1].value
			sum += Abs(v1 - v2)
			path = append(path, m[i-1].id)
		}
		if path[0] != 1 {
			for i, j := 0, len(path)-1; i < j; i, j = i+1, j-1 {
				path[i], path[j] = path[j], path[i]
			}
		}
		fmt.Fprintln(writer, sum, len(path))
		fmt.Fprintln(writer, &path)
		Flush()
	}

}

func Abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

type Path []int

func (p Path) String() string {
	s := ""
	for i := range p {
		s += fmt.Sprintf("%d ", p[i])
	}
	if len(s) > 0 {
		s = s[:len(s)-1]
	}
	return s
}

func (n *Path) Len() int           { return len(*n) }
func (n *Path) Less(a, b int) bool { return (*n)[a] < (*n)[b] }
func (n *Path) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m := make(Nodes, 0)

		for i := range s {
			m = append(m, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m[0]
		tail := m[len(m)-1]
		sort.Sort(&m)
		sum := 0
		path := make(Path, 0)

		for i, a, b := 1, false, false; i < len(m)+1; i++ {
			if m[i-1] == tail {
				b = true
			}
			if m[i-1] == head {
				a = true
			}
			if a && b {
				path = append(path, m[i-1].id)
				break
			}
			v1, v2 := m[i].value, m[i-1].value
			sum += Abs(v1 - v2)
			path = append(path, m[i-1].id)
		}
		for i := 0; i < len(path); i++ {
			if path[i] == 1 {
				path[0], path[i] = path[i], path[0]
				break
			}
		}
		fmt.Fprintln(writer, sum, len(path))
		fmt.Fprintln(writer, &path)
		Flush()
	}

}

func Abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

type Path []int

func (p Path) String() string {
	s := ""
	for i := range p {
		s += fmt.Sprintf("%d ", p[i])
	}
	if len(s) > 0 {
		s = s[:len(s)-1]
	}
	return s
}

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m := make(Nodes, 0)

		for i := range s {
			m = append(m, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m[0]
		tail := m[len(m)-1]
		sort.Sort(&m)
		sum := 0
		path := make(Path, 0)

		for i, a, b := 1, false, false; i < len(m)+1; i++ {
			if m[i-1] == tail {
				b = true
			}
			if m[i-1] == head {
				a = true
			}
			if a && b {
				path = append(path, m[i-1].id)
				break
			}
			v1, v2 := m[i].value, m[i-1].value
			sum += Abs(v1 - v2)
			path = append(path, m[i-1].id)
		}
		sort.Ints(path)
		fmt.Fprintln(writer, sum, len(path))
		fmt.Fprintln(writer, &path)
		Flush()
	}

}

func Abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

type Path []int

func (p *Path) String() string {
	s := ""
	for i := range *p {
		s += fmt.Sprintf("%d ", (*p)[i])
	}
	if len(s) > 0 {
		s = s[:len(s)-1]
	}
	return s
}

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m := make(Nodes, 0)

		for i := range s {
			m = append(m, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m[0]
		tail := m[len(m)-1]
		sort.Sort(&m)
		sum := 0
		path := make(Path, 0)

		for i, a, b := 1, false, false; i < len(m)+1; i++ {
			if m[i-1] == tail {
				b = true
			}
			if m[i-1] == head {
				a = true
			}
			if a && b {
				path = append(path, m[i-1].id)
				break
			}
			v1, v2 := m[i].value, m[i-1].value
			sum += Abs(v1 - v2)
			path = append(path, m[i-1].id)
		}
		fmt.Fprintln(writer, sum, len(path))
		fmt.Fprintln(writer, &path)
		Flush()
	}

}

func Abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

type Path []int

func (p *Path) String() string {
	s := ""
	for i := range *p {
		s += fmt.Sprintf("%d ", (*p)[i])
	}
	if len(s) > 0 {
		s = s[:len(s)-1]
	}
	return s
}

package main

import (
	"fmt"
)

const N = 3e5
const inf = 1e9

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var s string
		fmt.Scan(&s)
		n := len(s)
		var a [26][]int
		for i := 0; i < n; i++ {
			a[s[i]-'a'] = append(a[s[i]-'a'], i)
		}
		var x, y byte
		if s[0] < s[n-1] {
			x = s[0]
			y = s[n-1]
		} else {
			x = s[n-1]
			y = s[0]
		}
		var o []int
		o = append(o, 1)
		for i := x; i <= y; i++ {
			for j := 0; j < len(a[i-'a']); j++ {
				if a[i-'a'][j] != 0 && a[i-'a'][j] != n-1 {
					o = append(o, a[i-'a'][j]+1)
				}
			}
		}
		o = append(o, n)
		fmt.Println(y-x, " ", len(o))
		for i := 0; i < len(o); i++ {
			fmt.Print(o[i], " ")
		}
		fmt.Println()
	}
}

package main

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

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

func main() {

	defer out.Flush()

	t := 0
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}

	for ; t > 0; t-- {
		s := ""
		if _, err := fmt.Fscan(in, &s); err != nil {
			return
		}
		mp := make(map[uint8][]int)
		for i := 0; i < len(s); i++ {
			mp[s[i]] = append(mp[s[i]], i)
		}
		a, b := s[0], s[len(s)-1]
		count := 0
		if a < b {
			for i := a; i <= b; i++ {
				count += len(mp[i])
			}
			fmt.Fprintln(out, b-a, count)
			for i := a; i <= b; i++ {
				for _, j := range mp[i] {
					fmt.Fprint(out, j+1, " ")
				}
			}
		} else {
			for i := a; i >= b; i-- {
				count += len(mp[i])
			}
			fmt.Fprintln(out, a-b, count)
			for i := a; i >= b; i-- {
				for _, j := range mp[i] {
					fmt.Fprint(out, j+1)
				}
			}
		}
		fmt.Fprintln(out)
	}
}

package main

import "fmt"

func main() {

	solute := func(s string) {
		left := 0
		unknown := 0
		for i := 0; i < len(s); i++ {
			if s[i] == '(' {
				left++
			} else if s[i] == '?' {
				unknown++
			} else {
				if left > 0 {
					left--
				} else {
					unknown--
				}
			}
		}
		if unknown > 2 {
			fmt.Println("NO")
		} else if unknown == 2 && s[0] != '(' {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}

	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	for i := 0; i < n; i++ {
		var s string
		if _, err := fmt.Scanf("%s\n", &s); err != nil {
			return
		}
		solute(s)
	}

	return

}

package main

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

func distance(a, b byte) byte {
	if a < b {
		return b - a
	}
	return a - b
}

func printInts(arr []int) {
	buf := bytes.NewBuffer(nil)

	for i, v := range arr {
		if i > 0 {
			fmt.Fprint(buf, " ")
		}
		fmt.Fprint(buf, v)
	}
	fmt.Println(buf.String())
}

func main() {
	var cases int

	fmt.Scanln(&cases)

	buf := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		var str string
		fmt.Fscanln(buf, &str)

		fc := str[0]
		lc := str[len(str)-1]

		m := make([][]int, 256)
		for j := 0; j < len(str); j++ {
			c := str[j]

			m[c] = append(m[c], j+1)
		}
		fmt.Println(m)

		step := 1
		if fc > lc {
			step = -1
		}

		path := make([]int, 0, len(str))
		for c := fc; c != lc; c += byte(step) {
			fmt.Println(path)
			path = append(path, m[c]...)
		}
		path = append(path, m[lc]...)

		fmt.Println(distance(fc, lc), len(path))
		printInts(path)
	}

}

package main

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

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

func index(r rune) int {
	return int(r-'a') + 1
}

type pair struct {
	r rune
	i int
}

func solve() string {
	var s string
	fmt.Fscan(in, &s)
	var runes = []rune(s)
	var l, r = runes[0], runes[len(runes)-1]
	var reverse bool

	if l > r {
		l, r = r, l
		reverse = true
	}

	var res = make([]pair, 0, len(runes))

	for i, x := range runes {
		if x >= l && x <= r {
			res = append(res, pair{r: x, i: i + 1})
		}
	}

	if reverse {
		sort.Slice(res, func(i, j int) bool {
			if res[i].r < res[j].r {
				return false
			}
			return true
		})
	} else {
		sort.Slice(res, func(i, j int) bool {
			if res[i].r < res[j].r {
				return true
			}
			return false
		})
	}

	str1 := fmt.Sprintf("%d %d\n", abs(int(l-r)), len(res))
	var strArr = make([]string, len(res))
	for i := range res {
		strArr[i] = strconv.Itoa(res[i].i)
	}

	return str1 + strings.Join(strArr, " ")
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var tests = 1
	Fscan(in, &tests)

	var run_case func()
	run_case = func() {
		var n int
		var ans = []int{}
		//Fscan(in, &n)
		a := make([][]int, 0)

		var ss string
		Fscan(in, &ss)
		s := []byte(ss)
		n = len(s)
		for i := 0; i < n; i++ {
			if s[i] <= max(s[0], s[n-1]) && s[i] >= min(s[0], s[n-1]) {
				a = append(a, []int{int(s[i]), i})
			}
		}
		sort.Slice(a, func(i, j int) bool {
			if a[i][0] == a[j][0] {
				return i < j
			}
			if s[0] > s[n-1] {
				return a[i][0] > a[j][0]
			} else {
				return a[i][0] < a[j][0]
			}
		})
		for _, v := range a {
			ans = append(ans, v[1])
		}
		Fprintln(out, abs(s[0], s[n-1]), len(ans))
		for _, v := range ans {
			Fprint(out, v+1)
			Fprint(out, " ")
		}
		Fprintln(out)
	}

	for i := 0; i < tests; i++ {
		run_case()
	}
}
func max(a, b byte) byte {
	if a > b {
		return a
	}
	return b
}
func min(a, b byte) byte {
	if a < b {
		return a
	}
	return b
}
func abs(a, b byte) byte {
	if a > b {
		return a - b
	}
	return b - a
}