package main

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

var n, a, b int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(r, &n, &a, &b)

		solve()

		fmt.Println()
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() {
	if b < n/2 {
		fmt.Print(-1)
		return
	}
	if a > n/2 + 1 {
		fmt.Print(-1)
		return
	}
	if (a <= n/2 && b <= n/2) || (a >= n/2 + 1 && b >= n/2 + 1) {
		fmt.Print(-1)
		return
	}

	if a <= n/2 && b >= n/2 {
		for j := n/2 + 1; j <= n; j++ {
			if j == b {
				continue
			}
			fmt.Print(j)
			fmt.Print(" ")
		}
		fmt.Print(a)
		fmt.Print(" ")
		fmt.Print(b)
		fmt.Print(" ")

		for i := 1; i <= n/2; i++ {
			if i == a {
				continue
			}
			fmt.Print(i)
			fmt.Print(" ")
		}

	} else {
		for j := n/2 + 1; j <= n; j++ {
			fmt.Print(j)
			fmt.Print(" ")
		}
		for j := 1; j <= n/2; j++ {
			fmt.Print(j)
			fmt.Print(" ")
		}
	}

	//4 . . 5 . .

	//1 2 3 4 5 6  [4, 3]

}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

import (
	"bufio"
	"fmt"
	"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, a, b int
		fmt.Fscan(in, &n, &a, &b)

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

		min, max := (n/2)+1, n/2
		var swapped bool
		if a < min || b > max {
			arr[n-b], arr[n-a] = a, b
			swapped = true
		}

		// fmt.Println(min, max)
		if (a <= max && b <= max) || (a >= min && b >= min) || (!swapped && b < max) || (!swapped && a > min) {
			fmt.Fprintln(out, -1)
		} else {
			for i := 0; i < n; i++ {
				fmt.Fprintf(out, "%d ", arr[i])
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

/*
2
8 2 7
6 1 5
---
8 2 3 4 1 7 6 5
6 1 2 3 5 4
======
1
4 2 4
---
2 3 1 4
*/

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

	bld := strings.Builder{}

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

	for ; t > 0; t-- {
		var n, a, b int
		scanf("%d %d %d\n", &n, &a, &b)

		nums := make([]int, n)

		nums[0] = a
		nums[n-1] = b

		num := n

		for i := 1; i < n-1; i++ {
			for num == a || num == b {
				num--
			}

			nums[i] = num

			num--
		}

		leftMin := maxInt
		for i := 0; i < n/2; i++ {
			leftMin = min(leftMin, nums[i])
		}

		rightMax := minInt
		for i := n / 2; i < n; i++ {
			rightMax = max(rightMax, nums[i])
		}

		if leftMin != a || rightMax != b {
			fmt.Fprintln(&bld, -1)
		} else {
			for _, num := range nums {
				fmt.Fprintf(&bld, "%d ", num)
			}
			fmt.Fprintln(&bld)
		}
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(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 {
	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"
	"math"
	"os"
	"strings"
)

/*
2
8 2 7
6 1 5
---
8 2 3 4 1 7 6 5
6 1 2 3 5 4
======
1
4 2 4
---
2 3 1 4
*/

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

	bld := strings.Builder{}

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

	for ; t > 0; t-- {
		var n, a, b int
		scanf("%d %d %d\n", &n, &a, &b)

		nums := make([]int, n)

		nums[0] = a
		nums[n-1] = b

		num := n

		for i := 1; i < n-1; i++ {
			for num == a || num == b {
				num--
			}

			nums[i] = num

			num--
		}

		valid := true
		if len(nums) != n {
			valid = false
		} else {
			leftMin := maxInt
			for i := 0; i < n/2; i++ {
				leftMin = min(leftMin, nums[i])
			}

			rightMax := minInt
			for i := n / 2; i < n; i++ {
				rightMax = max(rightMax, nums[i])
			}

			if leftMin != a || rightMax != b {
				valid = false
			}
		}

		if valid {
			for _, num := range nums {
				fmt.Fprintf(&bld, "%d ", num)
			}
			fmt.Fprintln(&bld)
		} else {
			fmt.Fprintln(&bld, -1)
		}
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(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 {
	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 (
	"fmt"
)

func solve() {
	var n, a, b int16
	fmt.Scan(&n, &a, &b)
	v := make([]int16, n+1)
	v[1] = a
	i, j := int16(2), n
	for ; i <= n/2; i++ {
		if j == a || j <= 0 {
			fmt.Println(-1)
			return
		} else if j == b {
			j--
			i--
			continue
		}
		v[i] = j
		j--
	}
	v[n] = b
	if j >= b {
		j = b - 1
	}
	for i = n - 1; i >= n/2+1; i-- {
		if j <= 0 {
			fmt.Println(-1)
			return
		} else if j == a {
			j--
			i++
			continue
		}
		v[i] = j
		j--
	}
	for i, x := range v {
		if i > 0 {
			fmt.Printf("%v ", x)
		}
	}
	fmt.Println()

}

func main() {

	var t int16
	fmt.Scan(&t)
	for tc := int16(0); tc < t; tc++ {
		solve()
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)

func solve(){
	var n, a, b int
	fmt.Fscan(r, &n, &a, &b)
	arr := make([]int, 0, n)

	for i := 0; i < n; i++ {
		if n - i != a && n - i != b {
			arr = append(arr, n - i)
		}
	}
	arr = append(arr, b)

	arr = append(arr, 0)
	copy(arr[1:], arr[0:])
	arr[0] = a

	for i := 0; i < n; i++ {
		if i < n/2 && arr[i] < a || i >= n/2 && arr[i] > b {
			fmt.Println(-1)
			return
		}
	}

	for _, v := range arr {
		fmt.Print(v, " ")
	}

	fmt.Println()

}

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

package main

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

func min(a ...int32) int32 {
	ret := a[0]
	for _, v := range a {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func max(a ...int32) int32 {
	ret := a[0]
	for _, v := range a {
		if v > ret {
			ret = v
		}
	}
	return ret
}

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

	n := mustReadInt(r)
	for i := int64(0); i < n; i++ {
		nums := mustReadNNumbs(r, 3)
		n, a, b := nums[0], nums[1], nums[2]
		base := make([]int32, n)
		base[0] = int32(a)
		base[len(base)-1] = int32(b)
		if a > n/2 || b < n/2 || a == b {
			if !(a == n/2+1 && b == n/2) {
				fmt.Println(-1)
				continue
			}
		}

		last := int32(len(base))
		for i := 1; i < len(base)/2; i++ {
			if last == int32(b) {
				last--
			}
			base[i] = last
			last--
		}
		if last < int32(a) {
			fmt.Println(-1)
			continue
		}
		last = 1
		for i := len(base) / 2; i < len(base)-1; i++ {
			if last == int32(a) {
				last++
			}
			base[i] = last
			last++
		}
		if last > int32(b) {
			fmt.Println(-1)
			continue
		}
		for _, v := range base {
			fmt.Printf("%d ", v)
		}
		fmt.Printf("\n")
	}
}

func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}

func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

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

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var n, a, b int
    fmt.Fscan(input, &n, &a, &b)
    half := n/2

    ans := make([]int, 0)
    mp := make(map[int]bool)
    ans = append(ans, a)
    mp[a] = true
    mp[b] = true

    cur := n
    for i := 0; i < half - 1; i++ {
        for mp[cur] { cur-- }
        if cur < a {
            fmt.Fprintln(output, -1)
            return
        }
        ans = append(ans, cur)
        mp[cur] = true
    }

    ans = append(ans, b)
    for i := 0; i < half - 1; i++ {
        for mp[b] { b-- }
        if b < 1 {
            fmt.Fprintln(output, -1)
            return
        }
        ans = append(ans, b)
        mp[b] = true
    }

    for i := 0; i < len(ans); i++ {
        fmt.Fprint(output, ans[i], " ")
    }
    fmt.Fprintln(output)
}

package main

import "fmt"

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

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

func main(){
	var N_INPUTS, turn int
	var left, right []int

	fmt.Scanf("%d\n", &N_INPUTS)
	var inputs [][3]int
	var n, a, b int

	for turn=0; turn<N_INPUTS; turn++{
		fmt.Scanf("%d %d %d\n", &n, &a, &b)
		inputs = append(inputs, [3]int{n, a, b})
	}

	for _, inp := range inputs{
		n, a, b = inp[0], inp[1], inp[2]
		left = []int{}
		right = []int{}
		in_arr := make(map[int]int)
		for num:=1; num <= n; num++{
			if num < min(a,b) && len(right) < n/2{
				right = append(right, num)
				in_arr[num] = 1
			} else if num > max(a,b) && len(left) < n/2{
				left = append(left, num)
				in_arr[num] = -1
			} else{
				in_arr[num] = 0
			}
		}
		for num:=1; num<=n; num++{
			if num >= a && num != b && in_arr[num] == 0{
				left = append(left, num)
				in_arr[num] = -1
				if len(left) == n/2{
					break
				}
			}
		}
		for num:=1; num<=n; num++{
			if num <=b && num != a && in_arr[num] == 0{
				right = append(right, num)
				in_arr[num] = 1
				if len(right) == n/2{
					break
				}
			}
		}
		if len(left) < n/2 || len(right) < n/2 {
			fmt.Printf("-1")
		} else{
			for _, num := range left{
				fmt.Printf("%d ", num)
			}
			for _, num := range right{
				fmt.Printf("%d ", num)
			}
		}
		fmt.Println()
	}
}

package main

import "fmt"

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

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

func main(){
	var N_INPUTS, turn int

	fmt.Scanf("%d\n", &N_INPUTS)
	var inputs [][3]int
	var n, a, b int
	for turn=0; turn<N_INPUTS; turn++{
		fmt.Scanf("%d %d %d\n", &n, &a, &b)
		inputs = append(inputs, [3]int{n, a, b})
	}
	for _, inp := range inputs{
		n, a, b = inp[0], inp[1], inp[2]
		var left []int
		var right []int
		in_arr := make(map[int]string)
		for num:=1; num <= n; num++{
			if num < min(a,b) && len(right) < n/2{
				right = append(right, num)
				in_arr[num] = "r"
			} else if num > max(a,b) && len(left) < n/2{
				left = append(left, num)
				in_arr[num] = "l"
			} else{
				in_arr[num] = "0"
			}
		}
		for num:=1; num<=n; num++{
			if num >= a && num != b && in_arr[num] == "0"{
				left = append(left, num)
				in_arr[num] = "l"
				if len(left) == n/2{
					break
				}
			}
		}
		for num:=1; num<=n; num++{
			if num <=b && num != a && in_arr[num] == "0"{
				right = append(right, num)
				in_arr[num] = "r"
				if len(right) == n/2{
					break
				}
			}
		}
		if len(left) < n/2 || len(right) < n/2 {
			fmt.Printf("-1")
		} else{
			for _, num := range left{
				fmt.Printf("%d ", num)
			}
			for _, num := range right{
				fmt.Printf("%d ", num)
			}
		}
		fmt.Println()
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1612B
Date: 10/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1612/B
Problem: CF1612B
**/
func (in *CF1612B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, a, b := in.NextInt(), in.NextInt(), in.NextInt()
		if (a <= n/2 && b <= n/2) || (a > n/2 && b > n/2) {
			fmt.Println(-1)
		} else {
			arr := make([]int, n)
			arr[0] = a
			ans := true
			for i, j := n, 1; i >= 1; i-- {
				if i != a && i != b {
					arr[j] = i
					j++
					if i > n/2 && i <= a {
						ans = false
					} else if i <= n/2 && i >= b {
						ans = false
					}
				}
			}
			var sb strings.Builder
			arr[n-1] = b
			if ans {
				for i := 0; i < n; i++ {
					sb.WriteString(strconv.Itoa(arr[i]))
					sb.WriteString(" ")
				}
			} else {
				sb.WriteString("-1")
			}
			fmt.Println(sb.String())
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1612B
Date: 10/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1612/B
Problem: CF1612B
**/
func (in *CF1612B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, a, b := in.NextInt(), in.NextInt(), in.NextInt()
		if (a <= n/2 && b <= n/2) || (a > n/2 && b > n/2) {
			fmt.Println(-1)
		} else {
			arr := make([]int, n)
			arr[0] = a
			ans := true
			for i, j := n, 1; i >= 1; i-- {
				if i != a && i != b {
					arr[j] = i
					j++
					if i > n/2 && i <= a {
						ans = false
					} else if i <= n/2 && i >= b {
						ans = false
					}
				}
			}
			arr[n-1] = b
			if ans {
				for i := 0; i < n; i++ {
					fmt.Print(arr[i], " ")
				}
			} else {
				fmt.Print(-1)
			}
			fmt.Println()
		}
	}
}

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

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

package main

import "fmt"

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

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

func main(){
	var N_INPUTS, turn int

	fmt.Scanf("%d\n", &N_INPUTS)
	var inputs [][3]int
	var n, a, b int
	for turn=0; turn<N_INPUTS; turn++{
		fmt.Scanf("%d %d %d\n", &n, &a, &b)
		inputs = append(inputs, [3]int{n, a, b})
	}
	for _, inp := range inputs{
		n, a, b = inp[0], inp[1], inp[2]
		var left []int
		var right []int
		in_arr := make(map[int]string)
		for num:=1; num <= n; num++{
			if num < min(a,b) && len(right) < n/2{
				right = append(right, num)
				in_arr[num] = "r"
			} else if num > max(a,b) && len(left) < n/2{
				left = append(left, num)
				in_arr[num] = "l"
			} else{
				in_arr[num] = "0"
			}
		}
		for num:=1; num<=n; num++{
			if num >= a && in_arr[num] == "0"{
				left = append(left, num)
				in_arr[num] = "l"
				if len(left) == n/2{
					break
				}
			}
		}
		for num:=1; num<=n; num++{
			if num <=b && in_arr[num] == "0"{
				right = append(right, num)
				in_arr[num] = "r"
				if len(right) == n/2{
					break
				}
			}
		}
		if len(left) < n/2 || len(right) < n/2 {
			fmt.Printf("-1")
		} else{
			for _, num := range left{
				fmt.Printf("%d ", num)
			}
			for _, num := range right{
				fmt.Printf("%d ", num)
			}
		}
		fmt.Println()
	}
}

package main

import "fmt"

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

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

func main(){
	var N_INPUTS, turn int

	fmt.Scanf("%d\n", &N_INPUTS)
	var inputs [][3]int
	var n, a, b int
	for turn=0; turn<N_INPUTS; turn++{
		fmt.Scanf("%d %d %d\n", &n, &a, &b)
		inputs = append(inputs, [3]int{n, a, b})
	}
	for i, inp := range inputs{
		n, a, b = inp[0], inp[1], inp[2]
		var left []int
		var right []int
		in_arr := make(map[int]string)
		for num:=1; num <= n; num++{
			if num < min(a,b) && len(right) < n/2{
				right = append(right, num)
				in_arr[num] = "r"
			} else if num > max(a,b) && len(left) < n/2{
				left = append(left, num)
				in_arr[num] = "l"
			} else{
				in_arr[num] = "0"
			}
		}
		for num:=1; num<=n; num++{
			if num >= a && in_arr[num] == "0"{
				left = append(left, num)
				in_arr[num] = "l"
				if len(left) == n/2{
					break
				}
			}
		}
		for num:=1; num<=n; num++{
			if num <=b && in_arr[num] == "0"{
				right = append(right, num)
				in_arr[num] = "r"
				if len(right) == n/2{
					break
				}
			}
		}
		if len(left) < n/2 || len(right) < n/2 {
			fmt.Printf("-1")
		} else{
			for _, num := range left{
				fmt.Printf("%d ", num)
			}
			for _, num := range right{
				fmt.Printf("%d ", num)
			}
		}
		if i < N_INPUTS-1{
			fmt.Println()
		}
	}
}

package main

import "fmt"

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

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

func main(){
	var N_INPUTS, turn int

	fmt.Scanf("%d\n", &N_INPUTS)
	var inputs [][3]int
	var n, a, b int
	for turn=0; turn<N_INPUTS; turn++{
		fmt.Scanf("%d %d %d\n", &n, &a, &b)
		inputs = append(inputs, [3]int{n, a, b})
	}
	for i, inp := range inputs{
		n, a, b = inp[0], inp[1], inp[2]
		var left []int
		var right []int
		in_arr := make(map[int]string)
		for num:=1; num <= n; num++{
			if num < min(a,b) && len(right) < n/2{
				right = append(right, num)
				in_arr[num] = "r"
			} else if num > max(a,b) && len(left) < n/2{
				left = append(left, num)
				in_arr[num] = "l"
			} else{
				in_arr[num] = "0"
			}
		}
		for num:=1; num<=n; num++{
			if num >= a && in_arr[num] == "0"{
				left = append(left, num)
				in_arr[num] = "l"
				if len(left) == n/2{
					break
				}
			}
		}
		for num:=1; num<=n; num++{
			if num <=b && in_arr[num] == "0"{
				right = append(right, num)
				in_arr[num] = "r"
				if len(right) == n/2{
					break
				}
			}
		}
		if len(left) < n/2 || len(right) < n/2 {
			fmt.Println(-1)
		} else{
			for _, num := range left{
				fmt.Printf("%d ", num)
			}
			for _, num := range right{
				fmt.Printf("%d ", num)
			}
		}
		if i < N_INPUTS-1{
			fmt.Println()
		}
	}
}

package main

import "fmt"

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

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

func main(){
	var N_INPUTS, turn int

	fmt.Scanf("%d\n", &N_INPUTS)
	var inputs [][3]int
	var n, a, b int
	for turn=0; turn<N_INPUTS; turn++{
		fmt.Scanf("%d %d %d\n", &n, &a, &b)
		inputs = append(inputs, [3]int{n, a, b})
	}
	for _, inp := range inputs{
		n, a, b = inp[0], inp[1], inp[2]
		var left []int
		var right []int
		in_arr := make(map[int]string)
		for num:=1; num <= n; num++{
			if num < min(a,b) && len(right) < n/2{
				right = append(right, num)
				in_arr[num] = "r"
			} else if num > max(a,b) && len(left) < n/2{
				left = append(left, num)
				in_arr[num] = "l"
			} else{
				in_arr[num] = "0"
			}
		}
		for num:=1; num<=n; num++{
			if num >= a && in_arr[num] == "0"{
				left = append(left, num)
				in_arr[num] = "l"
				if len(left) == n/2{
					break
				}
			}
		}
		for num:=1; num<=n; num++{
			if num <=b && in_arr[num] == "0"{
				right = append(right, num)
				in_arr[num] = "r"
				if len(right) == n/2{
					break
				}
			}
		}
		if len(left) < n/2 || len(right) < n/2 {
			fmt.Println(-1)
		} else{
			for _, num := range left{
				fmt.Printf("%d ", num)
			}
			for _, num := range right{
				fmt.Printf("%d ", num)
			}
		}
		fmt.Println()
	}
}

package main

import "fmt"

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

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

func main(){
	var left []int
	var right []int
	var N_INPUTS int
	var n, a, b int
	in_arr := make(map[int]string)
	fmt.Scanf("%d\n", &N_INPUTS)
	fmt.Scanf("%d %d %d\n", &n, &a, &b)

	for num:=1; num <= n; num++{
		if num < min(a,b) && len(right) < n/2{
			right = append(right, num)
			in_arr[num] = "r"
		} else if num > max(a,b) && len(left) < n/2{
			left = append(left, num)
			in_arr[num] = "l"
		} else{
			in_arr[num] = "0"
		}
	}
	for num:=1; num<=n; num++{
		if num >= a && in_arr[num] == "0"{
			left = append(left, num)
			in_arr[num] = "l"
			if len(left) == n/2{
				break
			}
		}
	}
	for num:=1; num<=n; num++{
		if num <=b && in_arr[num] == "0"{
			right = append(right, num)
			in_arr[num] = "r"
			if len(right) == n/2{
				break
			}
		}
	}
	if len(left) < n/2 || len(right) < n/2 {
		fmt.Println(-1)
	} else{
		for _, num := range left{
			fmt.Printf("%d ", num)
		}
		for _, num := range right{
			fmt.Printf("%d ", num)
		}
	}
}

package main

import "fmt"

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

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

func main(){
	var left []int
	var right []int
	var N_INPUTS int
	var n, a, b int
	fmt.Scanf("%d\n", &N_INPUTS)
	fmt.Scanf("%d %d %d\n", &n, &a, &b)

	for num:=1; num <= n; num++{
		if num < min(a,b) && len(right) < n/2{
			right = append(right, num)
		} else if num > max(a,b) && len(left) < n/2{
			left = append(left, num)
		} else{
			if num >= a && len(left) < n/2{
				left = append(left, num)
			} else{
				right = append(right, num)
			}
		}
	}
	fmt.Println(left)
	fmt.Println(right)
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1612B
Date: 10/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1612/B
Problem: CF1612B
**/
func (in *CF1612B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, a, b := in.NextInt(), in.NextInt(), in.NextInt()
		if (a <= n/2 && b <= n/2) || (a > n/2 && b > n/2) {
			fmt.Println(-1)
		} else {
			arr := make([]int, n)
			arr[0] = a
			ans := true
			for i, j := n, 1; i >= 1; i-- {
				if i != a && i != b {
					arr[j] = i
					j++
					if i > n/2 && i <= a {
						ans = false
					} else if i <= n/2 && i >= b {
						ans = false
					}
				}
			}
			arr[n-1] = n
			if ans {
				for i := 0; i < n; i++ {
					fmt.Print(arr[i], " ")
				}
			} else {
				fmt.Print(-1)
			}
			fmt.Println()
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1612B
Date: 10/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1612/B
Problem: CF1612B
**/
func (in *CF1612B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, a, b := in.NextInt(), in.NextInt(), in.NextInt()
		if (a <= n/2 && b <= n/2) || (a > n/2 && b > n/2) {
			fmt.Println(-1)
		} else {
			fmt.Print(a, " ")
			if a < b {
				for i := n; i >= 1; i-- {
					if i != a && i != b {
						fmt.Printf("%d ", i)
					}
				}
			} else {
				for i := 1; i <= n; i++ {
					if i != a && i != b {
						fmt.Printf("%d ", i)
					}
				}
			}
			fmt.Printf("%d\n", b)
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1612B
Date: 10/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1612/B
Problem: CF1612B
**/
func (in *CF1612B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, a, b := in.NextInt(), in.NextInt(), in.NextInt()
		if (a <= n/2 && b <= n/2) || (a > n/2 && b > n/2) {
			fmt.Println(-1)
		} else {
			fmt.Print(a, " ")
			for i := n; i >= 1; i-- {
				if i != a && i != b {
					fmt.Printf("%d ", i)
				}
			}
			fmt.Printf("%d\n", b)
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1612B
Date: 10/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1612/B
Problem: CF1612B
**/
func (in *CF1612B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, a, b := in.NextInt(), in.NextInt(), in.NextInt()
		if (a <= n/2 && b <= n/2) || (a > n/2 && b > n/2) {
			fmt.Println(-1)
		} else {
			fmt.Print(a, " ")
			for i := 1; i <= n; i++ {
				if i != a && i != b {
					fmt.Printf("%d ", i)
				}
			}
			fmt.Printf("%d\n", b)
		}
	}
}

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

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

package main

import (
	"bufio"
	"fmt"
	"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, a, b int
		fmt.Fscan(in, &n, &a, &b)

		if (a <= n/2 && b <= n/2) || (a > n/2 && b > n/2) {
			fmt.Fprintln(out, -1)
		} else {
			for i := n; i > 0; i-- {
				d := i
				if a < b && i == b {
					d = a
				} else if a < b && i == a {
					d = b
				}
				fmt.Fprintf(out, "%d ", d)
			}
			fmt.Fprintln(out)
		}
	}
}


package main

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

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 redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

func solve() {
	var n, k int
	scan(&n, &k)
	friends := make(map[int]struct{}, k)
	for x, i := 0, 0; i < k; i++ {
		scan(&x)
		friends[x-1] = struct{}{}
	}
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		var u, v int
		scan(&u, &v)
		adj[u-1] = append(adj[u-1], v-1)
		adj[v-1] = append(adj[v-1], u-1)
	}

	minDist, _ := GetMinDistAndCnt(adj, friends)

	can, left := false, 0
	var walk func(parent, node, d int)
	walk = func(parent, node, d int) {
		if minDist[node] <= d {
			left++
			return
		}
		if node != 0 && len(adj[node]) == 1 {
			can = true
		}
		for _, next := range adj[node] {
			if next == parent {
				continue
			}
			walk(node, next, d+1)
		}
	}
	walk(-1, 0, 0)

	if can {
		printf("-1\n")
	} else {
		printf("%v\n", left)
	}
}

func GetMinDistAndCnt(adj [][]int, friends map[int]struct{}) ([]int, []int) {
	mindist := make([]int, len(adj))
	cnt := make([]int, len(adj))
	var walk func(parent, node int) (int, int)
	walk = func(parent, node int) (int, int) {
		D, C := (1 << 30), 0
		if _, ok := friends[node]; ok {
			D, C = 0, 1
		}
		for _, next := range adj[node] {
			if next == parent {
				continue
			}
			d, c := walk(node, next)
			C += c
			if D > d+1 {
				D = d + 1
			}
		}
		mindist[node] = D
		cnt[node] = C
		return D, C
	}
	walk(-1, 0)
	return mindist, cnt
}

package main
import (
  "fmt"
  "bufio"
  "os"
  "strconv"
)
/*
题意：一棵树中，V在根节点1，k个朋友分布在其他k个节点。若V到达任意叶节点，则V赢；
若V到达之前被任何朋友遇到，则朋友赢；求朋友赢的最小节点集合的大小，若V始终赢，返回-1。

若u子树中存在朋友f且dist(f,u)<=dist(u,1)，那么u子树只需要f这一个人就够了，
若u节点存在朋友则返回1，若到达叶节点则返回-1，任意子树返回-1则V赢。
dist(f,u)通过自底向上递推得到，up[u]表示u与最近的朋友节点的距离，up[f]=0。
*/
var sc *bufio.Scanner
func min(a,b int)int{if a<b{return a};return b}
func I()int{sc.Scan();v,_:=strconv.Atoi(sc.Text());return v}
func main(){
  inp,out:=os.Stdin,os.Stdout
  sc=bufio.NewScanner(inp);W:=bufio.NewWriter(out);sc.Split(bufio.ScanWords);defer W.Flush()

  t:=I()
  for i:=0;i<t;i++{
    n,k:=I(),I();up:=make([]int,n+1);for j:=1;j<=n;j++{up[j]=n};for j:=0;j<k;j++{up[I()]=0}
    G:=map[int][]int{}
    for i:=0;i<n-1;i++{u,v:=I(),I();G[u]=append(G[u],v);G[v]=append(G[v],u)}

    var f func(int,int,int)(int)
    f=func(u,fa,d int)(z int){
      sons:=true
      for _,v:=range G[u]{
        if v!=fa{
          s:=f(v,u,d+1)
          if s<0{sons=false}
          up[u]=min(up[u],up[v]+1);z+=s
        }
      }
      if up[u]<=d{return 1}
      if z==0 || !sons{return -1}
      return
    }
    fmt.Fprintln(W,f(1,0,0))
  }
}

package main
import (
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc *bufio.Scanner
func min(a,b int)int{if a<b{return a};return b}
func I()int{sc.Scan();v,_:=strconv.Atoi(sc.Text());return v}
func main(){
  inp,out:=os.Stdin,os.Stdout
  sc=bufio.NewScanner(inp);W:=bufio.NewWriter(out);sc.Split(bufio.ScanWords);defer W.Flush()

  t:=I()
  for i:=0;i<t;i++{
    n,k:=I(),I();up:=make([]int,n+1);for j:=1;j<=n;j++{up[j]=n};for j:=0;j<k;j++{up[I()]=0}
    G:=map[int][]int{}
    for i:=0;i<n-1;i++{u,v:=I(),I();G[u]=append(G[u],v);G[v]=append(G[v],u)}

    var f func(int,int,int)(int)
    f=func(u,fa,d int)(z int){
      child:=true
      for _,v:=range G[u]{
        if v!=fa{
          c:=f(v,u,d+1)
          if c<0{child=false}
          up[u]=min(up[u],up[v]+1);z+=c
        }
      }
      if up[u]<=d{return 1}
      if z==0 || !child{return -1}
      return
    }
    fmt.Fprintln(W,f(1,0,0))
  }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1611E2(_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)
		fr := make([]bool, n)
		for ; k > 0; k-- {
			Fscan(in, &v)
			fr[v-1] = true
		}
		g := 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)
		}

		minDep := make([]int, n)
		var build func(v, fa, d int)
		build = func(v, fa, d int) {
			minDep[v] = 1e9
			if fr[v] {
				minDep[v] = d
			}
			for _, w := range g[v] {
				if w != fa {
					build(w, v, d+1)
					minDep[v] = min(minDep[v], minDep[w])
				}
			}
		}
		build(0, -1, 0)

		var f func(v, fa, d int) int
		f = func(v, fa, d int) (ans int) {
			if d*2 >= minDep[v] {
				return 1
			}
			for _, w := range g[v] {
				if w != fa {
					res := f(w, v, d+1)
					if res < 0 {
						return -1
					}
					ans += res
				}
			}
			if ans == 0 {
				return -1
			}
			return
		}
		Fprintln(out, f(0, -1, 0))
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1611E2(_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)
		fr := make([]bool, n)
		for ; k > 0; k-- {
			Fscan(in, &v)
			fr[v-1] = true
		}
		g := 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)
		}

		minDep := make([]int, n)
		size := make([]int, n)
		var build func(v, fa, d int)
		build = func(v, fa, d int) {
			minDep[v] = 1e9
			if fr[v] {
				minDep[v] = d
				size[v] = 1
			}
			for _, w := range g[v] {
				if w != fa {
					build(w, v, d+1)
					minDep[v] = min(minDep[v], minDep[w])
					size[v] += size[w]
				}
			}
		}
		build(0, -1, 0)

		var f func(v, fa, d int) int
		f = func(v, fa, d int) (ans int) {
			if d*2 >= minDep[v] {
				return 1
			}
			if size[v] == 0 {
				return -1
			}
			for _, w := range g[v] {
				if w != fa {
					res := f(w, v, d+1)
					if res < 0 {
						return -1
					}
					ans += res
				}
			}
			return
		}
		Fprintln(out, f(0, -1, 0))
	}
}

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

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

package main

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

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 redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

func solve() {
	var n, k int
	scan(&n, &k)
	friends := make(map[int]struct{}, k)
	for x, i := 0, 0; i < k; i++ {
		scan(&x)
		friends[x-1] = struct{}{}
	}
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		var u, v int
		scan(&u, &v)
		adj[u-1] = append(adj[u-1], v-1)
		adj[v-1] = append(adj[v-1], u-1)
	}

	minDist := GetMinDist(adj, friends)

	can, left := false, 0
	var walk func(parent, node, d int)
	walk = func(parent, node, d int) {
		if minDist[node] <= d {
			left++
			return
		}
		if node != 0 && len(adj[node]) == 1 {
			can = true
		}
		for _, next := range adj[node] {
			if next == parent {
				continue
			}
			walk(node, next, d+1)
		}
	}
	walk(-1, 0, 0)

	if can {
		printf("-1\n")
	} else {
		printf("%v\n", left)
	}
}

func GetMinDist(adj [][]int, friends map[int]struct{}) []int {
	dist := make([]int, len(adj))
	for i := range dist {
		dist[i] = (1 << 30)
	}
	var walk func(parent, node int)
	walk = func(parent, node int) {
		if _, ok := friends[node]; ok {
			dist[node] = 0
			return
		}
		for _, next := range adj[node] {
			if next == parent {
				continue
			}
			walk(node, next)
			if dist[node] > dist[next]+1 {
				dist[node] = dist[next] + 1
			}
		}
	}
	walk(-1, 0)
	return dist
}

package main

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

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

const (
	MaxN int = 2e5 + 5
)

type Edge struct {
	u, v int
}

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

func NewGraph(n int) *Graph {
	return &Graph{
		adj: make([][]int, n+1),
		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 (
	T         int
	n, k      int
	g         *Graph
	deadPoint []bool
	ans       int
)

func calcDeadPoint(u int, dep int, par int) int {
	deadP := 0
	if deadPoint[u] {
		deadP = (dep + 1) / 2
	}
	for _, i := range g.adj[u] {
		v := g.e[i].v
		if v == par {
			continue
		}
		vDeadP := calcDeadPoint(v, dep+1, u)
		if (deadP == 0 || vDeadP < deadP) && vDeadP != 0 {
			deadP = vDeadP
		}
	}
	if dep == deadP {
		deadPoint[u] = true
	}
	return deadP
}

func calcPath(u int, par int) bool {
	if deadPoint[u] {
		ans++
		return false
	}

	isLeaf := true

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

		isLeaf = false
		if calcPath(v, u) {
			return true
		}
	}

	return isLeaf
}

func Init() {
	g = NewGraph(n)
	deadPoint = make([]bool, n+1)
}

func main() {
	_, _ = fmt.Fscan(rr, &T)
	for iCase := 0; iCase < T; iCase++ {
		_, _ = fmt.Fscan(rr, &n, &k)

		Init()

		for i := 0; i < k; i++ {
			var u int
			_, _ = fmt.Fscan(rr, &u)
			deadPoint[u] = true
		}

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

		calcDeadPoint(1, 0, 0)
		ans = 0
		if calcPath(1, 0) {
			_, _ = fmt.Fprintln(ww, -1)
		} else {
			_, _ = fmt.Fprintln(ww, ans)
		}
	}
	_ = ww.Flush()
}

package main

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

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n, k int
		fmt.Fscan(in, &n, &k)
		var friends = make(map[int]struct{})
		for i := 0; i < k; i++ {
			var x int
			fmt.Fscan(in, &x)
			x--
			friends[x] = struct{}{}
		}
		//fmt.Fprintln(out, "friends", friends)
		var g = make([][]int, n)
		for i := 0; i < n; i++ {
			g[i] = make([]int, 0)
		}
		for i := 0; i < n - 1; i++ {
			var v, u int
			fmt.Fscan(in, &v, &u)
			v--; u--
			//fmt.Fprintln(out, "v:", v, "u:", u)
			g[v] = append(g[v], u)
			g[u] = append(g[u], v)
		}
		//fmt.Fprintln(out, "g", g)

		var dp = make([]int, n)
		for i := 0; i < n; i++ {
			dp[i] = -1
		}
		var dfs func(v int, par int, len int) int
		dfs = func(v int, par int, len int) int {
			if _, ok := friends[v]; ok {
				dp[v] = len/2
			}
			for _, u := range g[v] {
				if par == u {
					continue
				}
				dp[v] = max(dp[v], dfs(u, v, len + 1) - 1)
			}
			return dp[v]
		}

		dfs(0, -1, 0)
		//fmt.Fprintln(out, "dp", dp)

		var ans func(v int, par int) int
		ans = func(v int, par int) int {
			//fmt.Fprintln(out, "ans(v)", v)
			if dp[v] >= 0 {
				return 1
			}
			var sum int
			leaf := true
			for _, u := range g[v] {
				if par == u {
					continue
				}
				leaf = false
				res := ans(u, v)
				if res < 0 {
					return -1
				}
				sum += res
			}
			if leaf {
				return -1
			}
			return sum
		}

		fmt.Fprintln(out, ans(0, -1))
	}
}

package main

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

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

var tree [][]int
var mark []bool
var rootDist []int

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

func count(node, parent int) (bool, int) {
	if mark[node] {
		return true, 1
	}
	if node != 1 && len(tree[node]) == 1 {
		return false, 0
	}
	var ans = 0
	for _, child := range tree[node] {
		if child != parent {
			flag, childCnt := count(child, node)
			if !flag {
				return false, 0
			}
			ans += childCnt
		}
	}
	return true, ans
}

func dfs(node, parent, dist int) int {
	var markDist int = 1e9
	if mark[node] {
		markDist = 0
	}
	rootDist[node] = dist
	for _, child := range tree[node] {
		if child != parent {
			markDist = min(markDist, dfs(child, node, dist+1)+1)
		}
	}

	if markDist <= rootDist[node] {
		mark[node] = true
	}
	return markDist
}

func solveCase() int {
	var n, k, a, b int
	fmt.Fscan(in, &n, &k)
	tree = make([][]int, n+1)
	mark = make([]bool, n+1)
	rootDist = make([]int, n+1)

	for i := 0; i < k; i++ {
		fmt.Fscan(in, &a)
		mark[a] = true
	}

	for i := 0; i < n-1; i++ {
		fmt.Fscan(in, &a, &b)
		tree[a] = append(tree[a], b)
		tree[b] = append(tree[b], a)
	}

	dfs(1, 1, 0)
	ok, cnt := count(1, 1)
	if !ok {
		return -1
	}
	return cnt
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fprintf(out, "%d\n", solveCase())
	}
	out.Flush()
}

package main
import (
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc *bufio.Scanner
func I()int{sc.Scan();v,_:=strconv.Atoi(sc.Text());return v}
func main(){
  inp,out:=os.Stdin,os.Stdout
  sc=bufio.NewScanner(inp);W:=bufio.NewWriter(out);sc.Split(bufio.ScanWords);defer W.Flush()

  t:=I()
  for i:=0;i<t;i++{
    n,k:=I(),I();Fris:=map[int]bool{}
    for j:=0;j<k;j++{Fris[I()]=true}
    G:=map[int][]int{}
    for i:=0;i<n-1;i++{u,v:=I(),I();G[u]=append(G[u],v);G[v]=append(G[v],u)}

    z,zs:=1,map[int]bool{}
    var f func(int,int,int)(bool,[]int)
    f=func(u,fa,d int)(lef bool,fri []int){//返回lef,fri
      if ok:=Fris[u];ok{zs[u]=true;return lef,[]int{d+1,u}}
      lef,fri=true,[]int{n,n+1}
      for _,v:=range G[u]{
        if v!=fa{
          lef=false;lef0,fri0:=f(v,u,d+1)
          lef=lef || lef0
          if fri0[0]<fri[0]{fri=fri0}
        }
      }
      if fri[0]!=n{lef=false}else{fri=[]int{0,0}}
      if lef && (fri[0]==0 || d<fri[0]-d){z=-1;return}
      zs[fri[1]]=true;return
    }
    _,_=f(1,0,0)
    if z>0{z=len(zs)}
    fmt.Fprintln(W,z)
  }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1611E2(_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)
		fr := make([]bool, n)
		for ; k > 0; k-- {
			Fscan(in, &v)
			fr[v-1] = true
		}
		g := 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)
		}

		var f func(v, fa, d int) (int, int)
		f = func(v, fa, d int) (int, int) {
			if fr[v] {
				return 1, d
			}
			ans, minD := 0, int(1e9)
			for _, w := range g[v] {
				if w != fa {
					res, dd := f(w, v, d+1)
					if res < 0 {
						return -1, 0
					}
					ans += res
					if dd < minD {
						minD = dd
					}
				}
			}
			if d*2 >= minD {
				return 1, minD
			}
			if ans == 0 {
				return -1, 0
			}
			return ans, minD
		}
		ans, _ := f(0, -1, 0)
		Fprintln(out, ans)
	}
}

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

package main

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

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

const (
	MaxN int = 2e5 + 5
)

type Edge struct {
	u, v int
}

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

func NewGraph(n int) *Graph {
	return &Graph{
		adj: make([][]int, n+1),
		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 (
	T         int
	n, k      int
	g         *Graph
	deadPoint []bool
	ans       int
)

func calcDeadPoint(u int, dep int, par int) int {
	deadP := 0
	if deadPoint[u] {
		deadP = (dep + 1) / 2
	}
	for _, i := range g.adj[u] {
		v := g.e[i].v
		if v == par {
			continue
		}
		vDeadP := calcDeadPoint(v, dep+1, u)
		if (deadP == 0 || vDeadP < deadP) && vDeadP != 0 {
			deadP = vDeadP
		}
	}
	if dep == deadP {
		deadPoint[u] = true
	}
	return deadP
}

func calcPath(u int, par int) bool {
	if deadPoint[u] {
		return false
	}

	isLeaf := true

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

		isLeaf = false
		if calcPath(v, u) {
			return true
		} else {
			ans++
		}
	}

	return isLeaf
}

func Init() {
	g = NewGraph(n)
	deadPoint = make([]bool, n+1)
}

func main() {
	_, _ = fmt.Fscan(rr, &T)
	for iCase := 0; iCase < T; iCase++ {
		_, _ = fmt.Fscan(rr, &n, &k)

		Init()

		for i := 0; i < k; i++ {
			var u int
			_, _ = fmt.Fscan(rr, &u)
			deadPoint[u] = true
		}

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

		calcDeadPoint(1, 0, 0)
		ans = 0
		if calcPath(1, 0) {
			_, _ = fmt.Fprintln(ww, -1)
		} else {
			_, _ = fmt.Fprintln(ww, ans)
		}
	}
	_ = ww.Flush()
}


package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		// fmt.Fprintln(w, "TTTTTTTTTT ", T) // ***

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

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d1[i])
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d2[i])
		}

		sort.Ints(d1)
		sort.Ints(d2)

		h := make([]int, n)
		var p1, p2, N int

		for _, v := range d2 {
			// fmt.Fprintln(w, "OOOOOOOOOOOOOOO ", v) // ***
			for _, l := range []int{d1[0]+v, abs(d1[0]-v)} {
				// fmt.Fprintln(w, "IIIIIIII ", l) // ***
				if l > int(2e9) { continue }
				if d2[n-1] > l {
					p1 = d2[n-1] - l
				} else {
					p1 = 0
				}
				p2 = p1 + l
				N = 0

				cm1 := make(map[int]int)
				cm2 := make(map[int]int)

				for i := 0; i < n; i++ {
					cm1[d1[i]]++
					cm2[d2[i]]++
				}

				i := n-1
				j := n-1

				for i >= 0 && j >= 0 && (d1[i] >= l || d2[j] >= l) {
					if d1[i] > d2[j] {
						if cm2[d1[i]-l] > 0 && cm1[d1[i]] > 0 {
							cm2[d1[i]-l]--
							cm1[d1[i]]--
							h[N] = p1 + d1[i]
							N++
						}
						i--
					} else {
						if cm1[d2[j]-l] > 0 && cm2[d2[j]] > 0 {
							cm1[d2[j]-l]--
							cm2[d2[j]]--
							h[N] = p1 + l - d2[j]
							N++
						}
						j--
					}
				}

				for i = 0; i < n && d1[i] < l; i++ {
					if cm2[l-d1[i]] > 0 && cm1[d1[i]] > 0 {
						cm2[l-d1[i]]--
						cm1[d1[i]]--
						h[N] = p1 + d1[i]
						N++
					}
				}

				/*
				for i := 0; i < n && d2[i] < l; i++ {
					if cm1[l-d2[i]] > 0 && cm2[d2[i]] > 0 {
						cm1[l-d2[i]]--
						cm2[d2[i]]--
						h[N] = l - d2[i]
					}
				}
				*/

				if N == n {
					break
				}
			}

			if N == n {
				break
			}

		}

		// fmt.Fprintln(w, "NNNNNNNN ", N)
		if N != n {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", h[i])
			}
			fmt.Fprintf(w, "\n%d %d\n", p1, p2)
		}

	}

}

package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		// fmt.Fprintln(w, "TTTTTTTTTT ", T) // ***

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

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d1[i])
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d2[i])
		}

		sort.Ints(d1)
		sort.Ints(d2)

		vis := make(map[int]bool)
		h := make([]int, n)
		var p1, p2, N int

		for _, v := range d2 {
			// fmt.Fprintln(w, "OOOOOOOOOOOOOOO ", v) // ***
			for _, l := range []int{d1[0]+v, abs(d1[0]-v)} {
				// fmt.Fprintln(w, "IIIIIIII ", l) // ***
				if l > int(2e9) { continue }
				if vis[l] { continue }
				vis[l] = true
				if d2[n-1] > l {
					p1 = d2[n-1] - l
				} else {
					p1 = 0
				}
				p2 = p1 + l
				N = 0

				cm1 := make(map[int]int)
				cm2 := make(map[int]int)

				for i := 0; i < n; i++ {
					cm1[d1[i]]++
					cm2[d2[i]]++
				}

				i := n-1
				j := n-1

				for i >= 0 && j >= 0 && (d1[i] >= l || d2[j] >= l) {
					if d1[i] > d2[j] {
						if cm2[d1[i]-l] > 0 && cm1[d1[i]] > 0 {
							cm2[d1[i]-l]--
							cm1[d1[i]]--
							h[N] = p1 + d1[i]
							N++
						}
						i--
					} else {
						if cm1[d2[j]-l] > 0 && cm2[d2[j]] > 0 {
							cm1[d2[j]-l]--
							cm2[d2[j]]--
							h[N] = p1 + l - d2[j]
							N++
						}
						j--
					}
				}

				for i = 0; i < n && d1[i] < l; i++ {
					if cm2[l-d1[i]] > 0 && cm1[d1[i]] > 0 {
						cm2[l-d1[i]]--
						cm1[d1[i]]--
						h[N] = p1 + d1[i]
						N++
					}
				}

				/*
				for i := 0; i < n && d2[i] < l; i++ {
					if cm1[l-d2[i]] > 0 && cm2[d2[i]] > 0 {
						cm1[l-d2[i]]--
						cm2[d2[i]]--
						h[N] = l - d2[i]
					}
				}
				*/

				if N == n {
					break
				}
			}

			if N == n {
				break
			}

		}

		// fmt.Fprintln(w, "NNNNNNNN ", N)
		if N != n {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", h[i])
			}
			fmt.Fprintf(w, "\n%d %d\n", p1, p2)
		}

	}

}

