package main

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

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

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

func fun() {
	var s string
	scanf("%s\n", &s)
	printf("%s\n", solve(s))
}

func solve(s string) string {
	n := len(s)
	ans := make([]byte, 0, n)
	oddIndex := 0
	evenIndex := 0
	for oddIndex < n && evenIndex < n {
		if s[oddIndex]%2 == 0 {
			oddIndex++
			continue
		}
		if s[evenIndex]%2 == 1 {
			evenIndex++
			continue
		}
		if s[oddIndex] < s[evenIndex] {
			ans = append(ans, s[oddIndex])
			oddIndex++
			continue
		}
		if s[evenIndex] < s[oddIndex] {
			ans = append(ans, s[evenIndex])
			evenIndex++
			continue
		}
	}
	for ; oddIndex < n; oddIndex++ {
		if s[oddIndex]%2 == 0 {
			continue
		}
		ans = append(ans, s[oddIndex])
	}
	for ; evenIndex < n; evenIndex++ {
		if s[evenIndex]%2 == 1 {
			continue
		}
		ans = append(ans, s[evenIndex])
	}
	return string(ans)
}

func main() {
	// Flush stdout
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fun()
	}
}

package main

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

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		solveOne(read())
	}
}

func solveOne(s string) {

	q := make([][]rune, 1)

	str := make([]rune, 1)
	str[0] = rune(s[0])
	q[0] = str

	for i := 1; i < len(s); i++ {
		if (s[i]-s[i-1])%2 == 0 {
			q[len(q)-1] = append(q[len(q)-1], rune(s[i]))
		} else {
			str := make([]rune, 1)
			str[0] = rune(s[i])
			q = append(q, str)
		}
	}

	ans := make([]rune, 0)

	for {
		if len(q) < 2 {
			ans = append(ans, q[0]...)
			break
		}
		if len(q[0]) == 0 {
			q = q[1:]
			continue
		}
		if len(q[1]) == 0 {
			if len(q) < 3 {
				q = q[:1]
			} else {
				q[2] = append(q[0], q[2]...)
				q = q[2:]
			}
			continue
		}
		cur := rune(q[0][0])
		cand := q[1][0]
		if cur > cand {
			ans = append(ans, cand)
			q[1] = q[1][1:]
		} else {
			ans = append(ans, cur)
			q[0] = q[0][1:]
		}
	}

	print(string(ans))

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanLines)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	q := 0
	fmt.Fscanf(in, "%d\n", &q)
	res := make([][]byte, q)
	var wg sync.WaitGroup
	wg.Add(q)
	for i := 0; i < q; i++ {
		s, _ := in.ReadBytes('\n')
		s = s[:len(s)-2]
		go func(id int, str []byte) {
			defer wg.Done()
			odds, evens := []byte{}, []byte{}
			for _, c := range str {
				if c%2 == 0 {
					odds = append(odds, c)
				} else {
					evens = append(evens, c)
				}
			}
			a, b := 0, 0
			for a < len(odds) && b < len(evens) {
				if odds[a] < evens[b] {
					res[id] = append(res[id], odds[a])
					a++
				} else {
					res[id] = append(res[id], evens[b])
					b++
				}
			}
			res[id] = append(res[id], odds[a:]...)
			res[id] = append(res[id], evens[b:]...)
		}(i, s)
	}
	wg.Wait()
	for _, s := range res {
		fmt.Println(string(s))
	}
}

package main

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		// str := strconv.FormatInt(A[i], 10)  // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var S []rune

func main() {
	t = ReadInt()

	for i := 0; i < t; i++ {
		S = ReadRuneSlice()
		// for j := 0; j < 150000; j++ {
		// 	S = append(S, '0')
		// }
		// for j := 0; j < 150000; j++ {
		// 	S = append(S, '9')
		// }

		// evens := make([]rune, 0, 300000+5)
		// odds := make([]rune, 0, 300000+5)
		evens := []rune{}
		odds := []rune{}
		for j := 0; j < len(S); j++ {
			if (S[j]-'0')%2 == 0 {
				evens = append(evens, S[j])
			} else {
				odds = append(odds, S[j])
			}
		}

		// answers := make([]rune, 0, 300000+5)
		answers := []rune{}
		e, o := 0, 0
		for e < len(evens) || o < len(odds) {
			if e == len(evens) {
				answers = append(answers, odds[o])
				o++
			} else if o == len(odds) {
				answers = append(answers, evens[e])
				e++
			} else if evens[e] < odds[o] {
				answers = append(answers, evens[e])
				e++
			} else {
				answers = append(answers, odds[o])
				o++
			}
		}

		fmt.Println(string(answers))
		// for j := 0; j < len(answers); j++ {
		// 	if j == len(answers)-1 {
		// 		fmt.Printf("%c\n", answers[j])
		// 	} else {
		// 		fmt.Printf("%c", answers[j])
		// 	}
		// }
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

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 main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	tt := 1
	fmt.Fscanf(in, "%d\n", &tt)
	for ii := 0; ii < tt; ii++ {
		n := ""
		fmt.Fscanf(in, "%s\n", &n)

		fmt.Fprintf(out, "%s\n", solve(n))
	}
	return
}

func solve(n string) string {
	a := []int{}
	b := []int{}
	for i := 0; i < len(n); i++ {
		cur := int(n[i] - '0')
		if cur%2 == 0 {
			a = append(a, cur)
		} else {
			b = append(b, cur)
		}
	}
	ans := []byte{}
	for len(a)+len(b) > 0 {
		if len(a) == 0 {
			ans = append(ans, '0'+byte(b[0]))
			b = b[1:]
		} else if len(b) == 0 {
			ans = append(ans, '0'+byte(a[0]))
			a = a[1:]
		} else if a[0] < b[0] {
			ans = append(ans, '0'+byte(a[0]))
			a = a[1:]
		} else {
			ans = append(ans, '0'+byte(b[0]))
			b = b[1:]
		}
	}
	return string(ans)
}

func help(i int, n int, total int, t []int, g []int, cur int, c1, c2, c3 int, remaining int) {
	//fmt.Println(i, cur)
	if i == n {
		if cur == total {
			cal(c1, c2, c3)
		}
		return
	}
	if cur > total {
		return
	}
	if cur+remaining < total {
		return
	}
	switch g[i] {
	case 1:
		help(i+1, n, total, t, g, cur+t[i], c1+1, c2, c3, remaining-t[i])
	case 2:
		help(i+1, n, total, t, g, cur+t[i], c1, c2+1, c3, remaining-t[i])
	case 3:
		help(i+1, n, total, t, g, cur+t[i], c1, c2, c3+1, remaining-t[i])
	}
	help(i+1, n, total, t, g, cur, c1, c2, c3, remaining-t[i])
}

func cal(c1, c2, c3 int) {
	a := []int{c1, c2, c3}
	sort.Ints(a)
	tmp := int64(try(c1, c2, c3, 0))
	tmp %= int64(mod)
	for i := 1; i <= c1; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c2; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c3; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	ans += tmp
	ans %= int64(mod)
}

func try(a, b, c int, last int) int64 {
	if a == 0 && b == 0 && c == 0 {
		return 1
	}
	if a < 0 || b < 0 || c < 0 {
		return 0
	}
	if last == 0 {
		return try(a-1, b, c, 1) + try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 1 {
		return try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 2 {
		return try(a-1, b, c, 1) + try(a, b, c-1, 3)
	}
	return try(a-1, b, c, 1) + try(a, b-1, c, 2)
}

package main

import (
	"fmt"
)

func main() {
	var str string
	var n int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&str)

		var oddArr, evenArr = []uint8{}, []uint8{}
		var oddIdx, evenIdx, strLen int
		strLen = len(str)
		var res = []uint8{}

		for j := 0; j < strLen; j++ {
			if str[j]%2 == 1 {
				oddArr = append(oddArr, str[j])
				oddIdx++
			} else {
				evenArr = append(evenArr, str[j])
				evenIdx++
			}
		}
		for x, y := 0, 0; x < oddIdx || y < evenIdx; {
			if y >= evenIdx || (x < oddIdx && oddArr[x] < evenArr[y]) {
				res = append(res, oddArr[x])
				x++
			} else {
				res = append(res, evenArr[y])
				y++
			}
		}
		fmt.Println(string(res))
	}
}

package main

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

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

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

func fun() {
	var s string
	scanf("%s\n", &s)
	printf("%s\n", solve(s))
}

func solve(s string) string {
	ans := []byte{}
	n := len(s)
	oddIndex := 0
	evenIndex := 0
	for oddIndex < n && evenIndex < n {
		if s[oddIndex]%2 == 0 {
			oddIndex++
			continue
		}
		if s[evenIndex]%2 == 1 {
			evenIndex++
			continue
		}
		if s[oddIndex] < s[evenIndex] {
			ans = append(ans, s[oddIndex])
			oddIndex++
			continue
		}
		if s[evenIndex] < s[oddIndex] {
			ans = append(ans, s[evenIndex])
			evenIndex++
			continue
		}
	}
	for ; oddIndex < n; oddIndex++ {
		if s[oddIndex]%2 == 0 {
			continue
		}
		ans = append(ans, s[oddIndex])
	}
	for ; evenIndex < n; evenIndex++ {
		if s[evenIndex]%2 == 1 {
			continue
		}
		ans = append(ans, s[evenIndex])
	}
	return string(ans)
}

func main() {
	// Flush stdout
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fun()
	}
}

