package main

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

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

func readLines(n int) []string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = readLine()
	}
	return res
}

func readInt() int {
	n, err := strconv.ParseInt(readLine(), 10, 32)
	if err != nil {
		panic(err)
	}
	return int(n)
}

func readInt2() (int, int) {
	as := readInts(2)
	return as[0], as[1]
}

func readInt3() (int, int, int) {
	as := readInts(3)
	return as[0], as[1], as[2]
}

func readUint() uint64 {
	n, err := strconv.ParseUint(readLine(), 10, 64)
	if err != nil {
		panic(err)
	}
	return n
}

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
}

func readStrings(n int) []string {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	return as
}

func arr(n, m int) [][]int {
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	return a
}

const N, MAXN int = 1e5 + 7, 1e9

var in = bufio.NewReader(os.Stdin)
var a, b [N]int

func maxVal(u, v int) int {
	if u > v {
		return u
	}
	return v
}

func minVal(u, v int) int {
	if u < v {
		return u
	}
	return v
}

func check(n, k, val int) bool {
	cnt := 0
	for i := 1; i <= n; i++ {
		b[i] = a[i]
		if a[i]*2 < val {
			cnt++
			b[i] = MAXN
		}
	}
	if cnt > k {
		return false
	} else if cnt == k {
		maxv := 0
		for i := 1; i < n; i++ {
			maxv = maxVal(maxv, minVal(b[i], b[i+1]))
		}
		return maxv >= val
	} else if cnt+1 == k {
		maxv := 0
		for i := 1; i <= n; i++ {
			maxv = maxVal(maxv, b[i])
		}
		return maxv >= val
	} else {
		return true
	}
}

func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, n, k, l, r, mid, ans int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		fmt.Fscan(in, &n, &k)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		l, r, ans = 1, MAXN, -1
		for l <= r {
			mid = (l + r) >> 1
			if check(n, k, mid) {
				l, ans = mid+1, mid
			} else {
				r = mid - 1
			}
		}
		fmt.Fprintln(out, ans)
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)
		P := readNNums(reader, n)
		res := solve(k, P)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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 X = 1000000000

func solve(k int, A []int) int {
	n := len(A)
	cnt := make([]int, n+1)

	check := func(x int) bool {
		if x > X {
			return false
		}
		// can we get x as the result within k steps
		for i := 0; i < n; i++ {
			cnt[i+1] = cnt[i]
			if 2*A[i] < x {
				cnt[i+1]++
			}
		}

		for i := 0; i+1 < n; i++ {
			kk := k
			if A[i] < x {
				kk--
			}
			if A[i+1] < x {
				kk--
			}
			if kk < 0 {
				continue
			}
			x := cnt[i] + cnt[n] - cnt[i+2]
			if x <= kk {
				return true
			}
		}

		return false
	}

	l, r := 0, X+1

	for l < r {
		mid := (l + r) / 2
		if !check(mid) {
			r = mid
		} else {
			l = mid + 1
		}
	}

	return r - 1
}

package main

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

type void struct{}
var member void

var (
	reader bufio.Reader
	writer bufio.Writer
)

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

func btoi(b bool) int {
	if b {
		return 1
	} else {
		return 0
	}
}

func solve() {
	var n, k int
	scan(&n, &k)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}

	if n == 2 {
		if k == 1 {
			printf("%v\n", max(a[0], a[1]))
		} else {
			printf("%v\n", 1000000000)
		}
		return
	}

	var f func(int) bool = func(mid int) bool {
		pref := make([]int, n)
		for i := 0; i < n; i++ {
			if i > 0 {
				pref[i] = pref[i - 1]
			}
			if a[i] * 2 < mid {
				pref[i]++
			}
		}

		suf := make([]int, n)
		for i := n - 1; i >= 0; i-- {
			if i + 1 < n {
				suf[i] = suf[i + 1]
			}
			if a[i] * 2 < mid {
				suf[i]++
			}
		}

		for i := 1; i < n - 2; i++ {
			var now int = btoi(a[i] < mid) + btoi(a[i + 1] < mid)
			if now + pref[i - 1] + suf[i + 2] <= k {
				return true
			}
		}

		{
			var now int = btoi(a[0] < mid) + btoi(a[1] < mid)
			if now + suf[2] <= k {
				return true
			}
		}

		{
			var now int = btoi(a[n - 2] < mid) + btoi(a[n - 1] < mid)
			if now + pref[n - 3] <= k {
				return true
			}
		}

		return false
	};

	var l, r int = 0, 1e9 + 1
	for ; r - l > 1; {
		var mid int = (l + r) / 2
		if f(mid) {
			l = mid
		} else {
			r = mid
		}
	}

	printf("%v\n", l)
}

func main() {
	inp, err := os.Open("in.txt")
	if err == nil {
		os.Stdin = inp
		outp, _ := os.Create("out.txt")
		os.Stdout = outp
		defer outp.Close()
		defer inp.Close()
	}
	reader = *bufio.NewReader(os.Stdin)
	writer = *bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	T = 1
	scan(&T)

	for ; T > 0; T-- {
		solve()
	}
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(&reader, a...)
}

func printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(&writer, format, a...)
}

package main

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

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 n, k int
		fmt.Fscan(r, &n, &k)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(n, k, a)
		fmt.Fprintln(w, w1)
	}
}

func do(n, k int, a []int) int {
	mx := int(1e9)
	if k >= n {
		return mx
	}
	b := make([]int, n)
	for i := range b {
		b[i] = i
	}
	sort.Slice(b, func(i, j int) bool {
		return a[b[i]] < a[b[j]]
	})
	t := &node{l: 1, r: n - 1}
	for i := 0; i < k-1; i++ {
		a[b[i]] = 1e9
	}
	for i := 1; i < n; i++ {
		v := a[i-1]
		if v > a[i] {
			v = a[i]
		}
		set(t, i, v)
	}
	r := 0
	for i := k - 1; i < n; i++ {
		var x, y int
		if b[i] > 0 {
			x = get(t, b[i], b[i])
			set(t, b[i], a[b[i]-1])
		}
		if b[i] < n-1 {
			y = get(t, b[i]+1, b[i]+1)
			set(t, b[i]+1, a[b[i]+1])
		}
		w := 2 * a[b[k-1]]
		if i == k-1 {
			if k < n {
				w = 2 * a[b[k]]
			} else {
				w = 2 * mx
			}
		}
		v := get(t, 1, n-1)
		if v > w {
			v = w
		}
		if r < v {
			r = v
		}
		if b[i] > 0 {
			set(t, b[i], x)
		}
		if b[i] < n-1 {
			set(t, b[i]+1, y)
		}
	}
	// dia<=2min{a_i}
	// dia<=max{min{a_i,a_{i+1}}}
	// max dia
	return r
}

type node struct {
	l, r, v int
	ln, rn  *node
}

func set(n *node, x, v int) {
	if n.l == n.r {
		n.v = v
		return
	}
	m := (n.l + n.r) / 2
	if n.ln == nil {
		n.ln = &node{l: n.l, r: m}
		n.rn = &node{l: m + 1, r: n.r}
	}
	if x <= m {
		set(n.ln, x, v)
	} else {
		set(n.rn, x, v)
	}
	n.v = n.ln.v
	if n.v < n.rn.v {
		n.v = n.rn.v
	}
}

func get(n *node, l, r int) int {
	if l <= n.l && n.r <= r {
		return n.v
	}
	m := (n.l + n.r) / 2
	if r <= m {
		return get(n.ln, l, r)
	} else if l >= m+1 {
		return get(n.rn, l, r)
	} else {
		v := get(n.ln, l, m)
		if v2 := get(n.rn, m+1, r); v < v2 {
			v = v2
		}
		return v
	}
}

package main

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

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 n, k int
		fmt.Fscan(r, &n, &k)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		if ti == 33 {
			fmt.Fprintln(w, n, k)
			for i := range a {
				fmt.Fprint(w, a[i], " ")
			}
			fmt.Fprintln(w)
		}
		w1 := do(n, k, a)
		fmt.Fprintln(w, w1)
	}
}

func do(n, k int, a []int) int {
	if k >= n {
		return 1e9
	}
	b := make([]int, n)
	for i := range b {
		b[i] = i
	}
	sort.Slice(b, func(i, j int) bool {
		return a[b[i]] < a[b[j]]
	})
	for i := 0; i < k; i++ {
		a[b[i]] = 1e9
	}
	r := a[b[k]]
	x := 2 * r
	for i := 1; i < n; i++ {
		y := a[i-1]
		if y > a[i] {
			y = a[i]
		}
		if y >= x {
			r = x
			break
		}
		if r < y {
			r = y
		}
	}
	return r
}

package main

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

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 n, k int
		fmt.Fscan(r, &n, &k)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(n, k, a)
		fmt.Fprintln(w, w1)
	}
}

func do(n, k int, a []int) int {
	if k >= n {
		return 1e9
	}
	b := make([]int, n)
	for i := range b {
		b[i] = i
	}
	sort.Slice(b, func(i, j int) bool {
		return a[b[i]] < a[b[j]]
	})
	for i := 0; i < k; i++ {
		a[b[i]] = 1e9
	}
	x := 2 * a[b[k]]
	r := 0
	for i := 1; i < n; i++ {
		y := a[i-1]
		if y > a[i] {
			y = a[i]
		}
		if y >= x {
			r = x
			break
		}
		if r < y {
			r = y
		}
	}
	return r
}


