On the number line there are $$$m$$$ points, $$$i$$$-th of which has integer coordinate $$$x_i$$$ and integer weight $$$w_i$$$. The coordinates of all points are different, and the points are numbered from $$$1$$$ to $$$m$$$.A sequence of $$$n$$$ segments $$$[l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]$$$ is called system of nested segments if for each pair $$$i, j$$$ ($$$1 \le i < j \le n$$$) the condition $$$l_i < l_j < r_j < r_i$$$ is satisfied. In other words, the second segment is strictly inside the first one, the third segment is strictly inside the second one, and so on.For a given number $$$n$$$, find a system of nested segments such that:  both ends of each segment are one of $$$m$$$ given points;  the sum of the weights $$$2\cdot n$$$ of the points used as ends of the segments is minimal. For example, let $$$m = 8$$$. The given points are marked in the picture, their weights are marked in red, their coordinates are marked in blue. Make a system of three nested segments:  weight of the first segment: $$$1 + 1 = 2$$$  weight of the second segment: $$$10 + (-1) = 9$$$  weight of the third segment: $$$3 + (-2) = 1$$$  sum of the weights of all the segments in the system: $$$2 + 9 + 1 = 12$$$     System of three nested segments

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of input test cases. An empty line is written before each test case. The first line of each test case contains two positive integers $$$n$$$ ($$$1 \le n \le 10^5$$$) and $$$m$$$ ($$$2 \cdot n \le m \le 2 \cdot 10^5$$$).  The next $$$m$$$ lines contain pairs of integers $$$x_i$$$ ($$$-10^9 \le x_i \le 10^9$$$) and $$$w_i$$$ ($$$-10^4 \le w_i \le 10^4$$$) — coordinate and weight of point number $$$i$$$ ($$$1 \le i \le m$$$) respectively. All $$$x_i$$$ are different. It is guaranteed that the sum of $$$m$$$ values over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output $$$n + 1$$$ lines: in the first of them, output the weight of the composed system, and in the next $$$n$$$ lines output exactly two numbers  — the indices of the points which are the endpoints of the $$$i$$$-th segment ($$$1 \le i \le n$$$). The order in which you output the endpoints of a segment is not important — you can output the index of the left endpoint first and then the number of the right endpoint, or the other way around. If there are several ways to make a system of nested segments with minimal weight, output any of them.

NoteThe first test case coincides with the example from the condition. It can be shown that the weight of the composed system is minimal.The second test case has only $$$6$$$ points, so you need to use each of them to compose $$$3$$$ segments.

package main

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

type point struct {
	x int
	y int
	z int
}

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	// Todo...
	solve = func() {
		var n, m int
		Fscan(in, &n, &m)
		var x, w int
		first := make([]point, 0)
		for i := 0; i < m; i++ {
			Fscan(in, &x, &w)
			first = append(first, point{x: w, y: x, z: i})
		}
		sort.Slice(first, func(i, j int) bool {
			if first[i].x == first[j].x {
				return first[i].z < first[j].z
			}
			return first[i].x < first[j].x
		})
		second := first[:2*n]
		sort.Slice(second, func(i, j int) bool {
			return second[i].y < second[j].y
		})
		//fmt.Println("second: ", second)
		sum := 0
		for _, v := range second {
			sum += v.x
		}
		Fprintln(out, sum)
		for i := 0; i < n; i++ {
			Fprintln(out, second[i].z+1, " ", second[2*n-i-1].z+1)
		}
	}
	// End...
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

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

type node struct {
	X   int
	W   int
	Idx int
}

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, m int
		fmt.Fscan(in, &n, &m)
		arr := make([]node, m)
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &arr[i].X, &arr[i].W)
			arr[i].Idx = i + 1
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i].W < arr[j].W
		})
		res := make([]node, 0)
		sum := 0
		for i := 0; i < n*2; i++ {
			res = append(res, arr[i])
			sum += arr[i].W
		}
		sort.Slice(res, func(i, j int) bool {
			return res[i].X < res[j].X
		})
		fmt.Fprintln(out, sum)
		for i := 0; i < n; i++ {
			fmt.Fprintln(out, res[i].Idx, res[2*n-i-1].Idx)
		}

	}
}

package main

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

type point struct {
	x  int
	w  int
	id int
}

