You are given two arrays $$$a$$$ and $$$b$$$, both consisting of $$$n$$$ integers.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$; $$$i \neq j$$$) and swap $$$a_i$$$ with $$$a_j$$$ and $$$b_i$$$ with $$$b_j$$$. You have to perform the swap in both arrays.You are allowed to perform at most $$$10^4$$$ moves (possibly, zero). Can you make both arrays sorted in a non-decreasing order at the end? If you can, print any sequence of moves that makes both arrays sorted.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of elements in both arrays. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the first array. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le n$$$) — the second array.

For each testcase, print the answer. If it's impossible to make both arrays sorted in a non-decreasing order in at most $$$10^4$$$ moves, print -1. Otherwise, first, print the number of moves $$$k$$$ $$$(0 \le k \le 10^4)$$$. Then print $$$i$$$ and $$$j$$$ for each move $$$(1 \le i, j \le n$$$; $$$i \neq j)$$$. If there are multiple answers, then print any of them. You don't have to minimize the number of moves.

package main

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

func isSort(length int, a []int) bool {
	for i := 0; i < length-1; i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

type Move struct {
	i int
	j int
}

func (s Move) String() string {
	return fmt.Sprintf("%d %d", s.i, s.j)
}

func solve(length int, array_a, array_b []int) int {
	return sort2(length, array_a, array_b)
}

func sort2(length int, a, b []int) int {
	moves := make([]Move, 0)
	for i := 0; i < length; i++ {
		for j := i + 1; j < length; j++ {

			if (a[i] > a[j] && b[i] >= b[j]) || (b[i] > b[j] && a[i] >= a[j]) {
				moves = append(moves, Move{
					i + 1, j + 1,
				})
				tmp1 := a[i]
				a[i] = a[j]
				a[j] = tmp1
				tmp1 = b[i]
				b[i] = b[j]
				b[j] = tmp1
			}
		}
	}
	for i := 0; i < length-1; i++ {
		if a[i] > a[i+1] || b[i] > b[i+1] {
			fmt.Println(-1)
			return -1
		}
	}
	fmt.Println(len(moves))
	for _, m := range moves {
		fmt.Println(m)
	}
	return 0
}
func main() {
	var tc int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	tc, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < tc; i++ {
		var length int
		scanner.Scan()
		length, _ = strconv.Atoi(scanner.Text())
		a1 := make([]int, length)
		a2 := make([]int, length)
		scanner.Scan()
		la1 := strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a1[i1], _ = strconv.Atoi(v)
		}
		scanner.Scan()
		la1 = strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a2[i1], _ = strconv.Atoi(v)
		}
		solve(length, a1, a2)

	}

}

package main

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

func isSort(length int, a []int) bool {
	for i := 0; i < length-1; i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

type Move struct {
	i int
	j int
}

func (s Move) String() string {
	return fmt.Sprintf("%d %d", s.i, s.j)
}

func solve(length int, array_a, array_b []int) int {
	// defer func() {
	// 	if err := recover(); err != nil {
	// 		fmt.Printf("array_a: %v\n", array_a)
	// 		fmt.Printf("array_b: %v\n", array_b)
	// 	}
	// }()
	sorted_a := make([]int, length)
	copy(sorted_a, array_a)
	sorted_b := make([]int, length)
	copy(sorted_b, array_b)
	sort.Ints(sorted_a)
	sort.Ints(sorted_b)
	index_a := make(map[int][]int)
	index_b := make(map[int][]int)
	for i, v := range array_a {
		if _, ok := index_a[v]; ok {
			index_a[v] = append(index_a[v], i)
		} else {
			index_a[v] = make([]int, 0)
			index_a[v] = append(index_a[v], i)
		}
	}
	for i, v := range array_b {
		if _, ok := index_b[v]; ok {
			index_b[v] = append(index_b[v], i)
		} else {
			index_b[v] = make([]int, 0)
			index_b[v] = append(index_b[v], i)
		}
	}
	canSort := false
	for i, v := range sorted_b {
		canSort = false
		for j, k1 := range index_b[v] {
			if sorted_a[i] == array_a[k1] {
				canSort = true
				index_b[v] = append(index_b[v][:j], index_b[v][j+1:]...)
				break

			}
		}
		if !canSort {
			return -1
		}
	}
	return 0
}

func sort2(length int, a, b []int) int {
	var move = 10e4
	moves := make([]Move, 0)
	for move >= 0 {
		if isSort(length, a) && isSort(length, b) {
			break
		}
		canSort := false
		for i := 0; i < length-1; i++ {
			for j := i + 1; j < length; j++ {
				if a[i] >= a[j] && b[i] >= b[j] {
					moves = append(moves, Move{
						i + 1, j + 1,
					})
					tmp1 := a[i]
					a[i] = a[j]
					a[j] = tmp1
					tmp1 = b[i]
					b[i] = b[j]
					b[j] = tmp1
					move--
					canSort = true
				}
			}
		}
		if !canSort {
			return -1
		}
	}
	if move <= 0 {
		return -1
	} else {
		fmt.Println(len(moves))
		for _, m := range moves {
			fmt.Println(m)
		}
		return 0
	}
}
func main() {
	var tc int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	tc, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < tc; i++ {
		var length int
		scanner.Scan()
		length, _ = strconv.Atoi(scanner.Text())
		a1 := make([]int, length)
		a2 := make([]int, length)
		scanner.Scan()
		la1 := strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a1[i1], _ = strconv.Atoi(v)
		}
		scanner.Scan()
		la1 = strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a2[i1], _ = strconv.Atoi(v)
		}
		c := solve(length, a1, a2)
		if c != -1 {
			sort2(length, a1, a2)
		} else {
			fmt.Println(c)
		}
	}

}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	var n int

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

		b := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &b[i])
		}

		moves := solveC(a, b)
		if moves != nil {
			Fprintln(out, len(moves))
			for i := range moves {
				Fprintln(out, moves[i].i, moves[i].j)
			}
			continue
		}
		Fprintln(out, -1)

	}
}

type pair struct {
	i, j int
}

func solveC(a, b []int) []pair {
	n := len(a)

	moves := make([]pair, 0)
	count := 0
	for i := 0; i < n; i++ {
		// fmt.Println("===========================")
		// fmt.Println(a)
		// fmt.Println(b)
		smallestIdxA := i
		smallestIdxB := i
		for j := i; j < n; j++ {
			if a[smallestIdxA] > a[j] {
				smallestIdxA = j
			}
			if b[smallestIdxB] > b[j] {
				smallestIdxB = j
			}
		}

		if i != smallestIdxA && b[i] >= b[smallestIdxA] {
			a[i], a[smallestIdxA] = a[smallestIdxA], a[i]
			b[i], b[smallestIdxA] = b[smallestIdxA], b[i]
			moves = append(moves, pair{i + 1, smallestIdxA + 1})
			i--
			count++
			if count > 10000 {
				return nil
			}
			continue
		}
		if i != smallestIdxB && a[i] >= a[smallestIdxB] {
			a[i], a[smallestIdxB] = a[smallestIdxB], a[i]
			b[i], b[smallestIdxB] = b[smallestIdxB], b[i]
			moves = append(moves, pair{i + 1, smallestIdxB + 1})
			i--
			count++
			if count > 10000 {
				return nil
			}
			continue
		}
	}

	if isSorted(a) && isSorted(b) {
		return moves
	}
	return nil
}

func isSorted(nums []int) bool {
	n := len(nums)
	for i := 0; i < n-1; i++ {
		if nums[i] > nums[i+1] {
			return false
		}
	}
	return true
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	var n int

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

		b := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &b[i])
		}

		ao := make([]int, len(a))
		bo := make([]int, len(b))
		copy(ao, a)
		copy(bo, b)

		moves := solveC(a, b)
		if moves != nil {
			Fprintln(out, len(moves))
			for i := range moves {
				Fprintln(out, moves[i].i, moves[i].j)
			}
			continue
		}

		moves = solveC(bo, ao)
		if moves != nil {
			Fprintln(out, len(moves))
			for i := range moves {
				Fprintln(out, moves[i].i, moves[i].j)
			}
			continue
		}
		Fprintln(out, -1)

	}
}

type pair struct {
	i, j int
}

func solveC(a, b []int) []pair {
	n := len(a)

	moves := make([]pair, 0)
	count := 0
	for i := 0; i < n; i++ {
		// fmt.Println("===========================")
		// fmt.Println(a)
		// fmt.Println(b)
		smallestIdxA := i
		smallestIdxB := i
		for j := i; j < n; j++ {
			if a[smallestIdxA] > a[j] {
				smallestIdxA = j
			}
			if b[smallestIdxB] > b[j] {
				smallestIdxB = j
			}
		}

		if i != smallestIdxA && b[i] >= b[smallestIdxA] {
			a[i], a[smallestIdxA] = a[smallestIdxA], a[i]
			b[i], b[smallestIdxA] = b[smallestIdxA], b[i]
			moves = append(moves, pair{i + 1, smallestIdxA + 1})
			i--
			count++
			if count > 10000 {
				return nil
			}
			continue
		}
		if i != smallestIdxB && a[i] >= a[smallestIdxB] {
			a[i], a[smallestIdxB] = a[smallestIdxB], a[i]
			b[i], b[smallestIdxB] = b[smallestIdxB], b[i]
			moves = append(moves, pair{i + 1, smallestIdxB + 1})
			i--
			count++
			if count > 10000 {
				return nil
			}
			continue
		}
	}

	if isSorted(a) && isSorted(b) {
		return moves
	}
	return nil
}

func isSorted(nums []int) bool {
	n := len(nums)
	for i := 0; i < n-1; i++ {
		if nums[i] > nums[i+1] {
			return false
		}
	}
	return true
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T,N,A,B,mina,minb int

	fmt.Fscan(in, &T)

	for i := 0;i < T;i++{
		fmt.Fscan(in, &N)
		listA := make([]int,N)
		listB := make([]int,N)
		mA := make([]int,N)
		mB := make([]int,N)
		for j := 0;j < N;j++{
			fmt.Fscan(in, &A)
			listA[j] = A
			mA[j] = A
			if mina > A{
				mina = A
			}
		}
		for j := 0;j < N;j++{
			fmt.Fscan(in, &B)
			listB[j] = B
			mB[j] = B
			if minb > B{
				minb = B
			}
		}
		sort.Ints(listA)
		sort.Ints(listB)
		list,judge := sortlist(listA,listB,mA,mB,N)
		if judge {
			ans,ans2 := swapsort(list,N)
			fmt.Println(ans)
			for i := 0;i < ans;i++{
				fmt.Println(ans2[i][0]+1,ans2[i][1]+1)
			}
		}else{
			fmt.Println(-1)
		}

	}
}

