package main
import("bufio";."fmt";."os";."strings")

func main() {
	in := bufio.NewReader(Stdin)
	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
		isP := true
		for i := 0; i < n/2; i++ {
			if s[i] != s[n-1-i] {
				isP = false
				break
			}
		}
		c := Count(s, "0")
		if isP {
			if c&1 > 0 && c > 1 {
				Println("ALICE")
			} else {
				Println("BOB")
			}
		} else if n&1 > 0 && s[n/2] == '0' && c == 2 {
			Println("DRAW")
		} else {
			Println("ALICE")
		}
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				fmt.Println("ALICE")
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					fmt.Println("ALICE")
				} else {
					if ZeroISThere == 2 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("ALICE")
					}
				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				fmt.Println("ALICE")
			} else {
				fmt.Println("ALICE")

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var s string
	scan(&s)
	var c0, c01, c00 int
	if n%2 == 1 && s[n/2] == '0' {
		c0++
	}
	for i := 0; i < n/2; i++ {
		if s[i] != s[n-1-i] {
			c01++
		} else if s[i] == '0' {
			c00++
		}
	}
	if c01 > 1 {
		printf("ALICE\n")
		return
	}
	if c00 == 0 {
		if c01 == 1 && c0 == 1 {
			printf("DRAW\n")
		}
		if c01 == 1 && c0 == 0 {
			printf("ALICE\n")
		}
		if c01 == 0 && c0 == 1 {
			printf("BOB\n")
		}
		return
	}
	if c0 == 0 && c01 == 1 {
		printf("ALICE\n")
		return
	}
	if c0 == 0 && c01 == 0 {
		printf("BOB\n")
		return
	}
	if c0 == 1 && c01 == 0 {
		printf("ALICE\n")
		return
	}
	if c0 == 1 && c01 == 1 {
		printf("ALICE\n")
		return
	}
}

package main

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

func main() {
	in := bufio.NewReader(Stdin)
	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
		isP := true
		for i := 0; i < n/2; i++ {
			if s[i] != s[n-1-i] {
				isP = false
				break
			}
		}
		c := Count(s, "0")
		if isP {
			if c&1 > 0 && c > 1 {
				Println("ALICE")
			} else {
				Println("BOB")
			}
		} else if n&1 > 0 && s[n/2] == '0' && c == 2 {
			Println("DRAW")
		} else {
			Println("ALICE")
		}
	}
}

package main
import("bufio";."fmt";."os";."strings")

