// If there are intersection, white part should be handle as two seperated parts.
package main

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

// (1, 1) is white
func calcBlock(x1, y1, x2, y2 int) (int64, int64) {
	width, height := x2-x1+1, y2-y1+1
	w, b := int64(width)*(int64(height)/2), int64(width)*(int64(height)/2)
	if height%2 == 1 {
		w, b = w+int64(width/2), b+int64(width/2)
		if width%2 == 1 {
			if (x2+y2)%2 == 0 {
				w++
			} else {
				b++
			}
		}
	}
	return w, b
}

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

func getIntsection(x1, y1, x2, y2, x3, y3, x4, y4 int) (int, int, int, int) {
	// fmt.Println("x1, y1, x2, y2, x3, y3, x4, y4", x1, y1, x2, y2, x3, y3, x4, y4)
	x5, y5 := max(x1, x3), max(y1, y3)
	x6, y6 := min(x2, x4), min(y2, y4)
	// fmt.Println(x5, y5, x6, y6)
	if (x5 > x6) || (y5 > y6) {
		return -1, -1, -1, -1
	}
	return x5, y5, x6, y6
}

func getNum(s *bufio.Scanner) int {
	s.Scan()
	num, _ := strconv.Atoi(s.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	t := getNum(scanner)

	for i := 0; i < t; i++ {
		n, m := getNum(scanner), getNum(scanner)
		x1, y1, x2, y2 := getNum(scanner), getNum(scanner), getNum(scanner), getNum(scanner)
		x3, y3, x4, y4 := getNum(scanner), getNum(scanner), getNum(scanner), getNum(scanner)
		// fmt.Println("case", x1, y1, x2, y2, x3, y3, x4, y4)
		x5, y5, x6, y6 := getIntsection(x1, y1, x2, y2, x3, y3, x4, y4)
		hasIntsection := x5 != -1

		tw, tb := calcBlock(1, 1, m, n)
		// b1 gonna become w
		_, b1 := calcBlock(x1, y1, x2, y2)
		tw, tb = tw+b1, tb-b1
		if hasIntsection {
			// intb gonna "become" b
			_, intb := calcBlock(x5, y5, x6, y6)
			tw, tb = tw-intb, tb+intb
		}
		// w2 gonna become b
		w2, _ := calcBlock(x3, y3, x4, y4)
		tw, tb = tw-w2, tb+w2

		fmt.Println(tw, tb)
	}
}

package main

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

func countWhite(x1,y1,x2,y2 int64)int64{
	var firstwhite bool =  false
	if (x1+y1)%2==0{
		firstwhite = true
	}
	var lenx int64= x2-x1+1
	var leny int64=y2-y1+1
	var ans int64 = 0
	if lenx%2==1{
		lenx--
		ans += (leny+1)/2
	}
	if lenx > 0{
		ans += (lenx/2)*leny
	}
	if firstwhite == false{
		return (x2-x1+1)*(y2-y1+1)-ans
	}
	return ans
}
func intct(x1,y1,x2,y2,x3,y3,x4,y4 int64)(bool,int64,int64,int64,int64){

	ok,nx1,nx2 := linein(x1,x2,x3,x4)
	if !ok {
		return false,0,0,0,0
	}
	ok,ny1,ny2 := linein(y1,y2,y3,y4)
	if !ok {
		return false,0,0,0,0
	}
	return true,nx1,ny1,nx2,ny2
}
func linein(x1,x2,x3,x4 int64)(bool,int64,int64)  {
	if x1 >= x3 && x1<=x4{
		if x2<=x4{
			return true,x1,x2
		} else{
			return true,x1,x4
		}
	}else if x3 >= x1&&x3 <= x2{
		if x4<=x2{
			return true,x3,x4
		} else{
			return true,x3,x2
		}
	}
	return false,-1,-1
}
func area(x1,y1,x2,y2 int64)int64  {
	return (x2-x1+1)*(y2-y1+1)
}
func main(){
	buf := bufio.NewReader(os.Stdin)
	var n int64
	var t int
	var m int64
	fmt.Fscanf(buf, "%d\n", &t)
	for i:=1 ;i <= t;i++{
		fmt.Fscanf(buf, "%d %d\n", &n,&m)
		var x1,x2,x3,x4 int64
		var y1,y2,y3,y4 int64
		fmt.Fscanf(buf, "%d %d %d %d\n", &x1,&y1,&x2,&y2)
		fmt.Fscanf(buf, "%d %d %d %d\n", &x3,&y3,&x4,&y4)
		var wcnt int64 = countWhite(1,1,m,n)
		var bcnt int64 = n*m-wcnt
	//	fmt.Printf("==  wcnt=%d bcnt=%d\n",wcnt,bcnt)
		wcnt -= countWhite(x1,y1,x2,y2)
		wcnt -= countWhite(x3,y3,x4,y4)
		bcnt -= area(x1,y1,x2,y2)-countWhite(x1,y1,x2,y2)
		bcnt -= area(x3,y3,x4,y4)-countWhite(x3,y3,x4,y4)
//		fmt.Printf("11==  wcnt=%d bcnt=%d %d %d %d %d\n",wcnt,bcnt,area(x1,y1,x2,y2),countWhite(x1,y1,x2,y2),area(x3,y3,x4,y4),countWhite(x3,y3,x4,y4))
		ok,inx1,iny1,inx2,iny2 := intct(x1,y1,x2,y2,x3,y3,x4,y4)
		if ok{
//			fmt.Printf("-> %d %d %d %d %d\n",inx1,iny1,inx2,iny2,countWhite(3,2,3,2))
			wcnt += countWhite(inx1,iny1,inx2,iny2)
			bcnt += area(inx1,iny1,inx2,iny2)-countWhite(inx1,iny1,inx2,iny2)
//			fmt.Printf("22==  wcnt=%d bcnt=%d\n",wcnt,bcnt)
		}
		var ansb int64= bcnt+area(x3,y3,x4,y4)
		fmt.Printf("%d %d\n",n*m-ansb,ansb)
	}

}

// If there are intersection, white part should be handle as two seperated parts.
package main

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

// (1, 1) is white
func calcBlock(a, b, c, d int) (int, int) {
	width, height := c-a+1, d-b+1
	w, b := width*(height/2), width*(height/2)
	if height%2 == 1 {
		w, b = w+width/2, b+width/2
		if width%2 == 1 {
			if (c+d)%2 == 0 {
				w++
			} else {
				b++
			}
		}
	}
	return w, b
}

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

func getIntsection(x1, y1, x2, y2, x3, y3, x4, y4 int) (int, int, int, int) {
	// fmt.Println("x1, y1, x2, y2, x3, y3, x4, y4", x1, y1, x2, y2, x3, y3, x4, y4)
	x5, y5 := max(x1, x3), max(y1, y3)
	x6, y6 := min(x2, x4), min(y2, y4)
	// fmt.Println(x5, y5, x6, y6)
	if (x5 > x6) || (y5 > y6) {
		return -1, -1, -1, -1
	}
	return x5, y5, x6, y6
}

func getNum(s *bufio.Scanner) int {
	s.Scan()
	num, _ := strconv.Atoi(s.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	t := getNum(scanner)
	for i := 0; i < t; i++ {
		n, m := getNum(scanner), getNum(scanner)
		x1, y1, x2, y2 := getNum(scanner), getNum(scanner), getNum(scanner), getNum(scanner)
		x3, y3, x4, y4 := getNum(scanner), getNum(scanner), getNum(scanner), getNum(scanner)
		// fmt.Println("case", x1, y1, x2, y2, x3, y3, x4, y4)
		x5, y5, x6, y6 := getIntsection(x1, y1, x2, y2, x3, y3, x4, y4)
		hasIntsection := x5 != -1

		tw, tb := calcBlock(1, 1, m, n)
		// b1 gonna become w
		_, b1 := calcBlock(x1, y1, x2, y2)
		tw, tb = tw+b1, tb-b1
		if hasIntsection {
			// intb gonna "become" b
			_, intb := calcBlock(x5, y5, x6, y6)
			tw, tb = tw-intb, tb+intb
		}
		// w2 gonna become b
		w2, _ := calcBlock(x3, y3, x4, y4)
		tw, tb = tw-w2, tb+w2

		fmt.Println(tw, tb)
	}
}


package main

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

func R(s string) (a string) {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	a = string(r)
	return
}

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

func yes() {
	p("YES")
}

func no() {
	p("NO")
}

func p(a ...interface{})            { fmt.Fprint(writer, a...) }
func pln(a ...interface{})          { fmt.Fprintln(writer, a...) }
func s(a ...interface{})            { fmt.Fscan(reader, a...) }
func pf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func sf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	//////////////////
	c := 0
	s(&c)
	for c != 0 {
		solve()
		c--
	}
	//////////////////
}

func solve() {
	var n uint64 = 0
	s(&n)
	m := make([]uint64, n)
	a := make([]uint64, n)
	var i uint64 = 0
	var j uint64 = 0
	for i+j < n*2 {
		x, y := 0, 0
		s(&x, &y)
		if x == 0 {
			m[i] = uint64(math.Abs(float64(y)))
			i++
		} else {
			a[j] = uint64(math.Abs(float64(x)))
			j++
		}
	}
	sort.Slice(m, func(i, j int) bool { return m[i] < m[j] })
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	i = 0
	sum := 0.0
	for i < n {
		sum += math.Sqrt(float64(m[i]*m[i] + a[i]*a[i]))
		i++
	}
	pf("%.15f\n", sum)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	scanf := func(f string, a ...interface{}) {
		if _, err := fmt.Fscanf(reader, f, a...); err != nil {
			log.Fatal(err)
		}
	}
	printf := func(f string, a ...interface{}) {
		if _, err := fmt.Fprintf(writer, f, a...); err != nil {
			log.Fatal(err)
		}
	}
	abs := func(a int64) int64 {
		if a >= 0 {
			return a
		}
		return -a
	}
	_, _ = scanf, printf
	defer func() {
		if err := writer.Flush(); err != nil {
			log.Fatal(err)
		}
	}()
	// Code goes below

	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)
		diamonds := make([]int64, 0, n)
		miners := make([]int64, 0, n)
		for j := 0; j < 2*n; j++ {
			var x, y int64
			scanf("%d %d\n", &x, &y)
			if x == 0 {
				miners = append(miners, abs(y))
			} else {
				diamonds = append(diamonds, abs(x))
			}
		}
		sort.Slice(diamonds, func(i, j int) bool {
			return diamonds[i] < diamonds[j]
		})
		sort.Slice(miners, func(i, j int) bool {
			return miners[i] < miners[j]
		})
		var totalDistance float64
		for j := 0; j < n; j++ {
			totalDistance += math.Hypot(float64(diamonds[j]), float64(miners[j]))
		}
		printf("%g\n", totalDistance)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	scanf := func(f string, a ...interface{}) {
		if _, err := fmt.Fscanf(reader, f, a...); err != nil {
			log.Fatal(err)
		}
	}
	printf := func(f string, a ...interface{}) {
		if _, err := fmt.Fprintf(writer, f, a...); err != nil {
			log.Fatal(err)
		}
	}
	abs := func(a int64) int64 {
		if a >= 0 {
			return a
		}
		return -a
	}
	_, _ = scanf, printf
	defer func() {
		if err := writer.Flush(); err != nil {
			log.Fatal(err)
		}
	}()
	// Code goes below

	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)
		diamonds := make([]int64, 0, n)
		miners := make([]int64, 0, n)
		for j := 0; j < 2*n; j++ {
			var x, y int64
			scanf("%d %d\n", &x, &y)
			if x == 0 {
				miners = append(miners, abs(y))
			} else {
				diamonds = append(diamonds, abs(x))
			}
		}
		sort.Slice(diamonds, func(i, j int) bool {
			return diamonds[i] < diamonds[j]
		})
		sort.Slice(miners, func(i, j int) bool {
			return miners[i] < miners[j]
		})
		var totalDistance float64
		//printf("case %d\n", i)
		for j := 0; j < n; j++ {
			distance := math.Hypot(float64(diamonds[j]), float64(miners[j]))
			//printf("distance: %g\n", distance)
			totalDistance += distance
		}
		printf("%g\n", totalDistance)
	}

}

