You are given three arrays $$$a$$$, $$$b$$$ and $$$c$$$. Initially, array $$$a$$$ consists of $$$n$$$ elements, arrays $$$b$$$ and $$$c$$$ are empty.You are performing the following algorithm that consists of two steps:   Step $$$1$$$: while $$$a$$$ is not empty, you take the last element from $$$a$$$ and move it in the middle of array $$$b$$$. If $$$b$$$ currently has odd length, you can choose: place the element from $$$a$$$ to the left or to the right of the middle element of $$$b$$$. As a result, $$$a$$$ becomes empty and $$$b$$$ consists of $$$n$$$ elements.  Step $$$2$$$: while $$$b$$$ is not empty, you take the middle element from $$$b$$$ and move it to the end of array $$$c$$$. If $$$b$$$ currently has even length, you can choose which of two middle elements to take. As a result, $$$b$$$ becomes empty and $$$c$$$ now consists of $$$n$$$ elements.  Refer to the Note section for examples.Can you make array $$$c$$$ sorted in non-decreasing order?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — the array $$$a$$$ itself. It's guaranteed that the sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test, print YES (case-insensitive), if you can make array $$$c$$$ sorted in non-decreasing order. Otherwise, print NO (case-insensitive).

package main

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	in := bufio.NewReader(os.Stdin)
	for i := 1; i <= t; i++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n+3)
		for j := 1; j <= n; j++ {
			fmt.Fscan(in, &arr[j])
		}
		arr[n+1]=10000000
		flag := false
		for j := n; j >= 1; j-=2 {
			if(arr[j-1]>arr[j]){
				arr[j-1],arr[j]=arr[j],arr[j-1]
			}
		}
		for j := 1; j <= n; j++ {
			if(arr[j]>arr[j+1]){
				flag=true
			}
		}
		if flag==true {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

func min(a int, nums ...int) int {
	min := a
	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

func index(num int) int {
	if num < 0 {
		return -num
	}
	return num + 1e9
}

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

	var t int

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

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

		for i := n % 2; i < n-1; i += 2 {
			if arr[i] > arr[i+1] {
				arr[i], arr[i+1] = arr[i+1], arr[i]
			}
		}

		if sort.IsSorted(sort.IntSlice(arr)) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func min(a int, nums ...int) int {
	min := a
	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

func index(num int) int {
	if num < 0 {
		return -num
	}
	return num + 1e9
}

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

	var t int

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

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

		for i := n % 2; i < n; i += 2 {
			if arr[i] > arr[i+1] {
				arr[i], arr[i+1] = arr[i+1], arr[i]
			}
		}

		if sort.IsSorted(sort.IntSlice(arr)) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func min(a int, nums ...int) int {
	min := a
	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

func index(num int) int {
	if num < 0 {
		return -num
	}
	return num + 1e9
}

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

	var t int

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		if n%2 != 0 {
			arr = append([]int{0}, arr...)
			n++
		}

		for i := 1; i < n; i += 2 {
			if arr[i] <= arr[i-1] {
				arr[i], arr[i-1] = arr[i-1], arr[i]
			}
		}
		if sort.IsSorted(sort.IntSlice(arr)) {
			fmt.Fprintln(out, "YES")
			continue
		}

		fmt.Fprintln(out, "NO")
	}
}

package main

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

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

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

	a := make([]int, n)

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

	for i := n - 2; i >= 0; i -= 2 {
		if a[i+1] < a[i] {
			a[i+1], a[i] = a[i], a[i+1]
		}
	}

	if sort.IntsAreSorted(a) {
		fmt.Fprintln(writer, "YES")
	} else {
		fmt.Fprintln(writer, "NO")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

		can := true
		for i := n - 4; i >= 0; i -= 2 {
			if a[i] > a[i+2] || a[i] > a[i+3] || a[i+1] > a[i+2] || a[i+1] > a[i+3] {
				can = false
				break
			}
		}
		if n%2 == 1 {
			for i := 1; i < 3; i++ {
				if i >= n {
					break
				}
				if a[0] > a[i] {
					can = false
					break
				}
			}
		}

		/*if n < 3 {
			fmt.Println("YES")
			continue
		}

		b := make([]int, n)
		if n%2 == 1 {
			b[n/2] = a[0]
		}
		for i := 0; i < n/2; i++ {
			b[n/2-i-1] = a[i*2+(n%2)]
			b[n/2+i+(n%2)] = a[i*2+1+(n%2)]
		}
		can := true
		for i := 0; i < n/2-(1-(n%2)); i++ {
			if b[i] < b[i+1] || b[n-i-1] < b[i+1] || b[i] < b[n-i-2] || b[n-i-1] < b[n-i-2] {
				can = false
				break
			}
		}*/
		// fmt.Println(b)
		if can {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

const mod = 998244353

type IntHeap []int
type any = interface{}

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 any) {
	// 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() any {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	hp := make(IntHeap, n)
	for i, v := range arr {
		hp[i] = v
	}
	heap.Init(&hp)
	cur := n - 1
	for hp.Len() > 0 {
		a := heap.Pop(&hp).(int)
		idx1 := cur
		idx2 := max(cur-1, 0)
		if a != max(arr[idx1], arr[idx2]) {
			fmt.Fprintln(out, "No")
			return
		}
		if hp.Len() > 0 {
			b := heap.Pop(&hp).(int)
			if b != min(arr[idx1], arr[idx2]) {
				fmt.Fprintln(out, "No")
				return
			}
		}
		cur -= 2
	}
	fmt.Fprintln(out, "Yes")
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for i := n - 1; i > 0; i -= 2 {
			if a[i-1] > a[i] {
				a[i-1], a[i] = a[i], a[i-1]
			}
		}
		if sort.IntsAreSorted(a) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}
func main() { CF1674D(os.Stdin, os.Stdout) }

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for i := n - 1; i > 0; i -= 2 {
			if a[i-1] > a[i] {
				a[i-1], a[i] = a[i], a[i-1]
			}
		}
		if sort.IntsAreSorted(a) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for i := n - 1; i > 0; i -= 2 {
			if a[i-1] > a[i] {
				a[i-1], a[i] = a[i], a[i-1]
			}
		}
		if sort.IntsAreSorted(a) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

	var T, n int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := append([]int{}, a...)
		sort.Ints(b)
		for i := n - 1; i > 0; i -= 2 {
			if !(a[i] == b[i] && a[i-1] == b[i-1] || a[i] == b[i-1] && a[i-1] == b[i]) {
				Fprintln(out, "NO")
				continue o
			}
		}
		Fprintln(out, "YES")
	}
}

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

package main

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

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

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

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

		for i := n % 2; i < n-1; i += 2 {
			if arr[i] > arr[i+1] {
				arr[i], arr[i+1] = arr[i+1], arr[i]
			}
		}

		f := true
		for i := 1; i < n; i++ {
			if arr[i-1] > arr[i] {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func max(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()

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

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

		f := true
		last := arr[0]
		idx := 1
		if n%2 == 0 && n > 1 {
			last = max(arr[0], arr[1])
			idx++
		}

		for i := idx; i < n-1; i += 2 {
			if min(arr[i], arr[i+1]) < last {
				f = false
				break
			}
			last = max(arr[i], arr[i+1])
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

import (
	"bufio"
	_ "embed"
	"fmt"
	"os"
)

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

func solve() {
	var n int
	fmt.Fscan(r, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &arr[i])
	}
	for i := n % 2; i < n-1; i += 2 {
		if arr[i] > arr[i+1] {
			arr[i], arr[i+1] = arr[i+1], arr[i]
		}
	}
	for i := 0; i < n-1; i++ {
		if arr[i] > arr[i+1] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

func main() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
		}
	}()
	defer w.Flush()
	var t int
	for fmt.Fscan(r, &t); t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		n := gi(); a := gis(n)
		lastl,lastr := 1000000,1000000
		ans := "YES"
		for i:=n-1;i>=0;i-=2 {
			if i == 0 {
				if a[i] > lastl || a[i] > lastr { ans = "NO" }
				break
			}
			if (a[i] > lastl || a[i-1] > lastr || a[i] > lastr || a[i-1] > lastl ) { ans = "NO"; break }
			lastl,lastr = a[i],a[i-1]
		}
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

// source: https://codeforces.com/contest/1674/problem/D?locale=en

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

func solve() string {
	var n int
	fmt.Fscan(in, &n)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	for i := n % 2; i < n; i += 2 {
		if a[i] > a[i+1] {
			a[i], a[i+1] = a[i+1], a[i]
		}
	}
	for i := 0; i < n-1; i++ {
		if a[i] > a[i+1] {
			return "NO"
		}
	}
	return "YES"
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

package main

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

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

func d1674(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var x int

loop:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		row := make([]int, n)
		st := make([]int, n)

		for i := 0; i < n; i++ {
			Fscan(in, &x)
			row[i] = x
			st[i] = x
		}
		sort.Ints(st)

		chk := func(i, j int) bool {
			return st[i] == row[i] && st[j] == row[j] || st[i] == row[j] && st[j] == row[i]
		}

		if n%2 == 1 {
			if st[0] != row[0] {
				Fprintln(out, "NO")
				continue loop
			}
		}
		for i := n % 2; i < n; i += 2 {
			if !chk(i, i+1) {
				Fprintln(out, "NO")
				continue loop
			}
		}

		Fprintln(out, "YES")
	}
}

package main

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

func main() {
	CF1674D(os.Stdin, os.Stdout)
}
func CF1674D(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()

	t := 0
	n := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		pos := 1
		if len(a)%2 == 1 {
			pos++
		}
		for ; pos < n; pos += 2 {
			if a[pos] < a[pos-1] {
				a[pos], a[pos-1] = a[pos-1], a[pos]
			}
		}
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				fmt.Fprintln(out, "NO")
				goto out
			}
		}
		fmt.Fprintln(out, "YES")
	out:
	}
}

package main

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

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

func solve() {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	if n&1 > 0 {
		a = append([]int{0}, a...)
		n++
	}
	for i := 0; i < n; i += 2 {
		if a[i] > a[i+1] {
			a[i], a[i+1] = a[i+1], a[i]
		}
	}
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			fmt.Fprintf(out, "NO\n")
			return
		}
	}
	fmt.Fprintf(out, "YES\n")
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		solve()
	}
}