package main

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

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

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)
		a := make([][]byte, n)
		for i := 0; i < n; i++ {
			a[i] = make([]byte, n)
			fmt.Fscan(in, &s)
			for j := range s {
				if i != j {
					a[i][j] = s[j]
				}
			}
		}
		if m%2 == 1 {
			fmt.Fprintln(out, "YES")
			fmt.Fprint(out, "1 2")
			for i := 1; i < m; i++ {
				if i%2 == 0 {
					fmt.Fprint(out, " 2")
				} else {
					fmt.Fprint(out, " 1")
				}
			}
			fmt.Fprintln(out)
		} else {
			if n == 2 {
				if a[0][1] != a[1][0] {
					fmt.Fprintln(out, "NO")
				} else {
					fmt.Fprintln(out, "YES")
					fmt.Fprint(out, "1 2")
					for i := 1; i < m; i++ {
						if i%2 == 0 {
							fmt.Fprint(out, " 2")
						} else {
							fmt.Fprint(out, " 1")
						}
					}
					fmt.Fprintln(out)
				}
			} else {
				fmt.Fprintln(out, "YES")
				if a[0][1] == a[1][2] && a[0][1] == a[2][0] {
					for i := 0; i <= m; i++ {
						fmt.Fprint(out, i%3+1, " ")
					}
					fmt.Fprintln(out)
				} else if a[0][1] == a[1][0] || a[1][2] == a[2][1] || a[2][0] == a[0][2] {
					if a[0][1] == a[1][0] {
						for i := 0; i <= m; i++ {
							fmt.Fprint(out, i%2+1, " ")
						}
						fmt.Fprintln(out)
					} else if a[1][2] == a[2][1] {
						for i := 0; i <= m; i++ {
							fmt.Fprint(out, i%2+2, " ")
						}
						fmt.Fprintln(out)
					} else if a[2][0] == a[0][2] {
						for i := 0; i <= m; i++ {
							fmt.Fprint(out, (i%2)*2+1, " ")
						}
						fmt.Fprintln(out)
					}
				} else {
					c, l, r := 1, 2, 3
					if a[0][1] == a[1][2] {
						c, l, r = 2, 1, 3
					} else if a[1][2] == a[2][0] {
						c, l, r = 3, 1, 2
					}
					if m%4 == 0 {
						for i := 0; i < m/4; i++ {
							fmt.Fprintf(out, "%d %d %d %d ", c, l, c, r)
						}
						fmt.Fprintln(out, c)
					} else {
						for i := 0; i < m/2; i++ {
							if i%2 == 0 {
								fmt.Fprint(out, r, " ")
							} else {
								fmt.Fprint(out, c, " ")
							}
						}
						fmt.Fprint(out, c)
						for i := 0; i < m/2; i++ {
							if i%2 == 0 {
								fmt.Fprint(out, " ", l)
							} else {
								fmt.Fprint(out, " ", c)
							}
						}
						fmt.Fprintln(out)
					}
				}
			}
		}
		out.Flush()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
		}
		for i, r := range g {
			for j := i + 1; j < n; j++ {
				if r[j] == g[j][i] {
					Fprintln(out, "YES")
					for k := 0; k <= m; k++ {
						if k&1 == 0 {
							Fprint(out, i+1, " ")
						} else {
							Fprint(out, j+1, " ")
						}
					}
					Fprintln(out)
					return
				}
			}
		}
		if n < 3 {
			if m&1 == 0 {
				Fprintln(out, "NO")
				return
			}
			Fprintln(out, "YES")
			for i := 0; i < m; i += 2 {
				Fprint(out, 1, 2, " ")
			}
			Fprintln(out)
			return
		}

		Fprintln(out, "YES")
		if g[0][1] == g[1][2] && g[1][2] == g[2][0] {
			for i := 0; i <= m; i++ {
				Fprint(out, i%3+1, " ")
			}
			Fprintln(out)
			return
		}

		x := [3]int{}
		if g[0][1] == g[0][2] {
			x = [3]int{0, 1, 2}
			if g[1][2] != g[0][1] {
				x = [3]int{0, 2, 1}
			}
		} else if g[1][0] == g[1][2] {
			x = [3]int{1, 0, 2}
			if g[0][2] != g[1][0] {
				x = [3]int{1, 2, 0}
			}
		} else {
			x = [3]int{2, 0, 1}
			if g[0][1] != g[2][0] {
				x = [3]int{2, 1, 0}
			}
		}
		for i := 0; i < 3; i++ {
			x[i]++
		}
		if m%2 > 0 {
			Fprint(out, x[0], " ")
			for i := 0; i < m-1; i += 2 {
				Fprint(out, x[1], x[0], " ")
			}
			Fprintln(out, x[1])
		} else if m%4 == 2 {
			Fprint(out, x[0], " ")
			for i := 0; i < m-2; i += 4 {
				Fprint(out, x[1], x[2], x[1], x[0], " ")
			}
			Fprintln(out, x[1], x[2])
		} else {
			Fprint(out, x[1], " ")
			for i := 0; i < m; i += 4 {
				Fprint(out, x[2], x[1], x[0], x[1], " ")
			}
			Fprintln(out)
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		G := make([][]byte, n)
		for i := 0; i < n; i++ {
			G[i], _ = reader.ReadBytes('\n')
		}
		res := solve(n, m, G)

		if len(res) == 0 {
			buf.WriteString("NO\n")
		} else {
			buf.WriteString("YES\n")
			for i := 0; i < len(res); i++ {
				buf.WriteString(fmt.Sprintf("%d ", res[i]))
			}
			buf.WriteByte('\n')
		}
	}
	fmt.Print(buf.String())
}

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
}

func solve(n int, m int, G [][]byte) []int {
	res := make([]int, m+1)
	if m&1 == 1 {
		for i := 0; i <= m; i++ {
			res[i] = (i & 1) + 1
		}
		//res[m] = 1
		return res
	}
	// then m is even
	var ok bool
	var pivot [2]int

	has := make([][]int, n)
	for i := 0; i < n; i++ {
		has[i] = make([]int, 2)
		for j := 0; j < 2; j++ {
			has[i][j] = -1
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			if G[i][j] == G[j][i] {
				pivot = [...]int{i, j}
				ok = true
			}
			has[i][int(G[i][j]-'a')] = j
		}
	}

	if ok {
		for i := 0; i <= m; i++ {
			res[i] = pivot[i&1] + 1
		}
		return res
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			cur := has[j][int(G[i][j]-'a')]
			if cur < 0 {
				continue
			}
			if (m/2)&1 == 1 {
				for k := 0; k <= m; k++ {
					if k%4 == 0 {
						res[k] = i + 1
					} else if k%4 == 2 {
						res[k] = cur + 1
					} else {
						res[k] = j + 1
					}
				}
			} else {
				var p int
				res[p] = j + 1
				p++
				for k := 0; k < m/2; k++ {
					if k&1 == 1 {
						res[p] = j + 1
					} else {
						res[p] = cur + 1
					}
					p++
				}
				for k := 0; k < m/2; k++ {
					if k&1 == 1 {
						res[p] = j + 1
					} else {
						res[p] = i + 1
					}
					p++
				}
				return res
			}

			return res
		}
	}

	return nil
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
		}
		for i, r := range g {
			for j := i + 1; j < n; j++ {
				if r[j] == g[j][i] {
					Fprintln(out, "YES")
					for k := 0; k <= m; k++ {
						if k&1 == 0 {
							Fprint(out, i+1, " ")
						} else {
							Fprint(out, j+1, " ")
						}
					}
					Fprintln(out)
					return
				}
			}
		}
		if n < 3 {
			if m&1 == 0 {
				Fprintln(out, "NO")
				return
			}
			Fprintln(out, "YES")
			for i := 0; i < m; i += 2 {
				Fprint(out, 1, 2, " ")
			}
			Fprintln(out)
			return
		}
		Fprintln(out, "YES")
		if g[0][1] == g[1][2] && g[1][2] == g[2][0] {
			for i := 1; i <= m; i++ {
				Fprint(out, i%3, " ")
			}
			Fprintln(out)
			return
		}
		x := [3]int{}
		if g[0][1] == g[0][2] {
			x = [3]int{0, 1, 2}
			if g[1][2] != g[0][1] {
				x = [3]int{0, 2, 1}
			}
		} else if g[1][0] == g[1][2] {
			x = [3]int{1, 0, 2}
			if g[0][2] != g[1][0] {
				x = [3]int{1, 2, 0}
			}
		} else {
			x = [3]int{2, 0, 1}
			if g[0][1] != g[2][0] {
				x = [3]int{2, 1, 0}
			}
		}
		if m%2 > 0 {
			Fprint(out, x[0], " ")
			for i := 0; i < m-1; i += 2 {
				Fprint(out, x[1], x[0], " ")
			}
			Fprintln(out, x[1])
		} else if m%4 == 0 {
			Fprint(out, x[0], " ")
			for i := 0; i < m-2; i += 4 {
				Fprint(out, x[1], x[2], x[1], x[0], " ")
			}
			Fprintln(out, x[1], x[2])
		} else {
			Fprint(out, x[1], " ")
			for i := 0; i < m; i += 4 {
				Fprint(out, x[2], x[1], x[0], x[1], " ")
			}
			Fprintln(out)
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
		}
		for i, r := range g {
			for j := i + 1; j < n; j++ {
				if r[j] == g[j][i] {
					Fprintln(out, "YES")
					for k := 0; k <= m; k++ {
						if k&1 == 0 {
							Fprint(out, i+1, " ")
						} else {
							Fprint(out, j+1, " ")
						}
					}
					Fprintln(out)
					return
				}
			}
		}
		if n < 3 {
			if m&1 == 0 {
				Fprintln(out, "NO")
				return
			}
			Fprintln(out, "YES")
			Fprint(out, 1, " ")
			for i := 0; i < m-1; i += 2 {
				Fprint(out, 2, 1)
			}
			Fprintln(out)
			return
		}
		Fprintln(out, "YES")
		if g[0][1] == g[1][2] && g[1][2] == g[2][0] {
			for i := 1; i <= m; i++ {
				Fprint(out, i%3, " ")
			}
			Fprintln(out)
			return
		}
		x := [3]int{}
		if g[0][1] == g[0][2] {
			x = [3]int{0, 1, 2}
			if g[1][2] != g[0][1] {
				x = [3]int{0, 2, 1}
			}
		} else if g[1][0] == g[1][2] {
			x = [3]int{1, 0, 2}
			if g[0][2] != g[1][0] {
				x = [3]int{1, 2, 0}
			}
		} else {
			x = [3]int{2, 0, 1}
			if g[0][1] != g[2][0] {
				x = [3]int{2, 1, 0}
			}
		}
		if m%2 > 0 {
			Fprint(out, x[0], " ")
			for i := 0; i < m-1; i += 2 {
				Fprint(out, x[1], x[0], " ")
			}
			Fprintln(out, x[1])
		} else if m%4 == 0 {
			Fprint(out, x[0], " ")
			for i := 0; i < m-2; i += 4 {
				Fprint(out, x[1], x[2], x[1], x[0], " ")
			}
			Fprintln(out, x[1], x[2])
		} else {
			Fprint(out, x[1], " ")
			for i := 0; i < m; i += 4 {
				Fprint(out, x[2], x[1], x[0], x[1], " ")
			}
			Fprintln(out)
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
		}
		for i, r := range g {
			for j := i + 1; j < n; j++ {
				if r[j] == g[j][i] {
					Fprintln(out, "YES")
					for k := 0; k <= m; k++ {
						if k&1 == 0 {
							Fprint(out, i+1, " ")
						} else {
							Fprint(out, j+1, " ")
						}
					}
					Fprintln(out)
					return
				}
			}
		}
		if n < 3 {
			Fprintln(out, "NO")
			return
		}
		Fprintln(out, "YES")
		if g[0][1] == g[1][2] && g[1][2] == g[2][0] {
			for i := 1; i <= m; i++ {
				Fprint(out, i%3, " ")
			}
			Fprintln(out)
			return
		}
		x := [3]int{}
		if g[0][1] == g[0][2] {
			x = [3]int{0, 1, 2}
			if g[1][2] != g[0][1] {
				x = [3]int{0, 2, 1}
			}
		} else if g[1][0] == g[1][2] {
			x = [3]int{1, 0, 2}
			if g[0][2] != g[1][0] {
				x = [3]int{1, 2, 0}
			}
		} else {
			x = [3]int{2, 0, 1}
			if g[0][1] != g[2][0] {
				x = [3]int{2, 1, 0}
			}
		}
		if m%2 > 0 {
			Fprint(out, x[0], " ")
			for i := 0; i < m-1; i += 2 {
				Fprint(out, x[1], x[0], " ")
			}
			Fprintln(out, x[1])
		} else if m%4 == 0 {
			Fprint(out, x[0], " ")
			for i := 0; i < m-2; i += 4 {
				Fprint(out, x[1], x[2], x[1], x[0], " ")
			}
			Fprintln(out, x[1], x[2])
		} else {
			Fprint(out, x[1], " ")
			for i := 0; i < m; i += 4 {
				Fprint(out, x[2], x[1], x[0], x[1], " ")
			}
			Fprintln(out)
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		G := make([][]byte, n)
		for i := 0; i < n; i++ {
			G[i], _ = reader.ReadBytes('\n')
		}
		res := solve(n, m, G)

		if len(res) == 0 {
			buf.WriteString("NO\n")
		} else {
			buf.WriteString("YES\n")
			for i := 0; i < len(res); i++ {
				buf.WriteString(fmt.Sprintf("%d ", res[i]))
			}
			buf.WriteByte('\n')
		}
	}
	fmt.Print(buf.String())
}

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
}