func sortlist(listA []int,listB []int,mA []int,mB []int,N int) ([]int, bool){
	list := make([]int,N)
	count := 0
	//judge := false
	for i := 0;i < N;i++ {
		judge := false
		for j := 0;j < N;j++ {
			if listA[i] == mA[j] && listB[i] == mB[j] {
				judge = true
				list[j] = count
				mA[j] = 101
				mB[j] = 101
				count++
				break
			}
		}
		if !judge{
			return list,judge
		}
	}
	return list,true
}

func swapsort(list []int,N int)(int,[][]int){
	listN := make([][]int,N)
	count := 0
	for i := 0;i < N;i++ {
		if list[i] != i{
			for j := 0;j < N;j++ {
				if list[j] == i{
					listN[count] = append(listN[count],i,j)
					list[i], list[j] = list[j], list[i]
					count++
				}
			}
		}
	}
	return count,listN
}

package main

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

type pair struct{ x, y int }

func sort(a []int, delta int) (p []pair) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := 0; j < n-i-1; j++ {
			if a[j] > a[j+1] {
				p = append(p, pair{j + delta, j + delta + 1})
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}
	return p
}

func Solve() {
	n := ri()
	var a, b []int
	for i := 0; i < n; i++ {
		a = append(a, ri())
	}
	for i := 0; i < n; i++ {
		b = append(b, ri())
	}
	p := sort(a, 0)
	for _, t := range p {
		b[t.x], b[t.y] = b[t.y], b[t.x]
	}
	for i := 0; i < n; i++ {
		j := i
		for j+1 < n && a[i] == a[j+1] {
			j++
		}
		t := sort(b[i:j+1], i)
		p = append(p, t...)
		i = j
	}
	if sort2.IntsAreSorted(b) {
		println(len(p))
		for _, t := range p {
			println(t.x+1, t.y+1)
		}
	} else {
		println(-1)
	}
}

func main() {
	T := 0 // 如果是单组样例，请讲 T := 0 改为 T := 1
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

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

// ri 将直接读入并返回一个 int
func ri() (x int) {
	scan(&x)
	return x
}

//rs 将直接读入并返回一个 string
func rs() (s string) {
	scan(&s)
	return s
}

//scan 用法与 fmt.scan() 相似，可以传入多个变量的地址进行读入操作
func scan(a ...interface{}) { Fscan(in, a...) }

//print 用法与 fmt.print() 相似，可以传入多个变量进行输出。注意，这个函数不会换行，多个变量之间有空格
func print(a ...interface{}) { Fprint(out, a...) }

//println 用法与 fmt.println() 相似，可以传入多个变量进行输出。这个函数会换行，多个变量之间有空格
func println(a ...interface{}) { Fprintln(out, a...) }

//min 可以传入多个 int 变量，求出这些变量的最小值
func min(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//max 可以传入多个 int 变量，求出这些变量的最大值
func max(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//sum 可以传入多个 int 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum(a ...int) int {
	ans := 0
	for _, x := range a {
		ans += x
	}
	return ans
}

package main

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

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

func CF1691C(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n int64
		fmt.Fscan(r, &n)
		a, b := make([]int64, n), make([]int64, n)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &b[i])
		}

		ans, ok := CF1691CS(a, b, n)
		if !ok {
			fmt.Fprintln(w, -1)
		} else {
			fmt.Fprintln(w, len(ans))
			for _, v := range ans {
				fmt.Fprintln(w, v[0]+1, v[1]+1)
			}
		}

	}
}

func CF1691CS(a, b []int64, n int64) ([][]int64, bool) {
	ans := make([][]int64, 0)

	for i := int64(0); i < n; i++ {
		for j := i + 1; j < n; j++ {
			if a[i] >= a[j] && b[i] >= b[j] {
				a[i], a[j] = a[j], a[i]
				b[i], b[j] = b[j], b[i]
				ans = append(ans, []int64{i, j})
			} else if a[i] <= a[j] && b[i] <= b[j] {
				continue
			} else {
				return nil, false
			}
		}
	}

	return ans, true
}

package main

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

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

func c1681(_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

loop:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a, b := []int{}, []int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			a = append(a, x)
		}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			b = append(b, x)
		}

		ha, hb := map[int]bool{}, map[int]bool{}
		for _, v := range a {
			ha[v] = true
		}
		for _, v := range b {
			hb[v] = true
		}

		ra, rb := map[int]int{}, map[int]int{}
		d := 0
		for i := 1; i <= n; i++ {
			if ha[i] {
				d++
				ra[i] = d
			}
		}
		d = 0
		for i := 1; i <= n; i++ {
			if hb[i] {
				d++
				rb[i] = d
			}
		}

		ar, br := []int{}, []int{}
		for _, v := range a {
			ar = append(ar, ra[v])
		}
		for _, v := range b {
			br = append(br, rb[v])
		}

		do := [][]int{}
		for i, v := range ar {
			do = append(do, []int{v, br[i], i})
		}

		sort.Slice(do, func(i, j int) bool {
			return do[i][0] < do[j][0] || do[i][0] == do[j][0] && do[i][1] < do[j][1]
		})

		for i := 1; i < n; i++ {
			if do[i][1] < do[i-1][1] {
				Fprintln(out, -1)
				continue loop
			}
		}
		//Fprintln(out, do)

		o := make([]int, n)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			p[i] = i
			o[i] = i
		}

		t := [][]int{}
		for i, v := range do {
			if o[i] != v[2] {
				j := p[v[2]]
				p[o[i]], p[v[2]] = j, i
				o[j], o[i] = o[i], o[j]
				t = append(t, []int{i, j})
			}
			//Fprintln(out, i, o)
		}

		Fprintln(out, len(t))
		for _, v := range t {
			Fprintln(out, v[0]+1, v[1]+1)
		}

		//// chk
		//Fprintln(out, a)
		//Fprintln(out, b)
		//for _, v := range t {
		//	a[v[0]], a[v[1]] = a[v[1]], a[v[0]]
		//	b[v[0]], b[v[1]] = b[v[1]], b[v[0]]
		//}
		//Fprintln(out, a)
		//Fprintln(out, b)
	}
}

package main

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

type Int int64

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

type pair struct {
	a, b  int
	index int
}

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 int
		Fscan(in, &n)
		a := make([]int, n)
		b := make([]int, n)

		p := make([]int, n)
		ind := make([]int, n)

		f := make([]pair, n)

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

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

		sort.SliceStable(f, func(i, j int) bool {
			if f[i].a == f[j].a {
				return f[i].b < f[j].b
			}
			return f[i].a < f[j].a
		})

		flag := true
		for i := 1; i < n; i++ {
			if f[i-1].a > f[i].a || f[i-1].b > f[i].b {
				Fprintln(out, -1)
				flag = false
				break
			}
		}

		if flag {
			res := list.New()
			for i := 0; i < n; i++ {
				if i != p[f[i].index] {
					res.PushBack(pair{i, p[f[i].index], -1})

					ind[i], ind[p[f[i].index]] = ind[p[f[i].index]], ind[i]

					for j := 0; j < n; j++ {
						p[ind[j]] = j
					}
				}
			}

			Fprintln(out, res.Len())
			for it := res.Front(); it != nil; it = it.Next() {
				pa := it.Value.(pair)
				Fprintln(out, pa.a+1, pa.b+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
}

type Void struct{}

var void Void

type HashSet struct {
	ma map[Int]Void
}

func NewHashSet() *HashSet {
	return &HashSet{
		ma: make(map[Int]Void),
	}
}

func (s *HashSet) add(x Int) bool {
	_, exists := s.ma[x]
	if !exists {
		s.ma[x] = void
		return true
	} else {
		return false
	}
}

func (s *HashSet) del(x Int) {
	delete(s.ma, x)
}

func (s *HashSet) exist(x Int) bool {
	_, exists := s.ma[x]
	return exists
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    Int // The value of the item; arbitrary.
	priority Int // The priority of the item in the queue.
	indices  Int
	// 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 NewItem(value, priority Int) *Item {
	return &Item{
		value:    value,
		priority: priority,
		index:    -1,
	}

}

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 Int, priority Int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

type SegTree struct {
	st []Segment
}

type Segment struct {
	l, r, val, add, minIndex Int
}

func newSegTree(n Int) SegTree {
	segTree := SegTree{make([]Segment, n<<2)}
	segTree.Build(1, 1, n)
	return segTree
}

func (segTree SegTree) Build(x, l, r Int) {
	segTree.st[x].l = l
	segTree.st[x].r = r
	if l == r {
		segTree.st[x].minIndex = l
		return
	}
	mid := (l + r) >> 1
	segTree.Build(x<<1, l, mid)
	segTree.Build(x<<1|1, mid+1, r)
}

func (segTree SegTree) push(x Int) {
	if segTree.st[x].add != 0 {
		segTree.modifyOne(x<<1, segTree.st[x].add)
		segTree.modifyOne(x<<1|1, segTree.st[x].add)
		segTree.st[x].add = 0
	}
}

func (segTree SegTree) update(x Int) {
	if segTree.st[x<<1].val < segTree.st[x<<1|1].val {
		segTree.st[x].val = segTree.st[x<<1].val
		segTree.st[x].minIndex = segTree.st[x<<1].minIndex
	} else {
		segTree.st[x].val = segTree.st[x<<1|1].val
		segTree.st[x].minIndex = segTree.st[x<<1|1].minIndex
	}
}

func (segTree SegTree) modifyOne(x, add Int) {
	segTree.st[x].val += add
	if segTree.st[x].l != segTree.st[x].r {
		segTree.st[x].add += add
	}
}

func (segTree SegTree) Modify(x, l, r, add Int) {
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		segTree.modifyOne(x, add)
		return
	}
	segTree.push(x)
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		segTree.Modify(x<<1, l, r, add)
	}
	if mid < r {
		segTree.Modify(x<<1|1, l, r, add)
	}
	segTree.update(x)
}

func updateRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes > res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) Query(x, l, r Int) (Int, Int) {
	res := Int(math.MaxInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateRes(res, resInd, segTree.st[x].val, segTree.st[x].minIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.Query(x<<1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.Query(x<<1|1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

type Graph struct {
	nodeSize Int
	edges    []Edge
	head     []Int
	dis      []Int
	vis      []bool
	nCnt     Int
	ans      []Int
}

type Edge struct {
	u, v, c, indices, next Int
}

func NewGraph(nodeSize Int) *Graph {
	return &Graph{
		nodeSize: nodeSize,
		edges:    make([]Edge, (2e5+10)<<2),
		head:     make([]Int, nodeSize+100),
		dis:      make([]Int, nodeSize+100),
		vis:      make([]bool, nodeSize+100),
		nCnt:     L1,
		ans:      make([]Int, nodeSize),
	}
}

func (g *Graph) addEdge(u Int, v Int, cost Int, indices Int) {
	g.nCnt++
	g.edges[g.nCnt] = Edge{u, v, cost, indices, g.head[u]}
	g.head[u] = g.nCnt
}

func (g *Graph) Dijkstra(begin Int) {
	for i := L1; i <= g.nodeSize; i++ {
		g.dis[i] = math.MaxInt64
	}
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)

	g.dis[begin] = 0
	heap.Push(&pq, &Item{begin, 0, -1, -1})

	id := L0

	for len(pq) > 0 {
		it := heap.Pop(&pq).(*Item)
		u := it.value
		if g.vis[u] {
			continue
		}
		g.vis[u] = true

		if it.indices != -1 && id < g.nodeSize-1 {
			g.ans[id] = it.indices
			id++
		}

		for i := g.head[u]; i != 0; i = g.edges[i].next {
			v := g.edges[i].v
			if g.dis[v] > g.dis[u]+g.edges[i].c {
				g.dis[v] = g.dis[u] + g.edges[i].c

				heap.Push(&pq, &Item{v, g.dis[v], g.edges[i].indices, -1})
			}
		}
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

type entry struct {
	a, b int
}

type es []entry

var reme = [][2]int{}

func (e es) Less(i, j int) bool {
	if e[i].a == e[j].a {
		return e[i].b < e[j].b
	} else {
		return e[i].a < e[j].a
	}
}

func (e es) Swap(i, j int) {
	e[i], e[j] = e[j], e[i]
	reme = append(reme, [2]int{i, j})
}

func (e es) Len() int {
	return len(e)
}

func slove() {
	defer func() {
		reme = make([][2]int, 0)
	}()
	var n int
	fmt.Fscan(r, &n)
	nums1 := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums1[i])
	}
	nums2 := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums2[i])
	}
	e := make(es, n)
	for i := range e {
		e[i].a = nums1[i]
		e[i].b = nums2[i]
	}
	sort.Sort(e)
	for i:=1;i<n;i++ {
		if e[i].b < e[i-1].b {
			fmt.Fprintln(w, "-1")
			return
		}
	}
	fmt.Fprintln(w, len(reme))
	for i := range reme {
		fmt.Fprintln(w, reme[i][0]+1, reme[i][1]+1)
	}
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

type pair struct {
	first, second int
}

var ans []pair

type IntSlice []int

func (x IntSlice) Len() int           { return len(x) }
func (x IntSlice) Less(i, j int) bool { return x[i] < x[j] }
func (x IntSlice) Swap(i, j int) {
	x[i], x[j] = x[j], x[i]
	ans = append(ans, pair{first: i, second: j})
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		ans = make([]pair, 0)

		n := io.ReadInt()
		a := io.ReadIntSlice(n)
		b := io.ReadIntSlice(n)

		c := make([]int, len(a))
		copy(c, a)

		sort.Stable(IntSlice(c))

		copy(c, b)
		for i := range ans {
			b[ans[i].first], b[ans[i].second] = b[ans[i].second], b[ans[i].first]
		}

		if sort.IntsAreSorted(b) {
			fmt.Println(len(ans))
			for i := 0; i < len(ans); i++ {
				fmt.Println(ans[i].first+1, ans[i].second+1)
			}
			continue
		}

		copy(c, b)

		sort.Stable(IntSlice(c))

		copy(c, a)
		for i := range ans {
			a[ans[i].first], a[ans[i].second] = a[ans[i].second], a[ans[i].first]
		}

		if sort.IntsAreSorted(a) {
			fmt.Println(len(ans))
			for i := 0; i < len(ans); i++ {
				fmt.Println(ans[i].first+1, ans[i].second+1)
			}
			continue
		}

		fmt.Println(-1)
	}
}

package main

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

func isSort(length int, a []int) bool {
	for i := 0; i < length-1; i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

type Move struct {
	i int
	j int
}

func (s Move) String() string {
	return fmt.Sprintf("%d %d", s.i, s.j)
}

func solve(length int, array_a, array_b []int) int {
	sorted_a := make([]int, length)
	copy(sorted_a, array_a)
	sorted_b := make([]int, length)
	copy(sorted_b, array_b)
	sort.Ints(sorted_a)
	sort.Ints(sorted_b)
	index_a := make(map[int][]int)
	index_b := make(map[int][]int)
	for i, v := range array_a {
		if _, ok := index_a[v]; ok {
			index_a[v] = append(index_a[v], i)
		} else {
			index_a[v] = make([]int, 0)
			index_a[v] = append(index_a[v], i)
		}
	}
	for i, v := range array_b {
		if _, ok := index_b[v]; ok {
			index_b[v] = append(index_b[v], i)
		} else {
			index_b[v] = make([]int, 0)
			index_b[v] = append(index_b[v], i)
		}
	}
	canSort := false
	for i, v := range sorted_b {
		for _, k1 := range index_b[v] {
			if sorted_a[i] == array_a[k1] {
				canSort = true
				delete(index_b, v)

			}
		}
		if !canSort {
			return -1
		}
	}
	return 0
}

func sort2(length int, a, b []int) int {
	var move = 10e4
	moves := make([]Move, 0)
	for move >= 0 {
		if isSort(length, a) && isSort(length, b) {
			break
		}
		canSort := false
		for i := 0; i < length-1; i++ {
			for j := i + 1; j < length; j++ {
				if a[i] >= a[j] && b[i] >= b[j] {
					moves = append(moves, Move{
						i + 1, j + 1,
					})
					tmp1 := a[i]
					a[i] = a[j]
					a[j] = tmp1
					tmp1 = b[i]
					b[i] = b[j]
					b[j] = tmp1
					move--
					canSort = true
				}
			}
		}
		if !canSort {
			return -1
		}
	}
	if move <= 0 {
		return -1
	} else {
		fmt.Println(len(moves))
		for _, m := range moves {
			fmt.Println(m)
		}
		return 0
	}
}
func main() {
	var tc int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	tc, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < tc; i++ {
		var length int
		scanner.Scan()
		length, _ = strconv.Atoi(scanner.Text())
		a1 := make([]int, length)
		a2 := make([]int, length)
		scanner.Scan()
		la1 := strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a1[i1], _ = strconv.Atoi(v)
		}
		scanner.Scan()
		la1 = strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a2[i1], _ = strconv.Atoi(v)
		}
		c := solve(length, a1, a2)
		if c != -1 {
			sort2(length, a1, a2)
		} else {
			fmt.Println(c)
		}
	}

}

package main

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

func isSort(length int, a []int) bool {
	for i := 0; i < length-1; i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

type Move struct {
	i int
	j int
}

func (s Move) String() string {
	return fmt.Sprintf("%d %d", s.i, s.j)
}

func solve(length int, array_a, array_b []int) int {
	sorted_a := make([]int, length)
	copy(sorted_a, array_a)
	sorted_b := make([]int, length)
	copy(sorted_b, array_b)
	sort.Ints(sorted_a)
	sort.Ints(sorted_b)
	index_a := make(map[int][]int)
	index_b := make(map[int][]int)
	for i, v := range array_a {
		if _, ok := index_a[v]; ok {
			index_a[v] = append(index_a[v], i)
		} else {
			index_a[v] = make([]int, 0)
			index_a[v] = append(index_a[v], i)
		}
	}
	for i, v := range array_b {
		if _, ok := index_b[v]; ok {
			index_b[v] = append(index_b[v], i)
		} else {
			index_b[v] = make([]int, 0)
			index_b[v] = append(index_b[v], i)
		}
	}
	canSort := false
	for i, v := range sorted_b {
		for _, k1 := range index_b[v] {
			if sorted_a[i] == array_a[k1] {
				canSort = true
			}
		}
		if !canSort {
			return -1
		}
	}
	return 0
}

func sort2(length int, a, b []int) int {
	var move = 10e4
	moves := make([]Move, 0)
	for move >= 0 {
		if isSort(length, a) && isSort(length, b) {
			break
		}
		canSort := false
		for i := 0; i < length-1; i++ {
			for j := i + 1; j < length; j++ {
				if a[i] >= a[j] && b[i] >= b[j] {
					moves = append(moves, Move{
						i + 1, j + 1,
					})
					tmp1 := a[i]
					a[i] = a[j]
					a[j] = tmp1
					tmp1 = b[i]
					b[i] = b[j]
					b[j] = tmp1
					move--
					canSort = true
				}
			}
		}
		if !canSort {
			return -1
		}
	}
	if move <= 0 {
		return -1
	} else {
		fmt.Println(len(moves))
		for _, m := range moves {
			fmt.Println(m)
		}
		return 0
	}
}
func main() {
	var tc int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	tc, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < tc; i++ {
		var length int
		scanner.Scan()
		length, _ = strconv.Atoi(scanner.Text())
		a1 := make([]int, length)
		a2 := make([]int, length)
		scanner.Scan()
		la1 := strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a1[i1], _ = strconv.Atoi(v)
		}
		scanner.Scan()
		la1 = strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a2[i1], _ = strconv.Atoi(v)
		}
		c := solve(length, a1, a2)
		if c != -1 {
			sort2(length, a1, a2)
		} else {
			fmt.Println(c)
		}
	}

}

package main

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