package main

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

type Item struct {
	x int
	y int
	t bool
	dist float64
}

func main()  {
	scanner := bufio.NewScanner(os.Stdin)

	k:= 0
	scanner.Scan()
	k,_ = strconv.Atoi(scanner.Text())
	for i:= 0; i<k ;i++ {
		scanner.Scan()
		num,_ := strconv.Atoi(scanner.Text())

		all := make([] Item, num*2)
		for j:=0; j<num*2 ;j++ {
			scanner.Scan()
			line := strings.Split(scanner.Text() ," ")
			x,_ := strconv.Atoi(line[0])
			y,_ := strconv.Atoi(line[1])

			cur := Item{x,y, x==0 , 0 }

			cur.dist = float64(x)/math.Sqrt2+ float64(y)/math.Sqrt2
			all[j]= cur
		}

		sort.Slice(all, func(i, j int) bool {
			return math.Abs(all[i].dist) < math.Abs(all[j].dist)
		})

		miner := make([] Item, 0)
		mine := make([] Item, 0)

		for _,val := range all {
			if val.t {
				miner = append(miner, val)
			} else {
				mine = append(mine, val)
			}
		}

		res := float64(0)

		for j:=0; j<num; j++ {

			res+=  math.Sqrt(math.Pow(float64(miner[j].x - mine[j].x) ,2.0) + math.Pow(float64(miner[j].y - mine[j].y) ,2.0));
		}

		os.Stdout.WriteString(strconv.FormatFloat(res, 'f', -1, 64) + "\n")

	}

}

package main

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

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

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var n, x, y int
	fmt.Fscan(in, &n)
	a := make([]int, 0)
	b := make([]int, 0)
	for i := 0; i < n*2; i++ {
		fmt.Fscan(in, &x, &y)
		if x == 0 {
			a = append(a, abs(y))
		} else {
			b = append(b, abs(x))
		}
	}
	sort.Ints(a)
	sort.Ints(b)
	var res float64
	for i := 0; i < n; i++ {
		res += calc(float64(a[i]), float64(b[i]))
	}
	fmt.Fprintf(out, "%.15f\n", res)
}

func calc(a, b float64) float64 {
	return math.Sqrt(a*a + b*b)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1495A(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n, x, y int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		var a, b []int
		for n *= 2; n > 0; n-- {
			Fscan(in, &x, &y)
			if x < 0 {
				x = -x
			}
			if y < 0 {
				y = -y
			}
			if x == 0 {
				a = append(a, y)
			} else {
				b = append(b, x)
			}
		}
		sort.Ints(a)
		sort.Ints(b)
		s := .0
		for i, y := range a {
			s += math.Hypot(float64(b[i]), float64(y))
		}
		Fprintf(out, "%.15f\n", s)
	}
}

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

package main

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

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

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

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

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

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

// --------------------------------------------------------------------- //

func solveC() {
	var n int
	scan(&n)
	xx := make([]int, 0, n)
	yy := make([]int, 0, n)
	for i := 0; i < 2*n; i++ {
		x, y := 0, 0
		scan(&x, &y)
		if x < 0 {
			x = -x
		}
		if y < 0 {
			y = -y
		}
		if x == 0 {
			yy = append(yy, y)
		} else {
			xx = append(xx, x)
		}
	}
	sort.Slice(xx, func(i, j int) bool { return xx[i] < xx[j] })
	sort.Slice(yy, func(i, j int) bool { return yy[i] < yy[j] })

	var res float64
	for i := range xx {
		x, y := float64(xx[i]), float64(yy[i])
		res += math.Sqrt(x*x + y*y)
	}
	printf("%v\n", res)
}

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for t > 0 {
		t--
		func() {
			n := getNextInt(scanner)
			xx := make([]int, 0)
			yy := make([]int, 0)
			for i := 0; i < n*2; i++ {
				x := getNextInt(scanner)
				y := getNextInt(scanner)
				if x < 0 {
					x = -x
				}
				if y < 0 {
					y = -y
				}
				if x == 0 {
					yy = append(yy, y)
					continue
				}
				xx = append(xx, x)
			}
			sort.Ints(xx)
			sort.Ints(yy)
			var ans float64
			for i := 0; i < n; i++ {
				ans += math.Sqrt(math.Pow(float64(xx[i]), 2) + math.Pow(float64(yy[i]), 2))
			}
			fmt.Fprintln(writer, ans)
		}()
	}
}

package main

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

func R(s string) (a string) {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	a = string(r)
	return
}

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

func yes() {
	p("YES")
}

func no() {
	p("NO")
}

func p(a ...interface{})            { fmt.Fprint(writer, a...) }
func pln(a ...interface{})          { fmt.Fprintln(writer, a...) }
func s(a ...interface{})            { fmt.Fscan(reader, a...) }
func pf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func sf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	//////////////////
	c := 0
	s(&c)
	for c != 0 {
		solve()
		c--
	}
	//////////////////
}