func solve(n int, m int, G [][]byte) []int {
	res := make([]int, m+1)
	if m&1 == 1 {
		for i := 0; i < m; i++ {
			res[i] = 1
			res[i+1] = 2
		}
		res[m] = 1
		return res
	}
	// then m is even
	var ok bool
	var pivot [2]int

	has := make([][]int, n)
	for i := 0; i < n; i++ {
		has[i] = make([]int, 2)
		for j := 0; j < 2; j++ {
			has[i][j] = -1
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			if G[i][j] == G[j][i] {
				pivot = [...]int{i, j}
				ok = true
			}
			has[i][int(G[i][j]-'a')] = j
		}
	}

	if ok {
		for i := 0; i <= m; i++ {
			res[i] = pivot[i&1] + 1
		}
		return res
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			cur := has[j][int(G[i][j]-'a')]
			if cur < 0 {
				continue
			}
			if (m/2)&1 == 1 {
				for k := 0; k <= m; k++ {
					if k%4 == 0 {
						res[k] = i + 1
					} else if k%4 == 2 {
						res[k] = cur + 1
					} else {
						res[k] = j + 1
					}
				}
			} else {
				var p int
				res[p] = j + 1
				p++
				for k := 0; k < m/2; k++ {
					if k&1 == 1 {
						res[p] = j + 1
					} else {
						res[p] = cur + 1
					}
					p++
				}
				for k := 0; k < m/2; k++ {
					if k&1 == 1 {
						res[p] = j + 1
					} else {
						res[p] = i + 1
					}
					p++
				}
				return res
			}

			return res
		}
	}

	return nil
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		G := make([][]byte, n)
		for i := 0; i < n; i++ {
			G[i], _ = reader.ReadBytes('\n')
		}
		res := solve(n, m, G)

		if len(res) == 0 {
			buf.WriteString("NO\n")
		} else {
			buf.WriteString("YES\n")
			for i := 0; i < len(res); i++ {
				buf.WriteString(fmt.Sprintf("%d ", res[i]))
			}
			buf.WriteByte('\n')
		}
	}
	fmt.Print(buf.String())
}

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
}

func solve(n int, m int, G [][]byte) []int {
	var ok bool
	var pivot [2]int
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = -1
		b[i] = -1
	}
	for i := 0; i < n && !ok; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			if G[i][j] == G[j][i] {
				pivot = [...]int{i + 1, j + 1}
				ok = true
				break
			}
			if G[i][j] == 'a' && a[i] < 0 {
				a[i] = j
			}
			if G[i][j] == 'b' && b[i] < 0 {
				b[i] = j
			}
		}
	}
	res := make([]int, m+1)

	if ok {
		for i := 0; i < m; i += 2 {
			res[i] = pivot[0]
			res[i+1] = pivot[1]
		}
		if m&1 == 0 {
			res[m] = pivot[0]
		}
	} else {
		// all (u, v) != (v, u)
		if m&1 == 0 && n == 2 {
			return nil
		}
		if m&1 == 1 {
			// ababa
			for i := 0; i < m; i += 2 {
				res[i] = 1
				res[i+1] = 2
			}
			res[m] = 1
		} else {
			//aaabbaaa
			h := (m - 2) / 2
			res[0] = 0
			i := 1
			for i < h {
				res[i] = a[res[i-1]]
				i++
			}
			res[i] = b[res[i-1]]
			i++
			res[i] = b[res[i-1]]
			i++
			for i < m {
				res[i] = a[res[i-1]]
				i++
			}
			for j := 0; j < m; j++ {
				res[j]++
			}
		}
	}

	return res
}

package main

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

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

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)
		a := make([][]byte, n)
		for i := 0; i < n; i++ {
			a[i] = make([]byte, n)
			fmt.Fscan(in, &s)
			for j := range s {
				if i != j {
					a[i][j] = s[j]
				}
			}
		}
		if m%2 == 1 {
			fmt.Fprintln(out, "YES")
			fmt.Fprint(out, "1 2")
			for i := 1; i < m; i++ {
				if i%2 == 0 {
					fmt.Fprint(out, " 2")
				} else {
					fmt.Fprint(out, " 1")
				}
			}
			fmt.Fprintln(out)
		} else {
			if n == 2 {
				if a[0][1] != a[1][0] {
					fmt.Fprintln(out, "NO")
				} else {
					fmt.Fprintln(out, "YES")
					fmt.Fprint(out, "1 2")
					for i := 1; i < m; i++ {
						if i%2 == 0 {
							fmt.Fprint(out, " 2")
						} else {
							fmt.Fprint(out, " 1")
						}
					}
					fmt.Fprintln(out)
				}
			} else {
				fmt.Fprintln(out, "YES")
				if a[0][1] == a[1][2] && a[0][1] == a[2][0] {
					for i := 0; i <= m; i++ {
						fmt.Fprint(out, i%3+1, " ")
					}
					fmt.Fprintln(out)
				} else {
					c, l, r := 1, 2, 3
					if a[0][1] == a[1][2] {
						c, l, r = 2, 1, 3
					} else if a[1][2] == a[2][0] {
						c, l, r = 3, 1, 2
					}
					if m%4 == 0 {
						for i := 0; i < m/4; i++ {
							fmt.Fprintf(out, "%d %d %d %d ", c, l, c, r)
						}
						fmt.Fprintln(out, c)
					} else {
						for i := 0; i < m/2; i++ {
							if i%2 == 0 {
								fmt.Fprint(out, r, " ")
							} else {
								fmt.Fprint(out, c, " ")
							}
						}
						fmt.Fprint(out, c)
						for i := 0; i < m/2; i++ {
							if i%2 == 0 {
								fmt.Fprint(out, " ", l)
							} else {
								fmt.Fprint(out, " ", c)
							}
						}
						fmt.Fprintln(out)
					}
				}
			}
		}
		out.Flush()
	}
}


package main

import (
	"fmt"
)

func main() {
	var t, n int
	fmt.Scan(&t)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Printf("%d ", arr[j])
		}

		fmt.Printf("\n")
	}

}

//s

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	res := make([][]int, 0, t)

	for i := 0; i < t; i++ {
		var n, x int
		fmt.Scan(&n)
		arr := make([]int, 0, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&x)
			arr = append(arr, x)
		}

		for j := 0; j < n/2; j++ {
			tmp := arr[j]
			arr[j] = arr[n-1-j]
			arr[n-1-j] = tmp
		}

		res = append(res, arr)
	}

	for i := 0; i < t; i++ {
		for _, v := range res[i] {
			fmt.Printf("%d ", v)
		}
		fmt.Printf("\n")
	}
}

//

package main

import (
	"fmt"
	// "sort"
	"strings"
)

func reverse(numbers []int) []int {
	for i := 0; i < len(numbers)/2; i++ {
		j := len(numbers) - i - 1
		numbers[i], numbers[j] = numbers[j], numbers[i]
	}
	return numbers
}

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var l int
		fmt.Scan(&l)
		var arr []int = make([]int, l)
		for j := 0; j < l; j++ {
			fmt.Scan(&arr[j])
		}
		fmt.Println(strings.Trim(fmt.Sprint(reverse(arr)), "[]"))
	}
}