package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		// fmt.Fprintln(w, "TTTTTTTTTT ", T) // ***

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

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d1[i])
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d2[i])
		}

		sort.Ints(d1)
		sort.Ints(d2)

		h := make([]int, n)
		var p1, p2, N int

		for _, v := range d2 {
			// fmt.Fprintln(w, "OOOOOOOOOOOOOOO ", v) // ***
			for _, l := range []int{d1[0]+v, abs(d1[0]-v)} {
				// fmt.Fprintln(w, "IIIIIIII ", l) // ***
				p1 = d2[n-1]
				p2 = d2[n-1] + l
				N = 0

				cm1 := make(map[int]int)
				cm2 := make(map[int]int)

				for i := 0; i < n; i++ {
					cm1[d1[i]]++
					cm2[d2[i]]++
				}

				i := n-1
				j := n-1

				for i >= 0 && j >= 0 && (d1[i] >= l || d2[j] >= l) {
					if d1[i] > d2[j] {
						if cm2[d1[i]-l] > 0 && cm1[d1[i]] > 0 {
							cm2[d1[i]-l]--
							cm1[d1[i]]--
							h[N] = p1 + d1[i]
							N++
						}
						i--
					} else {
						if cm1[d2[j]-l] > 0 && cm2[d2[j]] > 0 {
							cm1[d2[j]-l]--
							cm2[d2[j]]--
							h[N] = p1 + l - d2[j]
							N++
						}
						j--
					}
				}

				for i = 0; i < n && d1[i] < l; i++ {
					if cm2[l-d1[i]] > 0 && cm1[d1[i]] > 0 {
						cm2[l-d1[i]]--
						cm1[d1[i]]--
						h[N] = p1 + d1[i]
						N++
					}
				}

				/*
				for i := 0; i < n && d2[i] < l; i++ {
					if cm1[l-d2[i]] > 0 && cm2[d2[i]] > 0 {
						cm1[l-d2[i]]--
						cm2[d2[i]]--
						h[N] = l - d2[i]
					}
				}
				*/

				if N == n {
					break
				}
			}

			if N == n {
				break
			}

		}

		// fmt.Fprintln(w, "NNNNNNNN ", N)
		if N != n {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", h[i])
			}
			fmt.Fprintf(w, "\n%d %d\n", p1, p2)
		}

	}

}