package main

import "fmt"

func fun() {
	var s string
	fmt.Scanln(&s)
	fmt.Println(solve(s))
}

func solve(s string) string {
	ans := []byte{}
	n := len(s)
	oddIndex := 0
	evenIndex := 0
	for oddIndex < n && evenIndex < n {
		if s[oddIndex]%2 == 0 {
			oddIndex++
			continue
		}
		if s[evenIndex]%2 == 1 {
			evenIndex++
			continue
		}
		if s[oddIndex] < s[evenIndex] {
			ans = append(ans, s[oddIndex])
			oddIndex++
			continue
		}
		if s[evenIndex] < s[oddIndex] {
			ans = append(ans, s[evenIndex])
			evenIndex++
			continue
		}
	}
	for ; oddIndex < n; oddIndex++ {
		if s[oddIndex]%2 == 0 {
			continue
		}
		ans = append(ans, s[oddIndex])
	}
	for ; evenIndex < n; evenIndex++ {
		if s[evenIndex]%2 == 1 {
			continue
		}
		ans = append(ans, s[evenIndex])
	}
	return string(ans)
}

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

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for t := stdin.ReadInt(); t > 0; t-- {
		s := stdin.Read()
		o := NewDeque()
		e := NewDeque()
		for _, ch := range s {
			x := ch - '0'
			if x%2 == 0 {
				e.AppendLast(ch)
			} else {
				o.AppendLast(ch)
			}
		}

		n := len(s)
		ans := make([]rune, n)
		for i := 0; i < n; i++ {
			if e.IsEmpty() {
				ans[i] = o.PopFirst().(rune)
			} else if o.IsEmpty() {
				ans[i] = e.PopFirst().(rune)
			} else {
				r1 := o.PeekFirst().(rune)
				r2 := e.PeekFirst().(rune)
				if r1 < r2 {
					ans[i] = r1
					o.PopFirst()
				} else {
					ans[i] = r2
					e.PopFirst()
				}
			}
		}

		stdout.Println(string(ans))
	}
}

type Deque struct {
	head []interface{}
	tail []interface{}
}

func NewDeque() *Deque {
	return &Deque{
		head: []interface{}{},
		tail: []interface{}{},
	}
}

func (d *Deque) AppendLast(v interface{}) {
	d.tail = append(d.tail, v)
}

func (d *Deque) AppendFirst(v interface{}) {
	d.head = append(d.head, v)
}

func (d *Deque) PopLast() interface{} {
	if len(d.tail) == 0 {
		v := d.head[0]
		d.head = d.head[1:]
		return v
	} else {
		v := d.tail[len(d.tail)-1]
		d.tail = d.tail[:len(d.tail)-1]
		return v
	}
}

func (d *Deque) PopFirst() interface{} {
	if len(d.head) == 0 {
		v := d.tail[0]
		d.tail = d.tail[1:]
		return v
	} else {
		v := d.head[len(d.head)-1]
		d.head = d.head[:len(d.head)-1]
		return v
	}
}

func (d *Deque) IsEmpty() bool {
	return len(d.head) == 0 && len(d.tail) == 0
}

func (d *Deque) PeekFirst() interface{} {
	if len(d.head) == 0 {
		return d.tail[0]
	} else {
		return d.head[len(d.head)-1]
	}
}

func (d *Deque) PeekLast() interface{} {
	if len(d.tail) == 0 {
		return d.head[0]
	} else {
		return d.tail[len(d.tail)-1]
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	q := 0
	fmt.Fscanf(in, "%d\n", &q)
	res := make([][]byte, q)
	var wg sync.WaitGroup
	wg.Add(q)
	for i := 0; i < q; i++ {
		s, _ := in.ReadBytes('\n')
		s = s[:len(s)-1]
		go func(id int, str []byte) {
			defer wg.Done()
			odds, evens := []byte{}, []byte{}
			for _, c := range str {
				if c%2 == 0 {
					odds = append(odds, c)
				} else {
					evens = append(evens, c)
				}
			}
			a, b := 0, 0
			for a < len(odds) && b < len(evens) {
				if odds[a] < evens[b] {
					res[id] = append(res[id], odds[a])
					a++
				} else {
					res[id] = append(res[id], evens[b])
					b++
				}
			}
			res[id] = append(res[id], odds[a:]...)
			res[id] = append(res[id], evens[b:]...)
		}(i, s)
	}
	wg.Wait()
	for _, s := range res {
		fmt.Println(string(s))
	}
}


package main

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

type FastIn struct {
	scanner *bufio.Scanner
}

func MakeFastIn() (obj FastIn)  {
	obj = FastIn{}
	obj.scanner = bufio.NewScanner(os.Stdin)
	obj.scanner.Split(bufio.ScanWords)
	return
}

func (fi *FastIn) ReadInt() int {
	fi.scanner.Scan()
	ret, err := strconv.Atoi(fi.scanner.Text())
	if err != nil {
		panic(err)
	}
	return ret
}

func main() {
	fin := MakeFastIn()
	t := fin.ReadInt()
	for i := 0; i < t; i++ {
		n := fin.ReadInt()
		x := fin.ReadInt()
		p := make([]int, n)
		for j := 0; j < n; j++ {
			p[j] = fin.ReadInt()
		}

		sort.Ints(p[:])
		ans := 0
		cnt := 0
		for j := n-1; j >= 0; j-- {
			cnt += 1
			if int64(p[j]) * int64(cnt) >= int64(x) {
				cnt = 0
				ans += 1
			}
		}
		fmt.Printf("%d\n",ans)
	}
}

package main

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

type FastIn struct {
	scanner *bufio.Scanner
}

func MakeFastIn() (obj FastIn)  {
	obj = FastIn{}
	obj.scanner = bufio.NewScanner(os.Stdin)
	obj.scanner.Split(bufio.ScanWords)
	return
}

func (fi *FastIn) ReadInt() int {
	fi.scanner.Scan()
	ret, err := strconv.Atoi(fi.scanner.Text())
	if err != nil {
		panic(err)
	}
	return ret
}

func main() {
	fin := MakeFastIn()
	t := fin.ReadInt()
	for i := 0; i < t; i++ {
		n, x := fin.ReadInt(), fin.ReadInt()
		p := make([]int, n)
		for j := 0; j < n; j++ {
			p[j] = fin.ReadInt()
		}

		sort.Ints(p[:])
		ans, cnt := 0, 0
		for j := n-1; j >= 0; j-- {
			cnt += 1
			if int64(p[j]) * int64(cnt) >= int64(x) {
				cnt, ans = 0, ans + 1
			}
		}
		fmt.Printf("%d\n",ans)
	}
}


package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scanf("%d", &n)
    row := -1
    for i := 5; i*i <= n; i++ {
        if n%i == 0 {
            row = i
            break
        }
    }
    if row == -1 {
        fmt.Println(-1)
        return
    }
    col := n / row
    ans := ""
    foo := "aeiou"
    for i := 0; i < row; i++ {
        for j := 0; j < col; j++ {
            ans += string(foo[(i+j)%5])
        }
    }
    fmt.Println(ans)
    return
}