package main

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

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

func slove() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	for i := range nums {
		fmt.Fscan(r, &nums[i])
	}
	for i:=len(nums)%2;i+1<n;i+=2 {
		if nums[i] > nums[i+1] {
			nums[i], nums[i+1] = nums[i+1], nums[i]
		}
	}
	for i:=0;i+1<n;i++ {
		if nums[i] > nums[i+1] {
			fmt.Fprintln(w, "No")
			return
		}
	}
	fmt.Fprintln(w, "Yes")
}

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

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)
		for i := len(a) % 2; i+1 < len(a); i += 2 {
			a[i], a[i+1] = min(a[i], a[i+1]), max(a[i], a[i+1])
		}
		if sort.SliceIsSorted(a, func(i, j int) bool {
			return a[i] < a[j]
		}) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	in := bufio.NewReader(os.Stdin)
	for i := 1; i <= t; i++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n+3)
		for j := 1; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}
		fmt.Scanf("%d", &arr[n])
		arr[n+1]=10000000
		flag := false
		for j := n; j >= 1; j-=2 {
			if(arr[j-1]>arr[j]){
				arr[j-1],arr[j]=arr[j],arr[j-1]
			}
		}
		for j := 1; j <= n; j++ {
			if(arr[j]>arr[j+1]){
				flag=true
			}
		}
		if flag==true {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	in := bufio.NewReader(os.Stdin)
	for i := 1; i <= t; i++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n+3)
		for j := 1; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}
		fmt.Scanf("%d\n", &arr[n])
		arr[n+1]=10000000
		flag := false
		for j := n; j >= 1; j-=2 {
			if(arr[j-1]>arr[j]){
				arr[j-1],arr[j]=arr[j],arr[j-1]
			}
		}
		for j := 1; j <= n; j++ {
			if(arr[j]>arr[j+1]){
				flag=true
			}
		}
		if flag==true {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	in := bufio.NewReader(os.Stdin)
	for i := 1; i <= t; i++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n+3)
		for j := 1; j < n; j++ {
			fmt.Fscan(in, &arr[i])
		}
		fmt.Scanf("%d\n", &arr[n])
		arr[n+1]=10000000
		flag := false
		for j := n; j >= 1; j-=2 {
			if(arr[j-1]>arr[j]){
				arr[j-1],arr[j]=arr[j],arr[j-1]
			}
		}
		for j := 1; j <= n; j++ {
			if(arr[j]>arr[j+1]){
				flag=true
			}
		}
		if flag==true {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		arr := make([]int, n+3)
		for j := 1; j < n; j++ {
			fmt.Scanf("%d", &arr[j])
		}
		fmt.Scanf("%d\n", &arr[n])
		arr[n+1]=10000000
		flag := false
		for j := 1; j <= n; j+=2 {
			if(arr[j]>arr[j+1]){
				arr[j],arr[j+1]=arr[j+1],arr[j]
			}
		}
		for j := 1; j <= n; j++ {
			if(arr[j]>arr[j+1]){
				flag=true
			}
		}
		if flag==true {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		arr := make([]int, n+1)
		for j := 1; j < n; j++ {
			fmt.Scanf("%d", &arr[j])
		}
		fmt.Scanf("%d\n", &arr[n])
		flag := false
		for j := 0; j < n; j+=2 {
			if(arr[j]>arr[j+1]){
				arr[j],arr[j+1]=arr[j+1],arr[j]
			}
		}
		for j := 0; j < n; j++ {
			if(arr[j]>arr[j+1]){
				flag=true
			}
		}
		if flag==true {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		arr := make([]int, n+1)
		for j := 1; j < n; j++ {
			fmt.Scanf("%d", &arr[j])
		}
		fmt.Scanf("%d\n", &arr[n])
		flag := false
		for j := 1; j <= n-2; j++ {
			if (arr[j] > arr[j+1] && arr[j+1] > arr[j+2])||(arr[j] < arr[j+1] && arr[j+1] < arr[j+2]) {
				flag = true
			}
		}
		if flag==true {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		arr := make([]int, n+1)
		for j := 1; j < n; j++ {
			fmt.Scanf("%d", &arr[j])
		}
		fmt.Scanf("%d\n", &arr[n])
		flag := false
		for j := 1; j <= n-2; j++ {
			if arr[j] > arr[j+1] && arr[j+1] > arr[j+2] {
				flag = true
			}
		}
		if flag==true {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

func min(a int, nums ...int) int {
	min := a
	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

func index(num int) int {
	if num < 0 {
		return -num
	}
	return num + 1e9
}

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

	var t int

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

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

		for i := 1; i < n; i += 2 {
			if arr[i] <= arr[i-1] {
				arr[i], arr[i-1] = arr[i-1], arr[i]
			}
		}
		if sort.IsSorted(sort.IntSlice(arr)) {
			fmt.Fprintln(out, "YES")
			continue
		}

		fmt.Fprintln(out, "NO")
	}
}

package main

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

func min(a int, nums ...int) int {
	min := a
	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

func index(num int) int {
	if num < 0 {
		return -num
	}
	return num + 1e9
}

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

	var t int

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

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

		for i := 1; i < n; i += 2 {
			if arr[i] > arr[i-1] {
				arr[i], arr[i-1] = arr[i-1], arr[i]
			}
		}
		if sort.IsSorted(sort.IntSlice(arr)) {
			fmt.Fprintln(out, "YES")
			continue
		}

		for i := 1; i < n; i += 2 {
			if arr[i] < arr[i-1] {
				arr[i], arr[i-1] = arr[i-1], arr[i]
			}
		}
		if sort.IsSorted(sort.IntSlice(arr)) {
			fmt.Fprintln(out, "YES")
			continue
		}

		fmt.Fprintln(out, "NO")
	}
}

package main

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

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

2 1 2 3 1 4

2 1 2
1 3 1 2 4

3 1 5 3

3 1 5

*/

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

	a := make([]int, n)

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

	for i := n - 3; i >= 0; i -= 2 {
		if a[i] > a[i+1] || a[i] > a[i+2] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

/*
3
5
1 2 2 1 3
6
2 1 2 3 1 4
6
1 1 2 2 3 4
---
NO
NO
YES

1 1 2 2
3 2 1 1 2 4

1
3
3 2 1
---

1 3 2

1 3
2

*/

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

	a := make([]int, n)
	s := make([]int, n)

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

	sort.Ints(s)

	lft := make([]int, 0)
	rht := make([]int, 0)

	for i, num := range s {
		if i%2 == 0 {
			lft = append(lft, num)
		} else {
			rht = append(rht, num)
		}
	}

	i := 0
	j := 0

	for _, num := range a {
		lftRemCnt := len(lft) - 1
		rhtRemCnt := len(rht) - 1

		if lftRemCnt > rhtRemCnt {
			if i < len(lft) && num == lft[i] {
				i++
				continue
			}
		} else if rhtRemCnt > lftRemCnt {
			if j < len(rht) && num == rht[j] {
				j++
				continue
			}
		}

		if i < len(lft) && num == lft[i] {
			i++
			continue
		}

		if j < len(rht) && num == rht[j] {
			j++
			continue
		}

		fmt.Fprintln(writer, "NO")
		return
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

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

1 1 2 2 3 4

1 2 3
1 2 4

1 2 3
1 2

*/

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

	a := make([]int, n)
	s := make([]int, n)

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

	sort.Ints(s)

	lft := make([]int, 0)
	rht := make([]int, 0)

	for i, num := range s {
		if i%2 == 0 {
			lft = append(lft, num)
		} else {
			rht = append(rht, num)
		}
	}

	i := 0
	j := 0

	for _, num := range a {
		lftRemCnt := len(lft) - 1
		rhtRemCnt := len(rht) - 1

		if abs(lftRemCnt-rhtRemCnt) > 1 {
			fmt.Fprintln(writer, "NO")
			return
		}

		if i < len(lft) && num == lft[i] {
			i++
			continue
		}

		if j < len(rht) && num == rht[j] {
			j++
			continue
		}

		fmt.Fprintln(writer, "NO")
		return
	}

	lftRemCnt := len(lft) - 1
	rhtRemCnt := len(rht) - 1

	if abs(lftRemCnt-rhtRemCnt) > 1 {
		fmt.Fprintln(writer, "NO")
		return
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

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

1 1 2 2 3 4

1 2 3
1 2 4

1 2 3
1 2

*/

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

	a := make([]int, n)
	s := make([]int, n)

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

	sort.Ints(s)

	lft := make([]int, 0)
	rht := make([]int, 0)

	for i, num := range s {
		if i%2 == 0 {
			lft = append(lft, num)
		} else {
			rht = append(rht, num)
		}
	}

	i := 0
	j := 0

	for _, num := range a {
		lftRemCnt := len(lft) - 1
		rhtRemCnt := len(rht) - 1

		if abs(lftRemCnt-rhtRemCnt) > 1 {
			fmt.Fprintln(writer, "NO")
			return
		}

		if i < len(lft) && num == lft[i] {
			i++
			continue
		}

		if j < len(rht) && num == rht[j] {
			j++
			continue
		}

		fmt.Fprintln(writer, "NO")
		return
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

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

1 1 2 2 3 4

1 2 3
1 2 4

1 2 3
1 2

*/

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

	a := make([]int, n)
	s := make([]int, n)

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

	sort.Ints(s)

	lft := make([]int, 0)
	rht := make([]int, 0)

	for i, num := range s {
		if i%2 == 0 {
			lft = append(lft, num)
		} else {
			rht = append(rht, num)
		}
	}

	i := 0
	j := 0

	for _, num := range a {
		if i < len(lft) && num == lft[i] {
			i++
			continue
		}

		if j < len(rht) && num == rht[j] {
			j++
			continue
		}

		fmt.Fprintln(writer, "NO")
		return
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	var t, n int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
		}

		can := true
		for i := n - 4; i >= 0; i -= 2 {
			if a[i] > a[i+2] || a[i] > a[i+3] || a[i+1] > a[i+2] || a[i+1] > a[i+3] {
				can = false
				break
			}
		}
		if n%2 == 1 {
			for i := 1; i < 3; i++ {
				if i >= n {
					break
				}
				if a[0] > a[i] {
					can = false
					break
				}
			}
		}

		/*if n < 3 {
			fmt.Println("YES")
			continue
		}

		b := make([]int, n)
		if n%2 == 1 {
			b[n/2] = a[0]
		}
		for i := 0; i < n/2; i++ {
			b[n/2-i-1] = a[i*2+(n%2)]
			b[n/2+i+(n%2)] = a[i*2+1+(n%2)]
		}
		can := true
		for i := 0; i < n/2-(1-(n%2)); i++ {
			if b[i] < b[i+1] || b[n-i-1] < b[i+1] || b[i] < b[n-i-2] || b[n-i-1] < b[n-i-2] {
				can = false
				break
			}
		}*/
		// fmt.Println(b)
		if can {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
		}

		can := true
		for i := n - 4; i >= 0; i -= 2 {
			if a[i] > a[i+2] || a[i] > a[i+3] || a[i+1] > a[i+2] || a[i+1] > a[i+3] {
				can = false
				break
			}
		}
		if n%2 == 1 {
			for i := 1; i < 3; i++ {
				if i >= n {
					break
				}
				if a[0] > a[i] {
					can = false
					break
				}
			}
		}

		/*if n < 3 {
			fmt.Println("YES")
			continue
		}

		b := make([]int, n)
		if n%2 == 1 {
			b[n/2] = a[0]
		}
		for i := 0; i < n/2; i++ {
			b[n/2-i-1] = a[i*2+(n%2)]
			b[n/2+i+(n%2)] = a[i*2+1+(n%2)]
		}
		can := true
		for i := 0; i < n/2-(1-(n%2)); i++ {
			if b[i] < b[i+1] || b[n-i-1] < b[i+1] || b[i] < b[n-i-2] || b[n-i-1] < b[n-i-2] {
				can = false
				break
			}
		}*/
		// fmt.Println(b)
		if can {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
		}
		if n < 3 {
			fmt.Println("YES")
			continue
		}

		b := make([]int, n)
		if n%2 == 1 {
			b[n/2] = a[0]
		}
		for i := 0; i < n/2; i++ {
			b[n/2-i-1] = a[i*2+(n%2)]
			b[n/2+i+(n%2)] = a[i*2+1+(n%2)]
		}
		can := true
		for i := 0; i < n/2-(1-(n%2)); i++ {
			if b[i] < b[i+1] || b[n-i-1] < b[i+1] || b[i] < b[n-i-2] || b[n-i-1] < b[n-i-2] {
				can = false
				break
			}
		}
		// fmt.Println(b)
		if can {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

const mod = 998244353

type IntHeap []int
type any = interface{}

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 any) {
	// 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() any {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	hp := make(IntHeap, n)
	for i, v := range arr {
		hp[i] = v
	}
	heap.Init(&hp)
	cur := n - 1
	for hp.Len() > 0 {
		a := heap.Pop(&hp).(int)
		idx1 := cur
		idx2 := max(cur-1, 0)
		if a != max(arr[idx1], arr[idx2]) {
			fmt.Fprintln(out, "No")
			return
		}
		if hp.Len() > 0 {
			b := heap.Pop(&hp).(int)
			if b != min(arr[idx1], arr[idx2]) {
				fmt.Fprintln(out, "No")
				return
			}
		}
		cur -= 2
	}
	fmt.Fprintln(out, "Yes")
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin, _ := os.Open("/project/go/algo/input")
	//stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

const mod = 998244353

type IntHeap []int
type any = interface{}

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 any) {
	// 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() any {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	hp := make(IntHeap, n)
	for i, v := range arr {
		hp[i] = v
	}
	heap.Init(&hp)
	cur := n - 1
	for hp.Len() > 0 {
		a := heap.Pop(&hp).(int)
		idx1 := cur
		idx2 := max(cur-1, 0)
		if a != max(arr[idx1], arr[idx2]) {
			fmt.Fprintln(out, "No")
			return
		}
		if hp.Len() > 0 {
			b := hp.Pop().(int)
			if b != min(arr[idx1], arr[idx2]) {
				fmt.Fprintln(out, "No")
				return
			}
		}
		cur -= 2
	}
	fmt.Fprintln(out, "Yes")
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	//stdin, _ := os.Open("/project/go/algo/input")
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

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

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

			if arr[i] < min {
				min = arr[i]
			}
		}

		f := true
		if n%2 != 0 && min != arr[0] {
			f = false
		}

		for i := 1; i < n; i++ {
			if i > 1 && arr[i] < arr[i-2] {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

import (
	"bufio"
	_ "embed"
	"fmt"
	"os"
)

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

func solve() {
	var n int
	fmt.Fscan(r, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &arr[i])
	}
	for i := 0; i < n-1; i += 2 {
		if arr[i] > arr[i+1] {
			arr[i], arr[i+1] = arr[i+1], arr[i]
		}
	}
	for i := 0; i < n-1; i++ {
		if arr[i] > arr[i+1] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

func main() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
		}
	}()
	defer w.Flush()
	var t int
	for fmt.Fscan(r, &t); t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		n := gi(); a := gis(n)
		lastl,lastr := 1000000,1000000
		ans := "YES"
		for i:=n-1;i>=0;i-=2 {
			if i == 0 {
				if a[i] > lastl || a[i] > lastr { ans = "NO" }
				break
			}
			if (a[i] > lastl || a[i-1] > lastr ) && (a[i] > lastr || a[i-1] > lastl ) { ans = "NO"; break }
			lastl,lastr = a[i],a[i-1]
		}
		fmt.Fprintln(wrtr,ans)
	}
}


A palindrome is a string that reads the same backward as forward. For example, the strings "z", "aaa", "aba", and "abccba" are palindromes, but "codeforces" and "ab" are not. You hate palindromes because they give you déjà vu.There is a string $$$s$$$. You must insert exactly one character 'a' somewhere in $$$s$$$. If it is possible to create a string that is not a palindrome, you should find one example. Otherwise, you should report that it is impossible.For example, suppose $$$s=$$$ "cbabc". By inserting an 'a', you can create "acbabc", "cababc", "cbaabc", "cbabac", or "cbabca". However "cbaabc" is a palindrome, so you must output one of the other options.

The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The only line of each test case contains a string $$$s$$$ consisting of lowercase English letters. The total length of all strings does not exceed $$$3\cdot 10^5$$$.

For each test case, if there is no solution, output "NO". Otherwise, output "YES" followed by your constructed string of length $$$|s|+1$$$ on the next line. If there are multiple solutions, you may print any. You can print each letter of "YES" and "NO" in any case (upper or lower).

YES
cbabac
YES
aab
YES
zaza
YES
baa
NO
YES
nutforajarofatuna

NoteThe first test case is described in the statement.In the second test case, we can make either "aab" or "aba". But "aba" is a palindrome, so "aab" is the only correct answer.In the third test case, "zaza" and "zzaa" are correct answers, but not "azza".In the fourth test case, "baa" is the only correct answer.In the fifth test case, we can only make "aa", which is a palindrome. So the answer is "NO".In the sixth test case, "anutforajaroftuna" is a palindrome, but inserting 'a' elsewhere is valid.

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		word1:="a"+word
		for j:=0;j<len(word1);j++{
			if string(word1[j]) != string(word1[len(word1)-1-j]) {
				fmt.Fprintln(out,"YES")
				fmt.Fprintln(out,word1)
				goto out
			}
		}
		word= word+"a"
		for j:=0;j<len(word);j++{
			if string(word[j]) != string(word[len(word)-1-j]) {
				fmt.Fprintln(out,"YES")
				fmt.Fprintln(out,word)
				goto out
			}
		}
		fmt.Fprintln(out,"NO")
		out:
	}
}

package main

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

func binSearchLE(arr []int, target int) int {
	start := 0
	end := len(arr) - 1
	ans := -1
	for start <= end {
		mid := (start + end) / 2
		if arr[mid] <= target {
			start = mid + 1
		}
		if arr[mid] > target {
			ans = mid
			end = mid - 1
		}
	}
	if ans == -1 {
		if end == len(arr)-1 {
			return len(arr)
		} else {
			return 0
		}
	}
	return ans
}

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

//func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(os.Stdout, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntsArr(arrLen int) []int {
	arr := make([]int, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}
func scanIntsArr64(arrLen int) []int64 {
	arr := make([]int64, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}
func scanIntsLines(arrLen int) []int {
	arr := make([]int, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d\n", &arr[i])
	}
	return arr
}
func printIntsLines(arr []int) {
	for i := 0; i < len(arr); i++ {
		printf("%d\n", arr[i])
	}
}
func scanStrsLines(arrLen int) []string {
	arr := make([]string, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%s\n", &arr[i])
	}
	return arr
}
func printStrsLines(arr []string) {
	for i := 0; i < len(arr); i++ {
		printf("%s\n", arr[i])
	}
}

func sol2(word string) (string, string) {
	counts := 0
	pos := 0
	for j, letter := range word {
		if letter == 97 {
			counts++
			pos = j
		}
	}
	if counts == 0 {
		return "YES", word + "a"
	}
	if counts == len(word) {
		return "NO", ""
	}

	if counts == 1 && pos == len(word)/2 && len(word)%2 == 1 {
		return "YES", word + "a"
	}
	return "YES", strings.Join([]string{word[:pos], "a", word[pos:]}, "")
}

func sol(word string) (string, string) {
	counts := 0
	for _, letter := range word {
		if letter == 97 {
			counts++
		}
	}
	if counts == 0 {
		return "YES", word + "a"
	}
	if counts == len(word) {
		return "NO", ""
	}

	n := len(word)
	start := 0
	end := n-1
	for start <= end {
		if word[start] != word[end] {
			return "YES", strings.Join([]string{word[:start+1], "a", word[start+1:]}, "")
		}
		if n%2==0 && start+1 == end {
			return "YES", word+"a"
		}
		if n%2==1 && start == end {
			return "YES", word+"a"
		}
		start++
		end--
	}
	return "NO", ""
}

func main() {
	n := 0
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		word := ""
		scanf("%s\n", &word)
		a, b := sol(word)
		if a == "NO" {
			printf("%s\n", "NO")
			continue
		}
		printf("%s\n%s\n", a, b)
	}
}

package main
import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    // put your code here
    r := bufio.NewReader(os.Stdin)
    w := bufio.NewWriter(os.Stdout)
    defer w.Flush()
    var t int
    fmt.Fscan(r, &t)
    for i := 0; i < t; i++ {
        var s string
        fmt.Fscan(r, &s)
        if !isPalin(s + "a") {
            fmt.Fprintf(w, "YES\n%s\n", s + "a");
        } else if !isPalin("a" + s) {
            fmt.Fprintf(w, "YES\n%s\n", "a" + s);
        } else {
            fmt.Fprint(w, "NO\n");
        }
    }

}
func isPalin(s string) bool {
    l := len(s)
    for i := 0 ; i < l / 2; i++ {
        if s[i] != s[l - i - 1] {
            return false
        }
    }
    return true

}

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		s := getString(reader)
		front, end := count(s)
		if front == len(s) {
			writer.WriteString("NO\n")
		} else {
			writer.WriteString("YES\n")
			if front > end {
				writer.WriteString("a" + s + "\n")
			} else {
				writer.WriteString(s + "a\n")
			}
		}
	}
	writer.Flush()
}

func count(s string) (int, int) {
	var front, end int
	size := len(s)
	for i := 0; i < size && s[i] == 'a'; i++ {
		front++
	}
	for i := size - 1; i >= 0 && s[i] == 'a'; i-- {
		end++
	}
	return front, end
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1504A
Date: 6/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1504/A
Problem: CF1504A
**/
func (in *CF1504A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()

		ws := p(string('a') + str)
		if ws {
			ws = p(str + string('a'))
			str = str + string('a')
		} else {
			str = string('a') + str
		}
		if !ws {
			fmt.Println("YES")
			fmt.Println(str)
		} else {
			fmt.Println("NO")
		}
	}
}

func p(str string) bool {
	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str)-i-1] {
			return false
		}
	}
	return true
}

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

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