// github.com/EndlessCheng/codeforces-go
func main(){
	in:=bufio.NewReader(Stdin)
	T,n,s:=0,0,""
	for Fscan(in,&T);T>0;T--{
		Fscan(in,&n,&s)
		d:=0
		for i:=0;i<n/2;i++{if s[i]!=s[n-1-i]{d++}}
		if c:=Count(s,"0");d==0{
			if c&1>0&&c>1{Println("ALICE")
			}else{Println("BOB")}
		}else if n&1>0&&s[n/2]=='0'&&c==2{Println("DRAW")
		}else{Println("ALICE")}
	}
}

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, diff int
		var s string
		Fscan(in, &n, &s)
		for i, j := 0, n-1; i < j; i++ {
			if s[i] != s[j] {
				diff++
			}
			j--
		}
		c0 := strings.Count(s, "0")

		if diff == 0 {
			if c0&1 == 0 {
				Fprintln(out, "BOB")
			} else {
				if c0 == 1 {
					Fprintln(out, "BOB")
				} else {
					Fprintln(out, "ALICE")
				}
			}
			return
		}

		if n&1 == 0 || s[n/2] == '1' {
			Fprintln(out, "ALICE")
		} else {
			if diff == 1 {
				if c0 == 2 {
					Fprintln(out, "DRAW")
				} else {
					Fprintln(out, "ALICE")
				}
			} else {
				Fprintln(out, "ALICE")
			}
		}
	}

	T := 1
	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"
	"math"
	"os"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				if ZeroISThere == 1 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("BOb")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 1 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("BoB")
					}
				} else {
					if ZeroISThere == 2 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("ALICE")
					}
				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				if ZeroISThere == 2 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("DRAW")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 2 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("DRAW")
					}
				} else {
					fmt.Println("ALICE")
				}

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				if ZeroISThere == 1 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 1 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("BoB")
					}
				} else {
					if ZeroISThere == 2 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("ALICE")
					}
				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				if ZeroISThere == 2 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("DRAW")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 2 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("DRAW")
					}
				} else {
					fmt.Println("ALICE")
				}

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				if ZeroISThere == 1 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 1 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 2 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("ALICE")
					}
				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				if ZeroISThere == 2 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("DRAW")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 2 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("DRAW")
					}
				} else {
					fmt.Println("ALICE")
				}

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				if ZeroISThere == 1 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("ALICE")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 1 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("BOB")
					}
				} else {

					fmt.Println("ALICE")

				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				if ZeroISThere == 2 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("ALICE")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 2 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("DRAW")
					}
				} else {
					if ZeroISThere == 3 {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				if ZeroISThere == 1 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("ALICE")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 1 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("BOB")
					}
				} else {

					fmt.Println("ALICE")

				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				if ZeroISThere == 2 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("ALICE")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 2 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("ALICE")
					}
				} else {
					if ZeroISThere == 3 {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				if ZeroISThere == 1 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("ALICE")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 1 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("BOB")
					}
				} else {

					fmt.Println("ALICE")

				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				if ZeroISThere == 2 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("DRAW")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 2 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("DRAW")
					}
				} else {
					if ZeroISThere == 3 {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				if ZeroISThere == 1 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 1 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("ALICE")
					}
				} else {

					fmt.Println("ALICE")

				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				if ZeroISThere == 2 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("DRAW")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 2 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("DRAW")
					}
				} else {
					if ZeroISThere == 3 {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		k := int(n / 2)
		notequal := 0
		for i := 0; i < k; i++ {
			if string(STRING[i]) != string(STRING[n-1-i]) {
				notequal++
			}
		}
		ZeroISThere := 0
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ZeroISThere++
			}
		}
		if notequal == 0 {
			if n%2 == 0 {
				if ZeroISThere == 0 {
					fmt.Println("DRAW")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 0 {
						fmt.Println("DRAW")
					} else {
						fmt.Println("BOB")
					}
				} else {
					if ZeroISThere == 1 {
						fmt.Println("BOB")
					} else {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal == 1 {
			if n%2 == 0 {
				if ZeroISThere == 1 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("BOB")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 1 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("BOB")
					}
				} else {

					fmt.Println("ALICE")

				}

			}
		}
		if notequal == 2 {
			if n%2 == 0 {
				if ZeroISThere == 2 {
					fmt.Println("ALICE")
				} else {
					fmt.Println("DRAW")
				}
			} else {
				q := int((n - 1) / 2)
				if string(STRING[q]) == "1" {
					if ZeroISThere == 2 {
						fmt.Println("ALICE")
					} else {
						fmt.Println("DRAW")
					}
				} else {
					if ZeroISThere == 3 {
						fmt.Println("ALICE")

					}
				}

			}
		}
		if notequal > 2 {
			fmt.Println("ALICE")
		}

	}
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var s string
	scan(&s)
	var c0, c01, c00 int
	if n%2 == 1 && s[n/2] == '0' {
		c0++
	}
	for i := 0; i < n/2; i++ {
		if s[i] != s[n-1-i] {
			c01++
		} else if s[i] == '0' {
			c00++
		}
	}
	if c01 > 1 {
		printf("ALICE\n")
		return
	}
	if c00 == 0 {
		if c01 == 1 && c0 == 1 {
			printf("DRAW\n")
		}
		if c01 == 1 && c0 == 0 {
			printf("ALICE\n")
		}
		if c01 == 0 && c0 == 1 {
			printf("BOB\n")
		}
		return
	}
	if c0 == 0 && c01 == 1 {
		printf("ALICE\n")
		return
	}
	if c0 == 0 && c01 == 0 {
		printf("BOB\n")
		return
	}
	if c0 == 1 && c01 == 0 {
		printf("ALICE\n")
		return
	}
	if c0 == 1 && c01 == 1 {
		printf("BOB\n")
		return
	}
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	precompute()
	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

const inf = 1 << 30

var dp [1001][1001][2][2]int

func min(s []int) int {
	r := s[0]
	for _, i := range s {
		if r > i {
			r = i
		}
	}
	return r
}

func calcdp(c01, c00, c0, canrev, player int) {
	if dp[c01][c00][c0][canrev] != inf {
		return
	}
	res := []int{}
	if canrev == 1 && c01 > 0 {
		calcdp(c01, c00, c0, 0, player^1)
		res = append(res, -dp[c01][c00][c0][0])
	}
	if c01 > 0 {
		calcdp(c01-1, c00, c0, 1, player^1)
		res = append(res, -dp[c01-1][c00][c0][1]+1)
	}
	if c00 > 0 {
		calcdp(c01, c00-1, c0, 1, player^1)
		res = append(res, -dp[c01][c00-1][c0][1]+1)
	}
	if c0 > 0 {
		calcdp(c01, c00, c0-1, 1, player^1)
		res = append(res, -dp[c01][c00][c0-1][1]+1)
	}
	dp[c01][c00][c0][canrev] = min(res)
}

func precompute() {
	for i := range dp {
		for j := range dp[i] {
			for k := range dp[i][j] {
				for l := range dp[i][j][k] {
					dp[i][j][k][l] = inf
				}
			}
		}
	}
	dp[0][0][0][0] = 0
	dp[0][0][0][1] = 0
	for i := range dp {
		for j := range dp[i] {
			for k := range dp[i][j] {
				calcdp(i, j, k, 1, 0)
			}
		}
	}
}

func solve() {
	var n int
	scan(&n)
	var s string
	scan(&s)
	var c0, c01, c00 int
	if n%2 == 1 && s[n/2] == '0' {
		c0++
	}
	for i := 0; i < n/2; i++ {
		if s[i] != s[n-1-i] {
			c01++
		} else if s[i] == '0' {
			c00++
		}
	}
	var ans = "DRAW"
	if dp[c01][c00][c0][1] > 0 {
		ans = "BOB"
	}
	if dp[c01][c00][c0][1] < 0 {
		ans = "ALICE"
	}
	printf("%v\n", ans)
}


package main

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

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

		g := make([]int, m)
		a := make(map[int][]int, n)
		for i := 0; i < n; i++ {
			b := make([]int, m)
			for j := 0; j < m; j++ {
				fmt.Fscan(in, &b[j])
			}
			a[i] = b

			c := make([]int, m)
			copy(c, b)
			sort.Ints(c)
			for k := range b {
				if b[k] == c[k] {
					continue
				}
				g[k]++
			}
		}

		x, y := -1, -1
		f := true
		for i, v := range g {
			if v != 0 {
				if x < 0 {
					x = i
				} else if y < 0 {
					y = i
				} else {
					f = false
					break
				}
			}
		}

		if !f {
			fmt.Fprintln(out, -1)
		} else if x < 0 {
			fmt.Fprintln(out, 1, 1)
		} else {
		Loop:
			for _, row := range a {
				row[x], row[y] = row[y], row[x]
				for j := 1; j < m; j++ {
					if row[j] < row[j-1] {
						f = false
						break Loop
					}
				}
			}

			if !f {
				fmt.Fprintln(out, -1)
			} else {
				fmt.Fprintln(out, x+1, y+1)
			}
		}
	}
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
	"sort"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)
		mp := make(map[int]bool)
		keys := []int{0, 0}

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
			}
			b := make([]int, m)
			copy(b, a[i])
			sort.Ints(b)
			for j := 0; j < m; j++ {
				if a[i][j] != b[j] {
					mp[j] = true
				}
			}
		}

		if len(mp) == 2 {
			jj := 0
			for k := range mp {
				keys[jj] = k
				jj++
			}
			sort.Ints(keys)

			flag := true
			for i := 0; i < n && m > 1; i++ {
				a[i][keys[0]], a[i][keys[1]] = a[i][keys[1]], a[i][keys[0]]
				for j := 1; j < m; j++ {
					if a[i][j] < a[i][j-1] {
						flag = false
						break
					}
				}
			}
			if flag {
				Fprintln(out, keys[0]+1, keys[1]+1)
			} else {
				Fprintln(out, -1)
			}
		} else if len(mp) == 0 {
			Fprintln(out, 1, 1)
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]int {
	index := make([][]int, h)
	data := make([]int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

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

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M := gi(),gi(); A := make([][]int,N); for i:=0;i<N;i++ { A[i] = gis(M) }
		done := false; working := make([]int,M); badcols := make([]int,0)
		for i:=0;i<N;i++ {
			row := A[i]; copy(working,row); sort.Slice(working,func(i,j int) bool { return working[i] < working[j] } )
			for i:=0;i<M;i++ { if working[i] != row[i] { badcols = append(badcols,i) } }
			if len(badcols) == 0 { continue }
			if len(badcols) > 2 { fmt.Fprintln(wrtr,-1); done = true; break }
			good := true; c1,c2 := badcols[0],badcols[1]
			for ii:=0;ii<N;ii++ {
				row := A[ii]; row[c1],row[c2] = row[c2],row[c1]
				for i:=0;i<M-1;i++ { if row[i] > row[i+1] { good = false; break } }
			}
			if !good { fmt.Fprintln(wrtr,-1); } else { fmt.Fprintf(wrtr,"%v %v\n",c1+1,c2+1) }
			done = true; break
		}
		if !done { fmt.Fprintln(wrtr,"1 1") }
	}
}