func solve() {
	n := 0
	s(&n)
	m := make([]int, n)
	a := make([]int, n)
	i := 0
	j := 0
	for f := 0; f < n*2; f++ {
		x, y := 0, 0
		s(&x, &y)
		if x == 0 {
			m[i] = int(math.Abs(float64(y)))
			i++
		} else {
			a[j] = int(math.Abs(float64(x)))
			j++
		}
	}
	sort.Ints(m)
	sort.Ints(a)
	sum := 0.0
	for i := 0; i < n; i++ {
		sum += math.Sqrt(float64(m[i]*m[i] + a[i]*a[i]))
	}
	pf("%.15f\n", sum)
}

package main

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

func R(s string) (a string) {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	a = string(r)
	return
}

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

func yes() {
	p("YES")
}

func no() {
	p("NO")
}

func p(a ...interface{})   { fmt.Fprint(writer, a...) }
func pln(a ...interface{}) { fmt.Fprintln(writer, a...) }
func s(a ...interface{})   { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()
	//////////////////
	c := 0
	s(&c)
	for c != 0 {
		solve()
		c--
	}
	//////////////////
}

func solve() {
	n := 0
	s(&n)
	m := make([]int, n)
	a := make([]int, n)
	i := 0
	j := 0
	for i+j < n*2 {
		x, y := 0, 0
		s(&x, &y)
		if x == 0 {
			m[i] = int(math.Abs(float64(y)))
			i++
		} else {
			a[j] = int(math.Abs(float64(x)))
			j++
		}
	}
	sort.Ints(m)
	sort.Ints(a)
	sum := 0.0
	for i := 0; i < n; i++ {
		sum += math.Sqrt(float64(m[i]*m[i] + a[i]*a[i]))
	}
	pln(sum)
}


package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		println(solve(n, a))
	}
}

func solve(n int, a []int) int {
	max := Max(a...)
	for i := 0; i < n; i++ {
		if a[i] != max {
			continue
		}
		if (i-1 >= 0 && a[i-1] < a[i]) || (i+1 < n && a[i] > a[i+1]) {
			return i + 1
		}
	}
	return -1
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		mx := 0
		for i := range a {
			Fscan(in, &a[i])
			mx = max(mx, a[i])
		}

		for i, v := range a {
			if v == mx {
				if i>0 && v>a[i-1] || i+1<n && a[i+1] < v {
					Fprintln(out, i+1)
					return
				}
			}
		}

		Fprintln(out, -1)
		return
	}

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

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

package main

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

var t int

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

	fmt.Fscan(input, &t)

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

		arr := make([]int, n)
		mx := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
			if arr[i] > mx {
				mx = arr[i]
			}
		}

		ok := false
		for i := 0; i < n; i++ {
			if arr[i] == mx {

				if (i-1) >= 0 && arr[i-1] < mx {
					ok = true
					fmt.Println(i + 1)
					break
				}

				if (i+1) < n && arr[i+1] < mx {
					ok = true
					fmt.Println(i + 1)
					break
				}
			}
		}

		if ok == false {
			fmt.Println(-1)
		}
	}

}

//
// Created by aldair on 20/10/20.
// https://codeforces.com/problemset/problem/1433/C
//

package main

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

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

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

func remove(slice []int, i int) []int {
    return append(slice[:i], slice[i+1:]...)
}

func max(n1, n2 int) int {
    if n2 > n1 {
        return n2
    } else {
        return n1
    }
}

func main() {
    defer writer.Flush()

    var cases, n, piranha int
    scanf("%d\n", &cases)

    for; cases > 0; cases-- {
        scanf("%d\n", &n)
        piranhas := make([]int, 0, n)
        var maxi int
        for i := 0; i < n; i++ {
            scanf("%d", &piranha)
            piranhas = append(piranhas, piranha)
            maxi = max(maxi, piranha)
        }
        scanf("\n")

        var i int
        var dominant bool
        for; i < len(piranhas); i++ {
            if maxi == piranhas[i] {
                if i+1 < len(piranhas) && piranhas[i] > piranhas[i+1] || i-1 >= 0 && piranhas[i] > piranhas[i-1] {
                    dominant = true
                    break
                }
            }
        }
        if dominant {
            printf("%d\n", i+1)
        } else {
            printf("-1\n")
        }
    }
}

package main

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

func main() {
	var t, n, x int
	//file, _ := os.OpenFile("tmp", os.O_RDONLY, os.ModePerm)
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &t)
	//fmt.Sscanf(scanner.Text(), "%d\n", &t)
	for i := 0; i < t; i++ {

		fmt.Fscan(in, &n)
		pira := []int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x)
			pira = append(pira, x)
		}
		maxIL := -2
		maxL := 0
		maxIR := -2
		maxR := 0
		for i := 1; i < n; i++ {
			if maxL < pira[i] && pira[i-1] < pira[i] {
				maxIL = i
				maxL = pira[i]
			}
		}
		for i := n - 1; i > 0; i-- {
			if maxR < pira[i-1] && pira[i] < pira[i-1] {
				maxIR = i - 1
				maxR = pira[i-1]
			}
		}
		if maxR > maxL {
			fmt.Println(maxIR + 1)
		} else {
			fmt.Println(maxIL + 1)
		}
	}
}

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

package main

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

var T, n int

var _r = bufio.NewReader(os.Stdin)
var _w = bufio.NewWriter(os.Stdout)

func main() {
	for _, _ = fmt.Fscan(_r, &T); T > 0; T-- {
		_, _ = fmt.Fscan(_r, &n)
		a := make([]int, n+2)
		for i := 1; i <= n; i++ {
			_, _ = fmt.Fscan(_r, &a[i])
		}
		a[0] = 1e9 + 7
		a[n+1] = 1e9 + 7
		max_val := 0
		for i := 1; i <= n; i++ {
			if a[i] > max_val {
				max_val = a[i]
			}
		}
		for i := 1; i <= n; i++ {
			if a[i] == max_val && (a[i] > a[i-1] || a[i] > a[i+1]) {
				_, _ = fmt.Fprintln(_w, i)
				goto out
			}
		}
		_, _ = fmt.Fprintln(_w, -1)
	out:
		_ = _w.Flush()
	}

}

package main

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

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

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

func solveA() {
	var s string
	scanf("%s\n", &s)
	dig := int(s[0] - '0')
	len := len(s)
	ans := (dig - 1) * 10 + len * (len + 1) / 2
	printf("%d\n", ans)
}

func solveB() {
	n := 0
	scanf("%d\n", &n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &v[i])
		} else {
			scanf("%d ", &v[i])
		}
	}
	fir := -1
	lst := -1
	for i := 0; i < n; i++ {
		if v[i] == 0 {
			continue
		}
		if fir == -1 {
			fir = i
		}
		lst = i
	}
	ans := 0
	for i := fir; i <= lst; i++ {
		ans += 1 - v[i]
	}
	printf("%d\n", ans)
}

func solveC() {
	n := 0
	scanf("%d\n", &n)
	v := make([]int, n)
	indMx := 0
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &v[i])
		} else {
			scanf("%d ", &v[i])
		}
		if v[i] > v[indMx] {
			indMx = i
		}
	}
	ans := -1
	for i := indMx; i < n; i++ {
		if v[i] != v[indMx] {
			continue
		}
		if i - 1 >= 0 && v[i - 1] != v[indMx] {
			ans = i + 1
			break
		}
		if i + 1 < n && v[i + 1] != v[indMx] {
			ans = i + 1
			break
		}
	}
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveC()
	}
}

package main

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

func solve() {
	t := readInt()

	for j := 0; j < t; j++ {
		n := readInt()
		a := readInt64Array(n)
		ans := -1
		best := a[0]
		for i := 0; i < n; i++ {
			best = max(best, a[i])
		}
		for i := 0; i < n; i++ {
			if a[i] == best {
				if solveCase(a, i) {
					ans = i + 1
					break
				}
			}
		}
		fmt.Println(ans)
	}
}

func solveCase(a []int64, x int) bool {
	l := x - 1
	r := x + 1
	cur := a[x]
	for {
		ok := false
		for l >= 0 && a[l] < cur {
			cur++
			l--
			ok = true
		}
		for r < len(a) && a[r] < cur {
			cur++
			r++
			ok = true
		}
		if !ok {
			break
		}
	}
	return l == -1 && r == len(a)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

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

func main() {
	var t, n, x int
	//file, _ := os.OpenFile("tmp", os.O_RDONLY, os.ModePerm)
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &t)
	//fmt.Sscanf(scanner.Text(), "%d\n", &t)
	for i := 0; i < t; i++ {

		fmt.Fscan(in, &n)
		pira := []int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x)
			pira = append(pira, x)
		}
		maxI := -2
		minI := -2

		if n > 1 && pira[0] > pira[1] {
			maxI = 0
		}
		if n > 1 && pira[0] < pira[1] {
			minI = 0
		}
		for i := 1; i < n; i++ {
			if pira[i] > pira[i-1] {
				maxI = i
			}
		}
		for i := n - 1; i > 0; i-- {
			if pira[i] < pira[i-1] {
				minI = i - 1
			}
		}
		fmt.Println(max(maxI, minI) + 1)
	}
}

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