func solveCase(in io.Reader, out io.Writer) {
	var n, m int
	fmt.Fscan(in, &n, &m)

	points := make([]point, m)
	for i := 0; i < m; i++ {
		var x, w int
		fmt.Fscan(in, &x, &w)
		points[i] = point{
			x:  x,
			w:  w,
			id: i + 1,
		}
	}

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

	candidates := points[:n*2]

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

	total := 0
	for i := 0; i < len(candidates); i++ {
		total += candidates[i].w
	}
	fmt.Fprintln(out, total)

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d %d\n",
			candidates[i].id, candidates[len(candidates)-1-i].id)
	}
}

func CF1650C(rawIn io.Reader, rawOut io.Writer) {
	in := bufio.NewReader(rawIn)
	out := bufio.NewWriter(rawOut)
	defer out.Flush()

	var cases int
	fmt.Fscan(in, &cases)
	for cc := 0; cc < cases; cc++ {
		solveCase(in, out)
	}
}

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

package main

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

type point struct {
	x  int
	w  int
	id int
}

func solveCase(in io.Reader, out io.Writer) {
	var n, m int
	fmt.Fscan(in, &n, &m)

	points := make([]point, m)
	for i := 0; i < m; i++ {
		var x, w int
		fmt.Fscan(in, &x, &w)
		points[i] = point{
			x:  x,
			w:  w,
			id: i + 1,
		}
	}

	sort.SliceStable(points, func(i, j int) bool {
		return points[i].w < points[j].w
	})

	candidates := points[:n*2]

	sort.SliceStable(candidates, func(i, j int) bool {
		return candidates[i].x < candidates[j].x
	})

	total := 0
	for i := 0; i < len(candidates); i++ {
		total += candidates[i].w
	}
	fmt.Fprintln(out, total)

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d %d\n",
			candidates[i].id, candidates[len(candidates)-1-i].id)
	}
}

func CF1650C(rawIn io.Reader, rawOut io.Writer) {
	in := bufio.NewReader(rawIn)
	out := bufio.NewWriter(rawOut)
	defer out.Flush()

	var cases int
	fmt.Fscan(in, &cases)
	for cc := 0; cc < cases; cc++ {
		solveCase(in, out)
	}
}

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

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer func(out *bufio.Writer) {
		_ = out.Flush()
	}(out)
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n, m int
		_, _ = fmt.Fscan(in, &n, &m)
		points := make([][3]int, m)
		for i := 0; i < m; i++ {
			x, w := 0, 0
			fmt.Fscan(in, &x, &w)
			points[i][0] = w
			points[i][1] = x
			points[i][2] = i + 1
		}
		sort.Slice(points, func(i, j int) bool {
			return points[i][0] < points[j][0]
		})
		sum := int64(0)
		var x [][2]int
		for i := 0; i < n*2; i++ {
			sum += int64(points[i][0])
			x = append(x, [2]int{points[i][1], points[i][2]})
		}
		sort.Slice(x, func(i, j int) bool {
			return x[i][0] < x[j][0]
		})
		fmt.Fprintln(out, sum)
		for i := 0; i < len(x)/2; i++ {
			fmt.Fprintln(out, x[i][1], x[len(x)-1-i][1])
		}
	}
}

package main

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

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

	var T, n, m int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([]struct{ x, w, i int }, m)
		for i := range a {
			Fscan(in, &a[i].x, &a[i].w)
			a[i].i = i
		}
		sort.Slice(a, func(i, j int) bool { return a[i].w < a[j].w })
		a = a[:n*2]
		sort.Slice(a, func(i, j int) bool { return a[i].x < a[j].x })
		s := 0
		for _, p := range a {
			s += p.w
		}
		Fprintln(out, s)
		for i, p := range a[:n] {
			Fprintln(out, p.i+1, a[n*2-1-i].i+1)
		}
	}
}

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

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m int
	scanf("\n%d %d\n", &n, &m)

	type point struct {
		i int
		x int
		w int
	}

	points := make([]point, m)

	for i := range points {
		points[i].i = i + 1

		scanf("%d %d\n", &points[i].x, &points[i].w)
	}

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

	points = points[:2*n]

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

	weightSum := int64(0)

	for _, p := range points {
		weightSum += int64(p.w)
	}

	fmt.Fprintf(writer, "\n%d\n", weightSum)

	for i, lft := range points {
		if i >= n {
			break
		}

		rgt := points[len(points)-i-1]

		fmt.Fprintf(writer, "%d %d\n", lft.i, rgt.i)
	}
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

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

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	idx := 0
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx]
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

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

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