package main

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

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

	var k int
	fmt.Fscanf(in, "%d\n", &k)

	var n, m int
	for n = 5; float64(n) <= math.Sqrt(float64(k)); n++ {
		if k%n == 0 {
			m = k / n
			break
		}
	}
	if m == 0 {
		fmt.Fprintln(out, -1)
		return
	}
	for i := 0; i < n; i++ {
		fmt.Fprint(out, vowel(m, i))
	}
	fmt.Fprintln(out)
}

func vowel(len int, offset int) string {
	w := "aiueo"
	r := make([]byte, len)
	for i := 0; i < len; i++ {
		r[i] = w[(i+offset)%5]
	}
	return string(r)
}

package main

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

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

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

func main() {
	var k int
	scanf("%d\n", &k)
	ok := false
	var n, m int
	for i := 5; i <= k; i++ {
		if k%i == 0 && k/i >= 5 {
			ok = true
			n = i
			m = k / i
			break
		}
	}
	if !ok {
		fmt.Println(-1)
		return
	}
	var res = make([][]uint8, n)
	template := [][]uint8{
		{'a', 'e', 'u', 'i', 'o'},
		{'o', 'a', 'e', 'u', 'i'},
		{'i', 'o', 'a', 'e', 'u'},
		{'u', 'i', 'o', 'a', 'e'},
		{'e', 'u', 'i', 'o', 'a'},
	}
	for i := 0; i < n; i++ {
		res[i] = make([]uint8, m)
		for j := 0; j < m; j++ {
			res[i][j] = template[i%5][j%5]
		}
	}
	var ans []uint8
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			ans = append(ans, res[i][j])
		}
	}
	fmt.Println(string(ans))
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	k, _ := strconv.Atoi(scanner.Text())
	m := map[int]uint8{
		0: 'a', 1: 'e', 2: 'i', 3: 'o', 4: 'u',
	}
	for i := 5; i * i <= k; i++ {
		if k % i != 0 {
			continue
		}
		for x := 0; x < i; x++ {
			for y := 0; y < k / i; y++ {
				fmt.Printf("%c", m[(x + y) % 5])
			}
		}
		return
	}
	fmt.Print(-1)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	v := []byte{'a', 'e', 'i', 'o', 'u'}
	for i := 5; i <= n/5; i++ {
		if n%i == 0 {
			j := n / i
			if j < 5 {
				continue
			}
			a := make([][]byte, i)
			ans := []byte{}
			for k := 0; k < i; k++ {
				a[k] = make([]byte, j)
			}
			for k := 0; k < i; k++ {
				for q := 0; q < j; q++ {
					a[k][q] = v[(k+q)%5]
					ans = append(ans, v[(k+q)%5])
				}
				//fmt.Println(string(a[k]))
			}
			fmt.Fprintf(out, "%s\n", string(ans))
			return
		}
	}
	fmt.Fprintf(out, "-1\n")
	return
}

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

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

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

func ReadInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

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

func Build(n, m int) ([][]byte, bool) {
	if n < 5 || m < 5 {
		return nil, true
	}

	ret := make([][]byte, n)
	for i := 0; i < n; i++ {
		ret[i] = make([]byte, m)
	}

	str := "aeiou"
	for i := 0; i < 5; i++ {
		for j := 0; j < 5; j++ {
			ret[i][j] = str[(i+j)%len(str)]
		}
	}

	for i := 5; i < n; i++ {
		for j := 0; j < 5; j++ {
			ret[i][j] = str[j]
		}
	}

	for j := 5; j < m; j++ {
		for i := 0; i < 5; i++ {
			ret[i][j] = str[i]
		}
	}

	for i := 5; i < n; i++ {
		for j := 5; j < m; j++ {
			ret[i][j] = 'x'
		}
	}

	return ret, false
}

func Prepare(arr [][]byte) string {
	var b bytes.Buffer
	for i := 0; i < len(arr); i++ {
		for j := 0; j < len(arr[i]); j++ {
			b.WriteByte(arr[i][j])
		}
	}
	return b.String()
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := ReadInt()

	for i := 5; i < n; i++ {
		if n%i == 0 {
			j := n / i
			str, err := Build(i, j)
			if !err {
				fmt.Println(Prepare(str))
				return
			}
		}
	}

	fmt.Println("-1")
}

package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    for h := 5; h < n; h++ {
        if n % h != 0 || n / h < 5 {
            continue
        }
        w := n / h
        var s string
        for i := 0; i < h; i++ {
            for j := 0; j < w; j++ {
                x := (i + j) % 5
                s = s + "aiueo"[x:x+1]
            }
        }
        fmt.Println(s)
        return
    }
    fmt.Println(-1)
}

package main

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

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

	var k int
	fmt.Fscanf(in, "%d\n", &k)

	var n, m int
	for n = 5; float64(n) <= math.Sqrt(float64(k)); n++ {
		if k%n == 0 {
			m = k / n
			break
		}
	}
	if m == 0 {
		fmt.Fprintln(out, -1)
		return
	}

	for i := 0; i < n; i++ {
		fmt.Fprint(out, vowel(i))
		fmt.Fprint(out, rest(m-5))
	}
	fmt.Fprintln(out, "")
}

func vowel(offset int) string {
	w := "aiueo"
	var r []byte
	for i := 0; i < len(w); i++ {
		r = append(r, w[(i+offset)%5])
	}
	return string(r)
}

func rest(len int) string {
	var r []byte
	for i := 0; i < len; i++ {
		r = append(r, 'a')
	}
	return string(r)
}

package main

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

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

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

func main() {
	var k int
	scanf("%d\n", &k)
	ok := false
	var n, m int
	for i := 5; i <= k; i++ {
		if k%i == 0 && k/i >= 5 {
			ok = true
			n = i
			m = k / i
			break
		}
	}
	if !ok {
		fmt.Println(-1)
		return
	}
	var res = make([][]uint8, n)
	template := [][]uint8{
		{'a', 'y', 'u', 'i', 'o'},
		{'o', 'a', 'y', 'u', 'i'},
		{'i', 'o', 'a', 'y', 'u'},
		{'u', 'i', 'o', 'a', 'y'},
		{'y', 'u', 'i', 'o', 'a'},
	}
	for i := 0; i < n; i++ {
		res[i] = make([]uint8, m)
		for j := 0; j < m; j++ {
			if i < 5 && j < 5 {
				res[i][j] = template[i][j]
			} else {
				res[i][j] = 's'
			}
		}
	}
	var ans []uint8
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			ans = append(ans, res[i][j])
		}
	}
	fmt.Println(string(ans))
}