package main

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

func main() {
	var t, n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &t)
	for i := 0; i < t; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &n)
		scanner.Scan()
		piranha := strings.Split(scanner.Text(), " ")
		maxI := -2
		minI := -2
		if n > 1 && piranha[0] > piranha[1] {
			maxI = 0
		}
		if n > 1 && piranha[0] < piranha[1] {
			minI = 0
		}
		for i := 1; i < n; i++ {
			if piranha[i] > piranha[i-1] {
				maxI = i
			}
			if piranha[i] < piranha[i-1] {
				minI = i
			}
		}
		fmt.Println(max(maxI, minI))
	}
}

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

package main

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

func main() {
	var t, n, x int
	//file, _ := os.OpenFile("tmp", os.O_RDONLY, os.ModePerm)
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &t)
	//fmt.Sscanf(scanner.Text(), "%d\n", &t)
	for i := 0; i < t; i++ {

		fmt.Fscan(in, &n)
		pira := []int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x)
			pira = append(pira, x)
		}
		maxIL := -2
		maxL := 0
		maxIR := -2
		maxR := 0
		for i := 1; i < n; i++ {
			if maxL < pira[i] && pira[i-1] < pira[i] {
				maxIL = i
				maxL = pira[i]
			}
		}
		for i := n - 1; i > 0; i-- {
			if maxR < pira[i] && pira[i] < pira[i-1] {
				maxIR = i - 1
				maxR = pira[i]
			}
		}
		if maxIL == -2 {
			fmt.Println(maxIR + 1)
		} else {
			fmt.Println(maxIL + 1)
		}
	}
}

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

package main

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

func main() {
	var t, n, x int
	//file, _ := os.OpenFile("tmp", os.O_RDONLY, os.ModePerm)
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &t)
	//fmt.Sscanf(scanner.Text(), "%d\n", &t)
	for i := 0; i < t; i++ {

		fmt.Fscan(in, &n)
		pira := []int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x)
			pira = append(pira, x)
		}
		maxIL := -2
		maxL := 0
		maxIR := -2
		maxR := 0
		isAllSame := true
		for i := 0; i < n; i++ {
			if maxL < pira[i] {
				maxIL = i
				maxL = pira[i]
			}
			if pira[i] != pira[0] {
				isAllSame = false
			}
		}
		for i := n - 1; i >= 0; i-- {
			if maxR < pira[i] {
				maxIR = i
				maxR = pira[i]
			}
		}
		if isAllSame {
			fmt.Println("-1")
		} else if maxIL == 0 {
			fmt.Println(maxIR + 1)
		} else {
			fmt.Println(maxIL + 1)
		}
	}
}

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

package main

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

func main() {
	var t, n, x int
	//file, _ := os.OpenFile("tmp", os.O_RDONLY, os.ModePerm)
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &t)
	//fmt.Sscanf(scanner.Text(), "%d\n", &t)
	for i := 0; i < t; i++ {

		fmt.Fscan(in, &n)
		pira := []int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x)
			pira = append(pira, x)
		}
		maxIL := -2
		maxL := 0
		maxIR := -2
		maxR := 0
		isAllSame := true
		for i := 0; i < n; i++ {
			if maxL <= pira[i] {
				maxIL = i
				maxL = pira[i]
			}
			if pira[i] != pira[0] {
				isAllSame = false
			}
		}
		for i := n - 1; i >= 0; i-- {
			if maxR <= pira[i] {
				maxIR = i
				maxR = pira[i]
			}
		}
		if isAllSame {
			fmt.Println("-1")
		} else if maxIL == n-1 {
			fmt.Println(maxIR + 1)
		} else {
			fmt.Println(maxIL + 1)
		}
	}
}

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

package main

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

func main() {
	var t, n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &t)
	for i := 0; i < t; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &n)
		scanner.Scan()
		piranha := strings.Split(scanner.Text(), " ")
		maxI := -2
		if n > 1 && piranha[0] > piranha[1] {
			maxI = 0
		}
		for i := 1; i < n; i++ {
			if piranha[i] > piranha[i-1] {
				maxI = i
			}
		}
		fmt.Println(maxI + 1)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n int
	var pira [300011]int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &n)

		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &pira[i])
		}
		maxI := -2
		minI := -2

		if n > 1 && pira[0] > pira[1] {
			maxI = 0
		}
		if n > 1 && pira[0] < pira[1] {
			minI = 0
		}
		for i := 1; i < n; i++ {
			if pira[i] > pira[i-1] {
				maxI = i
			}
		}
		for i := n - 1; i > 0; i-- {
			if pira[i] < pira[i-1] {
				minI = i - 1
			}
		}
		fmt.Println(max(maxI, minI) + 1)
	}
}

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

package main

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

func main() {
	var t, n int
	var pira []int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &t)
	for i := 0; i < t; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &n)
		scanner.Scan()
		piranha := strings.Split(scanner.Text(), " ")
		for i := 0; i < n; i++ {
			in, _ := strconv.Atoi(piranha[i])
			pira = append(pira, in)
		}
		maxI := -2
		minI := -2

		if n > 1 && pira[0] > pira[1] {
			maxI = 0
		}
		if n > 1 && pira[0] < pira[1] {
			minI = 0
		}
		for i := 1; i < n; i++ {
			if pira[i] > pira[i-1] {
				maxI = i
			}
		}
		for i := n - 1; i > 0; i-- {
			if pira[i] < pira[i-1] {
				minI = i - 1
			}
		}
		fmt.Println(max(maxI, minI) + 1)
	}
}

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

package main

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

func main() {
	var t, n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &t)
	for i := 0; i < t; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &n)
		scanner.Scan()
		piranha := strings.Split(scanner.Text(), " ")
		maxI := -2
		minI := -2
		if n > 1 && piranha[0] > piranha[1] {
			maxI = 0
		}
		if n > 1 && piranha[0] < piranha[1] {
			minI = 0
		}
		for i := 1; i < n; i++ {
			if piranha[i] > piranha[i-1] {
				maxI = i
			}
			if piranha[i] < piranha[i-1] {
				minI = i
			}
		}
		fmt.Println(max(maxI, minI) + 1)
	}
}

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

package main

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

func main() {
	var t, n, x int
	//file, _ := os.OpenFile("tmp", os.O_RDONLY, os.ModePerm)
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &t)
	//fmt.Sscanf(scanner.Text(), "%d\n", &t)
	for i := 0; i < t; i++ {

		fmt.Fscan(in, &n)
		pira := []int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x)
			pira = append(pira, x)
		}
		maxIL := -2
		maxL := 0
		maxIR := -2
		maxR := 0
		for i := 0; i < n; i++ {
			if maxL < pira[i] {
				maxIL = i
				maxL = pira[i]
			}
		}
		for i := n - 1; i >= 0; i-- {
			if maxR < pira[i] {
				maxIR = i
				maxR = pira[i]
			}
		}
		if maxIL == 0 {
			if maxIR == n-1 {
				fmt.Println(-1)
			} else {
				fmt.Println(maxIR + 1)
			}
		} else {
			fmt.Println(maxIL + 1)
		}
	}
}

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

package main

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

func main() {
	var t, n int
	var pira [300011]int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Scanf(scanner.Text(), "%d", &t)
	for i := 0; i < t; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &n)
		scanner.Scan()
		piranha := strings.Split(scanner.Text(), " ")
		for i := 0; i < n; i++ {
			pira[i], _ = strconv.Atoi(piranha[i])
		}
		maxI := -2
		minI := -2

		if n > 1 && pira[0] > pira[1] {
			maxI = 0
		}
		if n > 1 && pira[0] < pira[1] {
			minI = 0
		}
		for i := 1; i < n; i++ {
			if pira[i] > pira[i-1] {
				maxI = i
			}
		}
		for i := n - 1; i > 0; i-- {
			if pira[i] < pira[i-1] {
				minI = i - 1
			}
		}
		fmt.Println(max(maxI, minI) + 1)
	}
}

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

package main

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