package main

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

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanInt := func(n *int) {
		scanner.Scan()
		num, _ := strconv.ParseInt(scanner.Text(), 10, 32)
		*n = int(num)
	}

	var t, n, p int
	scanInt(&t) // number of cases

	for i := 0; i < t; i++ {
		scanInt(&n)
		arrP := make([]string, n)

		for j := 1; j <= n; j++ {
			scanInt(&p)
			arrP[n-j] = fmt.Sprintf("%d", p)
		}

		fmt.Print(strings.Join(arrP, " ")+"\n")
	}
}

package main

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

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

func max(a, b int) int {
	if a == min(a, b) {
		return b
	}
	return a
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func GetNum(p string) int64 {
	var ans int64 = 0
	flag := true
	i := 0
	n := len(p)
	if p[i] == '-' {
		flag = false
		i++
	}
	for ; i < n; i++ {
		ans = (ans << 1) + (ans << 3) + int64(p[i]-'0')
	}
	if !flag {
		ans = -ans
	}
	return ans
}
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	return int(GetNum(intStr))
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func ReadInt64() int64 {
	int64Str := ReadString()
	return GetNum(int64Str)
}
func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

func init() {

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1<<10), int(2e+5))
	in.Split(bufio.ScanWords)

	out = make(chan string, 1<<4)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)
	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()
		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

func work() {
	n := ReadInt()
	p := ReadIntSlice(n)
	for i := n - 1; i >= 0; i-- {
		fmt.Printf("%d ", p[i])
	}
	fmt.Println()
}

func main() {

	for t := ReadInt(); t > 0; t-- {
		work()
	}
	close(out)
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		aa := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &aa[j])
		}
		for j := n - 1; j >= 0; j-- {
			fmt.Printf("%d ", aa[j])
		}
		fmt.Println()
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	for t := in(); t > 0; t-- {
		n := in()
		a := make([]int, n)

		for i := range a {
			a[i] = in()
		}

		for i := n - 1; i >= 0; i-- {
			fmt.Print(a[i], " ")
		}

		fmt.Println()
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		arr := [100]int{}
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Printf("%d ", arr[j])
		}

		fmt.Printf("\n")
	}

}

package main

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

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

	var t, n int
	fmt.Fscan(in, &t)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])

		}

		fmt.Fprintf(out, "\n")

	}

	defer out.Flush()
}

// kek

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		arr := [100]int{}
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
		}

		for j := 0; j < n/2; j++ {
			tmp := arr[j]
			arr[j] = arr[n-1-j]
			arr[n-1-j] = tmp
		}

		for j := 0; j < n; j++ {
			fmt.Printf("%d ", arr[j])
		}

		fmt.Printf("\n")
	}

}

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Printf("%d ", arr[j])
		}

		fmt.Printf("\n")
	}

}

//s

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)

	var t, n int
	fmt.Fscan(in, &n)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Printf("%d ", arr[j])
		}

		fmt.Printf("\n")
	}

}

//s

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &t)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(in, "%d ", &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])
			out.Flush()
		}

		fmt.Fprintf(out, "\n")
		out.Flush()
	}

}

//s

package main

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

func main() {
	var t, n int
	fmt.Scan(&t)

	scanner := bufio.NewScanner(os.Stdin)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		scanner.Scan()
		n, _ = strconv.Atoi(scanner.Text())
		// fmt.Scan(&n)
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Printf("%d ", arr[j])
		}

		fmt.Printf("\n")
	}

}

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(in, "%d ", &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])
		}

		fmt.Fprintf(out, "\n")
	}

	defer out.Flush()
}

//s

package main

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

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

	var t, n int
	fmt.Fscan(in, &n)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])
		}

		fmt.Fprintf(out, "\n")
	}

}

//s

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &t)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(in, "%d ", &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])
		}

		fmt.Fprintf(out, "\n")
		out.Flush()
	}

}

//s

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	res := make([][]int, 0, t)

	for i := 0; i < t; i++ {
		var n, x int
		fmt.Scan(&n)
		arr := make([]int, 0, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		tmp := arr[0]
		arr[0] = arr[1]
		arr[1] = tmp
		res = append(res, arr)
	}

	for i := 0; i < t; i++ {
		for _, v := range res[i] {
			fmt.Printf("%d ", v)
		}
		fmt.Printf("\n")
	}
}

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(in, "%d", &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])
		}

		fmt.Fprintf(out, "\n")
	}

}

//s

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &t)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(in, "%d ", &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])
		}

		fmt.Fprintf(out, "\n")
	}

	out.Flush()
}

//s

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(in, "%d ", &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])
		}

		fmt.Fprintf(out, "\n")
	}

	out.Flush()
}

//s

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(in, "%d", &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Printf("%d ", arr[j])
		}

		fmt.Printf("\n")
	}

}

//s

package main

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

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

	var t, n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := [100]int{}
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(in, "%d ", &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			fmt.Fprintf(out, "%d ", arr[j])
		}

		fmt.Fprintf(out, "\n")
	}
}

//s

package main

import (
	"fmt"
	"strings"
)

// 3
// 2
// 1 2
// 6
// 2 1 6 5 4 3
// 5
// 2 4 3 1 5
func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var l int
		fmt.Scan(&l)
		var arr []int = make([]int, l)
		for j := 0; j < l; j++ {
			fmt.Scan(&arr[j])
		}
		if l%2 == 0 {
			for j := 0; j < l-1; j++ {
				temp := arr[j]
				arr[j] = arr[j+1]
				arr[j+1] = temp
			}
		} else {
			for j := 0; j <= l-3; j++ {
				temp := arr[j]
				arr[j] = arr[j+2]
				arr[j+2] = temp
			}
		}
		fmt.Println(strings.Trim(fmt.Sprint(arr), "[]"))
	}
}

// 2 4 3 1 5
// 0 1 2 3 4
//     i

// 3 1 5 4 2

package main

import (
	"fmt"
	"strings"
)

// 3
// 2
// 1 2
// 6
// 2 1 6 5 4 3
// 5
// 2 4 3 1 5
func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var l int
		fmt.Scan(&l)
		var arr []int = make([]int, l)
		for j := 0; j < l; j++ {
			fmt.Scan(&arr[j])
		}
		if l%2 == 0 {
			for j := 0; j <= l-2; j = j + 2 {
				temp := arr[j]
				arr[j] = arr[j+1]
				arr[j+1] = temp
			}
		} else {
			for j := 0; j <= l-3; j++ {
				temp := arr[j]
				arr[j] = arr[j+2]
				arr[j+2] = temp
			}
			temp := arr[l-1]
			arr[l-1] = arr[l-2]
			arr[l-2] = temp
		}
		fmt.Println(strings.Trim(fmt.Sprint(arr), "[]"))
	}
}

// 2 4 3 1 5

// 3 1 5 2 4


package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		d := make([]int64, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &d[i])
		}

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

		var ans int64
		for i := 1; i < n; i++ {
			ans -= (d[i] - d[i-1]) * (int64(i)*int64(n-i) - 1)
		}

		fmt.Println(ans)
	}
}

package main

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

var input io.Reader = bufio.NewReader(os.Stdin)

//fmt.Fscan(input,&x)
//fmt.Println(x)
func main() {
	var T int
	fmt.Fscan(input, &T)
	for {
		var n int
		fmt.Fscan(input, &n)
		v := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &v[i])
		}
		sort.Ints(v[1:n+1])
		var ans int64 = 0
		sum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			sum[i] = sum[i-1] + int64(v[i])
			var tt int64 = int64(i)*int64(v[i]) - sum[i]
			ans += tt
		}
		fmt.Println(int64(v[n]) - ans)
		T--
		if T == 0 {
			break
		}
	}
}

package main

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

type ll []int64

func (a ll) Len() int           { return len(a) }
func (a ll) Less(i, j int) bool { return a[i]< a[j] }
func (a ll) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(r, &a[j])
		}

		ans := solve(a, n)
		fmt.Println(ans)
	}
}

func solve(d []int, n int) int64 {
	if n == 1 {
		return 0
	}

	sort.Ints(d)

	var cost int64

	cost = int64(d[len(d) - 1])

	k := 0
	dp := make([]int64, n)
	dp[0] = 0

	for i := 1; i < n; i++ {
		diff := d[i] - d[i - 1] // 2
		dp[i] = - int64(k) * int64(diff) + dp[i - 1] - int64(diff)
		k++

		cost += dp[i]
	}

	return cost

}

package main

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

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

	var T, n int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		d := make([]int, n)
		for i := range d {
			Fscan(in, &d[i])
		}
		sort.Ints(d)
		ans := int64(0)
		for i := int64(1); i < n; i++ {
			ans += int64(d[i]-d[i-1]) * (1 - i*(n-i))
		}
		Fprintln(out, ans)
	}
}

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

package main

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

func CF1540A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			Fscan(in, &arr[i])
		}
		if n < 3 {
			Fprintln(out, 0)
			continue
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})
		// sort.Ints(arr)
		var ans int64
		it := arr[2]
		ans = it
		c := int64(1)
		for i := 3; i < n; i++ {
			it = (arr[i]-arr[i-1])*c + it + arr[i] - arr[i-2]
			ans += it
			c++
		}
		Fprintln(out, -ans)

	}
}

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

package main

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

var input io.Reader = bufio.NewReader(os.Stdin)

//fmt.Fscan(input,&x)
//fmt.Println(x)
func main() {
	var T int
	fmt.Fscan(input, &T)
	for {
		var n int
		fmt.Fscan(input, &n)
		v := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &v[i])
		}
		V := v[1 : n+1]
		sort.Slice(V, func(i int, j int) bool {
			return i < j
		})
		var ans int64
		sum := make([]int, n+1)
		for i := 1; i <= n; i++ {
			sum[i] = sum[i-1] + v[i]
			ans += int64(i*v[i] - sum[i])
		}
		fmt.Println(int64(v[n]) - ans)
		T--
		if T == 0 {
			break
		}
	}
}


package main

import (
    "fmt"
)