package main

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

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

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

func main() {
	var k int
	scanf("%d\n", &k)
	ok := false
	var n, m int
	for i := 5; i <= k; i++ {
		if k%i == 0 && k/i >= 5 {
			ok = true
			n = i
			m = k / i
			break
		}
	}
	if !ok {
		fmt.Println(-1)
		return
	}
	var res = make([][]uint8, n)
	template := [][]uint8{
		{'a', 'e', 'u', 'i', 'o'},
		{'o', 'a', 'e', 'u', 'i'},
		{'i', 'o', 'a', 'e', 'u'},
		{'u', 'i', 'o', 'a', 'e'},
		{'e', 'u', 'i', 'o', 'a'},
	}
	for i := 0; i < n; i++ {
		res[i] = make([]uint8, m)
		for j := 0; j < m; j++ {
			res[i][j] = template[i%5][j%5]
		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Print(string(res[i][j]))
		}
		fmt.Println()
	}
	var ans []uint8
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			ans = append(ans, res[i][j])
		}
	}
	fmt.Println(string(ans))
}

package main

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

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

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

func main() {
	var k int
	scanf("%d\n", &k)
	ok := false
	var n, m int
	for i := 5; i <= k; i++ {
		if k%i == 0 && k/i >= 5 {
			ok = true
			n = i
			m = k / i
			break
		}
	}
	if !ok {
		fmt.Println(-1)
		return
	}
	var res = make([][]uint8, n)
	template := [][]uint8{
		{'a', 'y', 'u', 'i', 'o'},
		{'o', 'a', 'y', 'u', 'i'},
		{'i', 'o', 'a', 'y', 'u'},
		{'u', 'i', 'o', 'a', 'y'},
		{'y', 'u', 'i', 'o', 'a'},
	}
	for i := 0; i < n; i++ {
		res[i] = make([]uint8, m)
		for j := 0; j < m; j++ {
			res[i][j] = template[i%5][j%5]
		}
	}
	var ans []uint8
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			ans = append(ans, res[i][j])
		}
	}
	fmt.Println(string(ans))
}


package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()

	A := make([]string, N)
	for i := 0; i < N; i++ {
		A[i] = io.NextLine()
	}

	if h, w := N / 3, M / 3;
		(N % 3 == 0 && Valid(A,
			MakeRectangle(0, 0, h, M),
			MakeRectangle(h, 0, h << 1, M),
			MakeRectangle(h << 1, 0, N, M))) ||
		(M % 3 == 0 && Valid(A,
			MakeRectangle(0, 0, N, w),
			MakeRectangle(0, w, N, w << 1),
			MakeRectangle(0, w << 1, N, M))) {
		io.Println("YES")
	} else {
		io.Println("NO")
	}
}

type Rectangle struct {
	R0 int
	C0 int
	Rf int
	Cf int
}

func MakeRectangle(r0, c0, rf, cf int) *Rectangle {
	return &Rectangle {
		R0: r0,
		C0: c0,
		Rf: rf,
		Cf: cf,
	}
}

func Valid(A []string, r1, r2, r3 *Rectangle) bool {
	charSet := make(map[byte]bool)
	rects := [...]*Rectangle{r1, r2, r3}
	for _, rect := range rects {
		if !SameRectangle(A, rect.R0, rect.C0, rect.Rf, rect.Cf) {
			return false
		}
		charSet[A[rect.R0][rect.C0]] = true
	}
	return len(charSet) == 3
}

func SameRectangle(A []string, r0, c0, rf, cf int) bool {
	for r := r0; r < rf; r++ {
		for c := c0; c < cf; c++ {
			if A[r][c] != A[r0][c0] {
				return false
			}
		}
	}
	return true
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()

	A := make([]string, N)
	for i := 0; i < N; i++ {
		A[i] = io.NextLine()
	}

	if h, w := N / 3, M / 3;
		(N % 3 == 0 && Valid(A,
			MakeRectangle(0, 0, h, M),
			MakeRectangle(h, 0, h << 1, M),
			MakeRectangle(h << 1, 0, N, M))) ||
		(M % 3 == 0 && Valid(A,
			MakeRectangle(0, 0, N, w),
			MakeRectangle(0, w, N, w << 1),
			MakeRectangle(0, w << 1, N, M))) {
		io.Println("YES")
	} else {
		io.Println("NO")
	}
}

type Rectangle struct {
	R0 int
	C0 int
	Rf int
	Cf int
}

func MakeRectangle(r0, c0, rf, cf int) *Rectangle {
	return &Rectangle {
		R0: r0,
		C0: c0,
		Rf: rf,
		Cf: cf,
	}
}

func Valid(A []string, r1, r2, r3 *Rectangle) bool {
	charSet := make(map[byte]bool)
	rects := []*Rectangle{r1, r2, r3}
	for _, rect := range rects {
		if !SameRectangle(A, rect.R0, rect.C0, rect.Rf, rect.Cf) {
			return false
		}
		charSet[A[rect.R0][rect.C0]] = true
	}
	return len(charSet) == 3
}

func SameRectangle(A []string, r0, c0, rf, cf int) bool {
	for r := r0; r < rf; r++ {
		for c := c0; c < cf; c++ {
			if A[r][c] != A[r0][c0] {
				return false
			}
		}
	}
	return true
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    min, ansi, ansj := 1000, 0, 0
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    for i := 0; i < n; i++ {
        u := int(math.Abs(float64(a[i])-float64(a[(i+1)%n])))
        if min > u {
            min = u
            ansi = i+1
            ansj = ((i+1)%n)+1
        }
    }
    fmt.Println(ansi,ansj)
}

package main
import (
	"fmt"
	//"sort"
	//"unicode/utf8"
)
func main() {
	var n,vt1,vt2,aa,b int
	fmt.Scan(&n)
	a:=make([]int,101)
	for i:=1;i<=n;i++ {
		fmt.Scan(&a[i])
	}
	vt1=1
	vt2=n
	for i:=1;i<=n-1;i++ {
		aa=a[vt1]-a[vt2]
		if aa<0 {
			aa*=(-1)
		}
		b=a[i]-a[i+1]
		if b<0 {
			b*=(-1)
		}
		if aa>b {
			vt1=i
			vt2=i+1
		}
	}
	fmt.Println(vt1,vt2)

}

// 34A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    a := make([]int, 105)
    var n, j, k int
    b := 10000
    c := 0
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    a[n] = a[0]
    for i := 0; i < n; i++ {
        c = int(math.Abs(float64(a[i]) - float64(a[i+1])))
        if c < b {
            b = c
            j = i + 1
            k = j + 1
            if n+1 == k {
                k = 1
            }
        }
    }
    fmt.Print(j)
    fmt.Print(" ")
    fmt.Print(k)
    fmt.Println()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
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 n int
	fmt.Fscan(r, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a[i])
	}
	t := abs(a[0] - a[1])
	x := 0
	for i := 1; i < n; i++ {
		if abs(a[i-1] - a[i]) < t {
			t = abs(a[i-1] - a[i])
			x = i - 1
		}
	}
	if abs(a[0] - a[n-1]) < t {
		fmt.Fprintln(w, 1, n)
	} else {
		fmt.Fprintln(w, x+1, x+2)
	}
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    min, ansi, ansj := 1000, 0, 0
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    for i := 0; i < n; i++ {
        u := int(math.Abs(float64(a[i])-float64(a[(i+1)%n])))
        if min > u {
            min = u
            ansi = i+1
            ansj = (i+2)%n
        }
    }
    fmt.Println(ansi,ansj)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