func solve() {
	t := readInt()

	for j := 0; j < t; j++ {
		n := readInt()
		a := readInt64Array(n)
		ans := -1
		best := a[0]
		for i := 0; i < n; i++ {
			best = max(best, a[i])
		}
		for i := 0; i < n-1; i++ {
			if a[i] == best {
				if solveCase(a, i) {
					ans = i + 1
					break
				}
			}
		}
		fmt.Println(ans)
	}
}

func solveCase(a []int64, x int) bool {
	l := x - 1
	r := x + 1
	cur := a[x]
	for {
		ok := false
		for l >= 0 && a[l] < cur {
			cur++
			l--
			ok = true
		}
		for r < len(a) && a[r] < cur {
			cur++
			r++
			ok = true
		}
		if !ok {
			break
		}
	}
	return l == -1 && r == len(a)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

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

func solve() {
	t := readInt()

	for j := 0; j < t; j++ {
		n := readInt()
		a := readIntArray(n)
		ans := -1
		for i := 0; i < n - 1; i++ {
			if a[i] > a[i + 1] {
				if solveCase(a, i) {
					ans = i + 1
					break
				}
			}
		}
		if ans == -1 {
			if a[n - 1] > a[n - 2] && solveCase(a, n - 1) {
				ans = n
			}
		}
		fmt.Println(ans)
	}
}

func solveCase(a []int, x int) bool {
	l := x - 1
	r := x + 1
	cur := a[x]
	for {
		ok := false
		for l >= 0 && a[l] < cur {
			cur++
			l--
			ok = true
		}
		for r < len(a) && a[r] < cur {
			cur++
			r++
			ok = true
		}
		if !ok {
			break
		}
	}
	return l == -1 && r == len(a)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

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

func solve() {
	t := readInt()

	for j := 0; j < t; j++ {
		n := readInt()
		a := readInt64Array(n)
		ans := -1
		for i := 0; i < n - 1; i++ {
			if a[i] > a[i + 1] {
				if solveCase(a, i) {
					ans = i + 1
					break
				}
			}
		}
		if ans == -1 {
			if a[n - 1] > a[n - 2] && solveCase(a, n - 1) {
				ans = n
			}
		}
		fmt.Println(ans)
	}
}

func solveCase(a []int64, x int) bool {
	l := x - 1
	r := x + 1
	cur := a[x]
	for {
		ok := false
		for l >= 0 && a[l] < cur {
			cur++
			l--
			ok = true
		}
		for r < len(a) && a[r] < cur {
			cur++
			r++
			ok = true
		}
		if !ok {
			break
		}
	}
	return l == -1 && r == len(a)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

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

var t int

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

	fmt.Fscan(input, &t)

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

		arr := make([]int, n)
		mx := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
			if arr[i] > mx {
				mx = arr[i]
			}
		}

		ok := false
		for i := 0; i < n; i++ {
			if arr[i] == mx {

				if (i-1) > 0 && arr[i-1] < mx {
					ok = true
					fmt.Println(i + 1)
					break
				}

				if (i+1) < n && arr[i+1] < mx {
					ok = true
					fmt.Println(i + 1)
					break
				}
			}
		}

		if ok == false {
			fmt.Println(-1)
		}
	}

}

//
// Created by aldair on 20/10/20.
// https://codeforces.com/problemset/problem/1433/C
//

package main

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

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

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

func remove(slice []int, i int) []int {
    return append(slice[:i], slice[i+1:]...)
}

func main() {
    defer writer.Flush()

    var cases, n, size int
    scanf("%d\n", &cases)

    for; cases > 0; cases-- {
        scanf("%d\n", &n)
        piranhas := make([]int, 0, n)
        for i := 0; i < n; i++ {
            scanf("%d", &size)
            piranhas = append(piranhas, size)
        }
        scanf("\n")

        var i int
        var dominant bool
        for i = 0; i < len(piranhas); i++ {
            slc := piranhas[:]
            index := i
            dominant = false
            for; len(slc) != 1; {
                if index+1 < len(slc) && slc[index] > slc[index+1] {
                    slc = remove(slc, index+1)
                    slc[index]++
                } else if index-1 >= 0 && slc[index] > slc[index-1] {
                    slc = remove(slc, index-1)
                    index--
                    slc[index]++
                } else {
                    break
                }
            }
            if len(slc) == 1 {
                dominant = true
                break
            }
        }
        if dominant {
            printf("%d\n", i+1)
        } else {
            printf("-1\n")
        }
    }
}


package main

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

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

  var t int
  for fmt.Fscan(reader, &t); t > 0; t-- {
    var n, k int
    fmt.Fscan(reader, &n, &k)
    adj := make([][]int, n+1)
    degs := make([]int, n+1)
    done := make([]bool, n+1)
    time := make([]int, n+1)
    for i := 0; i < n-1; i++ {
      var u, v int
      fmt.Fscan(reader, &u, &v)
      adj[u] = append(adj[u], v)
      adj[v] = append(adj[v], u)
      degs[u]++
      degs[v]++
    }

    var queue []int
    for i := 1; i <= n; i++ {
      if degs[i] == 1 {
        queue = append(queue, i)
        time[i] = 1;
      }
    }
    j := 0
    for ; j < len(queue); j++ {
      v := queue[j]
      done[v] = true
      for _, u := range adj[v] {
        if !done[u] {
          degs[u]--
          if degs[u] == 1 {
            time[u] = time[v] + 1
            queue = append(queue, u)
          }
        }
      }
    }

    ans := 0
    for i := 1; i <= n; i++ {
      if time[i] > k {
        ans++
      }
    }
    fmt.Fprint(writer, ans, "\n")
  }
}

package main

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

type Edge struct {
	u, v int
}

type Graph struct {
	adj [][]int
	e   []*Edge
}

func NewGraph(n int) *Graph {
	adj := make([][]int, n+1)
	for i := range adj {
		adj[i] = make([]int, 0)
	}
	return &Graph{
		adj: adj,
		e:   make([]*Edge, 0),
	}
}

func (g *Graph) AddEdge(u, v int) {
	g.adj[u] = append(g.adj[u], len(g.e))
	g.e = append(g.e, &Edge{u, v})
}

type DPNode struct {
	id, dep int
}

type DepDP struct {
	dep [2]DPNode
}

func (d *DepDP) Update(v DPNode) {
	if v.dep >= d.dep[0].dep {
		d.dep[1] = d.dep[0]
		d.dep[0] = v
	} else if v.dep > d.dep[1].dep {
		d.dep[1] = v
	}
}

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)

	T int

	g    *Graph
	n, k int

	dp []DepDP
)

func dfs(u, par int) {
	for _, i := range g.adj[u] {
		v := g.e[i].v
		if v == par {
			continue
		}
		dfs(v, u)
		dp[u].Update(DPNode{
			id:  v,
			dep: dp[v].dep[0].dep + 1,
		})
	}
}

func dfsPar(u, par int) {
	if par != 0 {
		if dp[par].dep[0].id != u {
			dp[u].Update(DPNode{
				id:  par,
				dep: dp[par].dep[0].dep + 1,
			})
		} else {
			dp[u].Update(DPNode{
				id:  par,
				dep: dp[par].dep[1].dep + 1,
			})
		}
	}

	for _, i := range g.adj[u] {
		v := g.e[i].v
		if v == par {
			continue
		}
		dfsPar(v, u)
	}
}

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n, &k)
		g = NewGraph(n)

		for i := 1; i < n; i++ {
			var u, v int
			fmt.Fscan(rr, &u, &v)
			g.AddEdge(u, v)
			g.AddEdge(v, u)
		}

		dp = make([]DepDP, n+1)
		dfs(1, 0)
		dfsPar(1, 0)

		ans := 0
		for i := 1; i <= n; i++ {
			if dp[i].dep[1].dep >= k {
				ans++
			}
		}

		fmt.Fprintln(ww, ans)
	}
	_ = ww.Flush()
}

package main

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

var n, k int

var gr [][]int

var mp map[int]map[int]bool

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		gr = make([][]int, n + 1)

		for j := 0; j < n - 1; j++ {
			var u, v int
			fmt.Fscan(r, &u, &v)

			gr[u] = append(gr[u], v)
			gr[v] = append(gr[v], u)
		}

		ans := solve()

		fmt.Println(ans)
	}
}

type item struct {
	v int
	round int
}

var seen []bool