package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		// fmt.Fprintln(w, "TTTTTTTTTT ", T) // ***

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

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d1[i])
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d2[i])
		}

		sort.Ints(d1)
		sort.Ints(d2)

		h := make([]int, n)
		var p1, p2, N int

		for _, v := range d2 {
			// fmt.Fprintln(w, "OOOOOOOOOOOOOOO ", v) // ***
			for _, l := range []int{d1[0]+v, abs(d1[0]-v)} {
				// fmt.Fprintln(w, "IIIIIIII ", l) // ***
				p1 = d2[n-1]
				p2 = d2[n-1] + l
				N = 0

				cm1 := make(map[int]int)
				cm2 := make(map[int]int)

				for i := 0; i < n; i++ {
					cm1[d1[i]]++
					cm2[d2[i]]++
				}

				for i := n-1; i >= 0 && d1[i] >= l; i-- {
					if cm2[d1[i]-l] > 0 && cm1[d1[i]] > 0 {
						cm2[d1[i]-l]--
						cm1[d1[i]]--
						h[N] = p1 + d1[i]
						N++
					}
				}

				for i := n-1; i >= 0 && d2[i] >= l; i-- {
					if cm1[d2[i]-l] > 0 && cm2[d2[i]] > 0 {
						cm1[d2[i]-l]--
						cm2[d2[i]]--
						h[N] = p1 + l - d2[i]
						N++
					}
				}

				for i := 0; i < n && d1[i] < l; i++ {
					if cm2[l-d1[i]] > 0 && cm1[d1[i]] > 0 {
						cm2[l-d1[i]]--
						cm1[d1[i]]--
						h[N] = p1 + d1[i]
						N++
					}
				}

				/*
				for i := 0; i < n && d2[i] < l; i++ {
					if cm1[l-d2[i]] > 0 && cm2[d2[i]] > 0 {
						cm1[l-d2[i]]--
						cm2[d2[i]]--
						h[N] = l - d2[i]
					}
				}
				*/

				if N == n {
					break
				}
			}

			if N == n {
				break
			}

		}

		// fmt.Fprintln(w, "NNNNNNNN ", N)
		if N != n {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", h[i])
			}
			fmt.Fprintf(w, "\n%d %d\n", p1, p2)
		}

	}

}