type Rost struct {
	Index int
	Rost int
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscan(r, &n)
	a := make([]Rost, n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(r, &x)
		a[i] = Rost{i+1, x}
	}
	sort.Slice(a, func(i, j int) bool { return a[i].Rost < a[j].Rost})
	x := 0
	y := 1
	h := a[y].Rost - a[x].Rost
	for i := 2; i < n; i++ {
		if a[i].Rost - a[i-1].Rost < h {
			h = a[i].Rost - a[i-1].Rost
			x = i-1
			y = i
		}
	}
	fmt.Fprintln(w, a[x].Index, a[y].Index)

}


package main

import (
	"bufio"
	"bytes"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	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' || s[i] == '\r' {
			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
}

const H = 31

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	// A[i] 不能通过 *2 得到，只能通过 /2得到

	sort.Ints(A)

	pq := make(IntHeap, n)

	copy(pq, B)

	heap.Init(&pq)

	for i := n - 1; i >= 0; i-- {
		a := A[i]
		for pq[0] > a {
			b := heap.Pop(&pq).(int)
			b /= 2
			heap.Push(&pq, b)
		}
		if pq[0] < a {
			return false
		}
		heap.Pop(&pq)
	}
	return true
}

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

package main

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

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

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

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

func do(a, b []int) string {
	m := make(map[int]int)
	for _, v := range a {
		for v&1 == 0 {
			v >>= 1
		}
		m[v]++
	}
	// log.Print(m)
	for _, v := range b {
		for v > 0 && m[v] <= 0 {
			v >>= 1
		}
		if v == 0 {
			return "NO"
		}
		m[v]--
	}
	return "YES"
}

package main

import (
	"bufio"
	"bytes"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	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' || s[i] == '\r' {
			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
}

const H = 31

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	// A[i] 不能通过 *2 得到，只能通过 /2得到

	sort.Ints(A)

	pq := make(IntHeap, n)

	copy(pq, B)

	heap.Init(&pq)

	for i := n - 1; i >= 0; i-- {
		a := A[i]
		for pq[0] > a {
			b := heap.Pop(&pq).(int)
			for b > a {
				b >>= 1
			}
			heap.Push(&pq, b)
		}
		if pq[0] < a {
			return false
		}
		heap.Pop(&pq)
	}
	return true
}

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

package main

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

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

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	a := make(map[int]int)
	for i:=0;i<n;i++ {
		var aa int
		fmt.Fscan(rr, &aa)
		for aa % 2 == 0 {
			aa = aa >> 1
		}
		a[aa]++
	}
	b := make([]int, n)
	for i:=0;i<len(b);i++ {
		fmt.Fscan(rr, &b[i])
	}
	for i := range b {
		for a[b[i]] == 0 && b[i] > 0 {
			b[i] = b[i] >> 1
		}
		if b[i] == 0 {
			fmt.Fprintln(ww, "NO")
			return
		} else {
			a[b[i]]--
		}
	}
	fmt.Fprintln(ww, "YES")
}

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

package main

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

func solve(sc *bufio.Scanner, wr *bufio.Writer) {
  n := get(sc)
  a := map[int]int{}
  for i := 0; i < n; i++ {
    x := get(sc)
    for x > 0 && x % 2 == 0 {
      x /= 2
    }
    if _, in := a[x]; in {
      a[x]++
    } else {
      a[x] = 1
    }
  }
  for i := 0; i < n; i++ {
    x := get(sc)
    ok := false
    for {
      if v, in := a[x]; in && v > 0 {
        a[x]--
        ok = true
        break
      }
      if x == 0 {
        break
      }
      x /= 2
    }
    if !ok {
      wr.WriteString("NO\n")
      i++
      for i < n {
        sc.Scan()
        i++
      }
      return
    }
  }
  wr.WriteString("YES\n")
}

const (
  once = false
  maxBufSize = 10000000
)

func main() {
  sc := bufio.NewScanner(bufio.NewReader(os.Stdin))
  sc.Split(bufio.ScanWords)
  sc.Buffer(make([]byte, maxBufSize), maxBufSize)

  wr := bufio.NewWriter(os.Stdout)
  defer wr.Flush()

  if once {
    solve(sc, wr)
  } else {
    times := get(sc)
    for times > 0 {
      solve(sc, wr)
      times--
    }
  }
}

func get(sc *bufio.Scanner) int {
  x, _ := strconv.Atoi(str(sc))
  return x
}

func str(sc *bufio.Scanner) string {
  sc.Scan()
  return sc.Text()
}

func put(wr *bufio.Writer, i int) {
  wr.WriteString(strconv.Itoa(i))
}

func line(wr *bufio.Writer) {
  wr.WriteRune('\n')
}

func space(wr *bufio.Writer) {
  wr.WriteRune(' ')
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	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' || s[i] == '\r' {
			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
}

const H = 31

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	sort.Ints(A)
	// process from big to small
	root := NewNode()

	for _, num := range B {
		AddNum(root, num)
	}

	for i := n - 1; i >= 0; i-- {
		num := A[i]
		if !FindNum(root, num) {
			return false
		}
	}
	return true
}

type Trie struct {
	children []*Trie
	cnt      int
}

func NewNode() *Trie {
	node := new(Trie)
	node.children = make([]*Trie, 2)
	node.cnt = 0
	return node
}

func (node *Trie) AddNum(num int, p int) {
	if p < 0 {
		return
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		node.children[x] = NewNode()
	}
	node.children[x].AddNum(num, p-1)
	node.cnt++
}

func (node *Trie) FindNum(num int, p int) bool {
	if node.cnt == 0 {
		return false
	}
	if p < 0 {
		return true
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		return false
	}
	if !node.children[x].FindNum(num, p-1) {
		return false
	}
	node.cnt--
	return true
}

func AddNum(root *Trie, num int) {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			root.AddNum(num, i)
			break
		}
	}
}

func FindNum(root *Trie, num int) bool {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			return root.FindNum(num, i)
		}
	}
	return false
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	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' || s[i] == '\r' {
			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
}

const H = 31

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	sort.Ints(A)
	// process from big to small
	root := NewNode()

	for _, num := range B {
		AddNum(root, num)
	}

	for i := n - 1; i >= 0; i-- {
		num := A[i]
		if !FindNum(root, num) {
			return false
		}
	}
	return true
}

type Trie struct {
	children []*Trie
	cnt      int
}

func NewNode() *Trie {
	node := new(Trie)
	node.children = make([]*Trie, 2)
	node.cnt = 0
	return node
}

func (node *Trie) AddNum(num int, p int) {
	if p < 0 {
		return
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		node.children[x] = NewNode()
	}
	node.children[x].AddNum(num, p-1)
	node.cnt++
}

func (node *Trie) FindNum(num int, p int) bool {
	if p < 0 {
		return true
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		return false
	}
	if !node.children[x].FindNum(num, p-1) {
		return false
	}
	node.cnt--
	return node.cnt >= 0
}

func AddNum(root *Trie, num int) {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			root.AddNum(num, i)
			break
		}
	}
}

func FindNum(root *Trie, num int) bool {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			return root.FindNum(num, i)
		}
	}
	return false
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	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' || s[i] == '\r' {
			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
}