func isSort(length int, a []int) bool {
	for i := 0; i < length-1; i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

type Move struct {
	i int
	j int
}

func (s Move) String() string {
	return fmt.Sprintf("%d %d", s.i, s.j)
}

func solve(length int, array_a, array_b []int) int {
	sorted_a := make([]int, length)
	copy(sorted_a, array_a)
	sorted_b := make([]int, length)
	copy(sorted_b, array_b)
	sort.Ints(sorted_a)
	sort.Ints(sorted_b)
	index_a := make(map[int][]int)
	index_b := make(map[int][]int)
	for i, v := range array_a {
		if _, ok := index_a[v]; ok {
			index_a[v] = append(index_a[v], i)
		} else {
			index_a[v] = make([]int, 0)
			index_a[v] = append(index_a[v], i)
		}
	}
	for i, v := range array_b {
		if _, ok := index_b[v]; ok {
			index_b[v] = append(index_b[v], i)
		} else {
			index_b[v] = make([]int, 0)
			index_b[v] = append(index_b[v], i)
		}
	}
	canSort := false
	for i, v := range sorted_b {
		for _, k1 := range index_b[v] {
			if sorted_a[i] == array_a[k1] {
				canSort = true
			}
		}
		if !canSort {
			return -1
		}
	}
	return 0
}

func sort2(length int, a, b []int) int {
	var move = 10e4
	moves := make([]Move, 0)
	for move >= 0 {
		if isSort(length, a) && isSort(length, b) {
			break
		}
		canSort := false
		for i := 0; i < length-1; i++ {
			for j := i + 1; j < length; j++ {
				if a[i] >= a[j] && b[i] >= b[j] {
					moves = append(moves, Move{
						i + 1, j + 1,
					})
					tmp1 := a[i]
					a[i] = a[j]
					a[j] = tmp1
					tmp1 = b[i]
					b[i] = b[j]
					b[j] = tmp1
					move--
					canSort = true
				}
			}
		}
		if !canSort {
			return -1
		}
	}
	if move <= 0 {
		return -1
	} else {
		fmt.Println(len(moves))
		for _, m := range moves {
			fmt.Println(m)
		}
		return 0
	}
}
func main() {
	var tc int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	tc, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < tc; i++ {
		var length int
		scanner.Scan()
		length, _ = strconv.Atoi(scanner.Text())
		a1 := make([]int, length)
		a2 := make([]int, length)
		scanner.Scan()
		la1 := strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a1[i1], _ = strconv.Atoi(v)
		}
		scanner.Scan()
		la1 = strings.Split(scanner.Text(), " ")
		for i1, v := range la1 {
			a2[i1], _ = strconv.Atoi(v)
		}
		c := solve(length, a1, a2)
		fmt.Println(c)
		if c != -1 {
			sort2(length, a1, a2)
		}
	}

}

package main

import (
	"fmt"
)

func isSort(length int, a []int) bool {
	for i := 0; i < length-1; i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

type Move struct {
	i int
	j int
}

func (s Move) String() string {
	return fmt.Sprintf("%d %d", s.i, s.j)
}
func solve(length int, a, b []int) int {
	var move = 10e4
	moves := make([]Move, 0)
	for move >= 0 {
		if isSort(length, a) && isSort(length, b) {
			break
		}
		for i := 0; i < length-1; i++ {
			for j := i + 1; j < length; j++ {
				if a[i] >= a[j] && b[i] >= b[j] {
					moves = append(moves, Move{
						i + 1, j + 1,
					})
					tmp1 := a[i]
					a[i] = a[j]
					a[j] = tmp1
					tmp1 = b[i]
					b[i] = b[j]
					b[j] = tmp1
					move--
				}
			}
		}
		move--
	}
	if move <= 0 {
		fmt.Println(-1)
		return -1
	} else {
		fmt.Println(len(moves))
		for _, m := range moves {
			fmt.Println(m)
		}
		return 0
	}
}
func main() {
	var tc int
	fmt.Scanf("%d\n", &tc)
	for i := 0; i < tc; i++ {
		var length int
		fmt.Scanf("%d\n", &length)
		a1 := make([]int, length)
		a2 := make([]int, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%d", &a1[j])
		}
		for j := 0; j < length; j++ {
			fmt.Scanf("%d", &a2[j])
		}
		solve(length, a1, a2)
	}

}

package main

import (
	"fmt"
)

func isSort(length int, a []int) bool {
	for i := 0; i < length-1; i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

type Move struct {
	i int
	j int
}

func (s Move) String() string {
	return fmt.Sprintf("%d %d", s.i, s.j)
}
func solve(length int, a, b []int) int {
	var move = 10e4
	moves := make([]Move, 0)
	for move >= 0 {
		if isSort(length, a) && isSort(length, b) {
			break
		}
		for i := 0; i < length-1; i++ {
			for j := i + 1; j < length; j++ {
				if a[i] >= a[j] && b[i] >= b[j] {
					moves = append(moves, Move{
						i + 1, j + 1,
					})
					tmp1 := a[i]
					a[i] = a[j]
					a[j] = tmp1
					tmp1 = b[i]
					b[i] = b[j]
					b[j] = tmp1
					move--
				}
			}
		}
		move--
	}
	if move <= 0 {
		return -1
	} else {
		fmt.Println(len(moves))
		for _, m := range moves {
			fmt.Println(m)
		}
		return 0
	}
}
func main() {
	var tc int
	fmt.Scanf("%d\n", &tc)
	for i := 0; i < tc; i++ {
		var length int
		fmt.Scanf("%d\n", &length)
		a1 := make([]int, length)
		a2 := make([]int, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%d", &a1[j])
		}
		for j := 0; j < length; j++ {
			fmt.Scanf("%d", &a2[j])
		}
		res := solve(length, a1, a2)
		fmt.Printf("%d", res)
	}

}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	var n int

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

		b := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &b[i])
		}

		ao := make([]int, len(a))
		bo := make([]int, len(b))
		copy(ao, a)
		copy(bo, b)

		moves := solveC(a, b)
		if moves != nil {
			Fprintln(out, len(moves))
			for i := range moves {
				Fprintln(out, moves[i].i, moves[i].j)
			}
			continue
		}

		moves = solveC(bo, ao)
		if moves != nil {
			Fprintln(out, len(moves))
			for i := range moves {
				Fprintln(out, moves[i].i, moves[i].j)
			}
			continue
		}
		Fprintln(out, -1)

	}
}

type pair struct {
	i, j int
}

func solveC(a, b []int) []pair {
	n := len(a)

	moves := make([]pair, 0)
	count := 0
	for i := 0; i < n; i++ {
		// fmt.Println("===========================")
		// fmt.Println(a)
		// fmt.Println(b)
		smallestIdxA := i
		smallestIdxB := i
		for j := i; j < n; j++ {
			if a[smallestIdxA] > a[j] {
				smallestIdxA = j
			}
			if b[smallestIdxB] > b[j] {
				smallestIdxB = j
			}
		}

		if b[i] >= b[smallestIdxA] {
			a[i], a[smallestIdxA] = a[smallestIdxA], a[i]
			b[i], b[smallestIdxA] = b[smallestIdxA], b[i]
			moves = append(moves, pair{i + 1, smallestIdxA + 1})
			i--
			count++
			if count > 10000 {
				return nil
			}
			continue
		}
		if a[i] >= a[smallestIdxB] {
			a[i], a[smallestIdxB] = a[smallestIdxB], a[i]
			b[i], b[smallestIdxB] = b[smallestIdxB], b[i]
			moves = append(moves, pair{i + 1, smallestIdxB + 1})
			i--
			count++
			if count > 10000 {
				return nil
			}
			continue
		}
	}

	if isSorted(a) && isSorted(b) {
		return moves
	}
	return nil
}

func isSorted(nums []int) bool {
	n := len(nums)
	for i := 0; i < n-1; i++ {
		if nums[i] > nums[i+1] {
			return false
		}
	}
	return true
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	var n int

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

		b := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &b[i])
		}

		ao := make([]int, len(a))
		bo := make([]int, len(b))
		copy(ao, a)
		copy(bo, b)

		moves := solveC(a, b)
		if moves != nil {
			Fprintln(out, len(moves))
			for i := range moves {
				Fprintln(out, moves[i].i, moves[i].j)
			}
			continue
		}

		moves = solveC(bo, ao)
		if moves != nil {
			Fprintln(out, len(moves))
			for i := range moves {
				Fprintln(out, moves[i].i, moves[i].j)
			}
			continue
		}
		Fprintln(out, -1)

	}
}

type pair struct {
	i, j int
}

func solveC(a, b []int) []pair {
	n := len(a)

	moves := make([]pair, 0)
	for i := 0; i < n; i++ {
		// fmt.Println("===========================")
		// fmt.Println(a)
		// fmt.Println(b)
		smallestIdxA := i
		smallestIdxB := i
		for j := i; j < n; j++ {
			if a[smallestIdxA] > a[j] {
				smallestIdxA = j
			}
			if b[smallestIdxB] > a[j] {
				smallestIdxB = j
			}
		}

		if smallestIdxA != i && b[i] >= b[smallestIdxA] {
			a[i], a[smallestIdxA] = a[smallestIdxA], a[i]
			b[i], b[smallestIdxA] = b[smallestIdxA], b[i]
			moves = append(moves, pair{i + 1, smallestIdxA + 1})
			continue
		}
		if smallestIdxB != i && a[i] >= a[smallestIdxB] {
			a[i], a[smallestIdxB] = a[smallestIdxB], a[i]
			b[i], b[smallestIdxB] = b[smallestIdxB], b[i]
			moves = append(moves, pair{i + 1, smallestIdxB + 1})
			continue
		}
	}

	if isSorted(a) && isSorted(b) {
		return moves
	}
	return nil
}

func isSorted(nums []int) bool {
	n := len(nums)
	for i := 0; i < n-1; i++ {
		if nums[i] > nums[i+1] {
			return false
		}
	}
	return true
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	var n int

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

		b := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &b[i])
		}

		moves := solveC(a, b)
		if moves == nil {
			Fprintln(out, -1)
		} else {
			Fprintln(out, len(moves))
			for i := range moves {
				Fprintln(out, moves[i].i, moves[i].j)
			}
		}

	}
}

type pair struct {
	i, j int
}

