package main

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

func calc(n int, data []int) int {
	var res int
	if data[0] != 1 {
		res++
	}
	if data[n-1] != n {
		res++
	}
	switch res {
	case 2:
		if data[0] == n && data[n-1] == 1 {
			return 3
		}
		return 2
	case 1:
		return 1
	case 0:
	}
	for i, v := range data {
		if i+1 != v {
			return 1
		}
	}
	return 0
}

func main() {
	input := bufio.NewReader(os.Stdin)
	var T int
	fmt.Fscanln(input, &T)
	for k := 0; k < T; k++ {
		var n int
		fmt.Fscanln(input, &n)
		data := make([]int, n)
		for i := range data {
			_, err := fmt.Fscan(input, &data[i])
			if err != nil {
				panic(err)
			}
		}
		fmt.Fscanf(input, "\n")
		fmt.Println(calc(n, data))
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		a := make([]int, n)

		var posFirst int
		var posLast int
		flag := true

		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if a[i] == 1 {
				posFirst = i
			}
			if a[i] == n {
				posLast = i
			}
			if i != 0 && a[i] < a[i-1] {
				flag = false
			}
		}

		if flag {
			fmt.Println(0)
		} else if posFirst == 0 || posLast == n-1 {
			fmt.Println(1)
		} else if posFirst == n-1 && posLast == 0 {
			fmt.Println(3)
		} else {
			fmt.Println(2)
		}
	}
}

// 1525B. Permutation Sort
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		sorted := true
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				sorted = false
				break
			}
		}
		if sorted {
			fmt.Println(0)
		} else {
			if a[0] == n && a[n-1] == 1 {
				fmt.Println(3)
			} else if a[0] == 1 || a[n-1] == n {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		ARRAY := make([]int, n+1)
		contiuniopp := 0
		PlaceOfN := 0
		PlaceOfONe := 0
		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARRAY[i])
			if ARRAY[i] == i {
				contiuniopp++
			}
			if ARRAY[i] == n {
				PlaceOfN = i
			}
			if ARRAY[i] == 1 {
				PlaceOfONe = i
			}

		}
		if contiuniopp == n {
			fmt.Println(0)
		} else {
			if PlaceOfN == n || PlaceOfONe == 1 {
				fmt.Println(1)
			} else {
				if PlaceOfN == 1 && PlaceOfONe == n {
					fmt.Println(3)
				} else {
					fmt.Println(2)
				}
			}
		}

	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		if sort.IntsAreSorted(a) {
			Fprintln(out, 0)
			return
		}
		if a[0] == 1 || a[n-1] == n {
			Fprintln(out, 1)
		} else if a[0] == n && a[n-1] == 1 {
			Fprintln(out, 3)
		} else {
			Fprintln(out, 2)
		}
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

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

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

package main

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

/*
2
3
3 2 1
3
1 3 2
---
3
1
*/

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

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

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

		a := make([]int, n)

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

		if a[0] == n && a[n-1] == 1 {
			fmt.Fprintln(writer, 3)
			continue
		}

		if (a[0] == 1) != (a[n-1] == n) {
			fmt.Fprintln(writer, 1)
			continue
		}

		if a[0] != 1 && a[n-1] != n {
			fmt.Fprintln(writer, 2)
			continue
		}

		shouldSortCenter := false

		for i := 1; i < n-1; i++ {
			if a[i] != i+1 {
				shouldSortCenter = true
			}
		}

		if shouldSortCenter {
			fmt.Fprintln(writer, 1)
		} else {
			fmt.Fprintln(writer, 0)
		}
	}
}

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 divCeil(num, div int64) int64 {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

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

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

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		var n int
		fmt.Fscan(r, &n)

		p := make([]int, n)

		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &p[j])
		}
		fmt.Println(solve(p))
	}
}

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == len(p) && p[len(p) - 1] == 1 {
		return 3
	}

	if p[0] == 1 || p[len(p) - 1] == len(p) {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		var n int
		fmt.Fscan(r, &n)

		p := make([]int, n)

		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &p[j])
		}
		fmt.Println(solve(p))
	}
}

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == len(p) - 1 && p[len(p) - 1] == 1 {
		return 3
	}

	if p[0] == 1 || p[len(p) - 1] == len(p) {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		var n int
		fmt.Fscan(r, &n)

		p := make([]int, n)

		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &p[j])
		}
		fmt.Println(solve(p))
	}
}

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	reverse := true

	for i := 0; i < len(p) - 1; i++ {
		if p[i] != len(p) - i {
			reverse = false
			break
		}
	}

	if reverse {
		return 3
	}

	if p[0] == 1 || p[len(p) - 1] == len(p) {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		var n int
		fmt.Fscan(r, &n)

		p := make([]int, n)

		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &p[j])
		}
		fmt.Println(solve(p))
	}
}

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == 1 || p[len(p) - 1] == len(p) {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		var n int
		fmt.Fscan(r, &n)

		p := make([]int, n)

		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &p[j])
		}
		fmt.Println(solve(p))
	}
}

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == 1 || p[len(p) - 1] == 5 {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		var n int
		fmt.Fscan(r, &n)

		p := make([]int, n)

		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &p[j])
		}
		fmt.Println(solve(p))
	}
}

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == 1 {
		return 1
	} else {
		return 2
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		a := make([]int, n)

		var posFirst int
		var posLast int
		flag := true

		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if a[i] == 1 {
				posFirst = i
			}
			if a[i] == n {
				posLast = i
			}
			if i != 0 && a[i] < a[i-1] {
				flag = false
			}
		}

		if flag {
			fmt.Println(0)
		} else if posFirst == 0 || posLast == n-1 {
			fmt.Println(1)
		} else if posFirst == n-1 || posLast == 0 {
			fmt.Println(3)
		} else {
			fmt.Println(2)
		}
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		a := make([]int, n)

		var posFirst int
		var posLast int
		flag := true

		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if a[i] == 1 {
				posFirst = i
			}
			if a[i] == n {
				posLast = i
			}
			if i != 0 && a[i] < a[i-1] {
				flag = false
			}
		}

		if flag {
			fmt.Println(0)
		} else if posFirst == 0 || posLast == n-1 {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

// 1525B. Permutation Sort
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		sorted := true
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				sorted = false
				break
			}
		}
		if sorted {
			fmt.Println(0)
		} else {
			if a[0] == 1 || a[n-1] == n {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		ARRAY := make([]int, n+1)
		contiuniopp := 0
		PlaceOfN := 0
		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARRAY[i])
			if ARRAY[i] == i {
				contiuniopp++
			}
			if ARRAY[i] == n {
				PlaceOfN = i
			}

		}
		if contiuniopp == n {
			fmt.Println(0)
		} else {
			if PlaceOfN == n {
				fmt.Println(1)
			}
			if PlaceOfN == 1 {
				fmt.Println(3)
			}
			if PlaceOfN != 1 && PlaceOfN != n {
				fmt.Println(2)
			}
		}

	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		if sort.IntsAreSorted(a) {
			Fprintln(out, 0)
			return
		}
		if a[0] == 1 || a[n-1] == n {
			Fprintln(out, 1)
		} else {
			Fprintln(out, 2)
		}
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

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

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