const H = 30

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	sort.Ints(A)
	// process from big to small
	root := NewNode()

	for _, num := range B {
		AddNum(root, num)
	}

	for i := n - 1; i >= 0; i-- {
		num := A[i]
		if !FindNum(root, num) {
			return false
		}
	}
	return true
}

type Trie struct {
	children []*Trie
	cnt      int
}

func NewNode() *Trie {
	node := new(Trie)
	node.children = make([]*Trie, 2)
	node.cnt = 0
	return node
}

func (node *Trie) AddNum(num int, p int) {
	if p < 0 {
		return
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		node.children[x] = NewNode()
	}
	node.children[x].AddNum(num, p-1)
	node.cnt++
}

func (node *Trie) FindNum(num int, p int) bool {
	if p < 0 {
		return true
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		return false
	}
	if !node.children[x].FindNum(num, p-1) {
		return false
	}
	node.cnt--
	return node.cnt >= 0
}

func AddNum(root *Trie, num int) {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			root.AddNum(num, i)
			break
		}
	}
}

func FindNum(root *Trie, num int) bool {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			return root.FindNum(num, i)
		}
	}
	return false
}


package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var T, n, m, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		p := make([]bool, n)
		for ; m > 0; m-- {
			Fscan(in, &v)
			p[v-1] = true
		}
		for i := 0; i < n; i++ {
			st := i
			for ; p[i]; i++ {
			}
			sort.Ints(a[st : i+1])
		}
		if sort.IntsAreSorted(a) {
			Println("YES")
		} else {
			Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
out:
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)
		arr := make([]int, a)
		pos := make(map[int]bool, b)
		for i := 0; i < a; i++ {
			fmt.Scan(&arr[i])
		}
		for i := 0; i < b; i++ {
			var temp int
			fmt.Scan(&temp)
			pos[temp] = true
		}
		for i := 0; i < a-1; i++ {
			for j := 0; j < a-1; j++ {
				if arr[j] > arr[j+1] {
					if _, exists := pos[j+1]; exists {
						arr[j], arr[j+1] = arr[j+1], arr[j]
					} else {
						fmt.Println("NO")
						continue out
					}
				}
			}
		}
		fmt.Println("YES")

	}
}

package main

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

type Scan struct {
	f *os.File
	in *bufio.Reader
	out *bufio.Writer
}

func setup() *Scan {
	r := &Scan{ f: nil }

	inputFile := os.Getenv("INPUT_FILE")
	if inputFile != "" {
		var err error
		if r.f, err = os.Open(inputFile); err == nil {
			os.Stdin = r.f
		}
	}
	r.in = bufio.NewReader(os.Stdin)
	r.out = bufio.NewWriter(os.Stdout)

	return r
}

func (r *Scan) close() {
	if r.f != nil {
		r.f.Close()
	}
	r.out.Flush()
}

func (r *Scan) readString() string {
	var x string
	fmt.Fscan(r.in, &x)
	return x
}

func (r *Scan) readInt() int {
	x, err := strconv.Atoi(r.readString())
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) strings(refs ... *string) {
	for _, ref := range refs {
		*ref = r.readString()
	}
}

func (r *Scan) ints(refs ... *int) {
	for _, ref := range refs {
		*ref = r.readInt()
	}
}

func (r *Scan) print(s string) {
	fmt.Fprintf(r.out, "%s", s)
}

func main() {
	scan := setup()

	var t, n, m int

	scan.ints(&t)
	for tc := 0; tc < t; tc++ {
		scan.ints(&n, &m)

		a := make([]int, n)
		p := make([]bool, n)
		for i := 0; i<n; i++ {
			scan.ints(&a[i])
		}
		for i := 0; i<m; i++ {
			var x int
			scan.ints(&x)
			x--
			p[x] = true
		}

		pos := true
		for i := 0; i<n; i++ {
			swap := true
			for j := i+1; j<n; j++ {
				swap = swap && p[j-1]
				if a[j] < a[i]  && !swap {
					pos = false
				}
			}
		}

		if pos {
			scan.print("YES\n")
		} else {
			scan.print("NO\n")
		}
	}

	scan.close()
}

package main

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

type Scan struct {
	f *os.File
	in *bufio.Reader
	out *bufio.Writer
}

func setup() *Scan {
	r := &Scan{ f: nil }

	inputFile := os.Getenv("INPUT_FILE")
	if inputFile != "" {
		var err error
		if r.f, err = os.Open(inputFile); err == nil {
			os.Stdin = r.f
		}
	}
	r.in = bufio.NewReader(os.Stdin)
	r.out = bufio.NewWriter(os.Stdout)

	return r
}

func (r *Scan) close() {
	if r.f != nil {
		r.f.Close()
	}
}

func (r *Scan) readString() string {
	var x string
	fmt.Fscan(r.in, &x)
	return x
}

func (r *Scan) readInt() int {
	x, err := strconv.Atoi(r.readString())
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) strings(refs ... *string) {
	for _, ref := range refs {
		*ref = r.readString()
	}
}

func (r *Scan) ints(refs ... *int) {
	for _, ref := range refs {
		*ref = r.readInt()
	}
}

func (r *Scan) print(s string) {
	fmt.Printf("%s", s)
}