func main() {
    var q int
    fmt.Scanf("%d", &q)
    for i := 0; i < q; i++ {
        var n int64
        var ans = 0
        fmt.Scan(&n)
        for {
            if n <= 1 {
                break
            }
            if n % 2 == 0 {
                n /= 2
            } else if n % 3 == 0 {
                n = (2 * n) / 3
            } else if n % 5 == 0 {
                n = (4 * n) / 5
            } else {
                ans = -1
                break
            }
            ans++
        }
        fmt.Println(ans)
    }
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1176/A

package main

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

func _Solve(n int64, twos int, threes int, fives int) int {
	if n == 1 {
		return twos + 2*threes + 3*fives
	} else if n%2 == 0 {
		return _Solve(n/2, twos+1, threes, fives)
	} else if n%3 == 0 {
		return _Solve(n/3, twos, threes+1, fives)
	} else if n%5 == 0 {
		return _Solve(n/5, twos, threes, fives+1)
	}
	return -1
}

func Solve(n int64) int {
	return _Solve(n, 0, 0, 0)
}

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

	var q int
	var n int64

	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Fprintf(writer, "%d\n", Solve(n))
	}
}

package main

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

func main() {
	var t int
	var n int64
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		count := 0
		for {
			if n == 1 {
				break
			} else if n%2 == 0 {
				n = n / 2
			} else if n%3 == 0 {
				n = 2 * n / 3
			} else if n%5 == 0 {
				n = 4 * n / 5
			} else {
				break
			}
			count++
		}
		if n == 1 {
			fmt.Println(count)
		} else {
			fmt.Println(-1)
		}
	}
}

package main

import "fmt"

func main(){
    var q,c int
    var n int64
    fmt.Scanln(&q)
    for i := 1;i <= q;i ++{
        fmt.Scanln(&n)
        c = 0
        for n != 1{
            if n % 2 == 0{
	        n = n / 2
	    }else if n % 3 == 0{
		n = n / 3 * 2
	    }else if n % 5 == 0{
		n = n / 5 * 4
	    }else{
	    	break
            }
	    c ++
	}
        if n == 1{
	    fmt.Println(c)
	}else{
	    fmt.Println(-1)
	}
    }
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var n uint64
		fmt.Scan(&n)

		s := 0
		for n % 2 == 0 {
			n /= 2
			s += 1
		}
		for n % 3 == 0 {
			n /= 3
			s += 2
		}
		for n % 5 == 0 {
			n /= 5
			s += 3
		}

		if n > 1 {
			s = -1
		}

		fmt.Println(s)
	}
}

package main

import "fmt"

//http://codeforces.com/contest/1176/problem/A
func main() {

	var q int
	fmt.Scanf("%d", &q)

	for i := 0; i < q; i++ {
		var n int64
		var ans = 0
		fmt.Scan(&n)
		for {
			if n <= 1 {
				break
			}
			if n%2 == 0 {
				n /= 2
			} else if n%3 == 0 {
				n = (2 * n) / 3
			} else if n%5 == 0 {
				n = (4 * n) / 5
			} else {
				ans = -1
				break
			}
			ans++
		}
		fmt.Println(ans)
	}

	//fmt.Println(q)
}

package main

import (
	"fmt"
)

func main() {
	var t, n uint64
	fmt.Scan(&t)
	for t != 0 {
		fmt.Scan(&n)
		moves := 0
		for n != 1 {
			if n%2 == 0 {
				n = n / 2
			} else if n%3 == 0 {
				n = (2 * n) / 3
			} else if n%5 == 0 {
				n = (4 * n) / 5
			} else {
				break
			}
			moves++
		}
		if n != 1 {
			fmt.Println(-1)
		} else {
			fmt.Println(moves)
		}
		t--
	}
}

// 30
// Replace n with n/2 if n is divisible by 2;
// Replace n with 2n/3 if n is divisible by 3;
// Replace n with 4n/5 if n is divisible by 5.
// if 2 then 15
// if 3 then 30*2/3 = 20
// if 5 4*30/5 = 24

package main

import "fmt"

func main() {
    var q int
    var n int64
    fmt.Scanln(&q)
    for i := 0; i < q; i ++ {
        fmt.Scanln(&n)
        if n <= 1 {
            fmt.Println(0)
        } else {
            cnt := 0
            for n > 1 {
                if n % 2 == 0 {
                    n = n / 2
                    cnt ++
                } else if n % 3 == 0 {
                    n /= 3
                    cnt += 2
                } else if n % 5 == 0 {
                    n /= 5
                    cnt += 3
                } else {
                    cnt = -1
                    break
                }
            }
            fmt.Println(cnt)
        }
    }
}

package main

import "fmt"

func main(){
	var q int
	fmt.Scanln(&q)
	for i:= 0;i < q ; i++ {
		var n, ans int64 = 0, 0
		fmt.Scanln(&n)
		for ; n%5 ==0; n/=5{
			ans += 3
		}
		for ; n%3 ==0; n/=3{
			ans += 2
		}
		for ; n%2 ==0; n/=2{
			ans += 1
		}
		if n ==1 {
			fmt.Println(ans)
		} else{
			fmt.Println("-1")
		}
	}
}

package main

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

import "strconv"

func normaliseBy235(numberRaw string) (moves int) {
	number, err := strconv.ParseInt(numberRaw, 10, 64)
	if err != nil {
		moves = -1
		return
	}

	if number%7 == 0 {
		moves = -1
		return
	}

	if number == 1 {
		moves = 0
		return
	}

	for number%2 == 0 {
		number /= 2
		moves++
	}

	for number%5 == 0 {
		number /= 5
		moves += 3
	}

	for number%3 == 0 {
		number /= 3
		moves += 2
	}

	if number != 1 {
		moves = -1
	}

	return
}

func main() {

	var rawExpected string
	var expected int
	var err error

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {

		if len(rawExpected) == 0 {
			rawExpected = scanner.Text()
			expected, err = strconv.Atoi(rawExpected)
			if err != nil {
				panic(err)
			}
			continue
		}

		fmt.Println(normaliseBy235(scanner.Text()))
		expected--

		if expected == 0 {
			break
		}
	}
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		count := 0
		for {
			if n == 1 {
				break
			} else if n%2 == 0 {
				n = n / 2
			} else if n%3 == 0 {
				n = 2 * n / 3
			} else if n%5 == 0 {
				n = 4 * n / 5
			} else {
				break
			}
			count++
		}
		if n == 1 {
			fmt.Println(count)
		} else {
			fmt.Println(-1)
		}
	}
}

package main

import "fmt"

func main(){
    var q,n,c int
    fmt.Scanln(&q)
    for i := 1;i <= q;i ++{
        fmt.Scanln(&n)
        c = 0
        for n != 1{
            if n % 2 == 0{
	        n = n / 2
	    }else if n % 3 == 0{
		n = n / 3 * 2
	    }else if n % 5 == 0{
		n = n / 5 * 4
	    }else{
	    	break
            }
	    c ++
	}
        if n == 1{
	    fmt.Println(c)
	}else{
	    fmt.Println(-1)
	}
    }
}

package main

import (
	"fmt"
)

func main() {
	var t, n int
	fmt.Scan(&t)
	for t != 0 {
		fmt.Scan(&n)
		moves := 0
		for n != 1 {
			if n%2 == 0 {
				n = n / 2
			} else if n%3 == 0 {
				n = (2 * n) / 3
			} else if n%5 == 0 {
				n = (4 * n) / 5
			} else {
				break
			}
			moves++
		}
		if n != 1 {
			fmt.Println(-1)
		} else {
			fmt.Println(moves)
		}
		t--
	}
}

// 30

// Replace n with n/2 if n is divisible by 2;
// Replace n with 2n/3 if n is divisible by 3;
// Replace n with 4n/5 if n is divisible by 5.

// if 2 then 15
// if 3 then 30*2/3 = 20
// if 5 4*30/5 = 24

package main

import "fmt"

func main() {
    var q int
    var n int
    fmt.Scanln(&q)
    for i := 0; i < q; i ++ {
        fmt.Scanln(&n)
        if n <= 1 {
            fmt.Println(0)
        } else {
            cnt := 0
            for n > 1 {
                if n % 2 == 0{
                    n = n / 2
                    cnt ++
                } else if n % 3 == 0 {
                    n /= 3
                    cnt += 2
                } else if n % 5 == 0 {
                    n /= 5
                    cnt += 3
                } else {
                    cnt = -1
                    break
                }
            }
            fmt.Println(cnt)
        }

    }

}

package main

import "fmt"

func main() {
    var q int
    var n int
    fmt.Scanln(&q)
    for i := 0; i < q; i ++ {
        fmt.Scanln(&n)
        if n <= 1 {
            fmt.Println(1)
        } else {
            cnt := 0
            for n > 1 {
                if n % 2 == 0{
                    n = n / 2
                    cnt ++
                } else if n % 3 == 0 {
                    n /= 3
                    cnt += 2
                } else if n % 5 == 0 {
                    n /= 5
                    cnt += 3
                } else {
                    cnt = -1
                    break
                }
            }
            fmt.Println(cnt)
        }

    }

}

package main

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

func minDivisionFor235(n int) int {
	var moves int
	if n == 1 {
		return moves
	}

	for {
		if n%7 == 0 {
			return -1
		}

		if n%2 == 0 {
			n = n / 2
			moves++
		}

		if n%3 == 0 {
			n = (2 * n) / 3
			moves++
		}

		if n%5 == 0 {
			n = (4 * n) / 5
			moves++
		}

		if n == 1 {
			break
		}
	}

	return moves
}

func main() {

	var firstWord string
	var maxTimes, currTime int
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if err := scanner.Err(); err != nil {
			panic(err)
		}

		if firstWord == "" {
			firstWord = scanner.Text()
			maxTimes, _ = strconv.Atoi(firstWord)
			continue
		}

		if currTime > maxTimes-1 {
			continue
		}

		secondWord := scanner.Text()
		currTime++
		number, err := strconv.Atoi(secondWord)
		if err != nil {
			fmt.Println("-1")
			continue
		}

		fmt.Println(strconv.Itoa(minDivisionFor235(number)))
	}
}

package main

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