package main

import (
	"fmt"
        "math"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x)))
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < 0 {
						maxminus = math.Max(-a, maxminus)
					} else {
						maxplus = math.Max(a, maxplus)
					}
				}

			}
			if maxplus >= 0 && maxminus >= 0 {
				maxarea = math.Max(maxarea, maxplus + maxminus)
			}
		}
	}
	fmt.Printf("%f", (maxarea / 2.0))
}

package main

import (
    "fmt"
)

var n int
type Point struct {
    x, y float32
}
var ps []Point

func xmult(p0, p1, p2 Point) float32 {
    return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x)
}

func main() {
    fmt.Scanln(&n)
    ps := make([]Point, n)
    for i := 0; i < n; i++ {
       fmt.Scanln(&ps[i].x, &ps[i].y)
    }
    var res float32
    for i := 0; i < n; i++ {
        p1 := ps[i]
        for  j := i + 1; j < n; j ++ {
            p2 := ps[j]
            var mx, mn float32
            mx = -1e9
            mn = 1e9
            for k, p3 := range ps {
                if k == i || k == j {
                    continue
                }
                tmp := xmult(p1, p2, p3)
                if tmp > mx {
                    mx = tmp
                }
                if tmp < mn {
                    mn = tmp
                }
            }
            if mx - mn > res {
                res = mx - mn
            }
        }
    }
    fmt.Println(res*0.5)
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
	x := make(map[int]int)
	y := make(map[int]int)
	var a, b, n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d %d\n", &a, &b)
		if err != nil {
			fmt.Println(err)
		}
		x[i] = a
		y[i] = b

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Println(maxarea)
}

package main

import (
	"fmt"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x))) / 2.0
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Printf("%f", maxarea)
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
	x := make(map[int]int)
	y := make(map[int]int)
	var a, b, n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &a, &b)
		x[i] = a
		y[i] = b

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Println(maxarea)
}

package main

import (
	"fmt"
        "math"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x)))
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 1; i <= n; i++ {
		for j := i+1; j <= n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 1; k <= n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < 0 {
						maxminus = math.Max(-a, maxminus)
					} else {
						maxplus = math.Max(a, maxplus)
					}
				}

			}
			if maxplus >= 0 && maxminus >= 0 {
				maxarea = maxplus + maxminus
			}
		}
	}
	fmt.Printf("%f", (maxarea / 2.0))
}

package main

import (
	"fmt"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x)))
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Printf("%f", (maxarea / 2.0))
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
        x := make(map[int]int)
        y := make(map[int]int)
	var a,b,n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &a, &b)
                x[i] = a
                y[i] = b
	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Println(maxarea)
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
	x := make(map[int]int)
	y := make(map[int]int)
	var a, b, n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d %d\n", &a, &b)
                if err != nil {
                   fmt.Println(err)
                }
		x[i] = a
		y[i] = b

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Println(maxarea)
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
	x := make(map[int]int)
	y := make(map[int]int)
	var a, b, n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d %d\n", &a, &b)
                if err != nil {
                   fmt.Println(err)
                }
		x[i] = a
		y[i] = b

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Printf("%f", maxarea)
}

package main

import (
	"fmt"
        "math"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x)))
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 1; i <= n; i++ {
		for j := i+1; j <= n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 1; k <= n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < 0 {
						maxminus = math.Max(-a, maxminus)
					} else {
						maxplus = math.Max(a, maxminus)
					}
				}

			}
			if maxplus >= 0 && maxminus >= 0 {
				maxarea = maxplus + maxminus
			}
		}
	}
	fmt.Printf("%f", (maxarea / 2.0))
}

package main

import (
    "fmt"
)

var n int
type Point struct {
    x, y float32
}
var ps []Point

func xmult(p0, p1, p2 Point) float32 {
    return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x)
}

func main() {
    fmt.Scanln(&n)
    ps := make([]Point, n)
    for i := 0; i < n; i++ {
       fmt.Scanln(&ps[i].x, &ps[i].y)
    }
    var res float32
    for i := 0; i < n; i++ {
        p1 := ps[i]
        for  j := i + 1; j < n; j ++ {
            p2 := ps[j]
            var mx, mn float32
            for _, p3 := range ps {
                tmp := xmult(p1, p2, p3)
                if tmp > mx {
                    mx = tmp
                }
                if tmp < mn {
                    mn = tmp
                }
            }
            if mx - mn > res {
                res = mx - mn
            }
        }
    }
    fmt.Println(res*0.5)
}


package main

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

type SA []int

func (s SA) Len() int {
	return len(s)
}

func (s SA) Swap(a, b int) {
	tmp := s[a]
	s[a] = s[b]
	s[b] = tmp
}
func (s SA) Less(i, j int) bool {
	if s[i] < s[j] {
		return true
	}
	return false
}
func turnC(n, m, i, j, v int) int64 {
	line := 0
	if i <= m-1-j{
		line = j+i
	}else{
		line = m-1+(i-(m-1-j))
	}
	var ret = int64(v)
	ret = ret*10000+int64(line)
	//fmt.Printf("i=%d j=%d %d ret=%d\n",i,j,v,ret)
	return ret
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m, v int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	mapp := make(map[int64]int)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(buf, "%d", &v)
			mapp[turnC(n, m, i, j, v)]++
		}
		fmt.Fscanf(buf, "\n")
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(buf, "%d", &v)
			key := turnC(n, m, i, j, v)
			cnt, ok := mapp[key]
			if ok && cnt > 0 {
				mapp[key]--
			} else {
				fmt.Printf("NO\n")
				return
			}
		}
		fmt.Fscanf(buf, "\n")
	}
	fmt.Printf("YES\n")
}