func solveC(a, b []int) []pair {
	n := len(a)

	moves := make([]pair, 0)
	for i := 0; i < n; i++ {
		smallestIdx := i
		for j := i; j < n; j++ {
			if a[smallestIdx] > a[j] {
				smallestIdx = j
			}
		}
		if smallestIdx != i {
			a[i], a[smallestIdx] = a[smallestIdx], a[i]
			b[i], b[smallestIdx] = b[smallestIdx], b[i]
			moves = append(moves, pair{i + 1, smallestIdx + 1})
		}
	}

	if !isSorted(b) {
		return nil
	}
	return moves
}

func isSorted(nums []int) bool {
	n := len(nums)
	for i := 0; i < n-1; i++ {
		if nums[i] > nums[i+1] {
			return false
		}
	}
	return true
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T,N,A,B,mina,minb int

	fmt.Fscan(in, &T)

	for i := 0;i < T;i++{
		fmt.Fscan(in, &N)
		listA := make([]int,N)
		listB := make([]int,N)
		mA := make([]int,N)
		mB := make([]int,N)
		for j := 0;j < N;j++{
			fmt.Fscan(in, &A)
			listA[j] = A
			mA[j] = A
			if mina > A{
				mina = A
			}
		}
		for j := 0;j < N;j++{
			fmt.Fscan(in, &B)
			listB[j] = B
			mB[j] = B
			if minb > B{
				minb = B
			}
		}
		sort.Ints(listA)
		sort.Ints(listB)
		list,judge := sortlist(listA,listB,mA,mB,N)
		if judge {
			fmt.Println(swapsort(list,N))
		}else{
			fmt.Println(-1)
		}

	}
}

func sortlist(listA []int,listB []int,mA []int,mB []int,N int) ([]int, bool){
	list := make([]int,N)
	count := 0
	//judge := false
	for i := 0;i < N;i++ {
		judge := false
		for j := 0;j < N;j++ {
			if listA[i] == mA[j] && listB[i] == mB[j] {
				judge = true
				list[j] = count
				mA[j] = 101
				mB[j] = 101
				count++
				break
			}
		}
		if !judge{
			return list,judge
		}
	}
	return list,true
}

func swapsort(list []int,N int)int{
	count := 0
	for i := 0;i < N;i++ {
		if list[i] != i{
			for j := 0;j < N;j++ {
				if list[j] == i{
					list[i], list[j] = list[j], list[i]
					count++
				}
			}
		}
	}
	return count
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T,N,A,B,mina,minb int

	fmt.Fscan(in, &T)

	for i := 0;i < T;i++{
		fmt.Fscan(in, &N)
		listA := make([]int,N)
		listB := make([]int,N)
		mA := make([]int,N)
		mB := make([]int,N)
		for j := 0;j < N;j++{
			fmt.Fscan(in, &A)
			listA[j] = A
			mA[j] = A
			if mina > A{
				mina = A
			}
		}
		for j := 0;j < N;j++{
			fmt.Fscan(in, &B)
			listB[j] = B
			mB[j] = B
			if minb > B{
				minb = B
			}
		}
		sort.Ints(listA)
		sort.Ints(listB)
		list,judge := sortlist(listA,listB,mA,mB,N)
		if judge {
			fmt.Println(swapsort(list,N))
		}else{
			fmt.Println(-1)
		}

	}
}

func sortlist(listA []int,listB []int,mA []int,mB []int,N int) ([]int, bool){
	list := make([]int,N)
	count := 0
	//judge := false
	for i := 0;i < N;i++ {
		judge := false
		for j := 0;j < N;j++ {
			if listA[i] == mA[j] && listB[i] == mB[j] {
				judge = true
				list[j] = count
				mA[j] = 101
				mB[j] = 101
				count++
			}
		}
		if !judge{
			return list,judge
		}
	}
	return list,true
}

func swapsort(list []int,N int)int{
	count := 0
	for i := 0;i < N;i++ {
		if list[i] != i{
			for j := 0;j < N;j++ {
				if list[j] == i{
					list[i], list[j] = list[j], list[i]
					count++
				}
			}
		}
	}
	return count
}

package main

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

type pair struct{ x, y int }

func sort(a []int) (p []pair) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := 0; j < n-i-1; j++ {
			if a[j] > a[j+1] {
				p = append(p, pair{j, j + 1})
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}
	return p
}

func Solve() {
	n := ri()
	var a, b []int
	for i := 0; i < n; i++ {
		a = append(a, ri())
	}
	for i := 0; i < n; i++ {
		b = append(b, ri())
	}
	p := sort(a)
	for _, t := range p {
		b[t.x], b[t.y] = b[t.y], b[t.x]
	}
	for i := 0; i < n; i++ {
		j := i
		for j+1 < n && a[i] == a[j+1] {
			j++
		}
		t := sort(b[i : j+1])
		p = append(p, t...)
		i = j
	}
	if sort2.IntsAreSorted(b) {
		println(len(p))
		for _, t := range p {
			println(t.x+1, t.y+1)
		}
	} else {
		println(-1)
	}
}

func main() {
	T := 0 // 如果是单组样例，请讲 T := 0 改为 T := 1
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

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

// ri 将直接读入并返回一个 int
func ri() (x int) {
	scan(&x)
	return x
}

//rs 将直接读入并返回一个 string
func rs() (s string) {
	scan(&s)
	return s
}

//scan 用法与 fmt.scan() 相似，可以传入多个变量的地址进行读入操作
func scan(a ...interface{}) { Fscan(in, a...) }

//print 用法与 fmt.print() 相似，可以传入多个变量进行输出。注意，这个函数不会换行，多个变量之间有空格
func print(a ...interface{}) { Fprint(out, a...) }

//println 用法与 fmt.println() 相似，可以传入多个变量进行输出。这个函数会换行，多个变量之间有空格
func println(a ...interface{}) { Fprintln(out, a...) }

//min 可以传入多个 int 变量，求出这些变量的最小值
func min(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//max 可以传入多个 int 变量，求出这些变量的最大值
func max(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//sum 可以传入多个 int 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum(a ...int) int {
	ans := 0
	for _, x := range a {
		ans += x
	}
	return ans
}


Given three distinct integers $$$a$$$, $$$b$$$, and $$$c$$$, find the medium number between all of them.The medium number is the number that is neither the minimum nor the maximum of the given three numbers. For example, the median of $$$5,2,6$$$ is $$$5$$$, since the minimum is $$$2$$$ and the maximum is $$$6$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 6840$$$) — the number of test cases. The description of each test case consists of three distinct integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \leq a, b, c \leq 20$$$).

For each test case, output a single integer — the medium number of the three numbers.

package main

import "fmt"

func main() {
	var (
		t int
		a int
		b int
		c int
	)
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d %d\n", &a, &b, &c)
		if (b < a && a < c) || (c < a && a < b) {
			fmt.Println(a)
		} else if (a < b && b < c) || (c < b && b < a) {
			fmt.Println(b)
		} else {
			fmt.Println(c)
		}
	}
}

package main
import ("fmt")

func main() {
    var a,b,c,T int

    fmt.Scan(&T)

    for T>0 {
        fmt.Scan(&a)
        fmt.Scan(&b)
        fmt.Scan(&c)

        if a>b {
          a, b = b, a
        }
        if b>c {
          b, c = c, b
        }
        if a>b {
          a, b = b, a
        }

        fmt.Printf("%d\n", b)

        T--
    }

}

package main

import (
	"fmt"
	"sort"
)

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

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

func execute() {
	var s []int
	for i := 0; i < 3; i++ {
		var x int
		fmt.Scan(&x)
		s = append(s, x)
	}

	sort.Ints(s)
	fmt.Println(s[1])
}

/*
	A template for Go on codeforces.com
	Author: Yakov, frvr.ru
*/

package main

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

func main() {
	n := readInt()
	for i := 0; i < n; i++ {
		arr := readInts()
		sort.Ints(arr)
		writeLine(arr[1])
	}
}

/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */

var in = bufio.NewReader(os.Stdin)

type float = float32
type double = float64
type long = int64
type ulong = uint64

func typeOf(arg interface{}) string {
	switch reflect.TypeOf(arg).Kind() {
	case reflect.Int:
		return "int"
	case reflect.Int8:
		return "int8"
	case reflect.Int16:
		return "int16"
	case reflect.Int32:
		return "int32"
	case reflect.Int64:
		return "int64"
	case reflect.Uint:
		return "uint"
	case reflect.Uint8:
		return "uint8"
	case reflect.Uint16:
		return "uint16"
	case reflect.Uint32:
		return "uint32"
	case reflect.Uint64:
		return "uint64"
	case reflect.Float32:
		return "float32"
	case reflect.Float64:
		return "float64"
	case reflect.Complex64:
		return "complex64"
	case reflect.Complex128:
		return "complex128"
	case reflect.Bool:
		return "bool"
	case reflect.String:
		return "string"
	case reflect.Chan:
		return "chan"
	case reflect.Ptr:
		return "ptr"
	case reflect.Uintptr:
		return "uintptr"
	case reflect.UnsafePointer:
		return "unsafeptr"
	case reflect.Interface:
		return "interface"
	case reflect.Array:
		return "array"
	case reflect.Slice:
		return "slice"
	case reflect.Map:
		return "map"
	case reflect.Struct:
		return "struct"
	case reflect.Func:
		return "func"
	case reflect.Invalid:
		return "invalid"
	default:
		return "nil"
	}
}

/* ~~~~~~~~~~ */

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}