package main

import (
	"fmt"
)

func isPalindrome(s string) bool {
	var n int = len(s)
	for i := 0; i < n/2; i++ {
		if s[i] != s[n-i-1] {
			return false
		}
	}
	return true
}
func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		var s string
		fmt.Scan(&s)
		if !isPalindrome(s + string('a')) {
			fmt.Println("YES")
			fmt.Println(s + string('a'))
		} else if !isPalindrome(string('a') + s) {
			fmt.Println("YES")
			fmt.Println(string('a') + s)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func palindrome(str string) (bool, int) {
	length := len(str)
	idx := -1
	for i := 0; i < length/2+1; i++ {
		if str[i] != str[length-1-i] {
			if str[i] == 'a' {
				return false, i
			} else {
				return false, length - 1 - i
			}
		}
		if str[i] != 'a' && idx == -1 {
			idx = i
		}
	}
	return true, idx
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for case_idx := 0; case_idx < t; case_idx++ {
		var str string
		fmt.Fscanf(in, "%s\n", &str)
		ispalindrome, idx := palindrome(str)
		if ispalindrome {
			if idx == -1 {
				fmt.Fprintln(out, "NO")
			} else {
				fmt.Fprintf(out, "YES\na%s\n", str)
			}
		} else {
			fmt.Fprintln(out, "YES")
			for i := 0; i < len(str); i++ {
				if i == idx {
					fmt.Fprintf(out, "a")
				}
				fmt.Fprintf(out, "%c", str[i])

			}
			fmt.Fprintln(out)
		}
	}
	out.Flush()
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		s := ScanString()

		switch {
		case !isPalin("a" + s):
			fmt.Println("YES")
			fmt.Println("a" + s)
		case !isPalin(s + "a"):
			fmt.Println("YES")
			fmt.Println(s + "a")
		default:
			fmt.Println("NO")
		}
	}
}