package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		// fmt.Fprintln(w, "TTTTTTTTTT ", T) // ***

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

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d1[i])
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d2[i])
		}

		sort.Ints(d1)
		sort.Ints(d2)

		h := make([]int, n)
		var p1, p2, N int

		for _, v := range d2 {
			// fmt.Fprintln(w, "OOOOOOOOOOOOOOO ", v) // ***
			for _, l := range []int{d1[0]+v, abs(d1[0]-v)} {
				// fmt.Fprintln(w, "IIIIIIII ", l) // ***
				p1 = 0
				p2 = l
				N = 0

				cm1 := make(map[int]int)
				cm2 := make(map[int]int)

				for i := 0; i < n; i++ {
					cm1[d1[i]]++
					cm2[d2[i]]++
				}

				for i := n-1; i >= 0 && d1[i] >= l; i-- {
					if cm2[d1[i]-l] > 0 && cm1[d1[i]] > 0 {
						cm2[d1[i]-l]--
						cm1[d1[i]]--
						h[N] = d1[i]
						N++
					}
				}

				for i := n-1; i >= 0 && d2[i] >= l; i-- {
					if cm1[d2[i]-l] > 0 && cm2[d2[i]] > 0 {
						cm1[d2[i]-l]--
						cm2[d2[i]]--
						h[N] = l - d2[i]
						N++
					}
				}

				for i := 0; i < n && d1[i] < l; i++ {
					if cm2[l-d1[i]] > 0 && cm1[d1[i]] > 0 {
						cm2[l-d1[i]]--
						cm1[d1[i]]--
						h[N] = d1[i]
						N++
					}
				}

				/*
				for i := 0; i < n && d2[i] < l; i++ {
					if cm1[l-d2[i]] > 0 && cm2[d2[i]] > 0 {
						cm1[l-d2[i]]--
						cm2[d2[i]]--
						h[N] = l - d2[i]
					}
				}
				*/

				if N == n {
					break
				}
			}

			if N == n {
				break
			}

		}

		// fmt.Fprintln(w, "NNNNNNNN ", N)
		if N != n {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", h[i])
			}
			fmt.Fprintf(w, "\n%d %d\n", p1, p2)
		}

	}

}