/**
0 0
0 1
3
UDD
 */

package main

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

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	line, _ := r.ReadString('\n')
	intLine := parseInts(line)
	n, m = intLine[0], intLine[1]
	A := getNewMatrix(n, m, r)
	B := getNewMatrix(n, m, r)
	if isItPossibleToTransposeOneMatrixToAnother(A, B, n, m){
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

func isItPossibleToTransposeOneMatrixToAnother(A, B [][]int, n,m int) bool {
	var currentRow, currentCol int
	for i:=0; i<n; i++{
		currentRow = i
		currentCol = 0
		newDiagA := make([]int, min(currentRow+1, m))
		newDiagB := make([]int, min(currentRow+1, m))
		for currentRow>=0 && currentCol<m {
			newDiagA[currentCol] = A[currentRow][currentCol]
			newDiagB[currentCol] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
				return false
			}
		}
	}
	for i:=1; i<m; i++{
		currentRow = n-1
		currentCol = i
		newDiagA := make([]int, min(n, m-currentCol))
		newDiagB := make([]int, min(n, m-currentCol))
		for currentRow>=0 && currentCol<m{
			newDiagA[n-1-currentRow] = A[currentRow][currentCol]
			newDiagB[n-1-currentRow] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
				return false
			}
		}
	}
	return true
}

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

func getNewMatrix(n, m int, r *bufio.Reader) [][]int{
	A := make([][]int, n)
	for i:=0; i<n; i++ {
		line, _ := r.ReadString('\n')
		A[i] = parseInts(line)
	}
	return A
}

func parseInts(s string) []int {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
	)
	for i, f := range fields {
		ints[i], _ = strconv.Atoi(f)
	}
	return ints
}

package main

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

type input struct {
  scanner *bufio.Scanner
}

func NewInput() input {
  in := input{scanner: bufio.NewScanner(os.Stdin)}
  in.scanner.Split(bufio.ScanWords)
  return in
}

func (in* input) Token() string {
  in.scanner.Scan()
  return in.scanner.Text()
}

func (in* input) IntToken() int {
  result, _ := strconv.Atoi(in.Token())
  return result
}

func ReadDiags(in input, N, M int) [][]int {
  result := make([][]int, N + M - 1)
  for r := 0; r < N; r++ {
    for c := 0; c < M; c++ {
      result[r + c] = append(result[r + c], in.IntToken())
    }
  }
  for i := 0; i < N + M - 1; i++ {
    sort.Slice(
      result[i],
      func(a, b int) bool { return result[i][a] < result[i][b] },
    )
  }
  return result
}

func main() {
  in := NewInput()
  N := in.IntToken()
  M := in.IntToken()

  A := ReadDiags(in, N, M)
  B := ReadDiags(in, N, M)

  if reflect.DeepEqual(A, B) {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

// Author: sighduck
// URL: https://codeforces.com/contest/1136/problem/C

package main

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

func compareDiagonals(a [][]int, b [][]int, row int, column int, n int, m int) bool {
	aDiagonal := make(map[int]int)
	bDiagonal := make(map[int]int)
	count := 0
	for row+count < n && column-count >= 0 {
		aDiagonal[a[row+count][column-count]] += 1
		bDiagonal[b[row+count][column-count]] += 1
		count += 1
	}
	for elem, elemCount := range aDiagonal {
		if elemCount != bDiagonal[elem] {
			return false
		}
	}
	return true
}

func Solve(a [][]int, b [][]int, n int, m int) string {
	for j := 0; j < m; j++ {
		if !compareDiagonals(a, b, 0, j, n, m) {
			return "NO"
		}
	}
	for i := 1; i < n; i++ {
		if !compareDiagonals(a, b, i, m-1, n, m) {
			return "NO"
		}
	}
	return "YES"
}

func readMatrix(n int, m int, reader *bufio.Reader) [][]int {
	matrix := make([][]int, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%d", &matrix[i][j])
		}
		fmt.Fscanf(reader, "\n")
	}
	return matrix
}

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

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	a := readMatrix(n, m, reader)
	b := readMatrix(n, m, reader)

	fmt.Fprintf(writer, "%s\n", Solve(a, b, n, m))
}

package main

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

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	line, _ := r.ReadString('\n')
	intLine := parseInts(line)
	n, m = intLine[0], intLine[1]
	A := getNewMatrix(n, m, r)
	B := getNewMatrix(n, m, r)
	if isItPossibleToTransposeOneMatrixToAnother(A, B, n, m){
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

func isItPossibleToTransposeOneMatrixToAnother(A, B [][]int, n,m int) bool {
	var currentRow, currentCol int
	for i:=0; i<n; i++{
		currentRow = i
		currentCol = 0
		newDiagA := make([]int, min(currentRow+1, m))
		newDiagB := make([]int, min(currentRow+1, m))
		for currentRow>=0 && currentCol<m {
			newDiagA[currentCol] = A[currentRow][currentCol]
			newDiagB[currentCol] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
				return false
			}
		}
	}
	for i:=1; i<m; i++{
		currentRow = n-1
		currentCol = i
		newDiagA := make([]int, min(n, m-currentCol))
		newDiagB := make([]int, min(n, m-currentCol))
		for currentRow>=0 && currentCol<m{
			newDiagA[n-1-currentRow] = A[currentRow][currentCol]
			newDiagB[n-1-currentRow] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
				return false
			}
		}
	}
	return true
}

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

func getNewMatrix(n, m int, r *bufio.Reader) [][]int{
	A := make([][]int, n)
	for i:=0; i<n; i++ {
		line, _ := r.ReadString('\n')
		A[i] = parseInts(line)
	}
	return A
}

func parseInts(s string) []int {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
	)
	for i, f := range fields {
		ints[i], _ = strconv.Atoi(f)
	}
	return ints
}