func isPalin(s string) bool {
	runes := []rune(s)

	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		if runes[i] != runes[j] {
			return false
		}
	}

	return true
}

package main

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

var reader *bufio.Reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

type Pair struct {
	x, y int
}

type Pairs []Pair

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

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

func reverseRune(s *[]rune) {
	for i, j := 0, len(*s)-1; i < len(*s)/2; {
		(*s)[i], (*s)[j] = (*s)[j], (*s)[i]
		i++
		j--
	}
}

func main() {
	defer writer.Flush()

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

	for t > 0 {
		var str string
		scanf("%s\n", &str)
		str1, str2, f := "a"+str, str+"a", false
		str1Rune := []rune(str1)
		reverseRune(&str1Rune)
		if string(str1Rune) != str1 {
			f = true
			printf("%s\n%s\n", "YES", str1)
		}
		if f == false {
			str2Rune := []rune(str2)
			reverseRune(&str2Rune)
			if string(str2Rune) != str2 {
				printf("%s\n%s\n", "YES", str2)
				f = true
			}
		}
		if f == false {
			printf("%s\n", "NO")
		}
		t--
	}
}

package main

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

func processLine(line string) {
	palindrome := true
	for k := 0; k < len(line); k++ {
		if line[len(line) - 1 - k] != 'a' {
			Printf("YES\n%sa%s\n", line[:k], line[k:])
			return
		} else if !palindrome {
			Printf("YES\n%sa%s\n", line[:k], line[k:])
			return
		}
		if line[k] != line[len(line) - 1 - k] {
			palindrome = false
		}
	}
	if palindrome {
		Printf("NO\n")
	}
}