func solve() int {

	if n == 1 {
		if k > 0 {
			return 0
		}
		return 1
	}

	seen = make([]bool, n + 1)

	var queue []*item
	for i := 1; i <= n; i++ {
		if len(gr[i]) == 1 {
			seen[i] = true
			queue = append(queue, &item{i, 1})
		}
	}

	mp = make(map[int]map[int]bool)

	for i := 1; i <= n; i++ {
		chidren := gr[i]

		mp[i] = make(map[int]bool)

		for j := 0; j < len(chidren); j++ {
			mp[i][chidren[j]] = true
		}
	}

	round := 1

	removed := 0

	for ;len(queue) > 0 && round <= k; {
		it := queue[0]
		queue = queue[1:]

		if it.round > round {
			round++
			if round > k {
				break
			}
		}

		m := mp[it.v]

		var key int
		for k, _ := range m {
			key = k
			break
		}
		delete(m, key)

		m = mp[key]

		delete(m, it.v)
		removed++

		if len(m) == 1 {
			if !seen[key] {
				seen[key] = true
				queue = append(queue, &item{key, it.round + 1})
			}
		}
	}

	return  n - removed
}

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

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

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

package main

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

func die(v ...interface{}) {
	_, _, line, _ := runtime.Caller(1)
	fmt.Printf("die line %d: %v\n", line, v)
	os.Exit(-1)
}

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

type scanner struct {
	sc  *bufio.Scanner
	buf []byte
	max int
}

func newScanner() *scanner {
	rv := &scanner{max: bufio.MaxScanTokenSize}
	rv.sc = bufio.NewScanner(os.Stdin)
	rv.sc.Split(bufio.ScanWords)
	rv.buf = make([]byte, rv.max)
	rv.sc.Buffer(rv.buf, rv.max)
	return rv
}

func (s *scanner) nextInt() int {
	if !s.sc.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	rv, err := strconv.Atoi(s.sc.Text())
	if err != nil {
		die(err)
	}
	return rv
}

func (s *scanner) nextInt64() int64 {
	if !s.sc.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	rv, err := strconv.ParseInt(s.sc.Text(), 10, 64)
	if err != nil {
		die(err)
	}
	return rv
}

func (s *scanner) nextStr() string {
	if !s.sc.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	return s.sc.Text()
}

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

const (
	INIT = -1
	INF  = 1e9
)

var (
	n       int
	k       int
	adjList [][]int
	ld      []int
)

func diam() []int {
	d1 := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		d1[i] = INF
	}
	q := []int{1}
	d1[1] = 0
	for i := 0; i < len(q); i++ {
		u := q[i]
		for _, v := range adjList[u] {
			if d1[v] == INF {
				d1[v] = d1[u] + 1
				q = append(q, v)
			}
		}
	}
	s := 1 // furthest distance id from 1
	mx := 0
	for i := 2; i < len(d1); i++ {
		if mx < d1[i] {
			s = i
			mx = d1[i]
		}
	}

	//	fmt.Printf("s %d mx %d\n", s, mx)

	d2 := make([]int, n+1)
	p := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		d2[i] = INF
	}
	d2[s] = 0
	q = []int{s}
	p[s] = s
	for i := 0; i < len(q); i++ {
		u := q[i]
		for _, v := range adjList[u] {
			if d2[v] == INF {
				d2[v] = d2[u] + 1
				p[v] = u
				q = append(q, v)
			}
		}
	}

	t := INIT
	mx = INIT
	for i := 1; i < len(d2); i++ {
		if mx < d2[i] {
			t = i
			mx = d2[i]
		}
	}
	check(t != INIT)

	//	fmt.Printf("s %d t %d dist %d\n", s, t, d2[t])

	rv := []int{t}
	l := d2[t]
	for i := 0; i < l; i++ {
		rv = append(rv, p[t])
		t = p[t]
	}

	return rv

}

func getLD(u, p int) int {
	rv := 0
	for _, v := range adjList[u] {
		if v == p {
			continue
		}
		d := getLD(v, u)
		rv = max(rv, d+1)
	}

	ld[u] = rv
	return rv
}

func main() {
	sc := newScanner()
	tc := sc.nextInt()

	for ; tc > 0; tc-- {
		n = sc.nextInt()
		k = sc.nextInt()

		adjList = make([][]int, n+1)
		for i := range adjList {
			adjList[i] = make([]int, 0)
		}

		for i := 0; i+1 < n; i++ {
			u := sc.nextInt()
			v := sc.nextInt()

			adjList[u] = append(adjList[u], v)
			adjList[v] = append(adjList[v], u)
		}

		path := diam()
		//		fmt.Println(path)
		ld = make([]int, n+1)
		if (len(path))%2 == 0 {
			r1 := path[len(path)/2]
			r2 := path[len(path)/2-1]
			getLD(r1, r2)
			getLD(r2, r1)
		} else {
			r1 := path[len(path)/2]
			getLD(r1, INIT)
		}

		// for u := 1; u <= n; u++ {
		// 	fmt.Printf("u %d ld[u] %d\n", u, ld[u])
		// }
		// fmt.Println()

		ans := 0
		for u := 1; u <= n; u++ {
			if ld[u] >= k {
				ans++
			}
		}
		fmt.Println(ans)

	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var u []int
var v []int
var first[]int
var nex[]int
var cnt int
var d []int
func add(x, y int){
	cnt++
	u[cnt]=x
	v[cnt]=y
	nex[cnt]=first[x]
	first[x] = cnt
}
type Node struct{
	x int
	l int
}
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)

	for c:=1;c<=t;c++{
		var n int
		var k int
		cnt=0
		fmt.Fscan(in,&n,&k)
		u = make([]int,3*n)
		v = make([]int,3*n)
		first = make([]int,4*n)
		nex = make([]int,4*n)
		d = make([]int,4*n)
		vis := make([]int,n+5)
		mp := map[int]int{}
		for i:=1;i<=n-1;i++{
			var x , y int
			fmt.Fscan(in,&x,&y)
			add(x,y)
			add(y,x)
			d[x]++
			d[y]++
		}
		qr := []Node{}
		for i:=1;i<=n;i++{
			if d[i]==1||d[i]==0{
				qr = append(qr,Node{i,1})
				vis[i]=1
			}
		}
		for len(qr)!=0{
			now := qr[0]
			mp[now.l]++
			qr = qr[1:]
			for k:=first[now.x];k!=0;k=nex[k]{
				if vis[v[k]]==0 {
					d[v[k]]--
					if d[v[k]] == 1 || d[v[k]] == 0{
						vis[v[k]] = 1
						qr = append(qr, Node{v[k], now.l + 1})
					}
				}
			}
		}
		ans:=n
		for i:=1;i<=min(k,n);i++{
			ans -=mp[i]
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

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

	var T, n, k, v, w int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		g := make([][]int, n)
		d := make([]int, n)
		for i := 1; i < n; i++ {
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
			d[v]++
			d[w]++
		}
		if n < 3 {
			Fprintln(out, 0)
			continue
		}
		q := make([]int, 0, n)
		for i, d := range d {
			if d == 1 {
				q = append(q, i)
			}
		}
		for ; k > 0 && len(q) > 0; k-- {
			sz := len(q)
			for _, v := range q {
				for _, w := range g[v] {
					if d[w]--; d[w] == 1 {
						q = append(q, w)
					}
				}
			}
			q = q[sz:]
		}
		Fprintln(out, cap(q))
	}
}

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

package main

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

var g [4000005][]int

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t, n, k, a, b int

	_, _ = fmt.Fscan(r, &t)

	for ; t > 0; t-- {
		_, _ = fmt.Fscan(r, &n, &k)
		deg := make([]int, n + 1)
		for i := 1; i < n; i++ {
			_, _ = fmt.Fscan(r, &a, &b)
			g[a] = append(g[a], b)
			g[b] = append(g[b], a)
			deg[a]++
			deg[b]++
		}

		curLeaves := make([]int, 0)
		newLeaves := make([]int, 0)
		alive := n
		for i := 1; i <= n; i++ {
			if deg[i] < 2 {
				curLeaves = append(curLeaves, i)
			}
		}

		for alive > 0 && k > 0 {
			for _, v := range curLeaves {
				for _, u := range g[v] {
					deg[u]--
					if deg[u] == 1 {
						newLeaves = append(newLeaves, u)
					}
				}
			}

			alive -= len(curLeaves)
			curLeaves = newLeaves
			newLeaves = make([]int, 0)
			k--
		}

		fmt.Println(alive)

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

}

package main

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

type Edge struct {
	u, v int
}

type Graph struct {
	adj [][]int
	e   []*Edge
}

func NewGraph(n int) *Graph {
	adj := make([][]int, n+1)
	for i := range adj {
		adj[i] = make([]int, 0)
	}
	return &Graph{
		adj: adj,
		e:   make([]*Edge, 0),
	}
}

func (g *Graph) AddEdge(u, v int) {
	g.adj[u] = append(g.adj[u], len(g.e))
	g.e = append(g.e, &Edge{u, v})
}

type DPNode struct {
	id, dep int
}

type DepDP struct {
	dep [2]DPNode
}

func (d *DepDP) Update(v DPNode) {
	if v.dep >= d.dep[0].dep {
		d.dep[1] = d.dep[0]
		d.dep[0] = v
	} else if v.dep > d.dep[1].dep {
		d.dep[1] = v
	}
}

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)

	T int

	g    *Graph
	n, k int

	dp []DepDP
)