package main

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

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	line, _ := r.ReadString('\n')
	intLine := parseInts(line)
	n, m = intLine[0], intLine[1]
	A := getNewMatrix(n, m, r)
	B := getNewMatrix(n, m, r)
	if isItPossibleToTransposeOneMatrixToAnother(A, B, n, m){
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

func isItPossibleToTransposeOneMatrixToAnother(A, B [][]int, n,m int) bool {
	var currentRow, currentCol int
	for i:=0; i<n; i++{
		currentRow = i
		currentCol = 0
		newDiagA := make([]int, min(currentRow+1, m))
		newDiagB := make([]int, min(currentRow+1, m))
		for currentRow>=0 && currentCol<m {
			newDiagA[currentCol] = A[currentRow][currentCol]
			newDiagB[currentCol] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
			    if n==50 && m==50{
			        fmt.Println(newDiagA)
			        fmt.Println(newDiagB)
			    }
				return false
			}
		}
	}
	for i:=1; i<m; i++{
		currentRow = n-1
		currentCol = i
		newDiagA := make([]int, min(n, m-currentCol))
		newDiagB := make([]int, min(n, m-currentCol))
		for currentRow>=0 && currentCol<m{
			newDiagA[n-1-currentRow] = A[currentRow][currentCol]
			newDiagB[n-1-currentRow] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
			    if n==50 && m==50{
			        fmt.Println(newDiagA)
			        fmt.Println(newDiagB)
			    }
				return false
			}
		}
	}
	return true
}

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

func getNewMatrix(n, m int, r *bufio.Reader) [][]int{
	A := make([][]int, n)
	for i:=0; i<n; i++ {
		line, _ := r.ReadString('\n')
		A[i] = parseInts(line)
	}
	return A
}

func parseInts(s string) []int {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
	)
	for i, f := range fields {
		ints[i], _ = strconv.Atoi(f)
	}
	return ints
}

package main

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

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	line, _ := r.ReadString('\n')
	intLine := parseInts(line)
	n, m = intLine[0], intLine[1]
	A := getNewMatrix(n, m, r)
	B := getNewMatrix(n, m, r)
	if isItPossibleToTransposeOneMatrixToAnother(A, B, n, m){
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

func isItPossibleToTransposeOneMatrixToAnother(A, B [][]int, n,m int) bool {
	var currentRow, currentCol int
	for i:=0; i<n; i++{
		currentRow = i
		currentCol = 0
		newDiagA := make([]int, min(currentRow+1, m))
		newDiagB := make([]int, min(currentRow+1, m))
		for currentRow>=0 && currentCol<m {
			newDiagA[currentCol] = A[currentRow][currentCol]
			newDiagB[currentCol] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
			    if n==50 && m==50{
			        fmt.Println(v)
			        fmt.Println(newDiagB[ind])
			    }
				return false
			}
		}
	}
	for i:=1; i<m; i++{
		currentRow = n-1
		currentCol = i
		newDiagA := make([]int, min(n, m-currentCol))
		newDiagB := make([]int, min(n, m-currentCol))
		for currentRow>=0 && currentCol<m{
			newDiagA[n-1-currentRow] = A[currentRow][currentCol]
			newDiagB[n-1-currentRow] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
			    if n==50 && m==50{
			        fmt.Println(v)
			        fmt.Println(newDiagB[ind])
			    }
				return false
			}
		}
	}
	return true
}

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

func getNewMatrix(n, m int, r *bufio.Reader) [][]int{
	A := make([][]int, n)
	for i:=0; i<n; i++ {
		line, _ := r.ReadString('\n')
		A[i] = parseInts(line)
	}
	return A
}

func parseInts(s string) []int {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
	)
	for i, f := range fields {
		ints[i], _ = strconv.Atoi(f)
	}
	return ints
}


package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var y,x int
		fmt.Fscan(in,&y,&x)
		fmt.Fprintln(out,y/2+1,x/2+1)
	}
}

package main

import "fmt"

func main() {
	var t, n, m int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n, &m)
		fmt.Println((n+1)/2, (m+1)/2)
	}
}

package main

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

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

func (in *CF1739A) 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 *CF1739A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1739A
Date: 9/29/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1739/A
Problem: CF1739A
**/
func (in *CF1739A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		fmt.Println(int(math.Ceil(float64(n)/2.)), int(math.Ceil(float64(m)/2.)))
	}
}

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

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

package main

import "fmt"

func main() {
	var t int
	var n, m int
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&n)
		fmt.Scan(&m)

		fmt.Println((n/2)+1, (m/2)+1)
		t--
	}
}

package main

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

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

	var n, m, t int

	for fmt.Fscan(r, &t); t > 0; t-- {
		fmt.Fscan(r, &n, &m)

		if n == 2 && m == 3 {
			fmt.Fprintln(w, 1, 2)
		} else if n == 3 && m == 2 {
			fmt.Fprintln(w, 2, 1)
		} else if n == 3 && m == 3 {
			fmt.Fprintln(w, 2, 2)
		} else {
			fmt.Fprintln(w, 1, 1)
		}
	}
}

package main

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

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

	var n int
	Fscan(in, &n)
	for i := 1; i <= n; i++ {
		//fmt.Printf("%d/%d\n", i, n)
		var x int
		var y int
		//fmt.Scanf("%d %d\n", &n)
		Fscan(in, &x)
		Fscan(in, &y)

		if x <= 1 || y <= 1 {
			fmt.Printf("%d %d\n", 1, 1)
			continue
		}
		// if x >= 3 && y >= 3 {
		// 	fmt.Printf("%d %d\n", 1, 1)
		// 	continue
		// }
		fmt.Printf("%d %d\n", 2, 2)
	}
	// for i := 0; i < 9; i++ {
	// 	for j := 0; j < 9; j++ {
	// 		ans += cnt[i] * cnt[j] * cnt[i*j%9]
	// 	}
	// }
	//Fprint(out, ans)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	q, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; q > 0; q-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		m, _ := strconv.Atoi(arr[1])
		fmt.Println(n/2+1, m/2+1)
	}
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, m int
)

func solve(n, m int) (int, int) {
	if n == 1 || m == 1 {
		return 1, 1
	}
	if n < 4 && m < 4 {
		return 2, 2
	}
	return 1, 1
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m)
		fmt.Println(solve(n, m))
	}
}

package main

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

func solve(n, m int) (int, int) {
	if n <= 3 && m <= 3 {
		return n / 2 + 1, m / 2 + 1
	}

	return 1, 1
}

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

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

	for ; t > 0; t-- {
		var n, m int
		fmt.Fscan(in, &n, &m)
		i, j := solve(n, m)
		fmt.Println(i, j)
	}
}