func minDivisionFor235(n int) int {
	var moves int
	if n == 1 {
		return moves
	}

	for {
		if n%7 == 0 {
			return -1
		}

		if n%2 == 0 {
			n = n / 2
			moves++
		}

		if n%3 == 0 {
			n = (2 * n) / 3
			moves++
		}

		if n%5 == 0 {
			n = (4 * n) / 5
			moves++
		}

		if n == 1 {
			break
		}
	}

	return moves
}

func main() {

	var firstWord string
	// var maxTimes, currTime int
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if err := scanner.Err(); err != nil {
			panic(err)
		}

		if firstWord == "" {
			firstWord = scanner.Text()
			// maxTimes, _ = strconv.Atoi(firstWord)
			continue
		}

		// if currTime > maxTimes-1 {
		// 	break
		// }

		secondWord := scanner.Text()
		// currTime++
		number, err := strconv.Atoi(secondWord)
		if err != nil {
			fmt.Println("-1")
			continue
		}

		fmt.Println(strconv.Itoa(minDivisionFor235(number)))
	}
}

package main

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

func minDivisionFor235(n int) int {
	var moves int
	if n == 1 {
		return moves
	}

	for {
		if n%7 == 0 {
			return -1
		}

		if n%2 == 0 {
			n = n / 2
			moves++
		}

		if n%3 == 0 {
			n = (2 * n) / 3
			moves++
		}

		if n%5 == 0 {
			n = (4 * n) / 5
			moves++
		}

		if n == 1 {
			break
		}
	}

	return moves
}

func main() {

	var firstWord string
	var maxTimes, currTime int
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if err := scanner.Err(); err != nil {
			panic(err)
		}

		if firstWord == "" {
			firstWord = scanner.Text()
			maxTimes, _ = strconv.Atoi(firstWord)
			continue
		}

		if currTime > maxTimes-1 {
			break
		}

		secondWord := scanner.Text()
		currTime++
		number, err := strconv.Atoi(secondWord)
		if err != nil {
			continue
		}

		fmt.Println(minDivisionFor235(number))
	}
}

package main

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

func minDivisionFor235(n int) int {
	var moves int
	if n == 1 {
		return moves
	}

	for {
		if n%7 == 0 {
			return -1
		}

		if n%2 == 0 {
			n = n / 2
			moves++
		}

		if n%3 == 0 {
			n = (2 * n) / 3
			moves++
		}

		if n%5 == 0 {
			n = (4 * n) / 5
			moves++
		}

		if n == 1 {
			break
		}
	}

	return moves
}

func main() {

	var firstWord string
	// var maxTimes, currTime int
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if err := scanner.Err(); err != nil {
			panic(err)
		}

		if firstWord == "" {
			firstWord = scanner.Text()
			// maxTimes, _ = strconv.Atoi(firstWord)
			continue
		}

		// if currTime > maxTimes-1 {
		// 	break
		// }

		secondWord := scanner.Text()
		// currTime++
		number, err := strconv.Atoi(secondWord)
		if err != nil {
			// fmt.Println("-1")
			continue
		}

		fmt.Println(strconv.Itoa(minDivisionFor235(number)))
	}
}

package main

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

func minDivisionFor235(n int) int {
	var moves int
	if n == 1 {
		return moves
	}

	for {
		if n%7 == 0 {
			return -1
		}

		if n%2 == 0 {
			n = n / 2
			moves++
		}

		if n%3 == 0 {
			n = (2 * n) / 3
			moves++
		}

		if n%5 == 0 {
			n = (4 * n) / 5
			moves++
		}

		if n == 1 {
			break
		}
	}

	return moves
}

func main() {

	var firstWord string
	var maxTimes, currTime int
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if err := scanner.Err(); err != nil {
			panic(err)
		}

		if firstWord == "" {
			firstWord = scanner.Text()
			maxTimes, _ = strconv.Atoi(firstWord)
			continue
		}

		if currTime > maxTimes-1 {
			break
		}

		secondWord := scanner.Text()
		currTime++
		number, err := strconv.Atoi(secondWord)
		if err != nil {
			fmt.Println("-1")
			continue
		}

		fmt.Println(strconv.Itoa(minDivisionFor235(number)))
	}
}

package main

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

func minDivisionFor235(n int) int {
	var moves int
	if n == 1 {
		return moves
	}

	for {
		if n%7 == 0 {
			return -1
		}

		if n%2 == 0 {
			n = n / 2
			moves++
		}

		if n%3 == 0 {
			n = (2 * n) / 3
			moves++
		}

		if n%5 == 0 {
			n = (4 * n) / 5
			moves++
		}

		if n == 1 {
			break
		}
	}

	return moves
}

func main() {

	var firstWord string
	// var maxTimes, currTime int
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if err := scanner.Err(); err != nil {
			panic(err)
		}

		if firstWord == "" {
			firstWord = scanner.Text()
			// maxTimes, _ = strconv.Atoi(firstWord)
			continue
		}

		// if currTime > maxTimes-1 {
		// 	break
		// }

		secondWord := scanner.Text()
		// currTime++
		number, err := strconv.Atoi(secondWord)
		if err != nil {
			fmt.Println("-1")
			continue
		}

		fmt.Println(minDivisionFor235(number))
	}
}

package main

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

func minDivisionFor235(n int) int {
	var moves int
	if n == 1 {
		return moves
	}

	for {
		if n%7 == 0 {
			return -1
		}

		if n%2 == 0 {
			n = n / 2
			moves++
		}

		if n%3 == 0 {
			n = (2 * n) / 3
			moves++
		}

		if n%5 == 0 {
			n = (4 * n) / 5
			moves++
		}

		if n == 1 {
			break
		}
	}

	return moves
}

func main() {

	var firstWord string
	var maxTimes, currTime int
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if err := scanner.Err(); err != nil {
			panic(err)
		}

		if firstWord == "" {
			firstWord = scanner.Text()
			maxTimes, _ = strconv.Atoi(firstWord)
			continue
		}

		if currTime > maxTimes-1 {
			break
		}

		secondWord := scanner.Text()
		currTime++
		number, err := strconv.Atoi(secondWord)
		if err != nil {
			fmt.Println("-1")
			continue
		}

		fmt.Println(minDivisionFor235(number))
	}
}


package main

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	scanner := bufio.NewScanner(os.Stdin)
	// mod := int64(998244353998244353)
	for i := 0; i < t; i++ {
		var s string
		if scanner.Scan() {
			scanner.Text() // ignore n
		}
		var tempArr []string
		if scanner.Scan() {
			s = scanner.Text()
			tempArr = strings.Split(s, " ")
		}
		var arr []int
		for _, v := range tempArr {
			temp, _ := strconv.Atoi(v)
			arr = append(arr, temp)
		}

		var possible bool = true
		var lcms []int
		for i := 0; i < len(arr)-1; i++ {
			lcm := LCM(arr[i], arr[i+1])
			lcms = append(lcms, lcm)
			if i >= 1 {
				if GCD(lcms[i-1], lcms[i]) != arr[i] {
					possible = false
					break
				}
			}
		}
		if possible {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

// greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

// find Least Common Multiple (LCM) via GCD
func LCM(a, b int, integers ...int) int {
	result := a * b / GCD(a, b)

	for i := 0; i < len(integers); i++ {
		result = LCM(result, integers[i])
	}

	return result
}

package main

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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 n int
		fmt.Fscan(in, &n)

		aa := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}

		f := true
		for i := 1; i < n-1; i++ {
			if aa[i]%gcd(aa[i-1], aa[i+1]) > 0 {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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 n int
		fmt.Fscan(in, &n)

		aa := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}
		bb := make([]int64, n+1)
		bb[0] = aa[0]
		bb[n] = aa[n-1]
		for i := 1; i < n; i++ {
			bb[i] = lcm(aa[i-1], aa[i])
		}

		f := true
		for i := 0; i < n; i++ {
			if aa[i] != gcd(bb[i], bb[i+1]) {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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()

	var n, T int
	Fscan(in, &T)
	for ; T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		flag := true
		num := a[1]
		for i := 2; i <= n; i++ {
			x := lcm(a[i], a[i - 1])
			if gcd(num, x) != a[i - 1] {
			    flag = false
			    break
			}
			num = x
		}
		if flag {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

}

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
    return x / gcd(x, y) * y;
}

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

package main

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

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

func b1736(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var x int

	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			Fscan(in, &x)
			a[i] = x
		}

		ans := "YES"
		for i := 1; i < n-1; i++ {
			if gcd(a[i-1]/gcd(a[i-1], a[i]), a[i+1]/gcd(a[i+1], a[i])) != 1 {
				ans = "NO"
				break
			}
		}

		Fprintln(out, ans)
	}
}

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a % b)
}

func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
		}

		b := make([]int, n + 1)
		b[0] = a[0]
		cant := false

		for i := range a {
			if i != n - 1 {
				b[i + 1] = lcm(a[i], a[i+1])
			} else {
				b[i + 1] = a[i]
			}
			if gcd(b[i+1], b[i]) != a[i] {
				cant = true
				break
			}
		}

		if cant {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
		}
	}

}