func dfs(u, par int) {
	for _, i := range g.adj[u] {
		v := g.e[i].v
		if v == par {
			continue
		}
		dfs(v, u)
		dp[u].Update(DPNode{
			id:  v,
			dep: dp[v].dep[0].dep + 1,
		})
	}
}

func dfsPar(u, par int) {
	if par != 0 {
		if dp[par].dep[0].id != u {
			dp[u].Update(DPNode{
				id:  par,
				dep: dp[par].dep[0].dep + 1,
			})
		} else {
			dp[u].Update(DPNode{
				id:  par,
				dep: dp[par].dep[1].dep + 1,
			})
		}
	}

	for _, i := range g.adj[u] {
		v := g.e[i].v
		if v == par {
			continue
		}
		dfsPar(v, u)
	}
}

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n, &k)
		g = NewGraph(n)

		for i := 1; i < n; i++ {
			var u, v int
			fmt.Fscan(rr, &u, &v)
			g.AddEdge(u, v)
			g.AddEdge(v, u)
		}

		dp = make([]DepDP, n+1)
		dfs(1, 0)
		dfsPar(1, 0)

		fmt.Println(dp)
		ans := 0
		for i := 1; i <= n; i++ {
			if dp[i].dep[1].dep >= k {
				ans++
			}
		}

		fmt.Fprintln(ww, ans)
	}
	_ = ww.Flush()
}

package main

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

const Inf = 1000

type Edge struct {
	u, v int
}

type Graph struct {
	adj [][]int
	e   []*Edge
}

func NewGraph(n int) *Graph {
	adj := make([][]int, n+1)
	for i := range adj {
		adj[i] = make([]int, 0)
	}
	return &Graph{
		adj: adj,
		e:   make([]*Edge, 0),
	}
}

func (g *Graph) AddEdge(u, v int) {
	g.adj[u] = append(g.adj[u], len(g.e))
	g.e = append(g.e, &Edge{u, v})
}

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)

	T int

	g    *Graph
	n, k int

	dp [][2]int
)

func addDp(u, dep int) {
	if dep >= dp[u][0] {
		dp[u][1] = dp[u][0]
		dp[u][0] = dep
	} else if dep > dp[u][1] {
		dp[u][1] = dep
	}
}

func dfs(u, par, dep int) {
	for _, i := range g.adj[u] {
		v := g.e[i].v
		if v == par {
			continue
		}
		dfs(v, u, dep + 1)
		addDp(u, dp[v][0] + 1)
		addDp(v, dep + 1)
	}
}

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n, &k)
		g = NewGraph(n)

		for i := 1; i < n; i++ {
			var u, v int
			fmt.Fscan(rr, &u, &v)
			g.AddEdge(u, v)
			g.AddEdge(v, u)
		}

		dp = make([][2]int, n + 1)
		for i := 1; i <= n; i++ {
			if len(g.adj[i]) <= 1 {
				dfs(i, 0, 0)
				break
			}
		}

		ans := 0
		for i := 1; i <= n; i++ {
			if dp[i][1] >= k {
				ans++
			}
		}

		fmt.Fprintln(ww, ans)
	}
	_ = ww.Flush()
}

package main

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

const Inf = 1000

type Edge struct {
	u, v int
}

type Graph struct {
	adj [][]int
	e   []*Edge
}

func NewGraph(n int) *Graph {
	adj := make([][]int, n+1)
	for i := range adj {
		adj[i] = make([]int, 0)
	}
	return &Graph{
		adj: adj,
		e:   make([]*Edge, 0),
	}
}

func (g *Graph) AddEdge(u, v int) {
	g.adj[u] = append(g.adj[u], len(g.e))
	g.e = append(g.e, &Edge{u, v})
}

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)

	T int

	g    *Graph
	n, k int

	dp [][2]int
)

func addDp(u, dep int) {
	if dep >= dp[u][0] {
		dp[u][1] = dp[u][0]
		dp[u][0] = dep
	} else if dep > dp[u][1] {
		dp[u][1] = dep
	}
}

func dfs(u, par, dep int) {
	for _, i := range g.adj[u] {
		v := g.e[i].v
		if v == par {
			continue
		}
		dfs(v, u, dep + 1)
		addDp(u, dp[v][0] + 1)
		addDp(v, dep + 1)
	}
}

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n, &k)
		g = NewGraph(n)

		for i := 1; i < n; i++ {
			var u, v int
			fmt.Fscan(rr, &u, &v)
			g.AddEdge(u, v)
			g.AddEdge(v, u)
		}

		dp = make([][2]int, n + 1)
		for i := 1; i <= n; i++ {
			if len(g.adj[i]) <= 1 {
				dfs(i, 0, 1)
				addDp(i, 1)
				break
			}
		}

		ans := 0
		for i := 1; i <= n; i++ {
			if dp[i][1] >= k {
				ans++
			}
		}

		fmt.Fprintln(ww, ans)
	}
	_ = ww.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

const Inf = 1000

type Edge struct {
	u, v int
}

type Graph struct {
	adj [][]int
	e   []*Edge
}

func NewGraph(n int) *Graph {
	adj := make([][]int, n + 1)
	for i := range adj {
		adj[i] = make([]int, 0)
	}
	return &Graph{
		adj: adj,
		e:   make([]*Edge, 0),
	}
}

func (g *Graph) AddEdge(u, v int) {
	g.adj[u] = append(g.adj[u], len(g.e))
	g.e = append(g.e, &Edge{u, v})
}

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)

	T int

	g    *Graph
	n, k int

	step []int
)

func bfs(start int) {
	step = make([]int, start + 1)
	queue := list.New()
	queue.PushBack(start)
	for queue.Len() > 0 {
		pop := queue.Front()
		u := pop.Value.(int)
		queue.Remove(pop)

		for _, i := range g.adj[u] {
			v := g.e[i].v
			if step[v] == 0 {
				step[v] = step[u] + 1
				queue.PushBack(v)
			}
		}
	}
}

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n, &k)
		g = NewGraph(n + 1)

		for i := 1; i < n; i++ {
			var u, v int
			fmt.Fscan(rr, &u, &v)
			g.AddEdge(u, v)
			g.AddEdge(v, u)
		}

		for i := 1; i <= n; i++ {
			if len(g.adj[i]) <= 1 {
				g.AddEdge(n + 1, i)
			}
		}

		bfs(n + 1)

		ans := 0
		for i := 1; i <= n; i++ {
			if step[i] > k {
				ans++
			}
		}

		fmt.Fprintln(ww, ans)
	}
	_ = ww.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

const Inf = 1000

type Edge struct {
	u, v int
}

type Graph struct {
	adj [][]int
	e   []*Edge
}

func NewGraph(n int) *Graph {
	adj := make([][]int, n + 1)
	for i := range adj {
		adj[i] = make([]int, 0)
	}
	return &Graph{
		adj: adj,
		e:   make([]*Edge, 0),
	}
}

func (g *Graph) AddEdge(u, v int) {
	g.adj[u] = append(g.adj[u], len(g.e))
	g.e = append(g.e, &Edge{u, v})
}

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)

	T int

	g    *Graph
	n, k int

	step []int
)

func bfs(start int) {
	step = make([]int, start + 1)
	queue := list.New()
	queue.PushBack(start)
	for queue.Len() > 0 {
		pop := queue.Front()
		u := pop.Value.(int)
		queue.Remove(pop)

		for _, i := range g.adj[u] {
			v := g.e[i].v
			if step[v] == 0 {
				step[v] = step[u] + 1
				queue.PushBack(v)
			}
		}
	}
}

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n, &k)
		g = NewGraph(n + 1)

		for i := 1; i < n; i++ {
			var u, v int
			fmt.Fscan(rr, &u, &v)
			g.AddEdge(u, v)
			g.AddEdge(v, u)
		}

		for i := 1; i <= n; i++ {
			if len(g.adj[i]) <= 1 {
				g.AddEdge(n + 1, i)
			}
		}

		bfs(n + 1)

		ans := 0
		for _, i := range step {
			if i > k {
				ans++
			}
		}

		fmt.Fprintln(ww, ans)
	}
	_ = ww.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