func callIo(in io.Reader, out io.Writer) {
	var n int

	_, _ = Fscan(in, &n)
	if n < 1 || n > 10000 {
		panic("Invalid argument")
	}

	for i := 0; i < n; i++ {
		var line string
		_, _ = Fscan(in, &line)
		// process line
		//Printf("%d: %s\n", i, line)
		processLine(line)
	}
}

func main() {
	in := os.Stdin
	out := os.Stdout

	// buffer reader to for speed up:
	bufIn := bufio.NewReader(in)
	// buffer output to for speed up:
	bufOut := bufio.NewWriter(out)
	defer bufOut.Flush()

	// call your algorithm
	callIo(bufIn, bufOut)
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	s      string
)

func solve(s string) string {
	l := len(s)
	for i, x := range s {
		if x != 'a' {
			new_s := s[:l-i] + "a" + s[l-i:]
			return fmt.Sprintf("YES\n%s", new_s)
		}
	}
	return "NO"
}

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

package main
import (
	"bufio"
	."fmt"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	T, s := 0, ""
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		if i := strings.IndexFunc(s, func(r rune) bool { return r > 'a' }); i < 0 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			Fprintln(out, s[:len(s)-i]+"a"+s[len(s)-i:])
		}
	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}

func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}

func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}

func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		str := sc.next()
		N := len(str)
		l := 0
		r := N - 1
		for l <= r && str[l] == 'a' && str[r] == 'a' {
			r--
			l++
		}
		if l > r || (str[l] == 'a' && str[r] == 'a') {
			fmt.Fprintln(wr, "NO")
		} else if str[l] != 'a' {
			str = str[0:r+1] + "a" + str[r+1:]
			fmt.Fprintln(wr, "YES")
			fmt.Fprintln(wr, str)
		} else if str[r] != 'a' {
			str = str[0:l] + "a" + str[l:]
			fmt.Fprintln(wr, "YES")
			fmt.Fprintln(wr, str)
		}
	}
}