package main

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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 n int
		fmt.Fscan(in, &n)

		aa := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}
		f := true
		for i := 0; i < n-2; i++ {
			if gcd(aa[i], aa[i+2]) > gcd(aa[i], aa[i+1]) {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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 n int
		fmt.Fscan(in, &n)

		aa := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}
		if n <= 2 {
			fmt.Fprintln(out, "YES")
			continue
		}

		f := true
		for i := 1; i < n-1; i++ {
			d := lcm(aa[i], aa[i+1])
			if d > aa[i] {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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()

	var n, T int
	Fscan(in, &T)
	for ; T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		flag := true
		num := a[1]
		for i := 2; i <= n; i++ {
			x := lcm(a[i], num)
			if x <= 0 || gcd(num, x) != a[i - 1] {
			    flag = false
			    break
			}
			num = x
		}
		if flag {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

}

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
    return x / gcd(x, y) * y;
}

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

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()

	var n, T int
	Fscan(in, &T)
	for ; T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		flag := true
		num := a[1]
		for i := 2; i <= n; i++ {
			x := lcm(a[i], num)
			if gcd(num, x) != a[i - 1] {
			    flag = false
			    break
			}
		}
		if flag {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

}

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
    return x / gcd(x, y) * y;
}

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

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()

	var n, T int
	Fscan(in, &T)
	for ; T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		flag := true
		num := a[1]
		for i := 2; i <= n; i++ {
			x := a[i] / gcd(a[i], num)
			y := a[i-1] / num
			if gcd(x, y) != 1 {
				flag = false
				break
			}
			if num % a[i - 1] == 0 && num > a[i - 1] {
			    flag = false
			    break
			}
			num = num * x
		}
		if flag {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

}

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

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

package main

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

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

func b1736(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var x int

	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			Fscan(in, &x)
			a[i] = x
		}

		ans := "YES"
		for i := 1; i < n-1; i++ {
			if gcd(a[i-1], a[i+1]) != 1 {
				ans = "NO"
				break
			}
		}

		Fprintln(out, ans)
	}
}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		a, b, c := readThreeNums(reader)
		x, y := solve(a, b, c)
		fmt.Printf("%d %d\n", x, y)
	}
}

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
}

func solve(a, b, c int) (x int, y int) {
	if a >= c {
		x = -1
	} else {
		// A(x) < B(x) => a * x < [(x + b-1)/b * c)
		x = 1
	}

	if a > c {
		y = 1
	} else {
		// a <= c
		// A(y) > B(y) => a * y > [(y + b - 1) / b * c)
		// a * y > y / b * c, let y divides, y = b * n => a * b * n > n * c
		// => a * b > c
		if int64(a)*int64(b) > int64(c) {
			y = b
		} else {
			y = -1
		}
	}
	return
}

package main

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

var reader *bufio.Reader

func parseInt(s string) int {
	return int(parseInt64(s))
}

func parseInt64(s string) int64 {
	x, _ := strconv.ParseInt(s, 10, 64)
	return x
}

func readLine() string {
	if reader == nil {
		reader = bufio.NewReader(os.Stdin)
	}
	s, _ := reader.ReadString('\n')
	return strings.TrimSuffix(s, "\n")
}

func readFields() []string {
	return strings.Fields(readLine())
}

var t int

func main() {
	t := parseInt(readFields()[0])
	for tc := 0; tc < t; tc++ {
      f := readFields()
      a,b,c := parseInt64(f[0]), parseInt64(f[1]), parseInt64(f[2])
      if a < c {
        Print(1)
      } else {
        Print(-1)
      }
      Print(" ")
      if a*b > c {
        Print(b)
      } else {
        Print(-1)
      }
      Println()
    }
}

package main
import "fmt"

func main() {
    var t int;
    fmt.Scanln(&t);
    for kchk:=1; kchk<=t; kchk++{
    	var a, b, c int;
    	fmt.Scanln(&a, &b, &c);
    	if a >= c{
    		fmt.Println("-1 2");
    		continue;
    	}
    	var x int = -1;
    	if int64(a)*int64(b)>int64(c){
    		x = b;
    	}
    	fmt.Println(1,x);
    }

}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a,b,c int64
		fmt.Scanf("%d %d %d\n", &a, &b, &c)
		if b == 1 {
			if a == c {
				fmt.Println(-1, -1)
			} else if a > c {
				fmt.Println(-1, b)
			} else {
				fmt.Println(1, -1)
			}
			continue
		}

		if a <= (c / b) {
			fmt.Println(1, -1)
		} else if a >= c {
			fmt.Println(-1, b)
		} else {
			fmt.Println(1, b)
		}
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/contest/1373/problem/A
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	a, b, c int64
)

func main() {
	t = ReadInt()

	for i := 0; i < t; i++ {
		a, b, c = ReadInt64_3()

		solve()
	}
}

func solve() {
	var ans1, ans2 int64

	if a >= c {
		ans1 = -1
	} else {
		ans1 = 1
	}

	if a*b-c <= 0 {
		ans2 = -1
	} else {
		ans2 = b
	}

	fmt.Println(ans1, ans2)
}

func BinarySearch(initOK, initNG int64, isOK func(mid int64) bool) (ok int64) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"fmt"
)

func main() {
	var t, a, b, c, out1, out2 int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d %d\n", &a, &b, &c)
		// fmt.Printf("a = %d b = %d c = %d", a, b, c)
		if a >= c {
			out1 = -1
		} else {
			out1 = 1
		}
		if float64(c) / float64(b) >= float64(a) {
			out2 = -1
		} else {
			out2 = b
		}
		fmt.Printf("%d %d\n", out1, out2)
	}
}

package main

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

var nTest int
var a, b, c, x1, x2 int64

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &a, &b, &c)

		if a < c {
			x1 = 1
		} else {
			x1 = -1
		}

		if a*b <= c {
			x2 = -1
		} else {
			x2 = b
		}
		fmt.Fprintln(out, x1, x2)
	}

	out.Flush()
}

package main

import "fmt"

func main(){
    var t int;
    fmt.Scan(&t);
    for t > 0{
        var a,b,c int64;
        fmt.Scan(&a,&b,&c);
        if a < c{
            fmt.Print("1 ");
        } else {
            fmt.Print("-1 ");
        }
        if a*b <= c{
            fmt.Println(-1);
        } else{
            fmt.Println(b);
        }
        t--;
    }
}

package main

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