package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		fmt.Fprintln(w, "TTTTTTTTTT ", T) // ***

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

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d1[i])
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &d2[i])
		}

		sort.Ints(d1)
		sort.Ints(d2)

		h := make([]int, n)
		var p1, p2, N int

		for _, v := range d2 {
			fmt.Fprintln(w, "OOOOOOOOOOOOOOO ", v) // ***
			for _, l := range []int{d1[0]+v, abs(d1[0]-v)} {
				fmt.Fprintln(w, "IIIIIIII ", l) // ***
				p1 = 0
				p2 = l
				N = 0

				cm1 := make(map[int]int)
				cm2 := make(map[int]int)

				for i := 0; i < n; i++ {
					cm1[d1[i]]++
					cm2[d2[i]]++
				}

				for i := n-1; i >= 0 && d1[i] >= l; i-- {
					if cm2[d1[i]-l] > 0 && cm1[d1[i]] > 0 {
						cm2[d1[i]-l]--
						cm1[d1[i]]--
						h[N] = d1[i]
						N++
					}
				}

				for i := n-1; i >= 0 && d2[i] >= l; i-- {
					if cm1[d2[i]-l] > 0 && cm2[d2[i]] > 0 {
						cm1[d2[i]-l]--
						cm2[d2[i]]--
						h[N] = l - d2[i]
						N++
					}
				}

				for i := 0; i < n && d1[i] < l; i++ {
					if cm2[l-d1[i]] > 0 && cm1[d1[i]] > 0 {
						cm2[l-d1[i]]--
						cm1[d1[i]]--
						h[N] = d1[i]
						N++
					}
				}

				/*
				for i := 0; i < n && d2[i] < l; i++ {
					if cm1[l-d2[i]] > 0 && cm2[d2[i]] > 0 {
						cm1[l-d2[i]]--
						cm2[d2[i]]--
						h[N] = l - d2[i]
					}
				}
				*/

				if N == n {
					break
				}
			}

			if N == n {
				break
			}

		}

		fmt.Fprintln(w, "NNNNNNNN ", N)
		if N != n {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", h[i])
			}
			fmt.Fprintf(w, "\n%d %d\n", p1, p2)
		}

	}

}