package main

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

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

		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)

		k := len(STRING)
		b := 0
		ANS := ""
		for i := 0; i < k; i++ {
			if string(STRING[i]) != "a" {
				ANS = ANS + string(STRING[:(k-i)]) + "a" + string(STRING[(k-i):])
				b = 1
				fmt.Println("YES")
				fmt.Println(ANS)
				break
			}
		}
		if b == 0 {
			fmt.Println("NO")
		}

	}
}

package main

import "fmt"

func main() {
	var n int
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanln(&s)
		fmt.Println(solve(s))
	}
}

func solve(s string) string {
	start := 0
	end := len(s)
	for start < end {
		if s[start] != 'a' {
			return "YES\n" + s[:end] + "a" + s[end:]
		}
		if s[end-1] != 'a' {
			return "YES\n" + s[:start] + "a" + s[start:]
		}
		start++
		end--
	}
	return "NO"
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		count:= strings.Count(word,"a")
		if len(word) == count {
			fmt.Fprintln(out,"NO")
			continue
		}
		if len(word) == 1 || count == 0{
			fmt.Fprintln(out,"YES")
			fmt.Fprintln(out,word+"a")
			continue
		}
		var counter,tally int
		for j:=0;j<len(word);j++{
			if string(word[j]) == "a" {
				counter+=(j+1)
				tally++
			}
		}
		if counter/tally <= len(word)/2 {
			fmt.Fprintln(out,"YES")
			fmt.Fprintln(out,"a"+word)
		} else {
			fmt.Fprintln(out,"YES")
			fmt.Fprintln(out,word+"a")
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		if len(word) == strings.Count(word,"a") {
			fmt.Fprintln(out,"NO")
			continue
		}
		if len(word) == 1 {
			fmt.Fprintln(out,"YES")
			word+="a"
			fmt.Fprintln(out,word)
			continue
		}
		var list []int
		for j:=0;j<len(word);j++{
			if string(word[j]) == "a" {
				if j == len(word)-1 {
					list = append(list,0)
				} else if len(word)%2 != 0 && j == len(word)/2 {
					list = append(list,len(word)-j,len(word)-j-1)
				} else {
					list = append(list,len(word)-j)
				}
			}
		}
		fmt.Fprintln(out,"YES")
		count:=1
		for j:=0;j<len(word);j++{
			if count > 0 {
				tally:=0
				for k:=0;k<len(list);k++{
					if j == list[k] {
						tally++
					}
				}
				if tally == 0{
					fmt.Fprintf(out,"a")
					count--
				}
			}
			fmt.Fprintf(out,"%v",string(word[j]))
		}
		fmt.Fprintln(out,)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		if len(word) == strings.Count(word,"a") {
			fmt.Fprintln(out,"NO")
			continue
		}
		if len(word) == 1 {
			fmt.Fprintln(out,"YES")
			word+="a"
			fmt.Fprintln(out,word)
			continue
		}
		var list []int
		for j:=0;j<len(word);j++{
			if string(word[j]) == "a" {
				if j == len(word)-1 {
					list = append(list,0)
				} else {
					list = append(list,len(word)-j)
				}
			}
		}
		fmt.Fprintln(out,"YES")
		count:=1
		for j:=0;j<len(word);j++{
			if count > 0 {
				tally:=0
				for k:=0;k<len(list);k++{
					if j == list[k] {
						tally++
					}
				}
				if tally == 0{
					fmt.Fprintf(out,"a")
					count--
				}
			}
			fmt.Fprintf(out,"%v",string(word[j]))
		}
		fmt.Fprintln(out,)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		if len(word) == strings.Count(word,string(word[0])) {
			fmt.Fprintln(out,"NO")
			continue
		}
		var list []int
		for j:=0;j<len(word);j++{
			if string(word[j]) == "a" {
				if j == len(word)-1 {
					list = append(list,0)
				} else {
					list = append(list,len(word)-j)
				}
			}
		}
		fmt.Fprintln(out,"YES")
		count:=1
		for j:=0;j<len(word);j++{
			if count > 0 {
				tally:=0
				for k:=0;k<len(list);k++{
					if j == list[k] {
						tally++
					}
				}
				if tally == 0{
					fmt.Fprintf(out,"a")
					count--
				}
			}
			fmt.Fprintf(out,"%v",string(word[j]))
		}
		fmt.Fprintln(out,)
	}
}