type wtf struct {
	x, w, i int
}

func solve(cin *scanner, cout *writer, cerr *writer) {
	n, m := cin.NextInt(), cin.NextInt()
	a := make([]*wtf, m)
	for i := 0; i < m; i++ {
		x, w := cin.NextInt(), cin.NextInt()
		a[i] = &wtf{x, w, i + 1}
	}
	sort.Slice(a, func(i, j int) bool {
		return a[i].w < a[j].w
	})
	b := a[:n+n]
	sort.Slice(b, func(i, j int) bool {
		return b[i].x < b[j].x
	})
	var c int64
	for _, v := range b {
		c += int64(v.w)
	}
	cout.Println(c)
	for l := 0; l < n+n-1-l; l++ {
		r := n + n - 1 - l
		cout.Println(b[l].i, b[r].i)
	}
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

type point struct {
	x int
	y int
	z int
}

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	// Todo...
	solve = func() {
		var n, m int
		Fscan(in, &n, &m)
		var x, w int
		first := make([]point, 0)
		for i := 0; i < m; i++ {
			Fscan(in, &x, &w)
			first = append(first, point{x: w, y: x, z: i})
		}
		sort.Slice(first, func(i, j int) bool {
			return first[i].x < first[j].x
		})
		second := first[:2*n]
		sort.Slice(second, func(i, j int) bool {
			return second[i].y < second[j].y
		})
		sum := 0
		for _, v := range second {
			sum += v.x
		}
		Fprintln(out, sum)
		for i := 0; i < n; i++ {
			Fprintln(out, second[i].z, " ", second[2*n-i-1].z)
		}
	}
	// End...
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

type point struct {
	x int
	y int
}

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	// Todo...
	solve = func() {
		var n, m int
		Fscan(in, &n, &m)
		var x, w int
		first := make([]point, 0)
		for i := 0; i < m; i++ {
			Fscan(in, &x, &w)
			first = append(first, point{x: w, y: x})
		}
		sort.Slice(first, func(i, j int) bool {
			return first[i].x < first[j].x
		})
		second := first[:2*n]
		sort.Slice(second, func(i, j int) bool {
			return second[i].y < second[j].y
		})
		sum := 0
		for _, v := range second {
			sum += v.x
		}
		Fprintln(out, sum)
		for i := 0; i < n; i++ {
			Fprintln(out, second[i].y, " ", second[2*n-i-1].y)
		}
	}
	// End...
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

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

type node struct {
	X   int
	W   int
	Idx int
}

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, m int
		fmt.Fscan(in, &n, &m)
		arr := make([]node, m)
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &arr[i].X, &arr[i].W)
			arr[i].Idx = i + 1
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i].W < arr[j].W
		})
		res := make([]node, 0)
		sum := 0
		for i := 0; i < n*2; i++ {
			res = append(res, arr[i])
			sum += arr[i].W
		}
		sort.Slice(res, func(i, j int) bool {
			return arr[i].X < arr[j].X
		})
		fmt.Fprintln(out, sum)
		for i := 0; i < n; i++ {
			fmt.Fprintln(out, res[i].Idx, res[2*n-i-1].Idx)
		}

	}
}


Mike and Joe are playing a game with some stones. Specifically, they have $$$n$$$ piles of stones of sizes $$$a_1, a_2, \ldots, a_n$$$. These piles are arranged in a circle.The game goes as follows. Players take turns removing some positive number of stones from a pile in clockwise order starting from pile $$$1$$$. Formally, if a player removed stones from pile $$$i$$$ on a turn, the other player removes stones from pile $$$((i\bmod n) + 1)$$$ on the next turn.If a player cannot remove any stones on their turn (because the pile is empty), they lose. Mike goes first.If Mike and Joe play optimally, who will win?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$)  — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)  — the size of the piles.

For each test case print the winner of the game, either "Mike" or "Joe" on its own line (without quotes).