func main() {
	scan := setup()

	var t, n, m int

	scan.ints(&t)
	for tc := 0; tc < t; tc++ {
		scan.ints(&n, &m)

		a := make([]int, n)
		p := make([]bool, n)
		for i := 0; i<n; i++ {
			scan.ints(&a[i])
		}
		for i := 0; i<m; i++ {
			var x int
			scan.ints(&x)
			x--
			p[x] = true
		}

		pos := true
		for i := 0; i<n; i++ {
			swap := true
			for j := i+1; j<n; j++ {
				swap = swap && p[j-1]
				if a[j] < a[i]  && !swap {
					pos = false
				}
			}
		}

		if pos {
			scan.print("YES\n")
		} else {
			scan.print("NO\n")
		}
	}

	scan.close()
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	input := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	for t := input(); t > 0; t-- {
		n, m := input(), input()

		a := make([]int, n)
		b := make([]int, n)
		p := make([]int, m)

		for i := range a {
			a[i] = input()
			b[i] = a[i]
		}

		for i := range p {
			p[i] = input()
		}

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

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

		ok := true

		for i := range b {
			j := 0

			found := false
			for j = i; j < n; j++ {
				if a[j] == b[i] {
					found = true
					break
				}
			}

			if found {
				a[j] = 101

				d := j - i

				for k := range p {
					if p[k] > i && p[k] <= j {
						d--
					}
				}

				if d != 0 {
					ok = false
				}

				if !ok {
					break
				}
			}
		}

		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

package main

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

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

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

	t := readInt(scanner)
	for i := 0; i < t; i++ {
		n := readInt(scanner)
		m := readInt(scanner)

		// array elements
		a := make([]int, n)
		// swap positions
		p := make([]int, m)
		for j := 0; j < n; j++ {
			a[j] = readInt(scanner)
		}
		for j := 0; j < m; j++ {
			p[j] = readInt(scanner)
		}
		sort.Ints(p)

		// sort each contiguous segment independently
		l := 0
		for l < len(p) {
			r := l
			for r+1 < len(p) && p[r+1] == p[r] + 1 {
				r += 1
			}

			sort.Ints(a[p[l]-1:p[r]+1])
			l = r+1
		}
		if sort.IntsAreSorted(a) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

const MAXN = 110

var n, m int
var a, f [MAXN]int

func check() bool {
	for {
		sorted := true
		for i := 1; i < n; i++ {
			if a[i] > a[i+1] {
				sorted = false
				if f[i] == 0 {
					return false
				}
				a[i], a[i+1] = a[i+1], a[i]
				break
			}
		}
		if sorted {
			break
		}
	}
	return true
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for test := 1; test <= t; test++ {
		fmt.Scanf("%d %d\n", &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
			f[i] = 0
		}
		fmt.Scanf("\n")
		for i := 1; i <= m; i++ {
			var x int
			fmt.Scanf("%d", &x)
			f[x] = 1
		}
		fmt.Scanf("\n")

		if check() {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}

	}
}

/**
 * Copyright shopee
 * @Author : Yuxiang.Lei
 * @MailBox: Yuxiang.Lei@shopee.com
 * @Date : 2020-02-24
 * @Version: v2.4
 **/

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		s := readLine(reader)
		ss := strings.Split(string(s), " ")
		n, _ := strconv.Atoi(ss[0])
		m, _ := strconv.Atoi(ss[1])
		s = readLine(reader)
		ss = strings.Split(string(s), " ")
		an := make([]int, n)
		for i := 0; i < len(ss); i++ {
			an[i], _ = strconv.Atoi(ss[i])
		}
		s = readLine(reader)
		ss = strings.Split(string(s), " ")
		pn := make([]int, m)
		pmap := make(map[int]struct{})
		for i := 0; i < len(ss); i++ {
			pn[i], _ = strconv.Atoi(ss[i])
			pmap[pn[i]-1] = struct{}{}
		}
		// fmt.Println(n,m,an,pn)
		max, i, flag := 0, 0, true
		for i = 0; i < len(an); {
			j := getRange(pmap, i)
			tmin, tmax := getRangeOfAn(i, j, an)
			// fmt.Println(tmin, tmax, max)
			if max > tmin {
				flag = false
				break
			}
			max = tmax
			i = j + 1
		}
		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func getRangeOfAn(start, end int, list []int) (int, int) {
	min, max := list[start], list[start]
	if end >= len(list) {
		end = len(list) -1
	}
	for i := start + 1; i <= end; i++ {
		if min > list[i] {
			min = list[i]
		}
		if max < list[i] {
			max = list[i]
		}
	}
	return min, max
}

func getRange(m map[int]struct{}, start int) int {
	for {
		_, ok := m[start]
		if ok {
			start++
		} else {
			break
		}
	}
	return start
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

package main

import "fmt"

func find(f []int, x int) int {
	if x == f[x] {
		return x
	}
	f[x] = find(f, f[x])
	return f[x]
}

func merge(f []int, x int, y int) {
	f[find(f, x)] = find(f, y)
}

func solve(a []int, p []int) bool {
	n := len(a)
	f := make([]int, n)
	for i := range f {
		f[i] = i
	}
	for _, v := range p {
		merge(f, v, v+1)
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if a[i] > a[j] {
				if find(f, i) != find(f, j) {
					return false
				}
			}
		}
	}

	return true
}

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

	for cas := 1; cas <= T; cas++ {
		var n, m int
		fmt.Scan(&n, &m)
		var a []int = make([]int, n)
		for i := range a {
			fmt.Scan(&a[i])
		}
		var p []int = make([]int, m)
		for i := range p {
			var v int
			fmt.Scan(&v)
			p[i] = v - 1
		}

		if solve(a, p) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1311/B
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t    int
	n, m int
	A    []int
	P    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		A = ReadIntSlice(n)
		P = ReadIntSlice(m)

		solve()
	}
}

func solve() {
	for i := 0; i < m; i++ {
		P[i]--
	}

	for i := 0; i < n-1; i++ {
		for j := 1; j < n-i; j++ {
			if A[j-1] > A[j] {
				if sub(j-1, P) {
					A[j-1], A[j] = A[j], A[j-1]
				} else {
					fmt.Println("NO")
					return
				}
			}
		}
	}

	fmt.Println("YES")
}

func sub(a int, P []int) bool {
	for i := 0; i < len(P); i++ {
		if P[i] == a {
			return true
		}
	}
	return false
}

// AOJ
func bubbleSortAOJ(A []int, n int) int {
	flag := true
	res := 0
	for flag {
		flag = false
		for j := n - 1; j >= 1; j-- {
			if A[j-1] > A[j] {
				A[j-1], A[j] = A[j], A[j-1]
				res++
				flag = true
			}
		}
	}

	return res
}

// wikipedia
// ※最後尾の最大値から確定していく
func bubbleSortWikipedia(A []int, n int) int {
	res := 0
	for i := 0; i < n-1; i++ {
		for j := 1; j < n-i; j++ {
			if A[j-1] > A[j] {
				A[j-1], A[j] = A[j], A[j-1]
				res++
			}
		}
	}

	return res
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var t, n, m int

func main() {
	fmt.Fscan(reader, &t)
	for ; t != 0; t-- {
		fmt.Fscan(reader, &n, &m)
		a := make([]int, n)
		p := make(map[int]bool)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		for i := 0; i < m; i++ {
			var pi int
			fmt.Fscan(reader, &pi)
			p[pi-1] = true
		}
		ans := "YES"
		for i := 0; i < n; i++ {
			for j := 0; j < n-i-1; j++ {
				if a[j] > a[j+1] {
					if p[j] {
						a[j], a[j+1] = a[j+1], a[j]
					} else {
						ans = "NO"
						break
					}
				}
			}
			if ans == "NO" {
				break
			}
		}
		fmt.Println(ans)
	}
}

package main

import(
	"fmt"
)

func main(){
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Scan(&a,&b)
		var ar[101] int
		var arr[101] int
		for i:=0;i<a;i++{
			fmt.Scan(&ar[i])
		}
		var check=make(map[int]bool)
		for i:=0;i<b;i++{
			fmt.Scan(&arr[i])
			check[arr[i]-1]=true
		}
		for i:=0;;i++{
			var lock bool=false
			for j:=1;j<a;j++{
				if ar[j-1]>ar[j]{
					if check[j-1]{
						ar[j-1]=ar[j-1]+ar[j]
						//fmt.Println(ar[j-1])
						ar[j]=ar[j-1]-ar[j]
						//fmt.Println(ar[j])
						ar[j-1]=ar[j-1]-ar[j]
						//fmt.Println(ar[])
						//fmt.Print(ar[j-1]," ",ar[j],"\n")
						lock=true
					}
				}
			}
			if !lock{
				break
			}
		}
		i:=1
		for i<a && ar[i-1]<=ar[i]{
			i++
		}
		if i==a{
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}

	}
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		a := ScanIntSlice(n)
		p := ScanIntSlice(m)
		for i := 0; i < m; i++{
			p[i]--
		}
		sort.Ints(p)

		r := true
		for i :=0;i<n;i++ {
			for j:=0;j<m;j++ {
				if a[p[j]]>a[p[j]+1]{
					a[p[j]],a[p[j]+1] = a[p[j]+1], a[p[j]]
				}
			}
		}
		//P(a)
		//
		for i:=0; i<n-1; i++{
			if a[i]>a[i+1] {
				r = false
				break
			}
		}

		if r {
			P("YES")
		} else {
			P("NO")
		}
	}

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		a := ScanIntSlice(n)
		p := ScanIntSlice(m)
		for i := 0; i < m; i++{
			p[i]--
		}
		sort.Ints(p)

		r := true
		for i :=0;i<n;i++ {
			for j:=0;j<m;j++ {
				if a[p[j]]>a[p[j]+1]{
					a[p[j]],a[p[j]+1] = a[p[j]+1], a[p[j]]
				}

			}

		}
		for i:=0; i<n-1; i++{
			if a[i]>a[i+1] {
				r = false
				break
			}
		}

		if r {
			P("YES")
		} else {
			P("NO")
		}
	}

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan( &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)

		ar1 := make([]int, a)
		positions := make([]bool, a)

		for i := 0; i < a; i++ {
			fmt.Scan( &ar1[i])
		}

		for i := 0; i < b; i++ {
			var x int
			fmt.Scan( &x)
			positions[x-1] = true
		}

		valid := true
		for i := 0; i <a-1; i++ {
			for j := 0; j < a-i-1; j++ {
				if ar1[j] > ar1[j+1] && valid {
					if positions[j] {
						temp := ar1[j]
						ar1[j] = ar1[j+1]
						ar1[j+1] = temp
					} else {
						valid = false
					}
				} else if !valid {
					break
				}
			}
		}
		if valid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

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

type pair struct {
	val int
	index int
}

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

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

func main () {
	in := bufio.NewReader(os.Stdin);
	out := bufio.NewWriter(os.Stdout);
	t := 0;
	fmt.Fscan(in, &t);
	for i := 0; i < t; i++ {
		n, m := 0, 0;
		fmt.Fscan(in, &n, &m);
		a := make([]pair, n);
		x := 0;
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x);
			a[j] = pair{x, j};
		}

		sort.SliceStable(a, func (i, j int) bool {
			return a[i].val < a[j].val
		});

		p := make([]bool, n);
		for j := 0; j < m; j++ {
			var x int;
			fmt.Fscan(in, &x);
			p[x] = true;
		}
		ans := true;
		for key, item := range a {
			for j := Min(key + 1, item.index + 1); j < Max(key + 1, item.index + 1); j++ {
				if !p[j] {
					ans = false;
				}
			}
		}

		if (ans) {
			fmt.Fprintln(out, "YES");
		} else {
			fmt.Fprintln(out, "NO");
		}
	}
	out.Flush();
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan( &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)

		ar1 := make([]int, a)
		positions := make([]bool, a+1)

		for i := 0; i < a; i++ {
			fmt.Scan( &ar1[i])
		}

		for i := 0; i < b; i++ {
			var x int
			fmt.Scan( &x)
			positions[x] = true
		}

		valid := true
		for i := 1; i <= a-1; i++ {
			for j := i; j < a; j++ {
				if ar1[j-1] > ar1[j] && valid {
					if positions[j] {
						temp := ar1[j-1]
						ar1[j-1] = ar1[j]
						ar1[j] = temp
					} else {
						valid = false
					}
				} else if !valid {
					break
				}
			}
		}
		if valid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)

		ar1 := make([]int, a)
		positions := make([]bool, a+1)

		for i := 0; i < a; i++ {
			fmt.Scanf("%d", &ar1[i])
		}

		for i := 0; i < b; i++ {
			var x int
			fmt.Scanf("%d", &x)
			positions[x] = true
		}

		valid := true
		for i := 1; i <= a-1; i++ {
			for j := i; j < a; j++ {
				if ar1[j-1] > ar1[j] && valid {
					if positions[j] {
						temp := ar1[j-1]
						ar1[j-1] = ar1[j]
						ar1[j] = temp
					} else {
						valid = false
					}
				} else if !valid {
					break
				}
			}
		}
		if valid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan( &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)

		ar1 := make([]int, a)
		positions := make([]bool, a)

		for i := 0; i < a; i++ {
			fmt.Scan( &ar1[i])
		}

		for i := 0; i < b; i++ {
			var x int
			fmt.Scan( &x)
			positions[x-1] = true
		}

		valid := true
		for i := 0; i <a-1; i++ {
			for j := i; j < a-1; j++ {
				if ar1[j] > ar1[j+1] && valid {
					if positions[j] {
						temp := ar1[j]
						ar1[j] = ar1[j+1]
						ar1[j+1] = temp
					} else {
						valid = false
					}
				} else if !valid {
					break
				}
			}
		}
		if valid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