package main

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

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

var s, g, x, y, a [200005]int64

func main() {
  in := bufio.NewReader(os.Stdin)
  var n int
  fmt.Fscanf(in, "%d\n", &n)
  for i := 1; i <= n; i++ {
    fmt.Fscanf(in, "%d %d\n",&s[i],&g[i])
    if i == 1 {
      x[i] = s[i]+g[i]
    } else {
      x[i] = min(x[i-1]+1, s[i]+g[i])
    }
  }
  var tot int64
  for i := n; 1 <= i; i-- {
    if i == n {
      y[n] = s[n]+g[n]
    } else {
      y[i] = min(y[i+1]+1, s[i]+g[i])
    }
    a[i] = min(x[i], y[i])
    if s[i] <= a[i] && a[i] <= s[i]+g[i] {
      tot += a[i]-s[i]
    } else {
      fmt.Printf("-1\n")
      return
    }
  }
  out := bufio.NewWriter(os.Stdout)
  fmt.Fprintf(out, "%d\n", tot)
  for i := 1; i <= n; i++ {
    if i > 1 {
      fmt.Fprintf(out, " ")
    }
    fmt.Fprintf(out, "%d",a[i])
  }
  fmt.Fprintf(out, "\n")
  out.Flush()
}

package main

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

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

// io functions
var stdin *bufio.Reader
var stdout *bufio.Writer
func fastio() {
  stdin = bufio.NewReader(os.Stdin)
  stdout = bufio.NewWriter(os.Stdout)
}
func scan(buf ...interface{}) {
  for _, a := range buf {
    fmt.Fscan(stdin, a)
  }
}
func dbg(x ...interface{}) {
  if os.Getenv("LOCAL") != "true" {
    return
  }
  fmt.Fprint(os.Stderr, ">>>>")
  for _, a := range x {
    fmt.Fprint(os.Stderr, " ", a)
  }
  fmt.Fprintln(os.Stderr)
}

func main() {
  fastio()
  var n int
  scan(&n)
  s := make([]int64, n+1)
  g := make([]int64, n+1)
  x := make([]int64, n+1)
  y := make([]int64, n+1)
  a := make([]int64, n+1)
  for i := 1; i <= n; i++ {
    scan(&s[i],&g[i])
    dbg(s[i])
    if i == 1 {
      x[i] = s[i]+g[i]
    } else {
      x[i] = min(x[i-1]+1, s[i]+g[i])
    }
  }
  var tot int64
  for i := n; 1 <= i; i-- {
    if i == n {
      y[n] = s[n]+g[n]
    } else {
      y[i] = min(y[i+1]+1, s[i]+g[i])
    }
    a[i] = min(x[i], y[i])
    if s[i] <= a[i] && a[i] <= s[i]+g[i] {
      tot += a[i]-s[i]
    } else {
      fmt.Printf("-1\n")
      return
    }
  }
  fmt.Fprintf(stdout, "%d\n", tot)
  for i := 1; i <= n; i++ {
    if i > 1 {
      fmt.Fprintf(stdout, " ")
    }
    fmt.Fprintf(stdout, "%d",a[i])
  }
  fmt.Fprintf(stdout, "\n")
  stdout.Flush()
}

package main

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

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

// io functions
var stdin *bufio.Reader
var stdout *bufio.Writer
func fastio() {
  stdin = bufio.NewReader(os.Stdin)
  stdout = bufio.NewWriter(os.Stdout)
}
func scan(buf ...interface{}) {
  for _, a := range buf {
    fmt.Fscan(stdin, a)
  }
}
func dbg(x ...interface{}) {
  fmt.Fprint(os.Stderr, ">>>>")
  for _, a := range x {
    fmt.Fprint(os.Stderr, " ", a)
  }
  fmt.Fprintln(os.Stderr)
}

func main() {
  fastio()
  var n int
  scan(&n)
  s := make([]int64, n+1)
  g := make([]int64, n+1)
  x := make([]int64, n+1)
  y := make([]int64, n+1)
  a := make([]int64, n+1)
  for i := 1; i <= n; i++ {
    scan(&s[i],&g[i])
    if i == 1 {
      x[i] = s[i]+g[i]
    } else {
      x[i] = min(x[i-1]+1, s[i]+g[i])
    }
  }
  var tot int64
  for i := n; 1 <= i; i-- {
    if i == n {
      y[n] = s[n]+g[n]
    } else {
      y[i] = min(y[i+1]+1, s[i]+g[i])
    }
    a[i] = min(x[i], y[i])
    if s[i] <= a[i] && a[i] <= s[i]+g[i] {
      tot += a[i]-s[i]
    } else {
      fmt.Printf("-1\n")
      return
    }
  }
  fmt.Fprintf(stdout, "%d\n", tot)
  for i := 1; i <= n; i++ {
    if i > 1 {
      fmt.Fprintf(stdout, " ")
    }
    fmt.Fprintf(stdout, "%d",a[i])
  }
  fmt.Fprintf(stdout, "\n")
  stdout.Flush()
}

package main

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

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

var s, g, x, y, a [200005]int64

func main() {
  in := bufio.NewReader(os.Stdin)
  var n int
  fmt.Fscanf(in, "%d\n", &n)
  for i := 1; i <= n; i++ {
    fmt.Fscanf(in, "%d %d\n",&s[i],&g[i])
    if i == 1 {
      x[i] = s[i]+g[i]
    } else {
      x[i] = min(x[i-1]+1, s[i]+g[i])
    }
  }
  var tot int64
  for i := n; 1 <= i; i-- {
    if i == n {
      y[n] = s[n]+g[n]
    } else {
      y[i] = min(y[i+1]+1, s[i]+g[i])
    }
    a[i] = min(x[i], y[i])
    if s[i] <= a[i] && a[i] <= s[i]+g[i] {
      tot += a[i]-s[i]
    } else {
      fmt.Printf("-1\n")
      return
    }
  }
  fmt.Printf("%d\n", tot)
  for i := 1; i <= n; i++ {
    if i > 1 {
      fmt.Printf(" ")
    }
    fmt.Printf("%d",a[i])
  }
  fmt.Printf("\n")
}

package main

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

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

// io functions
var stdin *bufio.Reader
var stdout *bufio.Writer
func fastio() {
  stdin = bufio.NewReader(os.Stdin)
  stdout = bufio.NewWriter(os.Stdout)
}
func scan(buf ...interface{}) {
  for _, a := range buf {
    fmt.Fscan(stdin, a)
  }
}
func dbg(x ...interface{}) {
  fmt.Fprint(os.Stderr, ">>>>")
  for _, a := range x {
    fmt.Fprint(os.Stderr, " ", a)
  }
  fmt.Fprintln(os.Stderr)
}

func main() {
  fastio()
  var n int
  scan(&n)
  dbg(n)
  s := make([]int64, n+1)
  g := make([]int64, n+1)
  x := make([]int64, n+1)
  y := make([]int64, n+1)
  a := make([]int64, n+1)
  for i := 1; i <= n; i++ {
    scan(&s[i],&g[i])
    dbg(s[i], g[i])
    if i == 1 {
      x[i] = s[i]+g[i]
    } else {
      x[i] = min(x[i-1]+1, s[i]+g[i])
    }
  }
  var tot int64
  for i := n; 1 <= i; i-- {
    if i == n {
      y[n] = s[n]+g[n]
    } else {
      y[i] = min(y[i+1]+1, s[i]+g[i])
    }
    a[i] = min(x[i], y[i])
    if s[i] <= a[i] && a[i] <= s[i]+g[i] {
      tot += a[i]-s[i]
    } else {
      fmt.Printf("-1\n")
      return
    }
  }
  fmt.Fprintf(stdout, "%d\n", tot)
  for i := 1; i <= n; i++ {
    if i > 1 {
      fmt.Fprintf(stdout, " ")
    }
    fmt.Fprintf(stdout, "%d",a[i])
  }
  fmt.Fprintf(stdout, "\n")
  stdout.Flush()
}

package main

import "fmt"
import "unsafe"

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

var s, g, x, y, a [200005]int

func main() {
  var varr int
  fmt.Println("sizeof(int) =",unsafe.Sizeof(varr))
  var n int
  fmt.Scanf("%d\n", &n)
  for i := 1; i <= n; i++ {
    fmt.Scanf("%d %d\n",&s[i],&g[i])
    if i == 1 {
      x[i] = s[i]+g[i]
    } else {
      x[i] = min(x[i-1]+1, s[i]+g[i])
    }
  }
  var tot int
  for i := n; 1 <= i; i-- {
    if i == n {
      y[n] = s[n]+g[n]
    } else {
      y[i] = min(y[i+1]+1, s[i]+g[i])
    }
    a[i] = min(x[i], y[i])
    if s[i] <= a[i] && a[i] <= s[i]+g[i] {
      tot += a[i]-s[i]
    } else {
      fmt.Printf("-1\n")
      return
    }
  }
  fmt.Printf("%d\n", tot)
  for i := 1; i <= n; i++ {
    if i > 1 {
      fmt.Printf(" ")
    }
    fmt.Printf("%d",a[i])
  }
  fmt.Printf("\n")
}

package main

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

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

// io functions
var stdin *bufio.Reader
var stdout *bufio.Writer
func fastio() {
  stdin = bufio.NewReader(os.Stdin)
  stdout = bufio.NewWriter(os.Stdout)
}
func sci(buf ...*int) {
  for _, a := range buf {
    fmt.Fscanf(stdin, "%d ", a)
  }
}
func scl(buf ...*int64) {
  for _, a := range buf {
    fmt.Fscanf(stdin, "%d ", a)
  }
}
func dbg(x ...interface{}) {
  fmt.Fprintln(os.Stderr, ">>>>", x)
}

func main() {
  fastio()
  var n int
  sci(&n)
  s := make([]int64, n+1)
  g := make([]int64, n+1)
  x := make([]int64, n+1)
  y := make([]int64, n+1)
  a := make([]int64, n+1)
  for i := 1; i <= n; i++ {
    scl(&s[i],&g[i])
    dbg(s[i], g[i])
    if i == 1 {
      x[i] = s[i]+g[i]
    } else {
      x[i] = min(x[i-1]+1, s[i]+g[i])
    }
  }
  var tot int64
  for i := n; 1 <= i; i-- {
    if i == n {
      y[n] = s[n]+g[n]
    } else {
      y[i] = min(y[i+1]+1, s[i]+g[i])
    }
    a[i] = min(x[i], y[i])
    if s[i] <= a[i] && a[i] <= s[i]+g[i] {
      tot += a[i]-s[i]
    } else {
      fmt.Printf("-1\n")
      return
    }
  }
  fmt.Fprintf(stdout, "%d\n", tot)
  for i := 1; i <= n; i++ {
    if i > 1 {
      fmt.Fprintf(stdout, " ")
    }
    fmt.Fprintf(stdout, "%d",a[i])
  }
  fmt.Fprintf(stdout, "\n")
  stdout.Flush()
}