func main() {
	t := NextInt()
	for t > 0 {
		t--
		a, b, c := NextInt(), NextInt(), NextInt()
		ans1, ans2 := -1, -1
		if int64(a) * int64(b) > int64(c) {
			ans2 = b
		}
		if a < c {
			ans1 = 1
		}
		fmt.Println(ans1, ans2)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func NextDouble() float64 {
	f, err := strconv.ParseFloat(Next(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

package main

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

var reader *bufio.Reader

func parseInt(s string) int {
	return int(parseInt64(s))
}

func parseInt64(s string) int64 {
	x, _ := strconv.ParseInt(s, 10, 64)
	return x
}

func readLine() string {
	if reader == nil {
		reader = bufio.NewReader(os.Stdin)
	}
	s, _ := reader.ReadString('\n')
	return strings.TrimSuffix(s, "\n")
}

func readFields() []string {
	return strings.Fields(readLine())
}

var t int

func main() {
	t := parseInt(readFields()[0])
	for tc := 0; tc < t; tc++ {
      f := readFields()
      a,b,c := parseInt(f[0]), parseInt(f[1]), parseInt(f[2])
      if a < c {
        Print(1)
      } else {
        Print(-1)
      }
      Print(" ")
      if a*b > c {
        Print(b)
      } else {
        Print(-1)
      }
      Println()
    }
}

package main
import "fmt"

func main() {
    var t int;
    fmt.Scanln(&t);
    for kchk:=1; kchk<=t; kchk++{
    	var a, b, c int;
    	fmt.Scanln(&a, &b, &c);
    	if a >= c{
    		fmt.Println("-1 2");
    		continue;
    	}
    	var x int = -1;
    	if b*a>c{
    		x = b;
    	}
    	fmt.Println(1,x);
    }

}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a,b,c int64
		fmt.Scanf("%d %d %d", &a, &b, &c)
		if b == 1 {
			if a == c {
				fmt.Println(-1, -1)
			} else if a > c {
				fmt.Println(-1, 1)
			} else {
				fmt.Println(1, -1)
			}
			continue
		}

		if a * b <= c {
			fmt.Println(1, -1)
		} else if a >= c {
			fmt.Println(-1, 2)
		} else {
			fmt.Println(1 , b)
		}
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a,b,c int64
		fmt.Scanf("%d %d %d", &a, &b, &c)
		if b == 1 {
			if a == c {
				fmt.Println(-1, -1)
			} else if a > c {
				fmt.Println(-1, 1)
			} else {
				fmt.Println(1, -1)
			}
			continue
		}
		if a * b <= c {
			fmt.Println(1, -1)
		} else if a > c {
			fmt.Println(-1, 1)
		} else {
			fmt.Println(1 , b)
		}
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a,b,c int64
		fmt.Scanf("%d %d %d", &a, &b, &c)
		if b == 1 {
			if a == c {
				fmt.Println(-1, -1)
			} else if a > c {
				fmt.Println(-1, 1)
			} else {
				fmt.Println(1, -1)
			}
			continue
		}
		if a * b <= c {
			fmt.Println("1 -1")
		} else if a > c {
			fmt.Println("-1 1")
		} else {
			fmt.Println("1 ", b)
		}
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

import "fmt"

func main(){
    var t int;
    fmt.Scan(&t);
    for t > 0{
        var a,b,c int;
        fmt.Scan(&a,&b,&c);
        if a < c{
            fmt.Print("1 ");
        } else {
            fmt.Print("-1 ");
        }
        if a*b <= c{
            fmt.Println(-1);
        } else{
            fmt.Println(b);
        }
        t--;
    }
}

package main

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

func main() {
	t := NextInt()
	for t > 0 {
		t--
		a, b, c := NextInt(), NextInt(), NextInt()
		ans1, ans2 := -1, -1
		if int64(a) * int64(b) > int64(c) {
			ans2 = 1
		}
		if a < c {
			ans1 = 1
		}
		fmt.Println(ans1, ans2)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func NextDouble() float64 {
	f, err := strconv.ParseFloat(Next(), 64)
	if err != nil {
		panic(err)
	}
	return f
}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var (
		n, count int
		appt     string
	)
	fmt.Fscan(reader, &n)
	fmt.Fscan(reader, &appt)

	used := make(map[rune]bool)
	for _, vl := range appt {
		if !used[vl] {
			count++
			used[vl] = true
		}
	}

	pokemons := make(map[byte]int)

	var s, r int
	mn := n

	for i := 0; i < n; i++ {
		for s < count && r < n {
			add(&r, &s, pokemons, appt)
		}
		if s == count {
			mn = min(mn, r-i)
		}
		del(&i, &s, pokemons, appt)

	}

	fmt.Println(mn)
}

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

func add(r, s *int, poke map[byte]int, appt string) {
	if poke[appt[*r]] == 0 {
		*s++
	}
	poke[appt[*r]]++
	*r++
}

func del(i, s *int, poke map[byte]int, appt string) {
	if poke[appt[*i]] == 1 {
		*s--
	}
	poke[appt[*i]]--
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	used := make(map[rune]bool)

	var count int
	var appt string
	fmt.Fscan(reader, &appt)

	for _, vl := range appt {
		if !used[vl] {
			count++
			used[vl] = true
		}
	}

	pokemons := make(map[byte]int)

	var mn int = n
	var s, r int

	for i := 0; i < n; i++ {
		for s < count && r < n {
			if pokemons[appt[r]] == 0 {
				s++
			}
			pokemons[appt[r]]++

			r++
		}
		if s == count {
			mn = min(mn, r-i)
		}

		if pokemons[appt[i]] == 1 {
			s--
		}

		pokemons[appt[i]]--
	}

	fmt.Println(mn)
}

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

package main

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

type poke struct {
	pos []int
	v   byte
	j   int
	max int
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	//	s := strings.Split(text, " ")

	//	c, _ := strconv.Atoi(s[0])

	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")

	v := map[byte]poke{}

	for i := range text {
		val, ok := v[text[i]]
		if ok == false {
			val = poke{make([]int, len(text)), text[i], 0, 0}
		}
		val.pos[val.max] = i
		val.max += 1
		v[text[i]] = val
	}
	m := len(text)

	for i := range text {
		curpos := i
		if i < (len(text) - 1) {
			if text[i+1] == text[i] {
				continue
			}
		}
		found := false
		for k, pok := range v {
			found = false
			for j := pok.j; j < pok.max; j++ {
				//for j, vv := range pok.pos[pok.j:pok.max] {
				vv := pok.pos[j]
				if vv >= i {
					if vv > curpos {
						curpos = vv
					}
					pok.j = j
					v[k] = pok
					found = true
					break
				}
			}
			if found == false {
				break
			}
		}
		if found {
			c := (curpos - i) + 1
			if c < m {
				m = c
			}
		}
	}

	fmt.Println(m)
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

var n int
var s string
var cnt []int

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	fmt.Fscan(bufin, &n, &s)

	cnt = make([]int, 128)
	for i := range cnt {
		cnt[i] = 0
	}

	i := 0
	result := 0

	for j := 0; j < n; j++ {
		cnt[s[j]]++
		isNewChar := cnt[s[j]] == 1

		for cnt[s[i]] > 1 {
			cnt[s[i]]--
			i++
		}

		len := j - i + 1
		if isNewChar || (len < result) {
			result = len
		}
	}

	fmt.Fprintln(bufout, result)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	s := make([]byte, n)
	fmt.Scan(&s)

	a := make([]int32, 128)
	for i := range a {
		a[i] = 0
	}

	maxDiff := 0
	for i := 0; i < n; i++ {
		c := s[i]
		a[c]++
		if a[c] == 1 {
			maxDiff++
		}
	}

	for i := range a {
		a[i] = 0
	}

	minFlats := n
	diff := 0
	i := 0
	j := -1

	for (i < n) && (j < n) {
		for (diff < maxDiff) && (j+1 < n) {
			j++
			c := s[j]
			a[c]++
			if a[c] == 1 {
				diff++
			}
		}

		if diff == maxDiff {
			flats := j - i + 1
			if flats < minFlats {
				minFlats = flats
			}
		}

		c := s[i]
		a[c]--
		if a[c] == 0 {
			diff--
		}
		i++
	}

	fmt.Println(minFlats)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	s := make([]byte, n)
	fmt.Scan(&s)

	cnt := make([]int32, 128)
	for i := range cnt {
		cnt[i] = 0
	}

	result := 0
	i := 0

	for j := 0; j < n; j++ {
		cnt[s[j]]++
		isNew := cnt[s[j]] == 1

		for cnt[s[i]] > 1 {
			cnt[s[i]]--
			i++
		}

		len := j - i + 1
		if isNew || len < result {
			result = len
		}
	}

	fmt.Println(result)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]byte, n)
	fmt.Scan(&s)

	cnt := make([]int64, 128)
	for i := range cnt {
		cnt[i] = 0
	}

	ans := 0
	i := 0
	for j := 0; j < n; j++ {
		cnt[s[j]]++
		is_new := cnt[s[j]] == 1

		for cnt[s[i]] > 1 {
			cnt[s[i]]--
			i++
		}

		len := j - i + 1
		if is_new || len < ans {
			ans = len
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"os"
)

const dic = 127

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	str := make([]byte, n)
	if _, err := os.Stdin.Read(str); err != nil {
		panic(err)
	}

	// Build next tracker.
	next := make([][128]int, n)
	for i := range next[n-1] {
		next[n-1][i] = n
	}
	for i := n - 2; i >= 0; i-- {
		copy(next[i][:], next[i+1][:])
		next[i][str[i+1]] = i + 1
	}

	// Count pokemons
	var cur [dic]bool
	for _, ch := range str {
		cur[ch] = true
	}
	var total int
	for i, one := range cur {
		if one {
			total++
		}
		cur[i] = false
	}

	// Compute min span.
	var sum, minSpan, from, to int
	for {
		if sum == total {
			if minSpan == 0 || to-from < minSpan {
				minSpan = to - from
			}
			ch := str[from]
			if next[from][ch] >= to {
				cur[ch] = false
				sum--
			}
			from++
		} else {
			if to == n {
				fmt.Println(minSpan)
				return
			}
			ch := str[to]
			if !cur[ch] {
				cur[ch] = true
				sum++
			}
			to++
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	used := make(map[rune]bool)

	var count int
	var appt string
	fmt.Fscan(reader, &appt)

	for _, vl := range appt {
		if !used[vl] {
			count++
			used[vl] = true
		}
	}

	pokemons := make(map[byte]int)

	var mn int = n
	var s, r int

	for i := 0; i < n; i++ {
		for r < n {
			if pokemons[appt[r]] == 0 {
				s++
			}
			pokemons[appt[r]]++

			if s == count {
				mn = min(mn, r-i+1)
				break
			}
			r++
		}

		if r != n-1 {
			r++
		}

		if pokemons[appt[i]] == 1 {
			s--
		}

		pokemons[appt[i]]--
	}

	fmt.Println(mn)
}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	used := make(map[rune]bool)

	var count int
	var appt string
	fmt.Fscan(reader, &appt)

	for _, vl := range appt {
		if !used[vl] {
			count++
			used[vl] = true
		}
	}

	pokemons := make(map[byte]int)

	var mn int = n
	var s, r int

	for i := 0; i < n; i++ {
		for s < count && r < n {
			if pokemons[appt[r]] == 0 {
				s++
			}
			pokemons[appt[r]]++

			r++
		}
		if s == count {
			fmt.Println(i, r)
			mn = min(mn, r-i)
		}

		if pokemons[appt[i]] == 1 {
			s--
		}

		pokemons[appt[i]]--
	}

	fmt.Println(mn)
}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	used := make(map[rune]bool)

	var count int
	var appt string
	fmt.Fscan(reader, &appt)

	for _, vl := range appt {
		if !used[vl] {
			count++
			used[vl] = true
		}
	}

	pokemons := make(map[byte]int)

	var mn int = n
	var s, r int

	for i := 0; i < n; i++ {
		for r < n {
			pokemons[appt[r]]++
			if pokemons[appt[r]] == 1 {
				s++
			}
			if s == count {
				mn = min(mn, r-i+1)

				break
			}
			r++
		}
		if r+1 != n {
			r++
		}
		if pokemons[appt[i]] == 1 {
			s--
		}

		pokemons[appt[i]]--
	}

	fmt.Println(mn)
}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	used := make(map[rune]bool)

	var count int
	var appt string
	fmt.Fscan(reader, &appt)

	for _, vl := range appt {
		if !used[vl] {
			count++
			used[vl] = true
		}
	}

	pokemons := make(map[byte]int)

	var mn int = n
	var s, r int

	for i := 0; i < n; i++ {
		for r < n {
			pokemons[appt[r]]++
			if pokemons[appt[r]] == 1 {
				s++
			}
			if s == count {
				mn = min(mn, r-i+1)

				break
			}
			r++
		}
		if r != n-1 {
			r++
		}
		if pokemons[appt[i]] == 1 {
			s--
		}

		pokemons[appt[i]]--
	}

	fmt.Println(mn)
}

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

package main

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

type poke struct {
	pos []int
	v   byte
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	//	s := strings.Split(text, " ")

	//	c, _ := strconv.Atoi(s[0])

	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")

	v := map[byte]poke{}

	for i := range text {
		val, ok := v[text[i]]
		if ok == false {
			val = poke{[]int{}, text[i]}
		}
		val.pos = append(val.pos, i)
		v[text[i]] = val
	}
	m := len(text)

	for i := range text {
		curpos := i

		found := false
		for _, v := range v {
			found = false
			for _, vv := range v.pos {
				if vv >= curpos {
					curpos = vv
					found = true
					break
				}
			}
			if found == false {
				break
			}

		}
		if found {
			c := (curpos - i) + 1
			if c < m {
				m = c
			}
		}
	}

	fmt.Println(m)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	//	s := strings.Split(text, " ")

	//	c, _ := strconv.Atoi(s[0])

	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")

	v := map[byte]int{}

	for i := range text {
		v[text[i]]++
	}

	mv := len(text)
	mi := byte(0)

	for i, v := range v {
		if v < mv {
			mv = v
			mi = i
		}
	}

	m := len(text)
	lv := len(v)
	index := 0
	for i := 0; i < len(text); i++ {
		if text[i] == mi {
			index = i
			end := index
			start := index
			x := map[byte]bool{}
			for start > 0 {
				x[text[start]] = true
				if len(x) == lv {
					break
				}
				start--
			}

			for i := start; i <= end; i++ {
				x := map[byte]bool{}
				for j := i; j < len(text); j++ {
					x[text[j]] = true
					if len(x) == len(v) {
						c := j - i + 1
						if c < m {
							m = c
						}
					}
				}
			}
		}
	}

	fmt.Println(m)
}