package main

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

func binSearchLE(arr []int, target int) int {
	start := 0
	end := len(arr) - 1
	ans := -1
	for start <= end {
		mid := (start + end) / 2
		if arr[mid] <= target {
			start = mid + 1
		}
		if arr[mid] > target {
			ans = mid
			end = mid - 1
		}
	}
	if ans == -1 {
		if end == len(arr)-1 {
			return len(arr)
		} else {
			return 0
		}
	}
	return ans
}

func sol(words []string) []string {
	res := make([]string, 0, len(words) * 2)
	for i := range words {
		counts := 0
		pos := 0
		for j, letter := range words[i] {
			if letter == 97 {
				counts++
				pos = j
			}
		}
		if counts == 0 {
			res = append(res, "YES")
			res = append(res, words[i]+"a")
			continue
		}
		if counts != len(words[i]) && counts == 1 && pos == len(words[i])/2 && len(words[i]) % 2 == 1 {
			res = append(res, "YES")
			res = append(res, words[i]+"a")
			continue
		}
		if counts != len(words[i]) {
			res = append(res, "YES")
			res = append(res, strings.Join([]string{words[i][:pos], "a", words[i][pos:]}, ""))
			continue
		}
		res = append(res, "NO")
	}
	return res
}

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

//func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(os.Stdout, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntsArr(arrLen int) []int {
	arr := make([]int, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}