package main

import "fmt"

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

func main() {
  var n int
  fmt.Scanf("%d", &n)
  s := make([]int, n+1)
  g := make([]int, n+1)
  x := make([]int, n+1)
  y := make([]int, n+1)
  a := make([]int, n+1)
  for i := 1; i <= n; i++ {
    fmt.Scanf("%d %d",&s[i],&g[i])
    if i == 1 {
      x[i] = s[i]+g[i]
    } else {
      x[i] = min(x[i-1]+1, s[i]+g[i])
    }
  }
  var tot int
  for i := n; 1 <= i; i-- {
    if i == n {
      y[n] = s[n]+g[n]
    } else {
      y[i] = min(y[i+1]+1, s[i]+g[i])
    }
    a[i] = min(x[i], y[i])
    if s[i] <= a[i] && a[i] <= s[i]+g[i] {
      tot += a[i]-s[i]
    } else {
      fmt.Printf("-1\n")
      return
    }
  }
  fmt.Printf("%d\n", tot)
  for i := 1; i <= n; i++ {
    fmt.Printf("%d ",a[i])
  }
  fmt.Printf("\n")
}


package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

func main() {
	var h, m, n int
	fmt.Fscan(in, &h, &m, &n)
	ht := newHashTable(h, m)
	var ans int64
	for i := 0; i < n; i++ {
		var cmd string
		fmt.Fscan(in, &cmd)
		switch cmd {
		case "+":
			var id, hash int
			fmt.Fscan(in, &id, &hash)
			ans += int64(ht.add(id, hash))
		case "-":
			var id int
			fmt.Fscan(in, &id)
			ht.rem(id)
		default:
			panic(cmd)
		}
	}
	fmt.Println(ans)
}

type ptr struct {
	chain, i int
}

// Maždaug segment tree.
type chain []int

type hashTable struct {
	ptrs   []ptr
	chains []chain
	byID   map[int]ptr
}

func newHashTable(h, m int) *hashTable {
	r := &hashTable{ptrs: make([]ptr, h), byID: make(map[int]ptr)}
	for i := range r.ptrs {
		r.ptrs[i].chain = -1
	}
	for i := 0; i < m; i++ {
		if r.ptrs[i].chain != -1 {
			continue
		}
		sz := 0
		for j := i; r.ptrs[j].chain == -1; j = (j + m) % h {
			r.ptrs[j].chain = len(r.chains)
			r.ptrs[j].i = sz
			sz++
		}
		r.chains = append(r.chains, make(chain, 4*sz))
	}
	return r
}

func (h *hashTable) add(id, hash int) int {
	p := h.ptrs[hash]
	ch := h.chains[p.chain]
	q := ch.findFirstZero(p.i)
	ch.add(q, 1)
	h.byID[id] = ptr{p.chain, q}
	sz := len(ch) / 4
	return (q + sz - p.i) % sz
}

func (h *hashTable) rem(id int) {
	p := h.byID[id]
	h.chains[p.chain].add(p.i, -1)
}

func (ch chain) findFirstZero(i int) int {
	r := ch.ffz(i, 1, 0, len(ch)/4)
	if r == len(ch)/4 {
		return ch.ffz(0, 1, 0, len(ch)/4)
	}
	return r
}

func (ch chain) ffz(i, v, l, r int) int {
	if ch[v] == r-l {
		return r
	}
	if l + 1 == r {
		return l
	}
	m := (l + r) / 2
	if i < m {
		i := ch.ffz(i, v*2, l, m)
		if i < m {
			return i
		}
	}
	return ch.ffz(i, v*2+1, m, r)
}

func (ch chain) add(i, val int) {
	v := 1
	l := 0
	r := len(ch) / 4
	for l < r {
		ch[v] += val
		if l + 1 == r {
			break
		}
		m := (l + r) / 2
		if i < m {
			r = m
			v *= 2
		} else {
			l = m
			v = v*2 + 1
		}
	}
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

func main() {
	var h, m, n int
	fmt.Fscan(in, &h, &m, &n)
	ht := newHashTable(h, m)
	ans := 0
	for i := 0; i < n; i++ {
		var cmd string
		fmt.Fscan(in, &cmd)
		switch cmd {
		case "+":
			var id, hash int
			fmt.Fscan(in, &id, &hash)
			ans += ht.add(id, hash)
		case "-":
			var id int
			fmt.Fscan(in, &id)
			ht.rem(id)
		default:
			panic(cmd)
		}
	}
	fmt.Println(ans)
}

type ptr struct {
	chain, i int
}

// Maždaug segment tree.
type chain []int

type hashTable struct {
	ptrs   []ptr
	chains []chain
	byID   map[int]ptr
}

func newHashTable(h, m int) *hashTable {
	r := &hashTable{ptrs: make([]ptr, h), byID: make(map[int]ptr)}
	for i := range r.ptrs {
		r.ptrs[i].chain = -1
	}
	for i := 0; i < m; i++ {
		if r.ptrs[i].chain != -1 {
			continue
		}
		sz := 0
		for j := i; r.ptrs[j].chain == -1; j = (j + m) % h {
			r.ptrs[j].chain = len(r.chains)
			r.ptrs[j].i = sz
			sz++
		}
		r.chains = append(r.chains, make(chain, 4*sz))
	}
	return r
}

func (h *hashTable) add(id, hash int) int {
	p := h.ptrs[hash]
	ch := h.chains[p.chain]
	q := ch.findFirstZero(p.i)
	ch.add(q, 1)
	h.byID[id] = ptr{p.chain, q}
	sz := len(ch) / 4
	return (q + sz - p.i) % sz
}

func (h *hashTable) rem(id int) {
	p := h.byID[id]
	h.chains[p.chain].add(p.i, -1)
}

func (ch chain) findFirstZero(i int) int {
	r := ch.ffz(i, 1, 0, len(ch)/4)
	if r == len(ch)/4 {
		return ch.ffz(0, 1, 0, len(ch)/4)
	}
	return r
}

func (ch chain) ffz(i, v, l, r int) int {
	if ch[v] == r-l {
		return r
	}
	if l + 1 == r {
		return l
	}
	m := (l + r) / 2
	if i < m {
		i := ch.ffz(i, v*2, l, m)
		if i < m {
			return i
		}
	}
	return ch.ffz(i, v*2+1, m, r)
}

func (ch chain) add(i, val int) {
	v := 1
	l := 0
	r := len(ch) / 4
	for l < r {
		ch[v] += val
		if l + 1 == r {
			break
		}
		m := (l + r) / 2
		if i < m {
			r = m
			v *= 2
		} else {
			l = m
			v = v*2 + 1
		}
	}
}


package main

import (
	"fmt"
	"math"
)

func dist(x, y float64) float64 {
	return math.Sqrt(x*x + y*y)
}

func main() {
	t := 0
	fmt.Scan(&t)
	var x, y float64
	for i := 0; i < t; i++ {
		fmt.Scan(&x, &y)
		dst := dist(x, y)
		if dst == 0 {
			fmt.Println(0)
			continue
		}
		if dst == float64(int64(dst)) {
			fmt.Println(1)
			continue
		}

		// cx, cy := 0., 0.
		// move diagonally
		// for cx != x && cy != y {
		// 	cx++
		// 	cy++
		// }
		steps := 2
		fmt.Println(steps)
	}
}

package main

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

var T int

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

	Fscan(in, &T)
	for t := 0; t < T; t++ {
		var x, y int
		Fscan(in, &x, &y)
		if x == 0 && y == 0 {
			Fprintln(out, 0)
			continue
		}
		dis := x*x + y*y
		tmp := int(math.Sqrt(float64(dis)))
		if tmp * tmp == dis {
			Fprintln(out, 1)
		} else {
			Fprintln(out, 2)
		}
	}
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		x, _ := strconv.Atoi(ninps[0])
		y, _ := strconv.Atoi(ninps[1])

		tmp := math.Sqrt(float64((x*x + y*y))) - float64(int(math.Sqrt(float64((x*x + y*y)))))
		//fmt.Println("O1:", tmp)
		if tmp > 0 {
			done := false
			for i := 1; i < 50; i++ {
				for j := 1; j < 50; j++ {
					tmp = math.Sqrt(float64((math.Abs(float64((x-i))) * math.Abs(float64((x-i))) + math.Abs(float64((y-j)))*math.Abs(float64((y-j)))))) -
					float64(int(math.Sqrt(float64((math.Abs(float64((x-i))) * math.Abs(float64((x-i))) + math.Abs(float64((y-j)))*math.Abs(float64((y-j))))))))
					//fmt.Println("O:", tmp)
					if tmp > 0 {
						continue
					} else {
						fmt.Println("2")
						done = true
						break
					}
				}
				if done {
					break
				}
			}
		} else {
			if x == 0 && y == 0 {
				fmt.Println("0")
			} else {
				fmt.Println("1")
			}
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y float64
		fmt.Fscan(in,&x,&y)
		if x == 0 && y == 0 {
			fmt.Fprintln(out,0)
		} else {
			if isIntegral(math.Sqrt(x*x+y*y)) == true {
				fmt.Fprintln(out,1)
			} else {
				fmt.Fprintln(out,2)
			}
		}
	}
}
func isIntegral(val float64) bool {
	return val == float64(int(val))
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1657A
Date: 1/04/22
User: epradere
URL: https://codeforces.com/problemset/problem/1657/A
Problem: CF1657A
**/
func (in *CF1657A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		x, y := in.NextInt(), in.NextInt()
		if x == 0 && y == 0 {
			fmt.Println(0)
		} else {
			dist := math.Sqrt(float64((x * x) + (y * y)))
			compare := float64(int(dist))
			if dist == compare {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		}
	}
}

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

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

package main

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

func main() {

	reader := bufio.NewReader(os.Stdin)
	writter := bufio.NewWriter(os.Stdout)
	defer writter.Flush()

	t := 0
	fmt.Fscan(reader, &t)

	for t > 0 {
		x, y := 0, 0
		fmt.Fscan(reader, &x, &y)

		// p := make([]int, n)
		// for i := range p {
		// 	fmt.Fscan(reader, &p[i])
		// }

		fmt.Fprintln(writter, solve(x, y))

		t--
	}

	//fmt.Println(solve(8, 6))

	//fmt.Println(commonServices.Interger(1.00))
}

func solve(x, y int) int {

	count := 0

	for !(x == 0 && y == 0) {

		nowX, nowY := 0, 0
		finish := false

		for i := y; i >= 0; i-- {

			for j := x; j >= 0; j-- {
				if Interger(math.Sqrt(float64(i*i + j*j))) {
					nowX, nowY = j, i
					finish = true
					break
				}
			}

			if finish {
				break
			} else {
				return 0
			}

		}

		//fmt.Println(x, y)

		x -= nowX
		y -= nowY

		count++
	}

	return count
}

func Interger(num float64) bool {
	if num == float64(int64(num)) {
		return true
	} else {
		return false
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t, x, y int
	fmt.Scanf("%d ", &t)
	for ;t>0;t-=1{
		fmt.Scanf("%d %d ", &x, &y)
		dis := int(math.Sqrt(float64(x*x+y*y))+0.00000000001)
		if x == 0 && y == 0{
			fmt.Printf("0\n")
		} else if dis*dis == x*x+y*y{
			fmt.Printf("1\n")
		}else{
			fmt.Printf("2\n")
		}
	}
 }

package main

import (
	"fmt"
	"math"
)

type node struct{
	x int
	y int
}

func solve(a [64][64]int)(b [64][64]int){
	nmax := 51;
	okp := make([]node, 0)
	for xx:=0;xx<=nmax;xx++{
		for yy:=0;yy<=nmax;yy++{
			dis := int(math.Sqrt(float64(xx*xx+yy*yy))+0.000000001)
			if dis*dis == xx*xx+yy*yy{
				okp = append(okp, node{xx, yy})
			}
		}
	}
	for i:=0;i<=nmax;i++{
		for j:=0;j<=nmax;j++{
			a[i][j] = 1000;
		}
	}
	a[0][0] = 0;
	for i:=0;i<=nmax;i++{
		for j:=0;j<=nmax;j++{
			for _, val := range okp{
				if i+val.x <= nmax && j+val.y <= nmax && a[i+val.x][j+val.y] > a[i][j]+1{
					a[i+val.x][j+val.y] = a[i][j] + 1
				}
			}
		}
	}
	return a
}

func main() {
	var t, x, y int
	var a [64][64]int
	b := solve(a)
	fmt.Scanf("%d ", &t)
	for ;t>0;t-=1{
		fmt.Scanf("%d %d ", &x, &y)
		fmt.Printf("%d\n",b[x][y])
	}
 }

package main
import "fmt"
import "os"
import "bufio"
import "math"
//import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)
func main() {
	defer output.Flush()
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		a := 0
		b := 0
		fmt.Fscan(input,&a)
		fmt.Fscan(input,&b)
		if a==0 && b==0 {
			fmt.Fprintln(output,0)
		} else {
			sqrt := math.Sqrt(float64(a*a+b*b))
			if int(sqrt)*int(sqrt) == a*a+b*b {
				fmt.Fprintln(output,1)
			} else {
				fmt.Fprintln(output,2)
			}
		}
	}
}

package main

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

func square(a int) bool {
	var int_root int = int(math.Sqrt(float64(a)))
	return (int_root * int_root) == a
}

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

		if x == 0 && y == 0 {
			fmt.Fprintln(out, 0)
		} else if square(x*x + y*y) {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	valid := make(map[int]map[int]bool)
	for i := 1; i <= 50; i++ {
		valid[i] = make(map[int]bool)
		for j := 1; j <= 50; j++ {
			k := int(math.Sqrt(float64(i*i) + float64(j*j)))
			if i*i+j*j == k*k {
				valid[i][j] = true
				// fmt.Println(i, j)
			}
		}
	}
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t >= 1; t-- {
		var x, y int
		fmt.Scanf("%d %d\n", &x, &y)
		if x == 0 && y == 0 {
			fmt.Println(0)
			continue
		}
		if x == 0 || y == 0 {
			fmt.Println(1)
			continue
		}
		if valid[x][y] {
			fmt.Println(1)
			continue
		}
		fmt.Println(2)
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

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

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(x, y int) int {
	if x == 0 && y == 0 {
		return 0
	}
	c := x*x + y*y
	d := int(math.Sqrt(float64(c)))

	if d*d == c {
		return 1
	}
	return 2
}

package main

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

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

	var T, x, y int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x, &y)
		if x == 0 && y == 0 {
			Fprintln(out, 0)
		} else {
			s := x*x + y*y
			rt := int(math.Sqrt(float64(s)))
			if rt*rt == s {
				Fprintln(out, 1)
			} else {
				Fprintln(out, 2)
			}
		}
	}
}

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