package main

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

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

	var T, n, m int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		k := -1
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			if !sort.IntsAreSorted(a[i]) {
				k = i
			}
		}
		if k < 0 {
			Fprintln(out, 1, 1)
			continue
		}
		b := append([]int{}, a[k]...)
		sort.Ints(b)
		ps := []int{}
		for j, v := range a[k] {
			if v != b[j] {
				if len(ps) == 2 {
					Fprintln(out, -1)
					continue o
				}
				ps = append(ps, j)
			}
		}
		i, j := ps[0], ps[1]
		for _, r := range a {
			r[i], r[j] = r[j], r[i]
			if !sort.IntsAreSorted(r) {
				Fprintln(out, -1)
				continue o
			}
		}
		Fprintln(out, i+1, j+1)
	}
}

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

package main

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

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

	var T, n, m int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		k := -1
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			if !sort.IntsAreSorted(a[i]) {
				k = i
			}
		}
		if k < 0 {
			Fprintln(out, 1, 1)
			continue
		}
		ps := []int{}
		for j := 1; j < m; j++ {
			if a[k][j-1] > a[k][j] {
				if len(ps) == 2 {
					Fprintln(out, -1)
					continue o
				}
				ps = append(ps, j)
			}
		}
		var i, j int
		if len(ps) == 1 {
			j = ps[0]
			i = sort.SearchInts(a[k][:j], a[k][j]+1)
			for _, r := range a {
				r[i], r[j] = r[j], r[i]
				if !sort.IntsAreSorted(r) {
					r[i], r[j] = r[j], r[i]
					goto next
				}
				r[i], r[j] = r[j], r[i]
			}
			Fprintln(out, i+1, j+1)
			continue
		next:
			i = ps[0] - 1
			j = i + sort.SearchInts(a[k][i+1:], a[k][i])
		} else {
			i, j = ps[0]-1, ps[1]
		}
		for _, r := range a {
			r[i], r[j] = r[j], r[i]
			if !sort.IntsAreSorted(r) {
				Fprintln(out, -1)
				continue o
			}
		}
		Fprintln(out, i+1, j+1)
	}
}

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