package main

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

func main() {
	var tc int

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

	defer w.Flush()

	fmt.Fscan(r, &tc)

	for t := 0; t < tc; t++ {
		var n, m int
		fmt.Fscan(r, &n)
		fmt.Fscan(r, &m)

		o := solve(n, m)

		fmt.Fprintln(w, o[0], o[1])
	}
}

func solve(n, m int) []int {

	ans := make([]int, 2)

	ans[0], ans[1] = n, m

	for cn := 1; cn <= n; cn++ {
		for cm := 1; cm <= m; cm++ {
			if (cn+2) > n && (cn-2) < 1 && (cm+2) > m && (cm-2) < 1 {

				ans[0] = cn
				ans[1] = cm
			}
		}
	}
	return ans
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()

	fmt.Fscan(reader, &testCases)

	for testCase := 0; testCase < testCases; testCase++ {
		var n, m int
		fmt.Fscan(reader, &n)
		fmt.Fscan(reader, &m)

		on, om := solveA(n, m)

		fmt.Fprintln(writer, on, om)
	}
}

func solveA(n, m int) (int, int) {

	on, om := n, m

	for cn := 1; cn <= n; cn++ {
		for cm := 1; cm <= m; cm++ {
			moveScore := 4
			if (cn + 2) > n {
				moveScore--
			}
			if (cn - 2) < 1 {
				moveScore--
			}
			if (cm + 2) > m {
				moveScore--
			}
			if (cm - 2) < 1 {
				moveScore--
			}

			if moveScore == 0 {
				on = cn
				om = cm
			}
		}
	}
	return on, om
}

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

		if n == 1 || m == 1 || n > 3 || m > 3 {
			fmt.Fprintln(out, 1, 1)
		} else {
			fmt.Fprintln(out, 2, 2)
		}
	}
}

package main

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

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

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

func solve() {
	var n, m int
	scan(&n, &m)
	if n == 1 || m == 1 {
		printf("%d %d\n", n, m)
	} else {
		printf("2 2\n")
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		n int
		m int
	)

	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d ", &n, &m)
		if n == 1 || m == 1 {
			fmt.Println("1 1")
		} else {
			fmt.Println("2 2")
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		n int
		m int
	)

	fmt.Scanf("%d ", &t)
	fmt.Println("t =", t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d ", &n, &m)
		fmt.Println("n =", n, "m =", m)
		if n == 1 || m == 1 {
			fmt.Println("1 1")
		} else {
			fmt.Println("2 2")
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		n int
		m int
	)

	fmt.Scanf("%d", &t)
	fmt.Println("t =", t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d", &n, &m)
		fmt.Println("n =", n, "m =", m)
		if n == 1 || m == 1 {
			fmt.Println("1 1")
		} else {
			fmt.Println("2 2")
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		n int
		m int
	)

	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d", &n, &m)
		if n == 1 || m == 1 {
			fmt.Println("1 1")
		} else {
			fmt.Println("2 2")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n, m int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n, &m)
		fmt.Println(1, 1)
	}
}

package main

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

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

func (in *CF1739A) 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 *CF1739A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1739A
Date: 9/29/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1739/A
Problem: CF1739A
**/
func (in *CF1739A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextString()
		fmt.Println(n, m)
	}
}

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

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

package main

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

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

func (in *CF1739A) 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 *CF1739A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1739A
Date: 9/29/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1739/A
Problem: CF1739A
**/
func (in *CF1739A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		_, _ = in.NextInt(), in.NextString()
		fmt.Println(1, 1)
	}
}

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

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

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)

	fmt.Println((n/2)+1, (m/2)+1)
}

package main

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

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

	var n, m, t int

	for fmt.Fscan(r, &t); t > 0; t-- {
		fmt.Fscan(r, &n, &m)
		if m > n {
			temp := m
			m = n
			n = temp
		}

		if n == 2 && m == 3 {
			fmt.Fprintln(w, 1, 2)
		} else {
			fmt.Fprintln(w, 1, 1)
		}
	}
}


package main

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

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

	var t int

	fmt.Fscan(r, &t)

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

		a := make([]int, n)

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

		ans := solve(a, n)

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

func solve(a[]int, n int) []int {

	sort.Ints(a)

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		mp[a[i]]++
	}

	var b []int

	for k , v := range mp {
		if v > 1 {
			b = append(b, k)
		}
	}

	var s int
	var e int

	if len(b) > 0 {
		s = b[0]
		e = b[0]
	} else {

		var minD int = 1e9 + 5

		for k := 0; k < n - 1; k++ {
			if abs(a[k] - a[k + 1]) < minD {
				s = a[k]
				e = a[k + 1]
				minD = abs(a[k] - a[k + 1])
			}
		}

	}
	var ans []int
	ans = append(ans, s)

	startIndex := sort.Search(n, func(i int) bool {
		return a[i] >= s
	})

	for j := startIndex + 2 ; j < n; j++ {
		ans = append(ans, a[j])
	}

	for j := 0; j < startIndex; j++ {
		ans = append(ans, a[j])
	}

	ans = append(ans, e)
	return ans
}

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

	return x
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		if n == 2 {
			Fprintln(out, a[0],a[1])
			return
		}
		miI :=1
		for i := 1; i < n; i++ {
			if a[i]-a[i-1] < a[miI]-a[miI-1] {
				miI = i
			}
		}
		for _, v := range a[miI:] {
			Fprint(out, v, " ")
		}
		for _, v := range a[:miI] {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

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

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

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	cases()
	// solve()
}

/* --- Solution C --- */
func solve() {
	n := in.nextInt()

	heights := make([]int, n)
	for i := 0; i < n; i++ {
		h := in.nextInt()
		heights[i] = h
	}

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

	var pos int
	var diff int = 1e9 + 7
	for i := 0; i < n-1; i++ {
		if heights[i+1]-heights[i] < diff {
			diff = heights[i+1] - heights[i]
			pos = i + 1
		}
	}

	if n == 2 {
		out.printf("%d %d\n", heights[0], heights[1])
		return
	}
	for i, j := 0, pos; i < n; i, j = i+1, (j+1)%n {
		out.printf("%d ", heights[j])
	}
	out.println()

}

func cases() {
	tt := in.nextInt()
	for ; tt > 0; tt-- {
		solve()
	}
}