out:
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)
		arr := make([]int, a)
		pos := make(map[int]bool, b)
		for i := 0; i < a; i++ {
			fmt.Scan(&arr[i])
		}
		for i := 0; i < b; i++ {
			var temp int
			fmt.Scan(&temp)
			pos[temp] = true
		}
		for i := 0; i < a-1; i++ {
			for j := 0; j < a-2; j++ {
				if arr[j] > arr[j+1] {
					if _, exists := pos[j+1]; exists {
						arr[j], arr[j+1] = arr[j+1], arr[j]
					} else {
						fmt.Println("NO")
						continue out
					}
				}
			}
		}
		fmt.Println("YES")

	}
}

package main

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

type Scan struct {
	f *os.File
	in *bufio.Reader
	out *bufio.Writer
}

func setup() *Scan {
	r := &Scan{ f: nil }

	inputFile := os.Getenv("INPUT_FILE")
	if inputFile != "" {
		var err error
		if r.f, err = os.Open(inputFile); err == nil {
			os.Stdin = r.f
		}
	}
	r.in = bufio.NewReader(os.Stdin)
	r.out = bufio.NewWriter(os.Stdout)

	return r
}

func (r *Scan) close() {
	if r.f != nil {
		r.f.Close()
	}
}

func (r *Scan) readString() string {
	var x string
	fmt.Fscan(r.in, &x)
	return x
}

func (r *Scan) readInt() int {
	x, err := strconv.Atoi(r.readString())
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) strings(refs ... *string) {
	for _, ref := range refs {
		*ref = r.readString()
	}
}

func (r *Scan) ints(refs ... *int) {
	for _, ref := range refs {
		*ref = r.readInt()
	}
}

func (r *Scan) print(s string) {
	fmt.Printf("%s", s)
}

func main() {
	scan := setup()

	var t, a, b int

	scan.ints(&t)
	for tc := 0; tc < t; tc++ {
		scan.ints(&a, &b)
		diff := b-a
		mves := 0
		if diff > 0 {
			if (diff%2) == 1 {
				mves = 1
			} else {
				mves = 2
			}
		} else if diff < 0 {
			if (-diff)%2 == 1 {
				mves = 2
			} else {
				mves = 1
			}
		}
		fmt.Printf("%d\n", mves)
	}

	scan.close()
}

package main

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

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

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

	t := readInt(scanner)
	for i := 0; i < t; i++ {
		n := readInt(scanner)
		m := readInt(scanner)

		// array elements
		a := make([]int, n)
		// swap positions
		p := make([]int, m)
		for j := 0; j < n; j++ {
			a[j] = readInt(scanner)
		}
		for j := 0; j < m; j++ {
			p[j] = readInt(scanner)
		}

		// sort each contiguous segment independently
		l := 0
		for l < len(p) {
			r := l
			for r+1 < len(p) && p[r+1] == p[r] + 1 {
				r += 1
			}

			sort.Ints(a[p[l]-1:p[r]+1])
			l = r+1
		}
		if sort.IntsAreSorted(a) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

const MAXN = 110

var n, m int
var a, b, f [MAXN]int

func check() bool {
	for {
		sorted := true
		for i := 1; i < n; i++ {
			if a[i] > a[i+1] {
				sorted = false
				if f[i] == 0 {
					return false
				}
				a[i], a[i+1] = a[i+1], a[i]
				break
			}
		}
		if sorted {
			break
		}
	}
	return true
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 1; i <= t; i++ {
		fmt.Scanf("%d %d", &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
			f[i] = 0
		}
		for i := 1; i <= m; i++ {
			fmt.Scanf("%d", &b[i])
			f[b[i]] = 1
		}

		if check() {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}

	}
}