func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float32(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

/* ~~~~~~~~~~ */

// Too much overhead with universal method using interface{}, wait for the generics,
// but for now — just don't look at the redundancy of the code after that commentary :)

func readBools() []bool {
	strs := readStrings()
	arr := make([]bool, len(strs))
	for i, s := range strs {
		arr[i] = readBool(s)
	}
	return arr
}
func readBytes() []byte {
	strs := readStrings()
	arr := make([]byte, len(strs))
	for i, s := range strs {
		arr[i] = readByte(s)
	}
	return arr
}
func readDoubles() []double {
	strs := readStrings()
	arr := make([]double, len(strs))
	for i, s := range strs {
		arr[i] = readDouble(s)
	}
	return arr
}
func readFloats() []float {
	strs := readStrings()
	arr := make([]float, len(strs))
	for i, s := range strs {
		arr[i] = readFloat(s)
	}
	return arr
}
func readInts() []int {
	strs := readStrings()
	arr := make([]int, len(strs))
	for i, s := range strs {
		arr[i] = readInt(s)
	}
	return arr
}
func readLongs() []long {
	strs := readStrings()
	arr := make([]long, len(strs))
	for i, s := range strs {
		arr[i] = readLong(s)
	}
	return arr
}
func readULongs() []ulong {
	strs := readStrings()
	arr := make([]ulong, len(strs))
	for i, s := range strs {
		arr[i] = readULong(s)
	}
	return arr
}

/* ~~~~~~~~~~ */

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLine(arg ...interface{})             { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"index/suffixarray"
	"log"
	"math"
	"net"
	"os"
	"path"
	"sort"
	"strconv"
	"strings"
	"time"
)

// For Codeforces
func main() {
	io := newStdIO()
	defer io.Flush()
	for T := io.ScanUInt16(); T > 0; T-- {
		solve(&io)
	}
}
func solve(io *IO) {
	a := io.ScanInt32()
	b := io.ScanInt32()
	c := io.ScanInt32()
	io.PrintLn(a+b+c-Min(c, Min(a,b))-Max(a, Max(b,c)))
}

// #region INTERFACES

// From https://pkg.go.dev/golang.org/x/exp/constraints
type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}
type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
type Integer interface {
	Signed | Unsigned
}
type Float interface {
	~float32 | ~float64
}
type Complex interface {
	~complex64 | ~complex128
}
type Ordered interface {
	Integer | Float | ~string
}

type Prioritizable[T any] interface {
	PriorTo(x T) bool // If you take this as a relation: if (a,b) in R => (b,a) not in R
}

// #endregion
// #region TYPES WITH METHODS
// #region SingleLinkedList
type singleLinkedListNode[T comparable] struct {
	Value T
	Next  *singleLinkedListNode[T]
}

type SingleLinkedList[T comparable, IndexType Unsigned] struct {
	first  *singleLinkedListNode[T]
	last   *singleLinkedListNode[T]
	length IndexType
}

func NewSingleLinkedList[T comparable, IndexType Unsigned]() *SingleLinkedList[T, IndexType] {
	return &SingleLinkedList[T, IndexType]{
		first:  nil,
		last:   nil,
		length: 0,
	}
}
func (l *SingleLinkedList[T, I]) Len() I { return l.length }

// length > 0
func (l *SingleLinkedList[T, I]) First() T { return l.first.Value }

// length > 0
func (l *SingleLinkedList[T, I]) Last() T { return l.last.Value }

func (l *SingleLinkedList[T, I]) InsertFirst(value T) {
	if l.length == 0 {
		nodeToInsert := &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
		l.first = nodeToInsert
		l.last = nodeToInsert
	} else {
		l.first = &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
	}
	l.length++
}

func (l *SingleLinkedList[T, I]) InsertLast(value T) {
	if l.length == 0 {
		nodeToInsert := &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
		l.first = nodeToInsert
		l.last = nodeToInsert
	} else {
		l.last.Next = &singleLinkedListNode[T]{
			Value: value,
			Next:  nil,
		}
		l.last = l.last.Next
	}
	l.length++
}

// index <= length
func (l *SingleLinkedList[T, I]) InsertAt(index I, value T) {
	if index == 0 {
		l.InsertFirst(value)
		return
	}
	if index == l.length {
		l.InsertLast(value)
		return
	}

	n := l.first
	for index > 1 {
		n = n.Next
		index--
	}
	n.Next = &singleLinkedListNode[T]{
		Value: value,
		Next:  n.Next,
	}
	l.length++
}

func (l *SingleLinkedList[T, I]) Contains(value T) bool {
	tmp := l.first
	for i := I(0); i < l.length; i++ {
		if tmp.Value == value {
			return true
		}
		tmp = tmp.Next
	}
	return false
}
func (l *SingleLinkedList[T, I]) Clear() {
	l.first = nil
	l.last = nil
	l.length = 0
}

// index < length
func (l *SingleLinkedList[T, I]) GetElementAt(index I) T {
	n := l.first
	for index > 0 {
		n = n.Next
		index--
	}
	return n.Value
}

// index < length
func (l *SingleLinkedList[T, I]) SetElementAt(index I, value T) {
	n := l.first
	for index > 0 {
		n = n.Next
		index--
	}
	n.Value = value
}

func (l *SingleLinkedList[T, I]) RemoveFirst() T {
	tmp := l.first
	l.first = l.first.Next
	l.length--
	if l.length == 0 {
		l.last = nil
	}
	return tmp.Value
}
func (l *SingleLinkedList[T, I]) RemoveLast() (value T) {
	value = l.last.Value
	if l.length == 1 {
		l.first = nil
		l.last = nil
		l.length = 0
		return
	}

	tmp := l.first
	for i := I(2); i < l.length; i++ {
		tmp = tmp.Next
	}
	l.last = tmp
	return
}

func (l *SingleLinkedList[T, I]) RemoveAt(index I) T {
	if index == 0 {
		return l.RemoveFirst()
	}
	if index == l.length-1 {
		return l.RemoveLast()
	}

	tmp := l.first
	for i := I(1); i < index; i++ {
		tmp = tmp.Next
	}
	res := tmp.Next.Value
	tmp.Next = tmp.Next.Next
	return res
}

func (l *SingleLinkedList[T, I]) ToSlice() (res []T) {
	res = make([]T, 0, l.length)
	tmp := l.first
	for i := I(0); i < l.length; i++ {
		res = append(res, tmp.Value)
		tmp = tmp.Next
	}
	return
}
func (it *SingleLinkedList[T, I]) String() string {
	return "Qua:: " + fmt.Sprint(it.ToSlice())
}

// #endregion
// #region Queue

type Queue[T comparable, I Unsigned] struct {
	l SingleLinkedList[T, I]
}

func NewQueue[T comparable, I Unsigned]() *Queue[T, I] {
	return &Queue[T, I]{
		l: SingleLinkedList[T, I]{
			first:  nil,
			last:   nil,
			length: 0,
		},
	}
}
func (q *Queue[T, I]) Len() I          { return q.l.length }
func (q *Queue[T, I]) Enqueue(value T) { q.l.InsertLast(value) }
func (q *Queue[T, I]) Dequeue(T) T     { return q.l.RemoveFirst() }
func (q *Queue[T, I]) Preview() T      { return q.l.First() }
func (q *Queue[T, I]) String() string  { return q.l.String() }

// #endregion
// #region Stack

type Stack[T comparable, I Unsigned] struct {
	l SingleLinkedList[T, I]
}

func NewStack[T comparable, I Unsigned]() *Stack[T, I] {
	return &Stack[T, I]{
		l: SingleLinkedList[T, I]{
			first:  nil,
			last:   nil,
			length: 0,
		},
	}
}
func (s *Stack[T, I]) Len() I         { return s.l.length }
func (s *Stack[T, I]) Push(value T)   { s.l.InsertFirst(value) }
func (s *Stack[T, I]) Pop(T) T        { return s.l.RemoveFirst() }
func (s *Stack[T, I]) Preview() T     { return s.l.First() }
func (s *Stack[T, I]) String() string { return s.l.String() }

// #endregion
// #region Heap
type BinaryHeap[T Prioritizable[T], I Signed] struct {
	s []T
}

func NewBinaryHeap[T Prioritizable[T], I Signed](s []T) (h *BinaryHeap[T, I]) {
	h = &BinaryHeap[T, I]{
		s: s,
	}

	for i := (h.Len() - 2) / 2; i >= 0; i-- {
		h.heapifyDown(i)
	}
	return
}
func (h *BinaryHeap[T, I]) Len() I {
	return I(len(h.s))
}
func (h *BinaryHeap[T, I]) Push(value T) {
	h.s = append(h.s, value)
	h.heapifyUp(h.Len() - 1)
}
func (h *BinaryHeap[T, I]) Pop() (res T) {
	res = h.s[0]
	h.s[0] = h.s[h.Len()-1]
	h.s = h.s[:h.Len()-1]
	h.heapifyDown(0)
	return
}

func (h *BinaryHeap[T, I]) heapifyDown(index I) bool {
	origin := index
	for {
		j := index*2 + 2
		if j < h.Len() {
			if h.s[j-1].PriorTo(h.s[j]) {
				j--
			}
		} else {
			if j <= h.Len() && !h.s[j].PriorTo(h.s[index]) {
				h.s[j], h.s[index] = h.s[index], h.s[j]
			}
			break
		}
		if h.s[j].PriorTo(h.s[index]) {
			h.s[j], h.s[index] = h.s[index], h.s[j]
			index = j
		} else {
			break
		}
	}
	return origin != index
}
func (h *BinaryHeap[T, I]) heapifyUp(index I) {
	for {
		parent := (index - 1) / 2
		if parent == index || h.s[parent].PriorTo(h.s[index]) {
			break
		}
		h.s[index], h.s[parent] = h.s[parent], h.s[index]
		index = parent
	}
}

// #endregion

// #endregion

// #region FUNCTIONS
func Max[T Ordered](a, b T) T {
	if a >= b {
		return a
	}
	return b
}
func Min[T Ordered](a, b T) T {
	if a <= b {
		return a
	}
	return b
}
func Abs[T Integer | Float](a T) T {
	if a < 0 {
		return -a
	}
	return a
}
func Swap[T any](a, b *T) {
	*a, *b = *b, *a
}

// At least one != 0
func GCD[T Unsigned](a, b T) T {
	if b < a {
		Swap(&a, &b)
	}
	for {
		if a == 0 {
			return b
		}
		r := (b % a)
		b = a
		a = r
	}
}

// At least one != 0
func LCM[T Unsigned](a, b T) T {
	return (a * b) / GCD(a, b)
}

func First[T any](a T, _ any) T { return a }

// #endregion

// #region IO STUFF
type IO struct {
	r *bufio.Reader
	w *bufio.Writer
}

func newStdIO() IO {
	return IO{
		r: bufio.NewReader(os.Stdin),
		w: bufio.NewWriter(os.Stdout),
	}
}

// Is assumed that input.txt file exists
func newFileIO() IO {
	return IO{
		r: bufio.NewReader(First(os.Open("input.txt"))),
		w: bufio.NewWriter(First(os.OpenFile("output.txt", os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.ModePerm))),
	}
}