/* --- I/O --- */
const BUF_MAX_CAP int = 2e5 + 43

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

func (in *In) nextByte() byte {
	in.scanner.Scan()
	return in.scanner.Text()[0]
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)
		a.Sort()

		if len(a) == 2 {
			io.PrintlnIntSlice(a)
			continue
		}

		minDist := a[1] - a[0]
		for i := 2; i < a.Len(); i++ {
			minDist = min(minDist, a[i]-a[i-1])
		}

		i := 1
		for ; i < a.Len(); i++ {
			if a[i] - a[i-1] == minDist	{
				break
			}
		}

		io.PrintIntSlice(a[i:])
		io.PrintlnIntSlice(a[:i])
	}
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

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

		sort.Ints(h)

		index := low(h)

		ans := order(h, index)

		if n == 2 {
			ans = h
		}

		for i := 0; i < n; i++ {
			fmt.Printf("%d ", ans[i])
		}
		fmt.Println()
	}
}

func order(a []int, j int) (b []int) {
	b = a[j:]
	b = append(b, a[:j]...)

	return
}

func low(a []int) (index int) {
	n := len(a)
	diff := a[n-1]

	for i := 1; i < n; i++ {
		if a[i]-a[i-1] < diff {
			diff = a[i] - a[i-1]
			index = i
		}
	}

	return
}

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		sort.Ints(nums)
		shortest, pos := int(1e9), 0
		for i := 0; i < n - 1; i++ {
			if abs(nums[i] - nums[i+1]) < shortest {
				shortest, pos = abs(nums[i] - nums[i+1]), i
			}
		}

		Fprint(out, nums[pos], " ")
		for i := pos + 2; i < n; i++ {
			Fprint(out, nums[i], " ")
		}
		for i := 0; i < pos; i++ {
			Fprint(out, nums[i], " ")
		}

		Fprintln(out, nums[pos+1], " ")
	}
}

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

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

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

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

package main

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

const inf int = 1<<31 - 1

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

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

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

		h := make([]int, n)
		for i := range h {
			scanf("%d", &h[i])
		}
		scanf("\n") // \n
		sort.Ints(h)
		offset := 0
		if n > 2 {
			d_min := inf
			for i := 1; i < n; i++ {
				if d_min > h[i]-h[i-1] {
					d_min = h[i] - h[i-1]
					offset = i
				}
			}
		}
		for i := range h {
			v := h[(offset+i)%n]
			if i == 0 {
				printf("%d", v)
			} else {
				printf(" %d", v)
			}
		}
		printf("\n")
	}

	writer.Flush()
}

package main

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

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

	var t int
	fmt.Fscan(reader, &t)

	var n int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		arr := make([]int, n)
		for i := range arr {
			fmt.Fscan(reader, &arr[i])
		}
		sort.Ints(arr)

		if n == 2 {
			for _, num := range arr {
				fmt.Fprint(writer, num, " ")
			}
			fmt.Fprintln(writer)
			continue
		}

		mid, diff := 0, 1<<31-1
		for i := 0; i < n; i++ {
			if i+1 < n && arr[i+1]-arr[i] < diff {
				mid, diff = i+1, arr[i+1]-arr[i]
			}
		}
		for i := mid; i < n; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		for i := 0; i < mid; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		fmt.Fprintln(writer)
	}
}

package main

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

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

*/

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

	bld := strings.Builder{}

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

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

		h := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &h[i])
		}
		scanf("\n")

		sort.Ints(h)

		fstIdx := 0
		lstIdx := n - 1

		for i := 0; i < n-1; i++ {
			if h[i+1]-h[i] < h[lstIdx]-h[fstIdx] {
				fstIdx = i
				lstIdx = i + 1
			}
		}

		fmt.Fprintf(&bld, "%d ", h[fstIdx])

		for i := fstIdx + 1; i < n; i++ {
			if i != lstIdx {
				fmt.Fprintf(&bld, "%d ", h[i])
			}
		}
		for i := 0; i < fstIdx; i++ {
			fmt.Fprintf(&bld, "%d ", h[i])
		}

		fmt.Fprintf(&bld, "%d\n", h[lstIdx])
	}

	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 {
	fst int
	snd int
}

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)
}

func digitAt(num, pos int64) int64 {
	rem := num % int64(math.Pow(10, float64(pos)))
	return rem / int64(math.Pow(10, float64(pos-1)))
}

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		sort.Ints(nums)
		shortest, pos := int(1e9), 0
		for i := 0; i < n - 1; i++ {
			if abs(nums[i] - nums[i+1]) < shortest {
				shortest, pos = abs(nums[i] - nums[i+1]), i
			}
		}

		Fprint(out, nums[pos], " ")
		for i := 0; i < pos; i++ {
			Fprint(out, nums[i], " ")
		}
		for i := pos + 2; i < n; i++ {
			Fprint(out, nums[i], " ")
		}
		Fprintln(out, nums[pos+1], " ")
	}
}

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

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

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

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

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		smallest := int(1e9) + 1
		for k, v := range mp {
			if v > 1 {
				smallest = min(smallest, k)
			}
		}

		sort.Ints(nums)
		if smallest == int(1e9) + 1 {
			Fprint(out, nums[0], " ")
			for i := 2; i < n; i++ {
				Fprint(out, nums[i], " ")
			}
			Fprintln(out, nums[1])

		} else {
			pos := sort.SearchInts(nums, smallest)
			Fprint(out, smallest, " ")
			for i := pos + 2; i < n; i++ {
				Fprint(out, nums[i], " ")
			}
			for i := 0; i < pos; i++ {
				Fprint(out, nums[i], " ")
			}
			Fprintln(out, smallest)
		}
	}
}

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

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

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

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

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		smallest := int(1e9) + 1
		for k, v := range mp {
			if v > 1 {
				smallest = min(smallest, k)
			}
		}

		sort.Ints(nums)
		if smallest == int(1e9) + 1 {
			Fprint(out, nums[0], " ")
			for i := 2; i < n; i++ {
				Fprint(out, nums[i], " ")
			}
			Fprintln(out, nums[n - 1])

		} else {
			pos := sort.SearchInts(nums, smallest)
			Fprint(out, smallest, " ")
			for i := pos + 2; i < n; i++ {
				Fprint(out, nums[i], " ")
			}
			for i := 0; i < pos; i++ {
				Fprint(out, nums[i], " ")
			}
			Fprintln(out, smallest)
		}
	}
}

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

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

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

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