package main

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

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, m int
		Fscan(in, &n, &m)
		grid := make([][]int, n)
		for i := 0; i < n; i++ {
			grid[i] = make([]int, m)
		}
		var fi = -1
		var se = -1
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &grid[i][j])
			}
		}
		var get bool
		var cnt int
		var row = []int{}
		for i := 0; i < n; i++ {
			col := make([]int, m)
			for k := 0; k < m; k++ {
				col[k] = grid[i][k]
			}
			sort.Ints(col)
			pos := []int{}
			for j := 0; j < m; j++ {
				if grid[i][j] != col[j] {
					pos = append(pos, j+1)
				}
			}
			if len(pos) > 2 {
				Fprintln(out, -1)
				return
			}
			//Fprintln(out, "---", pos)
			if len(pos) == 2 {
				cnt++
				if !get {
					fi = pos[0]
					se = pos[1]
					get = true
				} else {
					if fi != pos[0] || se != pos[1] {
						Fprintln(out, -1)
						return
					}
				}
			}
			if len(pos) == 0 {
				row = append(row, i)
			}
		}
		if !get {
			Fprintln(out, 1, 1)
		} else {
			for i := 0; i < len(row); i++ {
				if grid[row[i]][fi-1] == grid[row[i]][se-1] {
					cnt++
				}
			}
			if cnt < n {
				Fprintln(out, -1)
				return
			}
			Fprintln(out, fi, se)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

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

func solve(arr [][]int) (int, int, bool) {
	m := len(arr[0])
	c := make([]int, m)
	b := []int{}
	for i, v := range arr {
		copy(c, arr[i])
		sort.Ints(c)
		for j := 0; j < m; j++ {
			if c[j] != v[j] {
				b = append(b, j)
			}
			if len(b) > 2 {
				return -1, -1, false
			}
		}
		if len(b) == 2 {
			break
		}
	}
	if len(b) == 0 {
		return 0, 0, true
	}
	x, y := b[0], b[1]
	for _, v := range arr {
		v[x], v[y] = v[y], v[x]
		if !sort.IntsAreSorted(v) {
			return -1, -1, false
		}
	}
	return x, y, true
}
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		arr := make([][]int, n)
		for i := range arr {
			arr[i] = make([]int, m)
			for k := 0; k < m; k++ {
				Fscan(in, &arr[i][k])
			}
		}
		// fmt.Println(arr)
		x, y, f := solve(arr)
		if !f {
			Fprintln(out, "-1")
		} else {
			Fprintf(out, "%d %d\n", x+1, y+1)
		}
	}
}

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

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
	"sort"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)
		mp := make(map[int]bool)
		keys := []int{1, 1}

		swopped := false

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
			}
		}
		for i := 0; i < n; i++ {
			if !swopped {
				swopped = true
				b := make([]int, m)
				copy(b, a[i])
				sort.Ints(b)
				for j := 0; j < m; j++ {
					if a[i][j] != b[j] {
						mp[j] = true
					}
				}
				if len(mp) > 0 {
					keys = make([]int, len(mp))
					j := 0
					for k := range mp {
						keys[j] = k
						j++
					}
					sort.Ints(keys)
					if len(mp) > 2 {
						break
					}
				}
			} else if m > 1 {
				a[i][keys[0]], a[i][keys[1]] = a[i][keys[1]], a[i][keys[0]]
				for j := 1; j < m; j++ {
					if a[i][j] < a[i][j-1] {
						mp[-1] = true
						break
					}

				}
			}
		}
		if len(mp) == 0 {
			Fprintln(out, 1, 1)
		} else if len(mp) == 2 && !mp[-1] {
			Fprintln(out, keys[0]+1, keys[1]+1)
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]int {
	index := make([][]int, h)
	data := make([]int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

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

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
	"sort"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)
		mp := make(map[int]bool)
		var keys []int

		swopped := false

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
			}
		}
		for i := 0; i < n; i++ {
			if !swopped {
				b := make([]int, m)
				copy(b, a[i])
				sort.Ints(b)
				for j := 0; j < m; j++ {
					if a[i][j] != b[j] {
						mp[j] = true
					}
				}
				if len(mp) > 0 {
					swopped = true
					keys = make([]int, len(mp))
					j := 0
					for k := range mp {
						keys[j] = k
						j++
					}
					sort.Ints(keys)
					if len(mp) > 2 {
						break
					}
				}
			} else {
				a[i][keys[0]], a[i][keys[1]] = a[i][keys[1]], a[i][keys[0]]
				for j := 1; j < m; j++ {
					if a[i][j] < a[i][j-1] {
						mp[-1] = true
						break
					}

				}
			}
		}
		if len(mp) == 0 {
			Fprintln(out, 1, 1)
		} else if len(mp) == 2 && !mp[-1] {
			Fprintln(out, keys[0]+1, keys[1]+1)
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]int {
	index := make([][]int, h)
	data := make([]int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

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

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
	"sort"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)
		mp := make(map[int]bool)
		var keys []int

		swopped := false

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
			}
		}
		for i := 0; i < n; i++ {
			if !swopped {
				b := make([]int, m)
				copy(b, a[i])
				sort.Ints(b)
				for j := 0; j < m; j++ {
					if a[i][j] != b[j] {
						mp[j] = true
					}
				}
				if len(mp) > 0 {
					keys = make([]int, len(mp))
					swopped = true
					j := 0
					for k := range mp {
						keys[j] = k
						j++
					}
					sort.Ints(keys)
					if len(mp) > 2 {
						break
					}
				}
			} else {
				a[i][keys[0]], a[i][keys[1]] = a[i][keys[1]], a[i][keys[0]]
				for j := 1; j < m; j++ {
					if a[i][j] < a[i][j-1] {
						mp[-1] = true
						break
					}

				}
			}
		}
		if len(mp) == 0 {
			Fprintln(out, 1, 1)
		} else if len(mp) == 2 {
			Fprintln(out, keys[0]+1, keys[1]+1)
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]int {
	index := make([][]int, h)
	data := make([]int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

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

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)

		use := false
		tj := -1
		fj := -1

		flag := true
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
				if !use && j > 0 {
					if a[i][j] < a[i][j-1] {
						if tj == -1 {
							tj = j
						} else {
							fj = j
							if a[i][j] <= a[i][tj] {
								tj = tj - 1
							}
						}
					}
				}
			}
			if tj != -1 && fj == -1 {
				tj, fj = tj-1, tj

			}
			if tj != -1 && fj != -1 {
				use = true
			}
		}
		for i := 0; i < n; i++ {
			if tj != -1 && fj != -1 {
				a[i][tj], a[i][fj] = a[i][fj], a[i][tj]
			}
			for j := 1; j < m && flag; j++ {
				if a[i][j] < a[i][j-1] {
					flag = false
				}
			}
		}
		if flag {
			if fj != -1 {
				Fprintln(out, tj+1, fj+1)
			} else {
				Fprintln(out, 1, 1)
			}
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

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

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M := gi(),gi(); A := make([][]int,N); for i:=0;i<N;i++ { A[i] = gis(M) }
		done := false; working := make([]int,M); badcols := make([]int,0)
		for i:=0;i<N;i++ {
			row := A[i]; copy(working,row); sort.Slice(working,func(i,j int) bool { return working[i] < working[j] } )
			for i:=0;i<M;i++ { if working[i] != row[i] { badcols = append(badcols,i) } }
			if len(badcols) == 0 { continue }
			if len(badcols) > 2 { fmt.Fprintln(wrtr,-1); done = true; break }
			good := true; c1,c2 := badcols[0],badcols[1]
			for ii:=0;i<N;i++ {
				row := A[ii]; row[c1],row[c2] = row[c2],row[c1]
				for i:=0;i<M-1;i++ { if row[i] > row[i+1] { good = false; break } }
			}
			if !good { fmt.Fprintln(wrtr,-1); } else { fmt.Fprintf(wrtr,"%v %v\n",c1,c2) }
			done = true; break
		}
		if !done { fmt.Fprintln(wrtr,"1 1") }
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M := gi(),gi(); A := make([][]int,N); for i:=0;i<N;i++ { A[i] = gis(M) }
		potBadCols := make(map[int]bool)
		for i:=0;i<N;i++ {
			row := A[i]
			for j:=0;j<M-1;j++ {
				if row[j] > row[j+1] { potBadCols[j] = true; potBadCols[j+1] = true }
			}
		}
		if len(potBadCols) == 0 { fmt.Fprintf(wrtr,"%v %v\n",1,1); continue }
		if len(potBadCols) > 6 { fmt.Fprintf(wrtr,"-1\n"); continue }
		pb := make([]int,0); for k := range potBadCols { pb = append(pb,k) }
		col1,col2 := -1,-1
		tryit := func(c1,c2 int) bool {
			good := true
			for i:=0;i<N;i++ {
				row := A[i]
				row[c1],row[c2] = row[c2],row[c1]
				for j:=0;j<M-1;j++ {
					if row[j] > row[j+1] { good = false; break }
				}
				row[c1],row[c2] = row[c2],row[c1]
				if !good { break }
			}
			return good
		}
		for i:=0;i<len(pb);i++ {
			for j:=i+1;j<len(pb);j++ {
				tcol1,tcol2 := pb[i],pb[j]
				good := true
				for _,c := range pb { if abs(tcol1-c) > 1 && abs(tcol2-c) > 1 { good = false } }
				if !good { continue }
				if tryit(tcol1,tcol2) { col1,col2 = tcol1,tcol2; break }
			}
			if col1 != -1 { break }
		}
		if col1 != -1 { fmt.Fprintf(wrtr,"%v %v\n",col1+1,col2+1) } else { fmt.Fprintf(wrtr,"-1\n") }
	}
}