NoteIn the first test case, Mike just takes all $$$37$$$ stones on his first turn.In the second test case, Joe can just copy Mike's moves every time. Since Mike went first, he will hit $$$0$$$ on the first pile one move before Joe does so on the second pile.

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		mi := 1000000000

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if a[i] < mi {
				mi = a[i]
			}
		}

		if n%2 == 1 {
			write(f, "Mike\n")
		} else {

			ok := true
			for i := 0; i < n; i++ {
				if a[i]-mi == 0 {
					if i%2 == 0 {
						ok = false
						break
					} else if i%2 == 1 {
						ok = true
						break
					}

				}
			}
			if ok {
				write(f, "Mike\n")
			} else {
				write(f, "Joe\n")
			}
		}
	}
}

package main

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

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

func CF1695B(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)
		arr := make([]int64, n)
		small := int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &arr[i])
			if arr[i] < arr[small] {
				small = i
			}
		}

		if n%2 == 1 || small%2 == 1 {
			fmt.Fprintln(w, "Mike")
		} else {
			fmt.Fprintln(w, "Joe")
		}

	}

}

package main

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

var (
	mike = "Mike"
	joe  = "Joe"
)

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

	var tests int
	fmt.Fscan(in, &tests)

	for i := 0; i < tests; i++ {
		var pilesCount int
		fmt.Fscan(in, &pilesCount)

		stones := make([]int, pilesCount)
		for o := 0; o < pilesCount; o++ {
			fmt.Fscan(in, &stones[o])
		}

		fmt.Fprintln(out, solve(pilesCount, stones))
	}
}

func solve(n int, stones []int) string {
	if n%2 > 0 {
		return mike
	}

	var min int
	for i := 0; i < len(stones); i++ {
		if stones[min] > stones[i] {
			min = i
		}
	}

	if (min%n)%2 > 0 {
		return mike
	}
	return joe
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
	a      []int
)