package main

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

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

	var t int
	fmt.Fscan(reader, &t)

	var n int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		arr := make([]int, n)
		for i := range arr {
			fmt.Fscan(reader, &arr[i])
		}
		sort.Ints(arr)

		if n == 2 {
			for _, num := range arr {
				fmt.Fprint(writer, num, " ")
			}
			fmt.Fprintln(writer)
			return
		}

		mid, diff := 0, 1<<31-1
		for i := 0; i < n; i++ {
			if i+1 < n && arr[i+1]-arr[i] < diff {
				mid, diff = i+1, arr[i+1]-arr[i]
			}
		}
		for i := mid; i < n; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		for i := 0; i < mid; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		fmt.Fprintln(writer)
	}
}

package main

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

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

	var t int
	fmt.Fscan(reader, &t)

	var n int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		arr := make([]int, n)
		for i := range arr {
			fmt.Fscan(reader, &arr[i])
		}
		sort.Ints(arr)
		mid := 0
		for ; mid+1 < n; mid++ {
			if arr[mid] == arr[mid+1] {
				break
			}
		}
		for i := mid + 1; i < n; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		for i := 0; i <= mid; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		fmt.Fprintln(writer)
	}
}

package main

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

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

	var t int

	fmt.Fscan(r, &t)

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

		a := make([]int, n)

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

		ans := solve(a, n)

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

func solve(a[]int, n int) []int {

	sort.Ints(a)

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		mp[a[i]]++
	}

	var b []int

	for k , v := range mp {
		if v > 1 {
			b = append(b, k)
		}
	}

	var s int
	var e int

	if len(b) > 0 {
		s = b[0]
		e = b[0]
	} else {

		var minD int = 1e9 + 5

		for k := 0; k < n - 1; k++ {
			if abs(a[k] - a[k + 1]) < minD {
				s = a[k]
				e = a[k + 1]
			}
		}

	}
	var ans []int
	ans = append(ans, s)

	startIndex := sort.Search(n, func(i int) bool {
		return a[i] >= s
	})

	for j := startIndex + 2 ; j < n; j++ {
		ans = append(ans, a[j])
	}

	for j := 0; j < startIndex; j++ {
		ans = append(ans, a[j])
	}

	ans = append(ans, e)
	return ans
}

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

	return x
}

package main

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

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

	var t int

	fmt.Fscan(r, &t)

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

		a := make([]int, n)

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

		ans := solve(a, n)

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

func solve(a[]int, n int) []int {

	//4 2 1 5 3 6 5 7 8

	// 1 2 3 4 5 5 6 7 8

	//5 6 7 8 1 2 3 4 5

	sort.Ints(a)

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		mp[a[i]]++
	}

	var b []int

	for k , v := range mp {
		if v > 1 {
			b = append(b, k)
		}
	}

	var s int
	var e int

	if len(b) > 0 {
		s = b[0]
		e = b[0]
	} else {
		s = a[0]
		e = a[1]
	}
	var ans []int
	ans = append(ans, s)

	startIndex := sort.Search(n, func(i int) bool {
		return a[i] >= s
	})

	for j := startIndex + 2 ; j < n; j++ {
		ans = append(ans, a[j])
	}

	for j := 0; j < startIndex; j++ {
		ans = append(ans, a[j])
	}

	ans = append(ans, e)
	return ans
}

package main

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

/*
5
5
1 4 2 3 1
2
1 2
2
4 2
2
3 3
3
1 2 3
---
1 2 3 4 1
1 2
2 4
3 3
1 3 2
*/

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

	bld := strings.Builder{}

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

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

		h := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &h[i])
		}
		scanf("\n")

		sort.Ints(h)

		fstIdx := 0
		lstIdx := n - 1

		for i, j := 0, n-2; i <= j; i, j = i+1, j-1 {
			if h[i+1]-h[i] < h[lstIdx]-h[fstIdx] {
				fstIdx = i
				lstIdx = i + 1
			}

			if h[j+1]-h[j] < h[lstIdx]-h[fstIdx] {
				fstIdx = j
				lstIdx = j + 1
			}
		}

		fmt.Fprintf(&bld, "%d ", h[fstIdx])

		if n == 4 {
			c := make([]int, 0)
			for i := 0; i < n; i++ {
				if i != fstIdx && i != lstIdx {
					c = append(c, h[i])
				}
			}
			if h[fstIdx] <= c[1] && c[0] <= h[lstIdx] {
				fmt.Fprintf(&bld, "%d %d ", c[1], c[0])
			} else {
				fmt.Fprintf(&bld, "%d %d ", c[0], c[1])
			}
		} else {
			for i := 0; i < n; i++ {
				if i != fstIdx && i != lstIdx {
					fmt.Fprintf(&bld, "%d ", h[i])
				}
			}
		}

		fmt.Fprintf(&bld, "%d\n", h[lstIdx])
	}

	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 {
	fst int
	snd int
}

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)
}