const Inf = 1000

type Edge struct {
	u, v int
}

type Graph struct {
	adj [][]int
	e   []*Edge
}

func NewGraph(n int) *Graph {
	adj := make([][]int, n + 1)
	for i := range adj {
		adj[i] = make([]int, 0)
	}
	return &Graph{
		adj: adj,
		e:   make([]*Edge, 0),
	}
}

func (g *Graph) AddEdge(u, v int) {
	g.adj[u] = append(g.adj[u], len(g.e))
	g.e = append(g.e, &Edge{u, v})
}

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)

	T int

	g    *Graph
	n, k int

	step []int
)

func bfs(start int) {
	step = make([]int, start + 1)
	queue := list.New()
	queue.PushBack(start)
	for queue.Len() > 0 {
		pop := queue.Front()
		u := pop.Value.(int)
		queue.Remove(pop)

		for _, i := range g.adj[u] {
			v := g.e[i].v
			if step[v] == 0 {
				step[v] = step[u] + 1
				queue.PushBack(v)
			}
		}
	}
}

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n, &k)
		g = NewGraph(n + 1)

		for i := 1; i < n; i++ {
			var u, v int
			fmt.Fscan(rr, &u, &v)
			g.AddEdge(u, v)
			g.AddEdge(v, u)
		}

		for i := 1; i <= n; i++ {
			if len(g.adj[i]) == 1 {
				g.AddEdge(n + 1, i)
			}
		}

		bfs(n + 1)

		ans := 0
		for _, i := range step {
			if i > k {
				ans++
			}
		}

		fmt.Fprintln(ww, ans)
	}
	_ = ww.Flush()
}

package main

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

var n, k int

var gr [][]int

var mp map[int]map[int]bool

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		gr = make([][]int, n + 1)

		for j := 0; j < n - 1; j++ {
			var u, v int
			fmt.Fscan(r, &u, &v)

			gr[u] = append(gr[u], v)
			gr[v] = append(gr[v], u)
		}

		ans := solve()

		fmt.Println(ans)
	}
}

type item struct {
	v int
	round int
}

var seen []bool

func solve() int {
	seen = make([]bool, n + 1)

	var queue []*item
	for i := 1; i <= n; i++ {
		if len(gr[i]) == 1 {
			seen[i] = true
			queue = append(queue, &item{i, 1})
		}
	}

	mp = make(map[int]map[int]bool)

	for i := 1; i <= n; i++ {
		chidren := gr[i]

		mp[i] = make(map[int]bool)

		for j := 0; j < len(chidren); j++ {
			mp[i][chidren[j]] = true
		}
	}

	round := 1

	removed := 0

	for ;len(queue) > 0 && round <= k; {
		it := queue[0]
		queue = queue[1:]

		if it.round > round {
			round++
			if round > k {
				break
			}
		}

		m := mp[it.v]

		var key int
		for k, _ := range m {
			key = k
			break
		}
		delete(m, key)

		m = mp[key]

		delete(m, it.v)
		removed++

		if len(m) == 1 {
			if !seen[key] {
				seen[key] = true
				queue = append(queue, &item{key, it.round + 1})
			}
		}
	}

	return  n - removed
}

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

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

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

package main

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

var n, k int

var gr [][]int

var mp map[int]map[int]bool

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		gr = make([][]int, n + 1)

		for j := 0; j < n - 1; j++ {
			var u, v int
			fmt.Fscan(r, &u, &v)

			gr[u] = append(gr[u], v)
			gr[v] = append(gr[v], u)
		}

		ans := solve()

		fmt.Println(ans)
	}
}

type item struct {
	v int
	round int
}

var seen []bool

func solve() int {
	seen = make([]bool, n + 1)

	var queue []*item
	for i := 1; i <= n; i++ {
		if len(gr[i]) == 1 {
			seen[i] = true
			queue = append(queue, &item{i, 1})
		}
	}

	mp = make(map[int]map[int]bool)

	for i := 1; i <= n; i++ {
		chidren := gr[i]

		mp[i] = make(map[int]bool)

		for j := 0; j < len(chidren); j++ {
			mp[i][chidren[j]] = true
		}
	}

	round := 1

	removed := 0

	for ;len(queue) > 0 && round <= k; {
		it := queue[0]
		queue = queue[1:]

		if it.round > round {
			round++
			if round > k {
				break
			}
		}

		m := mp[it.v]

		var key int
		for k, _ := range m {
			key = k
			break
		}
		delete(m, key)

		m = mp[key]

		delete(m, it.v)
		removed++

		if len(m) == 1 || len(m) == 0 {
			if !seen[key] {
				seen[key] = true
				queue = append(queue, &item{key, it.round + 1})
			}
		}
	}

	return  n - removed
}

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

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

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

package main

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

var n, k int

var gr [][]int

var mp map[int]map[int]bool

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		gr = make([][]int, n + 1)

		for j := 0; j < n - 1; j++ {
			var u, v int
			fmt.Fscan(r, &u, &v)

			gr[u] = append(gr[u], v)
			gr[v] = append(gr[v], u)
		}

		ans := solve()

		fmt.Println(ans)
	}
}

type item struct {
	v int
	round int
}

func solve() int {
	var queue []*item
	for i := 1; i <= n; i++ {
		if len(gr[i]) == 1 {
			queue = append(queue, &item{i, 1})
		}
	}

	mp = make(map[int]map[int]bool)

	for i := 1; i <= n; i++ {
		chidren := gr[i]

		mp[i] = make(map[int]bool)

		for j := 0; j < len(chidren); j++ {
			mp[i][chidren[j]] = true
		}
	}

	round := 1

	removed := 0

	for ;len(queue) > 0 && round <= k; {
		it := queue[0]
		queue = queue[1:]

		if it.round > round {
			round++
			if round > k {
				break
			}
		}

		m := mp[it.v]

		var key int
		for k, _ := range m {
			key = k
			break
		}
		delete(m, key)

		m = mp[key]

		delete(m, it.v)
		removed++

		if len(m) == 1 {
			queue = append(queue, &item{key, it.round + 1})
		}
	}

	return  n - removed
}

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

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var u []int
var v []int
var first[]int
var nex[]int
var cnt int
var d []int
func add(x, y int){
	cnt++
	u[cnt]=x
	v[cnt]=y
	nex[cnt]=first[x]
	first[x] = cnt
}
type Node struct{
	x int
	l int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)

	for c:=1;c<=t;c++{
		var n int
		var k int
		cnt=0
		fmt.Fscan(in,&n,&k)
		u = make([]int,3*n)
		v = make([]int,3*n)
		first = make([]int,4*n)
		nex = make([]int,4*n)
		d = make([]int,4*n)
		vis := make([]int,n+5)
		mp := map[int]int{}
		for i:=1;i<=n-1;i++{
			var x , y int
			fmt.Fscan(in,&x,&y)
			add(x,y)
			add(y,x)
			d[x]++
			d[y]++
		}
		qr := []Node{}
		for i:=1;i<=n;i++{
			if d[i]==1{
				qr = append(qr,Node{i,1})
				vis[i]=1
			}
		}
		for len(qr)!=0{
			now := qr[0]
			mp[now.l]++
			qr = qr[1:]
			for k:=first[now.x];k!=0;k=nex[k]{
				if vis[v[k]]==0 {
					d[v[k]]--
					if d[v[k]] == 1 || d[v[k]] == 0{
						vis[v[k]] = 1
						qr = append(qr, Node{v[k], now.l + 1})
					}
				}
			}
		}
		ans:=n
		for i:=1;i<=k;i++{
			ans -=mp[i]
		}
		fmt.Fprintln(out,ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var u []int
var v []int
var first[]int
var nex[]int
var cnt int
var d []int
func add(x, y int){
	cnt++
	u[cnt]=x
	v[cnt]=y
	nex[cnt]=first[x]
	first[x] = cnt
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)

	for c:=1;c<=t;c++{
		var n int
		var k int
		cnt=0
		fmt.Fscan(in,&n,&k)
		u = make([]int,3*n)
		v = make([]int,3*n)
		first = make([]int,4*n)
		nex = make([]int,4*n)
		d = make([]int,4*n)
		mp := map[int]int{}
		for i:=1;i<=n-1;i++{
			var x , y int
			fmt.Fscan(in,&x,&y)
			add(x,y)
			add(y,x)
			d[x]++
			d[y]++
		}
		for i:=1;i<=n;i++{
			mp[d[i]]++
		}
		ans:=n
		for i:=1;i<=k;i++{
			ans-=mp[i]
		}
		fmt.Fprintln(out,ans)
	}
}