package main

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

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

	var T, n, m int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		k := -1
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			if !sort.IntsAreSorted(a[i]) {
				k = i
			}
		}
		if k < 0 {
			Fprintln(out, 1, 1)
			continue
		}
		ps := []int{}
		for j := 1; j < m; j++ {
			if a[k][j-1] > a[k][j] {
				if len(ps) == 2 {
					Fprintln(out, -1)
					continue o
				}
				ps = append(ps, j)
			}
		}
		var i, j int
		if len(ps) == 1 {
			j = ps[0]
			i = sort.SearchInts(a[k][:j], a[k][j]+1)
		} else {
			i, j = ps[0]-1, ps[1]
		}
		for _, r := range a {
			r[i], r[j] = r[j], r[i]
			if !sort.IntsAreSorted(r) {
				Fprintln(out, -1)
				continue o
			}
		}
		Fprintln(out, i+1, j+1)
	}
}

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

package main

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

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, m int
		Fscan(in, &n, &m)
		grid := make([][]int, n)
		for i := 0; i < n; i++ {
			grid[i] = make([]int, m)
		}
		var fi = -1
		var se = -1
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &grid[i][j])
			}
		}
		var get bool
		var cnt int
		var row = []int{}
		for i := 0; i < n; i++ {
			col := make([]int, m)
			for k := 0; k < m; k++ {
				col[k] = grid[i][k]
			}
			sort.Ints(col)
			pos := []int{}
			for j := 0; j < m; j++ {
				if grid[i][j] != col[j] {
					pos = append(pos, j+1)
				}
			}
			if len(pos) > 2 {
				Fprintln(out, -1)
				return
			}
			//Fprintln(out, "---", pos)
			if len(pos) == 2 {
				cnt++
				if !get {
					fi = pos[0]
					se = pos[1]
					get = true
				} else {
					if fi != pos[0] || se != pos[1] {
						Fprintln(out, -1)
					}
				}
			}
			if len(pos) == 0 {
				row = append(row, i)
			}
		}
		if !get {
			Fprintln(out, 1, 1)
		} else {
			for i := 0; i < len(row); i++ {
				if grid[row[i]][fi-1] == grid[row[i]][se-1] {
					cnt++
				}
			}
			if cnt < n {
				Fprintln(out, -1)
				return
			}
			Fprintln(out, fi, se)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }


package main

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

type wrath struct{}

func (c *wrath) solve() int {
	inp := bufio.NewReader(os.Stdin)

	// read n
	var n int
	fmt.Fscanf(inp, "%d\n", &n)
	if n <= 1 {
		return 1
	}

	// stack
	stack := make([]int, 0, n>>1)

	var claw, killTo, i, j int
	for i = 0; i < n; i++ {
		fmt.Fscanf(inp, "%d", &claw)

		// i - claw
		if killTo = i - claw; killTo < 0 {
			killTo = 0
		}

		for j = len(stack) - 1; j >= 0; j-- {
			if stack[j] < killTo {
				break
			}
		}

		if j != len(stack)-1 {
			stack = stack[:j+1]
		}
		stack = append(stack, i)
	}

	return len(stack)
}

func main() {
	var w wrath
	fmt.Print(w.solve())
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt()

	var alives []int
	for i := 0; i < n; i++ {
		hook := readInt()
		dead := 0
		for j := len(alives) - 1; j >= 0; j-- {
			if i-alives[j] > hook {
				break
			}
			dead++
		}
		alives = append(alives[:len(alives)-dead], i)
	}

	fmt.Println(len(alives))
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

package main

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

func solve() {
	n := readInt()

	// read in all the claw lengths
	claws := make([]int, n, n)
	for i, _ := range claws {
		claws[i] = readInt()
	}

	alive_marker := n - 1
	var nalive = 0
	for i := n - 1; i >= 0; i-- {
		if i == alive_marker {
			nalive++
		}

		// move the marker to the left
		next := i - claws[i] - 1
		if next < alive_marker {
			alive_marker = next
		}

		if alive_marker < 0 {
			// noone else alive
			break
		}
	}
	fmt.Println(nalive)
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

func solve() {
	n := readInt()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = readInt64()
	}
	v := make([]bool, n)
	cnt := 0
	for i := n - 1; i >= 0; i-- {
		if !v[i] {
			l := a[i]
			for j := i - 1; j >= 0 && !v[j] && l > 0; j-- {
				cnt++
				v[j] = true
				l--
				l = max(a[j], l)
			}
		}
	}
	fmt.Println(n - cnt)
}

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

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt()

	if n == 1 {
		fmt.Println("1")
		return
	}

	l := make([]int, n)
	f := make([]bool, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = readInt()
		f[i] = true
	}

	for i := n - 2; i >= 0; i-- {
		xif := math.Max(float64(l[i + 1]), float64(x[i + 1]))
		xi := int(xif)
		if xi > 0 {
			x[i] = xi - 1
			f[i] = false
		}
	}

	nAlive := 0
	for i := 0; i < n; i++ {
		if f[i] {
			nAlive++;
		}
	}

	fmt.Println(nAlive)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

func readBigInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}

package main

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

var local = false
var scanner *bufio.Scanner

var l [1000000]int
var f [1000000]bool
var x [1000000]int

func main() {
	setup()
	n := readInt()

	if n == 1 {
		fmt.Println("1")
		return
	}

	for i := 0; i < n; i++ {
		l[i] = readInt()
		f[i] = true
	}

	for i := n - 2; i >= 0; i-- {
		xif := math.Max(float64(l[i + 1]), float64(x[i + 1]))
		xi := int(xif)
		if xi > 0 {
			x[i] = xi - 1
			f[i] = false
		}
	}

	nAlive := 0
	for i := 0; i < n; i++ {
		if f[i] {
			nAlive++;
		}
	}

	fmt.Println(nAlive)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

func readBigInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}