func solve(n int, a []int) string {
	if n%2 == 1 {
		return "Mike"
	}
	var p int
	var m = 1000000001
	for i := range a {
		if m > a[i] {
			p = i
			m = a[i]
		}
	}
	if p%2 == 0 {
		return "Joe"
	}
	return "Mike"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

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 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 gi64() int64     { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis64(n int) []int64  { res := make([]int64,n); for i:=0;i<n;i++ { res[i] = gi64() }; 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 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 vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
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 ia64(m int) []int64 { return make([]int64,m) }
func iai64(m int,v int64) []int64 { a := make([]int64,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi64(n int,m int,v int64) [][]int64 {
	r := make([][]int64,n); for i:=0;i<n;i++ { x := make([]int64,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill264(m int) ([]int64,[]int64) { a,b := ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i] = gi64(),gi64()}; return a,b }
func fill364(m int) ([]int64,[]int64,[]int64) { a,b,c := ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi64(),gi64(),gi64()}; return a,b,c }
func fill464(m int) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia64(m),ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi64(),gi64(),gi64(),gi64()}; return a,b,c,d }
func abs64(a int64) int64 { if a < 0 { return -a }; return a }
func rev64(a []int64) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max64(a,b int64) int64 { if a > b { return a }; return b }
func min64(a,b int64) int64 { if a > b { return b }; return a }
func maxarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr64(a []int64) int64 { ans := int64(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr64(a []int64) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint64(a,e int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd64(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended64(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended64(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv64(a,m int64) (int64,bool) { g,x,_ := gcdExtended64(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecint64string(a []int64) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.FormatInt(a,10) }; return strings.Join(astr," ") }
func makefact64(n int,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * int64(i) % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * int64(i+1) % mod }
	return fact,factinv
}
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 := gi(); A := gis(N)
		// If there are an odd number of piles, then the first person to play always wins, because he takes all the stones from the
		// first pile, and when it comes back around to the first pile, the other player has no stones to take.
		//
		// If there are an even number of piles, then any pile is only ever "drawn from" by one player.  An optimal strategy here
		// is just to take one stone when you have to draw in order to prolong the game.  The loser is the player that has to draw from the
		// "first minimum" pile
		ans := "Mike"
		if N % 2 == 0 {
			m,mi := 1000000001,-1
			for i,c := range A { if c < m { m,mi = c,i } }
			if mi % 2 == 0 { ans = "Joe" }
		}
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

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

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

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

func do(n int, a []int) string {
	m := "Mike"
	j := "Joe"
	if n%2 == 1 {
		return m
	}
	x := a[0]
	xi := 0
	for i := 0; i < n; i += 2 {
		if x > a[i] {
			x = a[i]
			xi = i
		}
	}
	y := a[1]
	yi := 1
	for i := 1; i < n; i += 2 {
		if y > a[i] {
			y = a[i]
			yi = i
		}
	}
	if x > y {
		return m
	}
	if x < y {
		return j
	}
	if xi < yi {
		return j
	}
	return m
}

package main

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

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

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

		aa := make([]int, n)
		min := math.MaxInt32
		mIdx := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
			if aa[i] < min {
				min = aa[i]
				mIdx = i
			}
		}

		if n%2 != 0 || n%2 == 0 && mIdx%2 != 0 {
			fmt.Fprintln(out, "Mike")
		} else {
			fmt.Fprintln(out, "Joe")
		}
	}
}

package main

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

/*
6
1
5
2
4 3
3
5 2 7
4
6 5 2 4
3
3 3 3
4
2 2 2 2
---
Mike
Mike
Mike
Joe
Mike
Joe
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	if n%2 != 0 {
		fmt.Fprintln(writer, "Mike")
	} else {
		minIdx := minIdx(a...)
		if minIdx%2 != 0 {
			fmt.Fprintln(writer, "Mike")
		} else {
			fmt.Fprintln(writer, "Joe")
		}
	}
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

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

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

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

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		mi := 1000000000

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if a[i] < mi {
				mi = a[i]
			}
		}
		if t == 65 {
			fmt.Println(n, a)
		}

		if n%2 == 1 {
			write(f, "Mike\n")
		} else {

			ok := true
			for i := 0; i < n; i++ {
				if a[i]-mi == 0 && i%2 == 0 {
					ok = false
					break
				}
			}
			if ok {
				write(f, "Mike\n")
			} else {
				write(f, "Joe\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		mi := 1000000000

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if a[i] < mi {
				mi = a[i]
			}
		}

		if n%2 == 1 {
			write(f, "Mike\n")
		} else {

			ok := true
			for i := 0; i < n; i++ {
				if a[i]-mi == 0 && i%2 == 0 {
					ok = false
					break
				}
			}
			if ok {
				write(f, "Mike\n")
			} else {
				write(f, "Joe\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		mike := make([]int, 0)
		joe := make([]int, 0)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if i%2 == 0 {
				mike = append(mike, a[i])
			} else {
				joe = append(joe, a[i])
			}
		}

		if n%2 == 1 {
			write(f, "Mike\n")
		} else {
			sort.Ints(mike)
			sort.Ints(joe)
			ok := false
			for i := 0; i < n/2; i++ {
				if mike[i] > joe[i] {
					ok = true
				}
			}
			if ok {
				write(f, "Mike\n")
			} else {
				write(f, "Joe\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		mike := 1000000000
		joe := 1000000000
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if i%2 == 0 {
				if a[i] < mike {
					mike = a[i]
				}
			} else {
				if a[i] < int(joe) {
					joe = a[i]
				}

			}
		}
		if t == 65 {
			fmt.Println(n, a)
		}
		if n%2 == 1 || mike > joe {
			write(f, "Mike\n")
		} else {
			write(f, "Joe\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		if t == 65 {
			fmt.Println(n, a)
		}
		mike := 1000000000
		joe := 1000000000
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if i%2 == 0 {
				if a[i] < mike {
					mike = a[i]
				}
			} else {
				if a[i] < int(joe) {
					joe = a[i]
				}

			}
		}
		if n%2 == 1 || mike > joe {
			write(f, "Mike\n")
		} else {
			write(f, "Joe\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		mike := 1000000000
		joe := 1000000000
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if i%2 == 0 {
				if a[i] < mike {
					mike = a[i]
				}
			} else {
				if a[i] < int(joe) {
					joe = a[i]
				}

			}
		}
		if n%2 == 1 || mike > joe {
			write(f, "Mike\n")
		} else {
			write(f, "Joe\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		mike := int64(0)
		joe := int64(0)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if i%2 == 0 {
				mike += int64(a[i])
			} else {
				joe += int64(a[i])
			}
		}
		if n%2 == 1 || mike > joe {
			write(f, "Mike\n")
		} else {
			write(f, "Joe\n")
		}
	}
}

package main

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

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

func CF1695B(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)
		arr := make([]int64, n)
		total := int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &arr[i])
			total += arr[i]
		}

		if n%2 == 1 && total%2 == 1 {
			fmt.Fprintln(w, "Mike")
		} else {
			fmt.Fprintln(w, "Joe")
		}

	}

}

package main

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

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

func CF1695B(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)
		arr := make([]int64, n)
		total := int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &arr[i])
			total += arr[i]
		}

		if n%2 == 1 || total%2 == 1 {
			fmt.Fprintln(w, "Mike")
		} else {
			fmt.Fprintln(w, "Joe")
		}

	}

}

package main

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

var (
	mike = "Mike"
	joe  = "Joe"
)

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

	var tests int
	fmt.Fscan(in, &tests)

	for i := 0; i < tests; i++ {
		var pilesCount int
		fmt.Fscan(in, &pilesCount)

		stones := make([]int, pilesCount)
		for o := 0; o < pilesCount; o++ {
			fmt.Fscan(in, &stones[o])
		}

		fmt.Fprint(out, solve(pilesCount, stones))
	}
}

func solve(n int, stones []int) string {
	if n%2 > 0 {
		return mike
	}

	var min int
	for i := 0; i < len(stones); i++ {
		if stones[min] > stones[i] {
			min = i
		}
	}

	if (min%n)%2 > 0 {
		return mike
	}
	return joe
}


Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0.Vitya quickly understood all tasks of the teacher, but can you do the same?You are given an array consisting of n non-negative integers, and m queries. Each query is characterized by one number x and consists of the following consecutive steps:  Perform the bitwise addition operation modulo 2 (xor) of each array element with the number x.  Find mex of the resulting array. Note that after each query the array changes.

First line contains two integer numbers n and m (1 ≤ n, m ≤ 3·105) — number of elements in array and number of queries. Next line contains n integer numbers ai (0 ≤ ai ≤ 3·105) — elements of then array. Each of next m lines contains query — one integer number x (0 ≤ x ≤ 3·105).

For each query print the answer on a separate line.

package main

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

const (
	MaxPow = 19
)

type BinaryTrie struct {
	alpha [2]*BinaryTrie
	level uint
	count int
}

func MakeTrie() *BinaryTrie {
	return &BinaryTrie{}
}

func (t *BinaryTrie) isFilled() bool {
	return t.count == 1 << t.level
}

func (t *BinaryTrie) addNum(value int) {
	var path [MaxPow]*BinaryTrie
	newValueAdded := false
	tree := t
	for i := MaxPow-1; i >= 0; i-- {
		c := value >> uint(i) & 1
		if tree.alpha[c] == nil {
			newValueAdded = true
			tree.alpha[c] = &BinaryTrie{
				level: uint(i),
			}
		}
		path[i] = tree.alpha[c]
		tree = tree.alpha[c]
	}
	if newValueAdded {
		for i := 0; i < MaxPow; i++ {
			path[i].count++
		}
	}
	t.count++
}

func (t *BinaryTrie) mex(value int) int {
	//fmt.Println("v: ", value)
	tree := t
	ans := 0
	for i := MaxPow-1; i >= 0; i-- {
		c := (value >> uint(i)) & 1
		//fmt.Println("Looking for ", c, "at ", i)
		k := c
		if tree == nil || tree.alpha[c] == nil {
			ans += (k ^ c) << uint(i)
			//fmt.Println("breaking")
			break
		}
		if tree.alpha[c].isFilled() {
			//fmt.Println("filled", tree.alpha[c])
			c = 1 - c
		}
		//fmt.Println(" Adding: ", (k ^ c) << uint(i))
		ans += (k ^ c) << uint(i)
		tree = tree.alpha[c]
	}
	return ans
}

//func (t *BinaryTrie) traverseTrie(s string) {
//	if t.alpha[0] != nil {
//		t.alpha[0].traverseTrie(s + "0")
//	}
//	if t.alpha[1] != nil {
//		t.alpha[1].traverseTrie(s + "1")
//	}
//
//	if t.alpha[0] == nil && t.alpha[1] == nil {
//		fmt.Println(s)
//	}
//}

var n, m int
var trie *BinaryTrie

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &m)
	trie = MakeTrie()
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(inBuf, "%d", &tmp)
		trie.addNum(tmp)
	}

	//trie.traverseTrie("")
	fmt.Fscanf(inBuf, "\n")
	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() }()
	curr := 0
	for i := 0; i < m; i++ {
		var tmp int
		fmt.Fscanf(inBuf, "%d\n", &tmp)
		curr ^= tmp
		fmt.Fprintln(outBuf, trie.mex(curr))
	}
}