func scanIntsArr64(arrLen int) []int64 {
	arr := make([]int64, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}
func scanIntsLines(arrLen int) []int {
	arr := make([]int, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d\n", &arr[i])
	}
	return arr
}
func printIntsLines(arr []int) {
	for i := 0; i < len(arr); i++ {
		printf("%d\n", arr[i])
	}
}
func scanStrsLines(arrLen int) []string {
	arr := make([]string, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%s\n", &arr[i])
	}
	return arr
}
func printStrsLines(arr []string) {
	for i := 0; i < len(arr); i++ {
		printf("%s\n", arr[i])
	}
}

func main() {
	n := 0
	scanf("%d\n", &n)
	words := scanStrsLines(n)
	printStrsLines(sol(words))
}

package main

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

func binSearchLE(arr []int, target int) int {
	start := 0
	end := len(arr) - 1
	ans := -1
	for start <= end {
		mid := (start + end) / 2
		if arr[mid] <= target {
			start = mid + 1
		}
		if arr[mid] > target {
			ans = mid
			end = mid - 1
		}
	}
	if ans == -1 {
		if end == len(arr)-1 {
			return len(arr)
		} else {
			return 0
		}
	}
	return ans
}

func sol(words []string) []string {
	res := make([]string, 0, len(words) * 2)
	for i := range words {
		counts := 0
		pos := 0
		for j, letter := range words[i] {
			if letter == 97 {
				counts++
				pos = j
			}
		}
		if counts == 0 {
			res = append(res, "YES")
			res = append(res, words[i]+"a")
			continue
		}
		if counts != len(words[i]) {
			res = append(res, "YES")
			res = append(res, strings.Join([]string{words[i][:pos], "a", words[i][pos:]}, ""))
			continue
		}
		res = append(res, "NO")
	}
	return res
}

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

//func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(os.Stdout, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntsArr(arrLen int) []int {
	arr := make([]int, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}
func scanIntsArr64(arrLen int) []int64 {
	arr := make([]int64, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}
func scanIntsLines(arrLen int) []int {
	arr := make([]int, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d\n", &arr[i])
	}
	return arr
}
func printIntsLines(arr []int) {
	for i := 0; i < len(arr); i++ {
		printf("%d\n", arr[i])
	}
}
func scanStrsLines(arrLen int) []string {
	arr := make([]string, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%s\n", &arr[i])
	}
	return arr
}
func printStrsLines(arr []string) {
	for i := 0; i < len(arr); i++ {
		printf("%s\n", arr[i])
	}
}

func main() {
	n := 0
	scanf("%d\n", &n)
	words := scanStrsLines(n)
	printStrsLines(sol(words))
}

package main
import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    // put your code here
    r := bufio.NewReader(os.Stdin)
    w := bufio.NewWriter(os.Stdout)
    defer w.Flush()
    var t int
    fmt.Fscan(r, &t)
    for i := 0; i < t; i++ {
        var s string
        fmt.Fscan(r, &s)
        l := len(s);
        flag := true
        for _, e := range s {
            if e != 'a' {
                flag = false
                break
            }
        }
        if !flag && s[0] != 'a' {
            fmt.Fprintf(w, "YES\n%s%s\n", s, "a");
        } else if !flag && s[l-1] != 'a' || !flag {
            fmt.Fprintf(w, "YES\n%s%s\n", "a", s);
        } else {
            fmt.Fprint(w, "NO\n");
        }
    }

}

package main
import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    // put your code here
    r := bufio.NewReader(os.Stdin)
    w := bufio.NewWriter(os.Stdout)
    defer w.Flush()
    var t int
    fmt.Fscan(r, &t)
    for i := 0; i < t; i++ {
        var s string
        fmt.Fscan(r, &s)
        l := len(s);
        flag := true
        for _, e := range s {
            if e != 'a' {
                flag = false
                break
            }
        }
        if !flag && s[0] != 'a' {
            fmt.Fprintf(w, "YES\n%s%s\n", s, "a");
        } else if !flag && s[l-1] != 'a' {
            fmt.Fprintf(w, "YES\n%s%s\n", "a", s);
        } else {
            fmt.Fprint(w, "NO\n");
        }
    }

}

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		s := getString(reader)
		if !a(s) {
			writer.WriteString("YES\n")
			if s[0] == 'a' {
				writer.WriteString("a" + s + "\n")
			} else {
				writer.WriteString(s + "a\n")
			}
		} else {
			writer.WriteString("NO\n")
		}
	}
	writer.Flush()
}

func a(s string) bool {
	for _, v := range s {
		if v != 'a' {
			return false
		}
	}
	return true
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1504A
Date: 6/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1504/A
Problem: CF1504A
**/
func (in *CF1504A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := string('a') + in.NextString()

		ws := p(string('a') + str)
		if ws {
			ws = p(str + string('a'))
		}
		if !ws {
			fmt.Println("YES")
			fmt.Println(str)
		} else {
			fmt.Println("NO")
		}
	}
}

func p(str string) bool {
	for i := 0; i <= len(str)/2; i++ {
		if str[i] != str[len(str)-i-1] {
			return false
		}
	}
	return true
}

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

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

package main

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

func palindrome(str string) (bool, int) {
	length := len(str)
	idx := -1
	for i := 0; i < length/2; i++ {
		if str[i] != str[length-1-i] {
			if str[i] == 'a' {
				return false, i
			} else {
				return false, length - 1 - i
			}
		}
		if str[i] != 'a' && idx == -1 {
			idx = i
		}
	}
	return true, idx
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for case_idx := 0; case_idx < t; case_idx++ {
		var str string
		fmt.Fscanf(in, "%s\n", &str)
		ispalindrome, idx := palindrome(str)
		if ispalindrome {
			if idx == -1 {
				fmt.Fprintln(out, "NO")
			} else {
				fmt.Fprintf(out, "YES\na%s\n", str)
			}
		} else {
			fmt.Fprintln(out, "YES")
			for i := 0; i < len(str); i++ {
				if i == idx {
					fmt.Fprintf(out, "a")
				}
				fmt.Fprintf(out, "%c", str[i])

			}
			fmt.Fprintln(out)
		}
	}
	out.Flush()
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		s := ScanString()

		switch {
		case isPalin("a" + s):
			fmt.Println("YES")
			fmt.Println("a" + s)
		case isPalin(s + "a"):
			fmt.Println("YES")
			fmt.Println(s + "a")
		default:
			fmt.Println("NO")
		}
	}
}

func isPalin(s string) bool {
	runes := []rune(s)

	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		if runes[i] != runes[j] {
			return false
		}
	}

	return true
}

package main

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

var reader *bufio.Reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

type Pair struct {
	x, y int
}

type Pairs []Pair

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

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

func reverseRune(s *[]rune) {
	for i, j := 0, len(*s)-1; i < len(*s)/2; {
		(*s)[i], (*s)[j] = (*s)[j], (*s)[i]
		i++
		j--
	}
}

func main() {
	defer writer.Flush()

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

	for t > 0 {
		var str string
		scanf("%s\n", &str)
		str1, str2, f := "a"+str, str+"a", false
		str1Rune := []rune(str1)
		reverseRune(&str1Rune)
		if string(str1Rune) != str1 {
			f = true
			printf("%s\n%s\n", "YES", string(str1Rune))
		}
		if f == false {
			str2Rune := []rune(str2)
			reverseRune(&str2Rune)
			if string(str2Rune) != str2 {
				printf("%s\n%s\n", "YES", string(str2Rune))
				f = true
			}
		}
		if f == false {
			printf("%s\n", "NO")
		}
		t--
	}
}

package main

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

func processLine(line string) {
	palindrome := true
	for k := 0; k < len(line); k++ {
		if line[k] != 'a' {
			Printf("YES\n%sa%s\n", line[:k], line[k:])
			return
		} else if !palindrome {
			Printf("YES\n%sa%s\n", line[:k], line[k:])
			return
		}
		if line[k] != line[len(line) - 1 - k] {
			palindrome = false
		}
	}
	if palindrome {
		Printf("NO\n")
	}
}

func callIo(in io.Reader, out io.Writer) {
	var n int

	_, _ = Fscan(in, &n)
	if n < 1 || n > 10000 {
		panic("Invalid argument")
	}

	for i := 0; i < n; i++ {
		var line string
		_, _ = Fscan(in, &line)
		// process line
		//Printf("%d: %s\n", i, line)
		processLine(line)
	}
}

func main() {
	in := os.Stdin
	out := os.Stdout

	// buffer reader to for speed up:
	bufIn := bufio.NewReader(in)
	// buffer output to for speed up:
	bufOut := bufio.NewWriter(out)
	defer bufOut.Flush()

	// call your algorithm
	callIo(bufIn, bufOut)
}