package main

import (
	"fmt"
	"math"
)

func check(x int, y int) bool {
	var z = int(math.Sqrt(float64(x*x + y*y)))
	return z*z == x*x+y*y
}

func main() {
	check(6, 8)
	var T, x, y int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		fmt.Scan(&x, &y)
		if x == 0 && y == 0 {
			fmt.Println(0)
		} else if check(x, y) {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func check(x int, y int) bool {
	var z = int(math.Sqrt(float64(x*x + y*y)))
	return z * z == x * x + y * y
}

func main()  {
	check(6, 8)
	var T, x, y int
	fmt.Scan(&T)
	for i := 0; i < T; i ++ {
		fmt.Scan(&x, &y)
		if x == 0 && y == 0 {
			fmt.Println(0)
		} else if check(x, y) {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

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-- {
		var x, y int
		fmt.Fscan(in, &x, &y)

		dist := x*x + y*y
		sqrt := int(math.Sqrt(float64(dist)))
		dist2 := sqrt * sqrt
		if x == 0 && y == 0 {
			fmt.Fprintln(out, 0)
		} else if dist == dist2 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

package main

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

/*

 */

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

	if x == 0 && y == 0 {
		fmt.Fprintln(writer, 0)
		return
	}

	num := math.Sqrt(float64(x*x + y*y))

	if num == float64(int64(num)) {
		fmt.Fprintln(writer, 1)
	} else {
		fmt.Fprintln(writer, 2)
	}
}

//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 {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return nums[minNumIdx]
}

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

	return nums[maxNumIdx]
}

//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 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"
	"math"
	"os"
)

var T int

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

	Fscan(in, &T)
	for t := 0; t < T; t++ {
		var x, y int
		Fscan(in, &x, &y)
		ans := 0
		curx, cury := 0, 0
		for i := x; i > curx; i-- {
			for j := y; j > cury; j-- {
				mx := (curx - i) * (curx - i)
				my := (cury - j) * (cury - j)
				dis := math.Sqrt(float64(mx + my))
				if int(dis)*int(dis) == mx+my {
					ans ++
					curx, cury = i, j
					i, j = x, y
				}
			}
		}
		Fprintln(out, ans)
	}
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		x, _ := strconv.Atoi(ninps[0])
		y, _ := strconv.Atoi(ninps[1])

		tmp := math.Sqrt(float64((x*x + y*y))) - float64(int(math.Sqrt(float64((x*x + y*y)))))
		//fmt.Println("O1:", tmp)
		if tmp > 0 {
			done := false
			for i := 1; i < 50; i++ {
				for j := 1; j < 50; j++ {
					tmp = math.Sqrt(float64(((x-i)*(x-i) + (y-j)*(y-j)))) - float64(int(math.Sqrt(float64(((x-i)*(x-i) + (y-j)*(y-j))))))
					//fmt.Println("O:", tmp)
					if tmp > 0 {
						continue
					} else {
						fmt.Println("2")
						done = true
						break
					}
				}
				if done {
					break
				}
			}
		} else {
			if x == 0 && y == 0 {
				fmt.Println("0")
			} else if x == 0 || y == 0 {
                                fmt.Println("2")
			} else {
				fmt.Println("1")
			}
		}
	}
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		x, _ := strconv.Atoi(ninps[0])
		y, _ := strconv.Atoi(ninps[1])

		tmp := math.Sqrt(float64((x*x + y*y))) - float64(int(math.Sqrt(float64((x*x + y*y)))))
		if tmp > 0 {
			done := false
			for i := 1; i < 50; i++ {
				for j := 1; j < 50; j++ {
					tmp = math.Sqrt(float64(((x-i)*(x-i) + (y-j)*(y-j)))) - float64(int(math.Sqrt(float64(((x-i)*(x-i) + (y-j)*(y-j))))))
					if tmp > 0 {
						continue
					} else {
						fmt.Println("2")
						done = true
						break
					}
				}
				if done {
					break
				}
			}
		} else {
			if x != 0 && y != 0 {
				fmt.Println("1")
			} else {
                                fmt.Println("0")
			}
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y float64
		fmt.Fscan(in,&x,&y)
		if x == 0 || y == 0 {
			fmt.Fprintln(out,0)
		} else {
			if isIntegral(math.Sqrt(x*x+y*y)) == true {
				fmt.Fprintln(out,1)
			} else {
				fmt.Fprintln(out,2)
			}
		}
	}
}
func isIntegral(val float64) bool {
	return val == float64(int(val))
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1657A
Date: 1/04/22
User: epradere
URL: https://codeforces.com/problemset/problem/1657/A
Problem: CF1657A
**/
func (in *CF1657A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		x, y := in.NextInt(), in.NextInt()
		if x != 0 && y != 0 {
			dist := math.Sqrt(float64((x * x) + (y * y)))
			compare := float64(int(dist))
			if dist == compare {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		} else {
			fmt.Println(0)
		}
	}
}

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

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

package main
import "fmt"
import "os"
import "bufio"
import "math"
//import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)
func main() {
	defer output.Flush()
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		a := 0
		b := 0
		fmt.Fscan(input,&a)
		fmt.Fscan(input,&b)
		if a==0 && b==0 {
			fmt.Fprintln(output,0)
		} else {
			sqrt := math.Sqrt(float64(a*a+b*b))
			if int(sqrt*sqrt) == a*a+b*b {
				fmt.Fprintln(output,1)
			} else {
				fmt.Fprintln(output,2)
			}
		}
	}
}

package main

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

func square(a int) bool {
	var int_root int = int(math.Sqrt(float64(a)))
	return (int_root * int_root) == a
}

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

		posX, posY := 0, 0
		var tot int
		for posX != x || posY != y {
			var max, maxA, maxB int
			for a := x - posX; a >= 0; a-- {
				for b := y - posY; b >= 0; b-- {
					if square(a*a+b*b) && a*a+b*b > max {
						max, maxA, maxB = a*a+b*b, a, b
					}
				}
			}

			posX += maxA
			posY += maxB
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	valid := make(map[int]map[int]bool)
	for i := 1; i <= 50; i++ {
		valid[i] = make(map[int]bool)
		for j := 1; j <= 50; j++ {
			k := int(math.Sqrt(float64(i*i) + float64(j*j)))
			if (i*i)+(j*j) == k*k {
				valid[i][j] = true
				// fmt.Println(i, j)
			}
		}
	}
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t >= 1; t-- {
		var x, y int
		fmt.Scanf("%d %d\n", &x, &y)
		if x == 0 && y == 0 {
			fmt.Println(0)
			continue
		}
		if valid[x][y] {
			fmt.Println(1)
			continue
		}
		fmt.Println(2)
	}
}