func digitAt(num, pos int64) int64 {
	rem := num % int64(math.Pow(10, float64(pos)))
	return rem / int64(math.Pow(10, float64(pos-1)))
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		miI :=1
		for i := 1; i < n; i++ {
			if a[i]-a[i-1] < a[miI]-a[miI-1] {
				miI = i
			}
		}
		for _, v := range a[miI:] {
			Fprint(out, v, " ")
		}
		for _, v := range a[:miI] {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

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

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


package main

import "os"
import "bufio"
import "strconv"
import "sort"

type int64arr []int64
func (a int64arr) Len() int { return len(a) }
func (a int64arr) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a int64arr) Less(i, j int) bool { return a[i] < a[j] }

func sel(x []int64, count int64) []int64 {
	var pos int64
	var temp int64
	for i:=0; int64(i)<count-1; i++ {
		pos = int64(i)
		for j:=i+1; int64(j)<count; j++ {
			if x[pos] > x[j] {
				pos = int64(j)
			}
		}
		if pos != int64(i) {
			temp = x[i]
			x[i] = x[pos]
			x[pos] = temp
		}
	}
	return x
}

func main(){
	var n, d, a, b, x, y, sum int64
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	d, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	a, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	b, _ = strconv.ParseInt(r.Text(), 0, 64)
	arr := make([]int64, n)
	arr2 := make([]int64, n)
	var i int
	for i=0; int64(i)<n; i++ {
		r.Scan()
		x, _ = strconv.ParseInt(r.Text(), 0, 64)
		r.Scan()
		y, _ = strconv.ParseInt(r.Text(), 0, 64)
		arr[i] = x*a+y*b
		arr2[i] = arr[i]
	}
	sort.Sort(int64arr(arr))
	for i=0; int64(i)<n; i++ {
		if sum+arr[i] > d {
			break
		}
		sum += arr[i]
	}
	count := i
	count1 := 0
	var limit int64
	w.WriteString(strconv.Itoa(count)+"\n")
	if count != 0 {
		limit = arr[count-1]
	}
	for i=0; int64(i)<n; i++ {
		if arr2[i] < limit {
			w.WriteString(strconv.Itoa(i+1)+" ")
			count1 += 1
		}
	}
	i = 0
	for count1 != count {
		if arr2[i] == limit {
			w.WriteString(strconv.Itoa(i+1)+" ")
			count1 += 1
		}
		i++
	}
	w.WriteString("\n")
	w.Flush()
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

type Person struct {
	Need, Rank int
}
type People []Person
func (people People) Len() int {
	return len(people)
}
func (people People) Swap(i, j int) {
	people[i], people[j] = people[j], people[i]
}
func (people People) Less(i, j int) bool {
	return people[i].Need < people[j].Need
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, d := scanInt(scanner), scanInt(scanner)
	a, b := scanInt(scanner), scanInt(scanner)
	people := make(People, n)
	for i, _ := range people {
		x, y := scanInt(scanner), scanInt(scanner)
		people[i].Need = a*x + b*y
		people[i].Rank = i+1
	}
	sort.Sort(people)
	pos := 0
	for {
		d -= people[pos].Need
		if d < 0 {
			break
		}
		pos++
		if pos == n {
			break
		}
	}
	writer.WriteString(fmt.Sprintf("%d\n", pos))
	if pos != 0 {
		writer.WriteString(fmt.Sprintf("%d", people[0].Rank))
	}
	for i := 1; i < pos; i++ {
		writer.WriteString(fmt.Sprintf(" %d", people[i].Rank))
	}
	writer.WriteString("\n")
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, d int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	d, _ = strconv.Atoi(r.Text())
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	y := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
		x[i] *= a
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
		y[i] *= b
	}
	count := 0
	client := make([]int, n)
	for j:=0; j<n; j++ {
		if x[j] + y[j] <= d {
			d -= x[j]+y[j]
			client[count] = j+1
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	for k:=0; k<count; k++ {
		w.WriteString(strconv.Itoa(client[k])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, d int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	d, _ = strconv.Atoi(r.Text())
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	xa := make([]int, n)
	y := make([]int, n)
	ya := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
		xa[i] = x[i]*a
		x[i] *= a
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
		ya[i] = y[i]*b
		y[i] *= b
	}
	for i:=0; i<n-1; i++ {
		for j:=i+1; j<n; j++ {
			if x[j] + y[j] < x[i] + y[i] {
				x[i], y[i], x[j], y[j] = x[j], y[j], x[i], y[i]

			}
		}
	}
	count := 0
	client := make([]int, n)
	for j:=0; j<n; j++ {
		if x[j] + y[j] <= d {
			d -= x[j]+y[j]
			for k:=0; k<n; k++ {
				if x[j] == xa[k] && y[j] == ya[k] {
					client[count] = k+1

					break
				}
			}
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	for k:=0; k<count; k++ {
		w.WriteString(strconv.Itoa(client[k])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, d int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	d, _ = strconv.Atoi(r.Text())
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	xa := make([]int, n)
	y := make([]int, n)
	ya := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
		xa[i] = x[i]*a
		x[i] *= a
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
		ya[i] = y[i]*b
		y[i] *= b
	}
	for i:=0; i<n-1; i++ {
		for j:=i+1; j<n; j++ {
			if x[j] + y[j] < x[i] + y[i] {
				x[i], y[i], x[j], y[j] = x[j], y[j], x[i], y[i]

			}
		}
	}
	count := 0
	client := make([]int, n)
	prev := 0
	for j:=0; j<n; j++ {
		if x[j] + y[j] <= d {
			d -= x[j]+y[j]
			for k:=0; k<n; k++ {
				if x[j] == xa[k] && y[j] == ya[k] {
					client[count] = k+1
					if client[count] == prev {
						client[count] += 1
					}
					prev = client[count]
					break
				}
			}
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	for k:=0; k<count; k++ {
		w.WriteString(strconv.Itoa(client[k])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, d int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	d, _ = strconv.Atoi(r.Text())
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	y := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
		x[i] *= a
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
		y[i] *= b
	}
	for i:=0; i<n-1; i++ {
		for j:=i+1; j<n; j++ {
			if x[j] + y[j] < x[i] + y[i] {
				x[i], y[i], x[j], y[j] = x[j], y[j], x[i], y[i]
			}
		}
	}
	count := 0
	client := make([]int, n)
	for j:=0; j<n; j++ {
		if x[j] + y[j] <= d {
			d -= x[j]+y[j]
			client[count] = j+1
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	for k:=0; k<count; k++ {
		w.WriteString(strconv.Itoa(client[k])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

type Person struct {
	Need, Rank int
}
type People []Person
func (people People) Len() int {
	return len(people)
}
func (people People) Swap(i, j int) {
	people[i], people[j] = people[j], people[i]
}
func (people People) Less(i, j int) bool {
	return people[i].Need < people[j].Need
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, d := scanInt(scanner), scanInt(scanner)
	a, b := scanInt(scanner), scanInt(scanner)
	people := make(People, n)
	for i, _ := range people {
		x, y := scanInt(scanner), scanInt(scanner)
		people[i].Need = a*x + b*y
		people[i].Rank = i+1
	}
	sort.Sort(people)
	var pos int
	for pos = 0; pos != n && d >= 0; pos++ {
		d -= people[pos].Need
	}
	writer.WriteString(fmt.Sprintf("%d\n", pos))
	if pos != 0 {
		writer.WriteString(fmt.Sprintf("%d", people[0].Rank))
	}
	for i := 1; i < pos; i++ {
		writer.WriteString(fmt.Sprintf(" %d", people[i].Rank))
	}
	writer.WriteString("\n")
}