func (io *IO) ScanInt8() (x int8)   { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt16() (x int16) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt32() (x int32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt64() (x int64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanUInt8() (x uint8)   { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt16() (x uint16) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt32() (x uint32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt64() (x uint64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanFloat32() (x float32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanFloat64() (x float64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanString() (x string) { fmt.Fscan(io.r, &x); return }

func (io *IO) Print(x ...any)   { fmt.Fprint(io.w, x...) }
func (io *IO) PrintLn(x ...any) { fmt.Fprintln(io.w, x...) }

func (io *IO) Flush() { io.w.Flush() }

// #endregion

// #region KEEP IMPORTS
func D() {
	_ = bufio.Reader{}
	_ = bytes.Buffer{}
	_ = suffixarray.Index{}
	_ = log.Default()
	_ = math.Abs(0)
	_ = net.Dialer{}
	_ = path.ErrBadPattern
	_ = sort.Float64sAreSorted(nil)
	_ = strconv.ErrRange
	_ = strings.Builder{}
	_ = time.ANSIC
	_ = newStdIO()
	_ = newFileIO()
}

// #endregion

package main

import (
	"fmt"
	"sort"
)

var t int

func solve() {
	vecs := [3]int{}
	fmt.Scanln(&vecs[0], &vecs[1], &vecs[2])
	sort.Ints(vecs[:])
	fmt.Println(vecs[1])
}

func main() {
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b,c int
		fmt.Fscan(in,&a,&b,&c)
		if (a > b && a < c) || (a > c && a < b) {
			fmt.Fprintln(out,a)
		} else if (b > a && b < c) || (b < a && b > c) {
			fmt.Fprintln(out,b)
		} else {
			fmt.Fprintln(out,c)
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

func solve() {
	arr := []int{}
	for i := 0; i < 3; i++ {
		a := 0
		fmt.Scan(&a)
		arr = append(arr, a)
	}
	sort.Ints(arr)
	fmt.Println(arr[1])
}

package main

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

const cf = true

func solve() {
	arr := []int{0, 0, 0}
	fmt.Fscan(in, &arr[0], &arr[1], &arr[2])
	sort.Ints(arr)
	fmt.Fprintln(out, arr[1])
}

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

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

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

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

type CF1760A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1760A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1760A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1760A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1760A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1760A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1760A
Date: 11/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1760/A
Problem: CF1760A
**/
func (in *CF1760A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		arr := []int{ in.NextInt(), in.NextInt(), in.NextInt()}
        sort.Ints(arr)
        fmt.Println(arr[1])
	}
}

func NewCF1760A(r *bufio.Reader) *CF1760A {
	return &CF1760A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1760A(bufio.NewReader(os.Stdin)).Run()
}

package main

import "fmt"

func solveMax(a, b, c int) int {
	if a > b && a > c {
		return a
	}

	if b > a && b > c {
		return b
	}

	return c
}

func solveMin(a, b, c int) int {
	if a < b && a < c {
		return a
	}

	if b < a && b < c {
		return b
	}

	return c
}

func solve(max, min, a, b, c int) int {
	if a == max {
		if b == min {
			return c
		} else {
			return b
		}
	}
	if b == max {
		if a == min {
			return c
		} else {
			return a
		}
	}
	if c == max {
		if a == min {
			return b
		} else {
			return a
		}

	}
	return b
}

func main() {
	var t int

	fmt.Scan(&t)
	for t > 0 {
		t--
		var a, b, c, max, min int
		fmt.Scan(&a, &b, &c)
		max = solveMax(a, b, c)
		min = solveMin(a, b, c)
		r := solve(max, min, a, b, c)
		fmt.Println(r)
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	a, b, c := readThreeInt(reader)

	if a <= b && b <= c || c <= b && b <= a {
		fmt.Fprintln(writer, b)
	} else if b <= a && a <= c || c <= a && a <= b {
		fmt.Fprintln(writer, a)
	} else {
		fmt.Fprintln(writer, c)
	}
}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func min[T int | int64](a, b T) T {
	if a < b {
		return a
	}

	return b
}

func max[T int | int64](a, b T) T {
	if a > b {
		return a
	}

	return b
}

func abs[T int | int64](a T) T {
	if a < 0 {
		return a * -1
	} else {
		return a
	}
}

func gcd[T int | int64](x, y T) T {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm[T int | int64](x, y T) T {
	return x * y / gcd(x, y)
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

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

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

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

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 32)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

		arr := make([]int, 3)
		fmt.Fscan(reader, &arr[0], &arr[1], &arr[2])

		output := solve(arr)

		fmt.Fprintln(writer, output)
	}
}

func solve(arr []int) int {

	sort.Ints(arr)

	return arr[1]

}

package main

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

func readArray(sc *bufio.Scanner) (arr []int) {
	sc.Scan()
	for _, value := range strings.Split(sc.Text(), " ") {
		number, _ := strconv.Atoi(value)
		arr = append(arr, number)
	}
	return
}

func readData(sc *bufio.Scanner) (a int, b int, c int) {
	sc.Scan()
	arr := strings.Split(sc.Text(), " ")
	a, _ = strconv.Atoi(arr[0])
	b, _ = strconv.Atoi(arr[1])
	c, _ = strconv.Atoi(arr[2])
	return
}

func Sum(x, y int, arr []int) int {
	left, right := len(arr)-x, len(arr)-x+y
	l := 0
	if left != 0 {
		l = arr[left-1]
	}
	r := len(arr)
	if right <= len(arr) {
		r = arr[right-1]
	}
	return r - l
}

// 001   1
// 1010100101

func solve(a, b, c int) int {
	arr := []int{a, b, c}
	sort.Ints(arr)
	return arr[1]
}

func main() {
	var n int
	fmt.Scanln(&n)
	sc := bufio.NewScanner(os.Stdin)
	for ; n > 0; n-- {
		a, b, c := readData(sc)
		fmt.Println(solve(a, b, c))
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		var sli []int
		scanner.Scan()
		tsl := strings.Split(scanner.Text(), " ")
		for j := 0; j < len(tsl); j++ {
			tn, _ := strconv.Atoi(tsl[j])
			sli = append(sli, tn)
		}
		sort.Ints(sli)
		fmt.Println(sli[1])
	}
}

package main

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

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

// source: _
func solve() {
	_, a := _readArr(3)
	sort.Ints(a)
	_print(a[1])
}

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

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr(x ...int) (int, []int) {
	var n int
	if len(x) == 0 {
		fmt.Fscan(in, &n)
	} else {
		n = x[0]
	}
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] > x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _min(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] < x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _sum(x ...int) int {
	res := 0
	for _, i := range x {
		res += i
	}
	return res
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}
func _makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		a := make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Ints(a)
		fmt.Println(a[1])
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		a := make([]int, 3)
		a[0], a[1], a[2] = nextInt(), nextInt(), nextInt()
		sort.Ints(a)
		fmt.Println(a[1])
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	//输入t
	var t int
	fmt.Fscan(in, &t)
	nums := make([]int, 3)
	for i := 0; i < t; i++ {
		for j := 0; j < 3; j++ {
			fmt.Fscan(in, &nums[j])
		}
		sort.Ints(nums)
		// 输出res
		fmt.Fprintln(out, nums[1])
	}
}

package main

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

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-- {

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

		sort.Ints(a)
		fmt.Fprintln(w, a[1])
	}

}

package main

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

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

	solve := func(curCase int) {
		a := make([]int, 3)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		Fprintln(out, a[1])
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

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

package main

import "fmt"

func main() {
	var (
		t int
		a int
		b int
		c int
	)
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d %d", &a, &b, &c)
		if (b < a && a < c) || (c < a && a < b) {
			fmt.Println(a)
		} else if (a < b && b < c) || (c < b && b < a) {
			fmt.Println(b)
		} else {
			fmt.Println(c)
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		a int
		b int
		c int
	)
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Scanln(&c)
		if (b < a && a < c) || (c < a && a < b) {
			fmt.Println(a)
		} else if (a < b && b < c) || (c < b && b < a) {
			fmt.Println(b)
		} else {
			fmt.Println(c)
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		a int
		b int
		c int
	)
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Scanln(&c)
		if ((a < b && a > c) || (a < c && a > b)) {
			fmt.Println(a)
		} else if ((b < a && b > c) || (b < c && b > a)) {
			fmt.Println(b)
		} else {
			fmt.Println(c)
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		a int
		b int
		c int
	)
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Scanln(&c)
		if (a < b && a > c) || (a < c && a > b) {
			fmt.Println(a)
		} else if (b < a && b > c) || (b < c && b > a) {
			fmt.Println(b)
		} else {
			fmt.Println(c)
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		a int
		b int
		c int
	)
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d %d", a, b, c)
		if (a < b && a > c) || (a < c && a > b) {
			fmt.Println(a)
		} else if (b < a && b > c) || (b < c && b > a) {
			fmt.Println(b)
		} else {
			fmt.Println(c)
		}
	}
}

package main
import ("fmt")

func main() {
    var a,b,c,T int

    fmt.Scan(&T)

    for T>0 {
        fmt.Scan(&a)
        fmt.Scan(&b)
        fmt.Scan(&c)

        if a>b {
          a, b = b, a
        }
        if b>c {
          b, c = c, b
        }
        if a>b {
          a, b = b, a
        }

        fmt.Println("%d\n", b)

        T--
    }

}

package main
import ("fmt")

func main() {
  var a,b,c int

  fmt.Scan(&a)
  fmt.Scan(&b)
  fmt.Scan(&c)

  if a>b {
      a, b = b, a
  }
  if b>c {
      b, c = c, b
  }
  if a>b {
      a, b = b, a
  }

  fmt.Println("%d\n", b)
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"index/suffixarray"
	"log"
	"math"
	"net"
	"os"
	"path"
	"sort"
	"strconv"
	"strings"
	"time"
)

// For Codeforces
func main() {
	io := newFileIO()
	defer io.Flush()
	for T := io.ScanUInt16(); T > 0; T-- {
		solve(&io)
	}
}
func solve(io *IO) {
	a := io.ScanInt32()
	b := io.ScanInt32()
	c := io.ScanInt32()
	io.PrintLn(a+b+c-Min(c, Min(a,b))-Max(a, Max(b,c)))
}

// #region INTERFACES

// From https://pkg.go.dev/golang.org/x/exp/constraints
type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}
type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
type Integer interface {
	Signed | Unsigned
}
type Float interface {
	~float32 | ~float64
}
type Complex interface {
	~complex64 | ~complex128
}
type Ordered interface {
	Integer | Float | ~string
}

type Prioritizable[T any] interface {
	PriorTo(x T) bool // If you take this as a relation: if (a,b) in R => (b,a) not in R
}

// #endregion
// #region TYPES WITH METHODS
// #region SingleLinkedList
type singleLinkedListNode[T comparable] struct {
	Value T
	Next  *singleLinkedListNode[T]
}

type SingleLinkedList[T comparable, IndexType Unsigned] struct {
	first  *singleLinkedListNode[T]
	last   *singleLinkedListNode[T]
	length IndexType
}

func NewSingleLinkedList[T comparable, IndexType Unsigned]() *SingleLinkedList[T, IndexType] {
	return &SingleLinkedList[T, IndexType]{
		first:  nil,
		last:   nil,
		length: 0,
	}
}
func (l *SingleLinkedList[T, I]) Len() I { return l.length }

// length > 0
func (l *SingleLinkedList[T, I]) First() T { return l.first.Value }

// length > 0
func (l *SingleLinkedList[T, I]) Last() T { return l.last.Value }

func (l *SingleLinkedList[T, I]) InsertFirst(value T) {
	if l.length == 0 {
		nodeToInsert := &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
		l.first = nodeToInsert
		l.last = nodeToInsert
	} else {
		l.first = &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
	}
	l.length++
}

func (l *SingleLinkedList[T, I]) InsertLast(value T) {
	if l.length == 0 {
		nodeToInsert := &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
		l.first = nodeToInsert
		l.last = nodeToInsert
	} else {
		l.last.Next = &singleLinkedListNode[T]{
			Value: value,
			Next:  nil,
		}
		l.last = l.last.Next
	}
	l.length++
}

// index <= length
func (l *SingleLinkedList[T, I]) InsertAt(index I, value T) {
	if index == 0 {
		l.InsertFirst(value)
		return
	}
	if index == l.length {
		l.InsertLast(value)
		return
	}

	n := l.first
	for index > 1 {
		n = n.Next
		index--
	}
	n.Next = &singleLinkedListNode[T]{
		Value: value,
		Next:  n.Next,
	}
	l.length++
}

func (l *SingleLinkedList[T, I]) Contains(value T) bool {
	tmp := l.first
	for i := I(0); i < l.length; i++ {
		if tmp.Value == value {
			return true
		}
		tmp = tmp.Next
	}
	return false
}
func (l *SingleLinkedList[T, I]) Clear() {
	l.first = nil
	l.last = nil
	l.length = 0
}

// index < length
func (l *SingleLinkedList[T, I]) GetElementAt(index I) T {
	n := l.first
	for index > 0 {
		n = n.Next
		index--
	}
	return n.Value
}

// index < length
func (l *SingleLinkedList[T, I]) SetElementAt(index I, value T) {
	n := l.first
	for index > 0 {
		n = n.Next
		index--
	}
	n.Value = value
}

func (l *SingleLinkedList[T, I]) RemoveFirst() T {
	tmp := l.first
	l.first = l.first.Next
	l.length--
	if l.length == 0 {
		l.last = nil
	}
	return tmp.Value
}
func (l *SingleLinkedList[T, I]) RemoveLast() (value T) {
	value = l.last.Value
	if l.length == 1 {
		l.first = nil
		l.last = nil
		l.length = 0
		return
	}

	tmp := l.first
	for i := I(2); i < l.length; i++ {
		tmp = tmp.Next
	}
	l.last = tmp
	return
}

func (l *SingleLinkedList[T, I]) RemoveAt(index I) T {
	if index == 0 {
		return l.RemoveFirst()
	}
	if index == l.length-1 {
		return l.RemoveLast()
	}

	tmp := l.first
	for i := I(1); i < index; i++ {
		tmp = tmp.Next
	}
	res := tmp.Next.Value
	tmp.Next = tmp.Next.Next
	return res
}

func (l *SingleLinkedList[T, I]) ToSlice() (res []T) {
	res = make([]T, 0, l.length)
	tmp := l.first
	for i := I(0); i < l.length; i++ {
		res = append(res, tmp.Value)
		tmp = tmp.Next
	}
	return
}
func (it *SingleLinkedList[T, I]) String() string {
	return "Qua:: " + fmt.Sprint(it.ToSlice())
}

// #endregion
// #region Queue

type Queue[T comparable, I Unsigned] struct {
	l SingleLinkedList[T, I]
}

func NewQueue[T comparable, I Unsigned]() *Queue[T, I] {
	return &Queue[T, I]{
		l: SingleLinkedList[T, I]{
			first:  nil,
			last:   nil,
			length: 0,
		},
	}
}
func (q *Queue[T, I]) Len() I          { return q.l.length }
func (q *Queue[T, I]) Enqueue(value T) { q.l.InsertLast(value) }
func (q *Queue[T, I]) Dequeue(T) T     { return q.l.RemoveFirst() }
func (q *Queue[T, I]) Preview() T      { return q.l.First() }
func (q *Queue[T, I]) String() string  { return q.l.String() }

// #endregion
// #region Stack

type Stack[T comparable, I Unsigned] struct {
	l SingleLinkedList[T, I]
}

func NewStack[T comparable, I Unsigned]() *Stack[T, I] {
	return &Stack[T, I]{
		l: SingleLinkedList[T, I]{
			first:  nil,
			last:   nil,
			length: 0,
		},
	}
}
func (s *Stack[T, I]) Len() I         { return s.l.length }
func (s *Stack[T, I]) Push(value T)   { s.l.InsertFirst(value) }
func (s *Stack[T, I]) Pop(T) T        { return s.l.RemoveFirst() }
func (s *Stack[T, I]) Preview() T     { return s.l.First() }
func (s *Stack[T, I]) String() string { return s.l.String() }

// #endregion
// #region Heap
type BinaryHeap[T Prioritizable[T], I Signed] struct {
	s []T
}

func NewBinaryHeap[T Prioritizable[T], I Signed](s []T) (h *BinaryHeap[T, I]) {
	h = &BinaryHeap[T, I]{
		s: s,
	}

	for i := (h.Len() - 2) / 2; i >= 0; i-- {
		h.heapifyDown(i)
	}
	return
}
func (h *BinaryHeap[T, I]) Len() I {
	return I(len(h.s))
}
func (h *BinaryHeap[T, I]) Push(value T) {
	h.s = append(h.s, value)
	h.heapifyUp(h.Len() - 1)
}
func (h *BinaryHeap[T, I]) Pop() (res T) {
	res = h.s[0]
	h.s[0] = h.s[h.Len()-1]
	h.s = h.s[:h.Len()-1]
	h.heapifyDown(0)
	return
}

func (h *BinaryHeap[T, I]) heapifyDown(index I) bool {
	origin := index
	for {
		j := index*2 + 2
		if j < h.Len() {
			if h.s[j-1].PriorTo(h.s[j]) {
				j--
			}
		} else {
			if j <= h.Len() && !h.s[j].PriorTo(h.s[index]) {
				h.s[j], h.s[index] = h.s[index], h.s[j]
			}
			break
		}
		if h.s[j].PriorTo(h.s[index]) {
			h.s[j], h.s[index] = h.s[index], h.s[j]
			index = j
		} else {
			break
		}
	}
	return origin != index
}
func (h *BinaryHeap[T, I]) heapifyUp(index I) {
	for {
		parent := (index - 1) / 2
		if parent == index || h.s[parent].PriorTo(h.s[index]) {
			break
		}
		h.s[index], h.s[parent] = h.s[parent], h.s[index]
		index = parent
	}
}

// #endregion

// #endregion

// #region FUNCTIONS
func Max[T Ordered](a, b T) T {
	if a >= b {
		return a
	}
	return b
}
func Min[T Ordered](a, b T) T {
	if a <= b {
		return a
	}
	return b
}
func Abs[T Integer | Float](a T) T {
	if a < 0 {
		return -a
	}
	return a
}
func Swap[T any](a, b *T) {
	*a, *b = *b, *a
}

// At least one != 0
func GCD[T Unsigned](a, b T) T {
	if b < a {
		Swap(&a, &b)
	}
	for {
		if a == 0 {
			return b
		}
		r := (b % a)
		b = a
		a = r
	}
}

// At least one != 0
func LCM[T Unsigned](a, b T) T {
	return (a * b) / GCD(a, b)
}

func First[T any](a T, _ any) T { return a }

// #endregion

// #region IO STUFF
type IO struct {
	r *bufio.Reader
	w *bufio.Writer
}

func newStdIO() IO {
	return IO{
		r: bufio.NewReader(os.Stdin),
		w: bufio.NewWriter(os.Stdout),
	}
}

// Is assumed that input.txt file exists
func newFileIO() IO {
	return IO{
		r: bufio.NewReader(First(os.Open("input.txt"))),
		w: bufio.NewWriter(First(os.OpenFile("output.txt", os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.ModePerm))),
	}
}

func (io *IO) ScanInt8() (x int8)   { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt16() (x int16) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt32() (x int32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt64() (x int64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanUInt8() (x uint8)   { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt16() (x uint16) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt32() (x uint32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt64() (x uint64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanFloat32() (x float32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanFloat64() (x float64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanString() (x string) { fmt.Fscan(io.r, &x); return }

func (io *IO) Print(x ...any)   { fmt.Fprint(io.w, x...) }
func (io *IO) PrintLn(x ...any) { fmt.Fprintln(io.w, x...) }

func (io *IO) Flush() { io.w.Flush() }

// #endregion

// #region KEEP IMPORTS
func D() {
	_ = bufio.Reader{}
	_ = bytes.Buffer{}
	_ = suffixarray.Index{}
	_ = log.Default()
	_ = math.Abs(0)
	_ = net.Dialer{}
	_ = path.ErrBadPattern
	_ = sort.Float64sAreSorted(nil)
	_ = strconv.ErrRange
	_ = strings.Builder{}
	_ = time.ANSIC
	_ = newStdIO()
	_ = newFileIO()
}

// #endregion