package main

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

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

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

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

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

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

/**

Run solve the problem CF1744B
Date: 10/22/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/B
Problem: CF1744B
**/
func (in *CF1744B) Run() {
	var buff strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n, q := in.NextInt(), in.NextInt()
		sum := int64(0)
		odd, even := 0, 0
		for i := 0; i < n; i++ {
			val := in.NextInt64()
			if val%2 == 0 {
				even++
			} else {
				odd++
			}
			sum += val
		}

		for i := 0; i < q; i++ {
			ty, val := in.NextInt(), in.NextInt64()
			if ty == 0 {
				sum += val * int64(even)
				if val%2 != 0 {
					odd += even
					even = 0
				}
			} else {
				sum += val * int64(odd)
				if val%2 != 0 {
					even += odd
					odd = 0
				}
			}
			buff.WriteString(fmt.Sprintf("%v\n", sum))
		}
	}
	fmt.Print(buff.String())
}

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

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

package main

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

var reader = bufio.NewReader(os.Stdin)

var n, m int

func solve(typ, x int) {
	if x%2 == 0 {
		// will not change the odd even
		if typ == 0 { // even
			sum += even * x
		} else {
			sum += odd * x
		}
	} else { // will change the odd even, x is odd number
		if typ == 0 { // operating even number
			sum += even * x
			odd += even
			even = 0
		} else { // operating odd number
			sum += odd * x
			even += odd
			odd = 0
		}
	}
	fmt.Println(sum)
}

var odd, even, sum int

func main() {
	var t int

	fmt.Fscan(reader, &t)

	for t > 0 {
		t--
		odd, sum, even = 0, 0, 0
		var q, n int
		fmt.Fscan(reader, &n, &q)
		a := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a)
			if (a % 2) == 0 {
				even++
			} else {
				odd++
			}
			sum += a
		}

		for i := 0; i < q; i++ {
			var q1, q2 int
			fmt.Fscan(reader, &q1, &q2)
			solve(q1, q2)
		}
	}
}

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

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

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

		var n, q int
		fmt.Fscan(reader, &n, &q)

		arr := make([]int, n)
		// queries := make([][]int, q)
		sum := 0
		evenCnt, oddCnt := 0, 0
		for i := 0; i < n; i++ {
			var e int
			fmt.Fscan(reader, &e)
			arr[i] = e
			sum += e

			if e%2 == 0 {
				evenCnt++
			} else {
				oddCnt++
			}
		}

		output := make([]int, q)
		for i := 0; i < q; i++ {
			var tp, value int

			// queries[i] = make([]int, 2)
			fmt.Fscan(reader, &tp, &value)
			// queries[i][0] = tp
			// queries[i][1] = value
			if tp == 0 {
				sum += evenCnt * value
				if value%2 != 0 {
					evenCnt = 0
					oddCnt = n
				}
			} else {
				sum += oddCnt * value
				if value%2 != 0 {
					oddCnt = 0
					evenCnt = n
				}
			}
			output[i] = sum
		}

		// output := solve(&arr, &queries, n, q)

		for _, v := range output {

			fmt.Fprintln(writer, v)
		}
	}
}

func solve(arr *[]int, queries *[][]int, n, q int) []int {
	sum := make([]int, q)

	for i := 0; i < q; i++ {
		tp := (*queries)[i][0]

		if tp == 0 {
			for j := 0; j < n; j++ {
				if (*arr)[j]%2 == 0 {
					(*arr)[j] += (*queries)[i][1]
				}
				sum[i] += (*arr)[j]
			}
		} else {
			for j := 0; j < n; j++ {
				if (*arr)[j]%2 != 0 {
					(*arr)[j] += (*queries)[i][1]
				}
				sum[i] += (*arr)[j]
			}
		}
	}

	return sum
}

package main

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

var in = bufio.NewReader(os.Stdin)

func  gcd(a, b int) int {
  for b != 0 {
      a, b = b, a%b
  }
  return a
}

func pl(a ...interface{}) { fmt.Println(a...) }
func pf(format string, a ...interface{}) { fmt.Printf(format, a...) }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }

func main() {
	var T int
	scan(&T)

	for ; T > 0; T-- {
    var n, q int
    scan(&n, &q)
    a := make([]int, n, n)
    var sum, o, e int
    for i := range a {
      scan(&a[i])
      if a[i] % 2 == 0 {
        e++
      } else {
        o++
      }
      sum += a[i]
    }
    for i := 0; i < q; i ++ {
      var t, x int
      scan(&t, &x)
      if t == 0 {
        sum += x * e
      } else {
        sum += x * o
      }
      pf("%d\n", sum)
      switch {
        case x % 2 == 1 && t == 0:
          o += e
          e = 0
        case x % 2 == 1 && t == 1:
          e += o
          o = 0
      }
    }
	}
}

func ys(b bool) string { return map[bool]string {true: "YES", false: "NO"}[b] }

package main

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

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

func sum(nums []int) (int, int, int) {
  sum := 0
  even := 0
  for i := 0; i < len(nums); i++ {
    if nums[i] % 2 == 0 {
      even++
    }
    sum += nums[i]
  }

  return sum, even, len(nums) - even
}

func main() {
  writer.Flush()
  var test int
  fmt.Fscanf(reader, "%d\n", &test)

  for test > 0 {
    var n, q int
    fmt.Fscanf(reader, "%d %d\n", &n, &q)
    nums := make([]int, n)
    for i := 0; i < n; i++ {
      fmt.Fscanf(reader, "%d",&nums[i])
    }

    initSum, even, odd := sum(nums)

    fmt.Fscanf(reader, "\n")
    for i := 0; i < q; i++ {
      var x, val int
      fmt.Fscanf(reader, "%d %d\n", &x, &val)
      if x == 1 {
        initSum += odd * val
        if val % 2 == 1 {
          even += odd
          odd = 0
        }
      } else {
        initSum += even *val
        if val % 2 == 1 {
          odd += even
          even = 0
        }
      }

      fmt.Println(initSum)
    }
    test--
  }
}

package main

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

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

	var T int

	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, q int
		fmt.Fscan(r, &n, &q)

		a := make([]int, n)

		var evenSum, oddSum, evenCount, oddCount int64

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

			if a[i]%2 == 0 {
				evenCount++
				evenSum += int64(a[i])
			} else {
				oddCount++
				oddSum += int64(a[i])
			}
		}

		for i := 1; i <= q; i++ {
			var x, y int
			fmt.Fscan(r, &x, &y)

			if x == 0 {
				if y%2 == 0 {
					evenSum += evenCount * int64(y)
				} else {
					oddSum += evenSum + evenCount*int64(y)
					oddCount += evenCount
					evenCount = 0
					evenSum = 0
				}
			} else { //Add to odd numbers
				if y%2 == 0 {
					oddSum += oddCount * int64(y)
				} else {
					evenSum += oddSum + oddCount*int64(y)
					evenCount += oddCount
					oddCount = 0
					oddSum = 0
				}
			}

			fmt.Fprintln(w, oddSum+evenSum)
		}
	}
}

package main

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

const (
	N = 1e5 + 10
)

var (
	t, n, q, op       int
	x, ans, even, odd int64
	a                 []int64
)

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

	fmt.Fscan(r, &t)
	a = make([]int64, N)
	for ; t != 0; t-- {
		fmt.Fscan(r, &n, &q)
		even, odd, ans = 0, 0, 0
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
			ans += a[i]
			if a[i]%2 == 0 {
				even++
			} else {
				odd++
			}
		}
		for i := 0; i < q; i++ {
			fmt.Fscan(r, &op, &x)
			if op == 0 {
				ans += x * even
				if x%2 == 1 {
					odd += even
					even = 0
				}
			} else {
				ans += x * odd
				if x%2 == 1 {
					even += odd
					odd = 0
				}
			}
			fmt.Fprintln(w, ans)
		}

	}
}

package main

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

func trim(s string) string {
	return s[:len(s)-2]
}

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

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

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func checkNumberPowerOfTwo(n int) int {
	return n & (n - 1)
}

func sliceStr2Int(arr []string) []int {
	var arrInt []int
	for _, i := range arr {
		num, _ := strconv.Atoi(i)
		arrInt = append(arrInt, num)
	}

	return arrInt
}

func sliceIntFromConsole() []int {
	arrLine, _ := reader.ReadString('\n')
	return sliceStr2Int(strings.Split(trim(arrLine), " "))
}

func numberFromConsole() int {
	numberLine, _ := reader.ReadString('\n')
	number, _ := strconv.Atoi(trim(numberLine))
	return number
}

var reader = bufio.NewReader(os.Stdin)

func main() {
	test := numberFromConsole()
	for t := 0; t < test; t++ {
		nq := sliceIntFromConsole()
		q := nq[1]

		a := sliceIntFromConsole()
		var sum int
		nums := make([]int, 2)
		// first element -- amount of even numbers in a slice
		// second element -- amount of odd numbers in a slice

		for _, v := range a {
			sum += v
			nums[v%2]++
		}

		for request := 0; request < q; request++ {
			req := sliceIntFromConsole()
			sum += nums[req[0]] * req[1]
			fmt.Println(sum)

			if req[1]%2 == 1 {
				nums[abs(req[0]-1)] += nums[req[0]]
				nums[req[0]] = 0
			}
		}
	}
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, q, evens, odds, res int
		fmt.Fscan(r, &n, &q)

		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(r, &a)
			odds += a%2
			res += a
		}
		evens = n - odds

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

			if t == 0 {
				res += evens*x
				if x % 2 == 1 {
					evens = 0
					odds = n
				}
			} else {
				res += odds*x
				if x % 2 == 1 {
					odds = 0
					evens = n
				}
			}

			fmt.Fprintln(w, res)
		}
	}

}

package main

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

func solution_1(input io.Reader, output io.Writer) {
	in := bufio.NewReader(input)
	var n int
	_, err := fmt.Fscanf(in, "%d\n", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		var narr int
		_, err := fmt.Fscanf(in, "%d\n", &narr)
		if err != nil {
			panic(err)
		}

		arr := make([]int, 0, narr)
		for j := 0; j < narr; j++ {
			var v int
			_, err := fmt.Fscanf(in, "%d", &v)
			if err != nil {
				panic(err)
			}
			arr = append(arr, v)
		}
		fmt.Fscanf(in, "\n")
		var s string
		_, err = fmt.Fscanf(in, "%s\n", &s)
		fmt.Fprintln(output, numberReplacement(arr, s))
	}
}

func solution_2(input io.Reader, output io.Writer) {
	in := bufio.NewReader(input)
	var n int
	_, err := fmt.Fscanf(in, "%d\n", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		var narr, q int
		_, err := fmt.Fscanf(in, "%d %d\n", &narr, &q)
		if err != nil {
			panic(err)
		}

		arr := make([]int, 0, narr)
		for j := 0; j < narr; j++ {
			var v int
			_, err := fmt.Fscanf(in, "%d", &v)
			if err != nil {
				panic(err)
			}
			arr = append(arr, v)
		}
		fmt.Fscanf(in, "\n")

		nOdd := 0
		nEven := 0
		sum := 0

		for _, n := range arr {
			sum += n
			if n%2 == 0 {
				nEven++
			} else {
				nOdd++
			}
		}
		for j := 0; j < q; j++ {
			var a, b int
			fmt.Fscanf(in, "%d %d\n", &a, &b)
			if a == 0 {
				sum += nEven * b
				if b%2 != 0 {
					nOdd += nEven
					nEven = 0
				}
			}

			if a == 1 {
				sum += nOdd * b
				if b%2 != 0 {
					nEven += nOdd
					nOdd = 0
				}
			}
			fmt.Fprintln(output, sum)
		}

	}
}

func numberReplacement(arr []int, s string) string {
	if len(arr) != len(s) {
		return "NO"
	}

	someMap := make(map[int]byte)
	for i, n := range arr {
		if v, ok := someMap[n]; !ok {
			someMap[n] = s[i]
		} else {
			if v != s[i] {
				return "NO"
			}
		}
	}

	return "YES"
}

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

package main

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

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

//func solve() {
//	var v0, v1 = make([]int, 0), make([]int, 0)
//	n, q := _readInt(), _readInt()
//	for i := 0; i < n; i++ {
//		x := _readInt()
//		if x%2 == 0 {
//			v0 = append(v0, x)
//		} else {
//			v1 = append(v1, x)
//		}
//	}
//
//	for i := 0; i < q; i++ {
//		var tar, dest []int
//		t, x := _readInt(), _readInt()
//		if t == 0 {
//			tar, dest = v0, v1
//		} else {
//			tar, dest = v1, v0
//		}
//
//		for j := range tar {
//			tar[j] += x
//		}
//	}
//
//}

func solve() {
	n, q := _readInt(), _readInt()
	var s0, n0, s1, n1 int64
	var res int64

	for i := 0; i < n; i++ {
		x := int64(_readInt())
		if x%2 == 0 {
			n0++
			s0 += x
		} else {
			n1++
			s1 += x
		}
		res += x
	}

	for i := 0; i < q; i++ {
		t, x := _readInt(), int64(_readInt())
		if t == 0 {
			res += n0 * x
		} else {
			res += n1 * x
		}
		if x%2 != 0 {
			if t == 0 {
				n1 += n0
				n0 = 0
			} else {
				n0 += n1
				n1 = 0
			}
		}
		_print(res)
	}

}

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

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr() (int, []int) {
	var n int
	fmt.Fscan(in, &n)
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func _min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}

package main

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

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

func solve() {
    var n, q int
    Fscan(in, &n, &q)

    var sum int = 0
    even := 0
    odd := 0
    a := make([]int, n)
    for i := 0; i < n; i++ {
        Fscan(in, &a[i])
        sum += a[i]
        if a[i] % 2 == 1 {
            odd++
        } else {
            even++
        }
    }

    for ; q > 0; q-- {
        var op, x int
        Fscan(in, &op, &x)

        if op == 1 {
            sum += x * odd

            if x % 2 == 1 {
                even = n
                odd = 0
            }
        } else {
            sum += x * even

            if x % 2 == 1 {
                odd = n
                even = 0
            }
        }

        Fprintln(out, sum)
    }
}

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

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

		var sum int64
		var e, o int
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			sum += v
			if v%2 == 0 {
				e++
			} else {
				o++
			}
		}

		for i := 0; i < q; i++ {
			var d, x int64
			fmt.Fscan(in, &d, &x)
			if d == 0 {
				sum += int64(e) * x
				if x%2 != 0 {
					o += e
					e = 0
				}
			} else {
				sum += int64(o) * x
				if x%2 != 0 {
					e += o
					o = 0
				}
			}
			fmt.Fprintln(out, sum)
		}
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		n, q := nextInt(), nextInt()
		a := make([]int, n)
		sum := int64(0)
		odd, even := int64(0), int64(0)
		for i := 0; i < n; i++ {
			a[i] = nextInt()
			sum += int64(a[i])
			if a[i]%2 == 0 {
				even++
			}
		}
		odd = int64(n) - even
		for q > 0 {
			q--
			t, x := nextInt(), nextInt()
			if t == 0 {
				sum += even * int64(x)
				if x%2 == 1 {
					odd += even
					even = 0
				}
			} else {
				sum += odd * int64(x)
				if x%2 == 1 {
					even += odd
					odd = 0
				}
			}
			fmt.Println(sum)
		}
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

package main

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

const cf = true

func solve() {
	var n, q int
	fmt.Fscan(in, &n, &q)
	even, odd := 0, 0
	evenCnt, oddCnt := 0, 0
	var num int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &num)
		if num%2 == 0 {
			even += num
			evenCnt++
		} else {
			odd += num
			oddCnt++
		}
	}
	var tp, val int
	for i := 0; i < q; i++ {
		fmt.Fscan(in, &tp, &val)
		if tp == 0 {
			even += evenCnt * val
			if val%2 == 1 {
				odd += even
				even = 0
				oddCnt += evenCnt
				evenCnt = 0
			}
		} else {
			odd += oddCnt * val
			if val%2 == 1 {
				even += odd
				odd = 0
				evenCnt += oddCnt
				oddCnt = 0
			}
		}
		fmt.Fprintln(out, even+odd)
	}
}

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

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

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

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

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

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

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

/**

Run solve the problem CF1744B
Date: 10/22/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/B
Problem: CF1744B
**/
func (in *CF1744B) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n, q := in.NextInt(), in.NextInt()
		sum := int64(0)
		odd, even := 0, 0
		for i := 0; i < n; i++ {
			val := in.NextInt64()
			if val%2 == 0 {
				even++
			} else {
				odd++
			}
			sum += val
		}
		var buff strings.Builder
		for i := 0; i < q; i++ {
			ty, val := in.NextInt(), in.NextInt64()
			if ty == 0 {
				sum += val * int64(even)
				if val%2 != 0 {
					odd += even
					even = 0
				}
			} else {
				sum += val * int64(odd)
				if val%2 != 0 {
					even += odd
					odd = 0
				}
			}
			buff.WriteString(fmt.Sprintf("%v\n", sum))
		}
		fmt.Print(buff.String())
	}

}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1744B
Date: 10/22/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/B
Problem: CF1744B
**/
func (in *CF1744B) Run() {
	var buff strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n, q := in.NextInt(), in.NextInt()
		sum := int64(0)
		odd, even := 0, 0
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			val := in.NextInt64()
			arr[i] = val
			if val%2 == 0 {
				even++
			} else {
				odd++
			}
			sum += val
		}

		for i := 0; i < q; i++ {
			ty, val := in.NextInt(), in.NextInt64()
			if ty == 0 {
				sum += val * int64(even)
				if val%2 != 0 {
					odd += even
					even = 0
				}
			} else {
				sum += val * int64(odd)
				if val%2 != 0 {
					even += odd
					odd = 0
				}
			}
			buff.WriteString(fmt.Sprintf("%v\n", sum))
		}
	}
	fmt.Print(buff.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1744B
Date: 10/22/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/B
Problem: CF1744B
**/
func (in *CF1744B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, q := in.NextInt(), in.NextInt()
		sum := int64(0)
		odd, even := 0, 0
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			val := in.NextInt64()
			arr[i] = val
			if val%2 == 0 {
				even++
			} else {
				odd++
			}
			sum += val
		}

		for i := 0; i < q; i++ {
			ty, val := in.NextInt(), in.NextInt64()
			if ty == 0 {
				sum += val * int64(even)
				if val%2 != 0 {
					odd += even
					even = 0
				}
			} else {
				sum += val * int64(odd)
				if val%2 != 0 {
					even += odd
					odd = 0
				}
			}
			fmt.Println(sum)
		}

	}
}

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

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

package main
// github.com/jamesgrimard/codeforces
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 n,l,sum,o,e int
		fmt.Fscan(in,&n,&l)
		for j:=0;j<n;j++{
			var holder int
			fmt.Fscan(in,&holder)
			sum += holder
			if holder & 1 == 1 {
				o++
			} else {
				e++
			}
		}
		for j:=0;j<l;j++{
			var b,x int
			fmt.Fscan(in,&b,&x)
			if b == 1 { // going after all the odds
				sum += (o * x)
				if x & 1 == 1 { // odds + odds
					e += o
					o = 0
				}
			} else { // going after all the evens
				sum += (e * x)
				if x & 1 == 1 { // evens + odds
					o += e
					e = 0
				}
			}
			fmt.Fprintln(out,sum)
		}
	}
}
// take input -> if odd++ else, even++
// if b odd, if x odd : else if x even:

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.Replace(text, "\r\n", "", -1)
	t, _ := strconv.Atoi(text)
	for i := 0; i < t; i++ {
		text, _ = reader.ReadString('\n')
		text = strings.Replace(text, "\r\n", "", -1)
		n, _ := strconv.Atoi(strings.Split(text, " ")[1])

		text, _ := reader.ReadString('\n')
		text = strings.Replace(text, "\r\n", "", -1)
		rawArr := strings.Split(text, " ")
		evenCount := 0
		notEvenCount := 0
		evenIsEven := true
		notEvenIsEven := false
		evenSum := 0
		notEvenSum := 0
		for _, s := range rawArr {
			num, _ := strconv.Atoi(s)
			if num%2 == 0 {
				evenSum = evenSum + num
				evenCount++
			} else {
				notEvenSum = notEvenSum + num
				notEvenCount++
			}
		}
		for j := 0; j < n; j++ {
			text, _ = reader.ReadString('\n')
			text = strings.Replace(text, "\r\n", "", -1)
			val, _ := strconv.Atoi(strings.Split(text, " ")[1])
			if strings.Split(text, " ")[0] == "0" {
				if evenIsEven {
					evenSum = evenSum + val*evenCount
					if val%2 != 0 {
						evenIsEven = false
					}
				}
				if notEvenIsEven {
					notEvenSum = notEvenSum + val*notEvenCount
					if val%2 != 0 {
						notEvenIsEven = false
					}
				}
			} else {
				if !evenIsEven {
					evenSum = evenSum + val*evenCount
					if val%2 == 1 {
						evenIsEven = true
					}
				}
				if !notEvenIsEven {
					notEvenSum = notEvenSum + val*notEvenCount
					if val%2 == 1 {
						notEvenIsEven = true
					}
				}
			}
			fmt.Println(evenSum + notEvenSum)
		}
	}
}

func add(arr []int, even bool, val int) {
	for i := 0; i < len(arr); i++ {
		if even {
			if arr[i]%2 == 0 {
				arr[i] = arr[i] + val
			}
		} else {
			if arr[i]%2 != 0 {
				arr[i] = arr[i] + val
			}
		}
	}
}

func replaceAtIndex(in string, r rune, i int) string {
	out := []rune(in)
	out[i] = r
	return string(out)
}

func arrayToString(A []int, delim string) string {
	var buffer bytes.Buffer
	for i := 0; i < len(A); i++ {
		buffer.WriteString(strconv.Itoa(A[i]))
		if i != len(A)-1 {
			buffer.WriteString(delim)
		}
	}
	return buffer.String()
}

package main

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

var in = bufio.NewReader(os.Stdin)

func  gcd(a, b int) int {
  for b != 0 {
      a, b = b, a%b
  }
  return a
}

func pl(a ...interface{}) { fmt.Println(a...) }
func pf(format string, a ...interface{}) { fmt.Printf(format, a...) }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }

func main() {
	var T int
	scan(&T)

	for ; T > 0; T-- {
    var n, q int
    scan(&n, &q)
    a := make([]int, n, n)
    var sum, o, e int
    for i := range a {
      scan(&a[i])
      if a[i] % 2 == 0 {
        e++
      } else {
        o++
      }
      sum += a[i]
    }
    for i := 0; i < q; i ++ {
      var t, x int
      scan(&t, &x)
      if t == 0 {
        sum += x * e
      } else {
        sum += x * o
      }
      pf("Test #%d: %d\n", T, sum)
      switch {
        case x % 2 == 1 && t == 0:
          o += e
          e = 0
        case x % 2 == 1 && t == 1:
          e += o
          o = 0
      }
    }
	}
}

func ys(b bool) string { return map[bool]string {true: "YES", false: "NO"}[b] }


package main

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

// github.com/EndlessCheng/codeforces-go
type node1 struct {
	lr       [2]*node1
	priority uint
	key      int
	dupCnt   int
	sz       int
}

func (o *node1) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node1) size() int {
	if o != nil {
		return o.sz
	}
	return 0
}

func (o *node1) maintain() { o.sz = o.dupCnt + o.lr[0].size() + o.lr[1].size() }

func (o *node1) rotate(d int) *node1 {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	o.maintain()
	x.maintain()
	return x
}

type treap1 struct {
	rd   uint
	root *node1
}

func (t *treap1) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap1) _put(o *node1, key int) *node1 {
	if o == nil {
		return &node1{priority: t.fastRand(), key: key, dupCnt: 1, sz: 1}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.dupCnt++
	}
	o.maintain()
	return o
}

func (t *treap1) put(key int) { t.root = t._put(t.root, key) }

func (t *treap1) _delete(o *node1, key int) *node1 {
	if o == nil {
		return nil
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._delete(o.lr[d], key)
	} else {
		if o.dupCnt > 1 {
			o.dupCnt--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			d = 0
			if o.lr[0].priority > o.lr[1].priority {
				d = 1
			}
			o = o.rotate(d)
			o.lr[d] = t._delete(o.lr[d], key)
		}
	}
	o.maintain()
	return o
}

func (t *treap1) delete(key int) { t.root = t._delete(t.root, key) }

func newTreap1() *treap1 { return &treap1{rd: uint(time.Now().UnixNano())/2 + 1} }

func (t *treap1) lowerBound(key int) (lb *node1) {
	for o := t.root; o != nil; {
		switch c := o.cmp(key); {
		case c == 0:
			lb = o
			o = o.lr[0]
		case c > 0:
			o = o.lr[1]
		default:
			return o
		}
	}
	return // NOTE: check nil
}

func (t *treap1) prev(key int) (prev *node1) {
	for o := t.root; o != nil; {
		if o.cmp(key) <= 0 {
			o = o.lr[0]
		} else {
			prev = o
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func (t *treap1) next(key int) (next *node1) {
	for o := t.root; o != nil; {
		if o.cmp(key) == 0 {
			next = o
			o = o.lr[0]
		} else {
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

// 有 k 个元素小于 o.key
func (t *treap1) kth(k int) (o *node1) {
	for o = t.root; o != nil; {
		if ls := o.lr[0].size(); k < ls {
			o = o.lr[0]
		} else {
			k -= o.dupCnt + ls
			if k < 0 {
				return
			}
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 2e9

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		l, r := -inf, inf
		t := newTreap1()
		t.put(b[0])
		for i := 1; i < n; i++ {
			v := b[i]
			if v < l || v > r {
				Fprintln(out, "NO")
				return
			}
			if v == b[i-1] {
				t.put(-inf)
				t.put(inf)
			} else if v < b[i-1] {
				if v == l {
					t.put(-inf)
					t.put(-inf)
				} else {
					t.put(v)
					t.put(-inf)
				}
			} else {
				if v == r {
					t.put(inf)
					t.put(inf)
				} else {
					t.put(v)
					t.put(inf)
				}
			}
			lo := t.kth(i - 1)
			if lo == nil {
				l = -inf
			} else {
				l = lo.key
			}
			ro := t.kth(i + 1)
			if ro == nil {
				r = inf
			} else {
				r = ro.key
			}
		}
		Fprintln(out, "YES")
	}

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

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

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

package main

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &b[i])
		}

		c := make([]int, n)
		copy(c, b)
		sort.Ints(c)

		for i := range b {
			b[i] = sort.SearchInts(c, b[i]) + 1
		}

		cnt := make([]int, n+1)
		for i := b[0]; i <= n; i += i & (-i) {
			cnt[i]++
		}

		ok := true
		for i := 1; i < n; i++ {
			if b[i-1] > b[i] && sum(cnt, b[i-1]-1)-sum(cnt, b[i]) > 0 ||
				b[i-1] <= b[i] && sum(cnt, b[i]-1)-sum(cnt, b[i-1]) > 0 {
				ok = false
				break
			}
			for j := b[i]; j <= n; j += j & (-j) {
				cnt[j]++
			}
		}
		if ok {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

func sum(cnt []int, i int) int {
	var out int
	for ; i > 0; i -= i & (-i) {
		out += cnt[i]
	}
	return out
}

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) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	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 (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	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 InitInts1D(n int, val int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = val
	}
	return res
}
func InitInts2D(n, m int, val int) [][]int {
	res := make([][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts1D(m, val)
	}
	return res
}
func InitInts3D(n, m, k int, val int) [][][]int {
	res := make([][][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts2D(m, k, val)
	}
	return res
}

type StepState struct {
	step, dist int
}
type PriorityQueue []*StepState

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	if pq[i].step != pq[j].step {
		return pq[i].step < pq[j].step
	}
	return pq[i].dist < pq[j].dist
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Push(x interface{}) {
	item := x.(*StepState)
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type AvlNode struct {
	key    int
	height int
	size   int
	left   *AvlNode
	right  *AvlNode
}

func NewAvlNode(key int) *AvlNode {
	return &AvlNode{
		key:    key,
		height: 0,
		size:   1,
		left:   nil,
		right:  nil,
	}
}

type AvlTree struct {
	root *AvlNode
}

func NewAvlTree() *AvlTree {
	return &AvlTree{}
}

func (t *AvlTree) height(node *AvlNode) int {
	if node == nil {
		return -1
	}
	return node.height
}

func (t *AvlTree) size(node *AvlNode) int {
	if node == nil {
		return 0
	}
	return node.size
}

func (t *AvlTree) balanceFactor(node *AvlNode) int {
	return t.height(node.right) - t.height(node.left)
}

func (t *AvlTree) fixHeight(node *AvlNode) {
	hl := t.height(node.left)
	hr := t.height(node.right)
	newHeight := hl + 1
	if newHeight < hr+1 {
		newHeight = hr + 1
	}
	node.height = newHeight
}

func (t *AvlTree) fixSize(node *AvlNode) {
	node.size = t.size(node.left) + t.size(node.right) + 1
}

func (t *AvlTree) fixNode(node *AvlNode) {
	t.fixHeight(node)
	t.fixSize(node)
}

func (t *AvlTree) rotateRight(p *AvlNode) *AvlNode {
	q := p.left
	p.left = q.right
	q.right = p
	t.fixNode(p)
	t.fixNode(q)
	return q
}

func (t *AvlTree) rotateLeft(q *AvlNode) *AvlNode {
	p := q.right
	q.right = p.left
	p.left = q
	t.fixNode(q)
	t.fixNode(p)
	return p
}

func (t *AvlTree) balance(node *AvlNode) *AvlNode {
	t.fixNode(node)
	if t.balanceFactor(node) == 2 {
		if t.balanceFactor(node.right) < 0 {
			node.right = t.rotateRight(node.right)
		}
		return t.rotateLeft(node)
	}
	if t.balanceFactor(node) == -2 {
		if t.balanceFactor(node.left) > 0 {
			node.left = t.rotateLeft(node.left)
		}
		return t.rotateRight(node)
	}
	return node
}

func (t *AvlTree) insert(node *AvlNode, key int) *AvlNode {
	if node == nil {
		return NewAvlNode(key)
	}
	if key < node.key {
		node.left = t.insert(node.left, key)
	} else {
		node.right = t.insert(node.right, key)
	}
	tes := t.balance(node)
	return tes
}

func (t *AvlTree) Insert(key int) {
	t.root = t.insert(t.root, key)
}

func (t *AvlTree) findByOrder(node *AvlNode, order int) int {
	if node == nil {
		return -1
	}
	if order == t.size(node.left) {
		return node.key
	} else if order < t.size(node.left) {
		return t.findByOrder(node.left, order)
	} else {
		return t.findByOrder(node.right, order-t.size(node.left)-1)
	}
}

func (t *AvlTree) FindByOrder(order int) int {
	return t.findByOrder(t.root, order)
}

func (t *AvlTree) orderOfKey(node *AvlNode, key int) int {
	if node == nil {
		return 0
	} else if node.key == key {
		return t.size(node.left)
	} else if key < node.key {
		return t.orderOfKey(node.left, key)
	} else {
		return t.size(node.left) + 1 + t.orderOfKey(node.right, key)
	}
}

func (t *AvlTree) OrderOfKey(key int) int {
	return t.orderOfKey(t.root, key)
}

func (t *AvlTree) keyLessThan(node *AvlNode, key int, curLessMax int) int {
	if node == nil {
		return curLessMax
	}
	if node.key < key {
		return t.keyLessThan(node.right, key, node.key)
	} else {
		return t.keyLessThan(node.left, key, curLessMax)
	}
}

func (t *AvlTree) KeyLessThan(key int) int {
	return t.keyLessThan(t.root, key, -1)
}

func (t *AvlTree) findMin(node *AvlNode) *AvlNode {
	if node.left == nil {
		return node
	}
	return t.findMin(node.left)
}

func (t *AvlTree) removeMin(node *AvlNode) *AvlNode {
	if node.left == nil {
		return node.right
	}
	node.left = t.removeMin(node.left)
	return t.balance(node)
}

func (t *AvlTree) remove(p *AvlNode, key int) *AvlNode {
	if p == nil {
		return nil
	}
	if key < p.key {
		p.left = t.remove(p.left, key)
	} else if key > p.key {
		p.right = t.remove(p.right, key)
	} else {
		q := p.left
		r := p.right
		if r == nil {
			return q
		}
		minRight := t.findMin(r)
		minRight.right = t.removeMin(r)
		minRight.left = q
		return t.balance(minRight)
	}
	return t.balance(p)
}

func (t *AvlTree) Remove(key int) {
	t.root = t.remove(t.root, key)
}

const (
	INF = 1000000001
)

func process(N int, b []int) string {
	avl := NewAvlTree()
	avl.Insert(b[0])
	curSize := 1
	for i := 1; i < N; i++ {
		order := avl.OrderOfKey(b[i])
		// fmt.Println(b[i], order, avl.FindByOrder(order))
		if avl.FindByOrder(order) == b[i] {
			if order == curSize/2-1 {
				avl.Insert(-INF)
				avl.Insert(-INF)
			} else if order == curSize/2 {
				avl.Insert(-INF)
				avl.Insert(INF)
			} else if order == curSize/2+1 {
				avl.Insert(INF)
				avl.Insert(INF)
			} else {
				return "NO"
			}
		} else if order == curSize/2 {
			avl.Insert(b[i])
			avl.Insert(-INF)
		} else if order == curSize/2+1 {
			avl.Insert(b[i])
			avl.Insert(INF)
		} else {
			return "NO"
		}
		curSize += 2
	}
	return "YES"
}

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

	TC := sc.NextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.NextInt()
		b := sc.NextInts(N)

		fmt.Fprintln(wr, process(N, b))
	}

}

package main

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

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

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

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

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

		ans := solve(b, n)

		fmt.Println(ans)
		//b - 6 4 5

		//a - 6 4 -3 5 7
		//
	}
}

func solve(b []int, n int) string {

	mp := newIntIntTreeMap(func(a int, b int) bool {
		return a < b
	})

	if len(b) == 1 || len(b) == 2 {
		return "YES"
	}

	mp.Set(b[0], 0)
	mp.Set(b[1], 0)

	for i := 2; i < n; i++ {
		prev := b[i - 1]

		cur := b[i]

		if cur == prev {
			continue
		}

		if cur > prev {

			it := mp.UpperBound(prev)

			if it.Valid() && it.Key() < cur {
				return "NO"
			}

		} else {
			it := mp.LowerBound(prev)
			it.Prev()

			if it.node != nil && it.Key() > cur {
				return "NO"
			}
		}

		mp.Set(cur, 0)
	}

	return "YES"
}

type intIntTreeMap struct {
	endNode   *nodeIntIntTreeMap
	beginNode *nodeIntIntTreeMap
	count     int
	// Less returns a < b
	Less func(a int, b int) bool
}

type nodeIntIntTreeMap struct {
	right   *nodeIntIntTreeMap
	left    *nodeIntIntTreeMap
	parent  *nodeIntIntTreeMap
	isBlack bool
	key     int
	value   int
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newIntIntTreeMap(less func(a int, b int) bool) *intIntTreeMap {
	endNode := &nodeIntIntTreeMap{isBlack: true}
	return &intIntTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *intIntTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *intIntTreeMap) Set(key int, value int) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeIntIntTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *intIntTreeMap) Del(key int) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeIntIntTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *intIntTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *intIntTreeMap) Get(id int) (int, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *intIntTreeMap) Contains(id int) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *intIntTreeMap) Range(from, to int) (forwardIteratorIntIntTreeMap, forwardIteratorIntIntTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *intIntTreeMap) LowerBound(key int) forwardIteratorIntIntTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntIntTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *intIntTreeMap) UpperBound(key int) forwardIteratorIntIntTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntIntTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *intIntTreeMap) Iterator() forwardIteratorIntIntTreeMap {
	return forwardIteratorIntIntTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *intIntTreeMap) Reverse() reverseIteratorIntIntTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightIntIntTreeMap(node)
	}
	return reverseIteratorIntIntTreeMap{tree: t, node: node}
}

func (t *intIntTreeMap) findNode(id int) *nodeIntIntTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	if x.right != nil {
		return mostLeftIntIntTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	if x.left != nil {
		return mostRightIntIntTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftIntIntTreeMap(x *nodeIntIntTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightIntIntTreeMap(x *nodeIntIntTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *intIntTreeMap) insertFixup(x *nodeIntIntTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftIntIntTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightIntIntTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightIntIntTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftIntIntTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeIntIntTreeMap(root *nodeIntIntTreeMap, z *nodeIntIntTreeMap) {
	var y *nodeIntIntTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorIntIntTreeMap(z)
	}
	var x *nodeIntIntTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeIntIntTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftIntIntTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightIntIntTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftIntIntTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightIntIntTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftIntIntTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightIntIntTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorIntIntTreeMap struct {
	tree *intIntTreeMap
	node *nodeIntIntTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorIntIntTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntIntTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorIntIntTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntIntTreeMap) Prev() {
	i.node = predecessorIntIntTreeMap(i.node)
	if i.node == nil {
		//panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorIntIntTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorIntIntTreeMap) Value() int { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorIntIntTreeMap struct {
	tree *intIntTreeMap
	node *nodeIntIntTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorIntIntTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntIntTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorIntIntTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntIntTreeMap) Prev() {
	if i.node != nil {
		i.node = successorIntIntTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorIntIntTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorIntIntTreeMap) Value() int { return i.node.value }

package main

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

//Treap Implementation
type node1 struct {
	lr       [2]*node1
	priority uint
	key      int
	dupCnt   int
	sz       int
}

func (o *node1) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node1) size() int {
	if o != nil {
		return o.sz
	}
	return 0
}

func (o *node1) maintain() { o.sz = o.dupCnt + o.lr[0].size() + o.lr[1].size() }

func (o *node1) rotate(d int) *node1 {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	o.maintain()
	x.maintain()
	return x
}

type treap1 struct {
	rd   uint
	root *node1
}

func (t *treap1) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap1) _put(o *node1, key int) *node1 {
	if o == nil {
		return &node1{priority: t.fastRand(), key: key, dupCnt: 1, sz: 1}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.dupCnt++
	}
	o.maintain()
	return o
}

func (t *treap1) put(key int) { t.root = t._put(t.root, key) }

func (t *treap1) _delete(o *node1, key int) *node1 {
	if o == nil {
		return nil
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._delete(o.lr[d], key)
	} else {
		if o.dupCnt > 1 {
			o.dupCnt--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			d = 0
			if o.lr[0].priority > o.lr[1].priority {
				d = 1
			}
			o = o.rotate(d)
			o.lr[d] = t._delete(o.lr[d], key)
		}
	}
	o.maintain()
	return o
}

func (t *treap1) delete(key int) { t.root = t._delete(t.root, key) }

func newTreap1() *treap1 { return &treap1{rd: uint(time.Now().UnixNano())/2 + 1} }

func (t *treap1) lowerBound(key int) (lb *node1) {
	for o := t.root; o != nil; {
		switch c := o.cmp(key); {
		case c == 0:
			lb = o
			o = o.lr[0]
		case c > 0:
			o = o.lr[1]
		default:
			return o
		}
	}
	return // NOTE: check nil
}

func (t *treap1) prev(key int) (prev *node1) {
	for o := t.root; o != nil; {
		if o.cmp(key) <= 0 {
			o = o.lr[0]
		} else {
			prev = o
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func (t *treap1) next(key int) (next *node1) {
	for o := t.root; o != nil; {
		if o.cmp(key) == 0 {
			next = o
			o = o.lr[0]
		} else {
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func (t *treap1) kth(k int) (o *node1) {
	for o = t.root; o != nil; {
		if ls := o.lr[0].size(); k < ls {
			o = o.lr[0]
		} else {
			k -= o.dupCnt + ls
			if k < 0 {
				return
			}
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	solve := func(Case int) {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		const inf int = 1e9
		t := newTreap1()
		t.put(a[0])
		ok := true
		for i := 1; i < n; i++ {
			v := a[i]
			prev := a[i-1]
			if v < prev {
				it := t.prev(prev)
				if it != nil && v < it.key {
					ok = false
					break
				}
			} else if v > prev {
				it := t.next(prev)
				if it != nil && v > it.key {
					ok = false
					break
				}
			}
			t.put(v)
		}
		if ok == true {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}

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

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

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

package main

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

var _rbuf = bufio.NewReader(os.Stdin)
var _wbuf = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { _wbuf.Flush(); fmt.Fscan(_rbuf, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_wbuf, f, a...) }

func main() {
	defer _wbuf.Flush()

	var t int
	scan(&t)
	for ; t > 0; t-- {
		var n int
		scan(&n)
		b := make([]int, n)
		for i := range b {
			scan(&b[i])
		}
		if solve(n, b) {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

func solve(n int, b []int) bool {
	c := make([]int, n)
	copy(c, b)
	sort.Ints(c)
	//c = unique(c)
	for i := range b {
		b[i] = sort.SearchInts(c, b[i]) + 1
	}

	m := len(c)
	bits := make([]int, m+1)
	add := func(i int) {
		for ; i <= m; i += i & (-i) {
			bits[i]++
		}
	}
	sum := func(i int) int {
		ret := 0
		for ; i > 0; i -= i & (-i) {
			ret += bits[i]
		}
		return ret
	}

	add(b[0])
	for i := 1; i < n; i++ {
		if b[i-1] > b[i] {
			if sum(b[i-1]-1)-sum(b[i]) > 0 {
				return false
			}
		} else if sum(b[i]-1)-sum(b[i-1]) > 0 {
			return false
		}
		add(b[i])
	}
	return true
}

func unique(a []int) []int {
	j := 1
	for i := 1; i < len(a); i++ {
		if a[i] != a[i-1] {
			a[j] = a[i]
			j++
		}
	}
	return a[:j]
}

package main

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

// Tags:
// Fenwick Tree

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &b[i])
		}

		c := make([]int, n)
		copy(c, b)
		sort.Ints(c)

		for i := range b {
			b[i] = sort.SearchInts(c, b[i]) + 1
		}

		cnt := make([]int, n+1)
		add(cnt, n, b[0])

		ok := true
		for i := 1; i < n; i++ {
			if b[i-1] > b[i] && query(cnt, b[i-1]-1)-query(cnt, b[i]) > 0 ||
				b[i-1] <= b[i] && query(cnt, b[i]-1)-query(cnt, b[i-1]) > 0 {
				ok = false
				break
			}
			add(cnt, n, b[i])
		}
		if ok {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

func add(cnt []int, n, i int) {
	for ; i <= n; i += i & (-i) {
		cnt[i]++
	}
}

func query(cnt []int, i int) int {
	var out int
	for ; i > 0; i -= i & (-i) {
		out += cnt[i]
	}
	return out
}

package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority uint
	key      int
	dupCnt   int
	sz       int
}

func (o *node) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) size() int {
	if o != nil {
		return o.sz
	}
	return 0
}

func (o *node) maintain() { o.sz = o.dupCnt + o.lr[0].size() + o.lr[1].size() }

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	o.maintain()
	x.maintain()
	return x
}

type treap struct {
	rd   uint
	root *node
}

func (t *treap) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: t.fastRand(), key: key, dupCnt: 1, sz: 1}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.dupCnt++
	}
	o.maintain()
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._delete(o.lr[d], key)
	} else {
		if o.dupCnt > 1 {
			o.dupCnt--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			d = 0
			if o.lr[0].priority > o.lr[1].priority {
				d = 1
			}
			o = o.rotate(d)
			o.lr[d] = t._delete(o.lr[d], key)
		}
	}
	o.maintain()
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func newTreap() *treap { return &treap{rd: uint(time.Now().UnixNano())/2 + 1} }

func (t *treap) lowerBound(key int) (lb *node) {
	for o := t.root; o != nil; {
		switch c := o.cmp(key); {
		case c == 0:
			lb = o
			o = o.lr[0]
		case c > 0:
			o = o.lr[1]
		default:
			return o
		}
	}
	return // NOTE: check nil
}

func (t *treap) prev(key int) (prev *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) <= 0 {
			o = o.lr[0]
		} else {
			prev = o
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func (t *treap) next(key int) (next *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) == 0 {
			next = o
			o = o.lr[0]
		} else {
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

// 有 k 个元素小于 o.key
func (t *treap) kth(k int) (o *node) {
	for o = t.root; o != nil; {
		if ls := o.lr[0].size(); k < ls {
			o = o.lr[0]
		} else {
			k -= o.dupCnt + ls
			if k < 0 {
				return
			}
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 2e9

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		l, r := -inf, inf
		t := newTreap()
		t.put(b[0])
		for i := 1; i < n; i++ {
			v := b[i]
			if v < l || v > r {
				Fprintln(out, "NO")
				return
			}
			if v == b[i-1] {
				t.put(-inf)
				t.put(inf)
			} else if v < b[i-1] {
				if v == l {
					x := -inf
					o := t.prev(l)
					if o != nil {
						x = o.key
					}
					t.put(x)
					t.put(x)
				} else {
					t.put(v)
					t.put(l)
				}
			} else {
				if v == r {
					x := inf
					o := t.next(r)
					if o != nil {
						x = o.key
					}
					t.put(x)
					t.put(x)
				} else {
					t.put(v)
					t.put(r)
				}
			}

			//lo := t.lowerBound(v)
			//if lo == nil {
			//	t.put(v)
			//	t.put(inf)
			//} else if lo.key == v {
			//	if v == l {
			//		x := -inf
			//		o := t.prev(l)
			//		if o != nil {
			//			x = o.key
			//		}
			//		t.put(x)
			//		t.put(x)
			//	} else if v == r {
			//		x := inf
			//		o := t.next(r)
			//		if o != nil {
			//			x = o.key
			//		}
			//		t.put(x)
			//		t.put(x)
			//	} else {
			//		t.put(l)
			//		t.put(r)
			//	}
			//
			//} else {
			//	t.put(l)
			//	t.put(v)
			//}
			lo := t.kth(i - 1)
			if lo == nil {
				l = -inf
			} else {
				l = lo.key
			}
			ro := t.kth(i + 1)
			if ro == nil {
				r = inf
			} else {
				r = ro.key
			}
		}
		Fprintln(out, "YES")
	}

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

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority uint
	key      int
	dupCnt   int
	sz       int
}

func (o *node) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) size() int {
	if o != nil {
		return o.sz
	}
	return 0
}

func (o *node) maintain() { o.sz = o.dupCnt + o.lr[0].size() + o.lr[1].size() }

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	o.maintain()
	x.maintain()
	return x
}

type treap struct {
	rd   uint
	root *node
}

func (t *treap) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: t.fastRand(), key: key, dupCnt: 1, sz: 1}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.dupCnt++
	}
	o.maintain()
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._delete(o.lr[d], key)
	} else {
		if o.dupCnt > 1 {
			o.dupCnt--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			d = 0
			if o.lr[0].priority > o.lr[1].priority {
				d = 1
			}
			o = o.rotate(d)
			o.lr[d] = t._delete(o.lr[d], key)
		}
	}
	o.maintain()
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func newTreap() *treap { return &treap{rd: uint(time.Now().UnixNano())/2 + 1} }

func (t *treap) lowerBound(key int) (lb *node) {
	for o := t.root; o != nil; {
		switch c := o.cmp(key); {
		case c == 0:
			lb = o
			o = o.lr[0]
		case c > 0:
			o = o.lr[1]
		default:
			return o
		}
	}
	return // NOTE: check nil
}

func (t *treap) prev(key int) (prev *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) <= 0 {
			o = o.lr[0]
		} else {
			prev = o
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func (t *treap) next(key int) (next *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) == 0 {
			next = o
			o = o.lr[0]
		} else {
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

// 有 k 个元素小于 o.key
func (t *treap) kth(k int) (o *node) {
	for o = t.root; o != nil; {
		if ls := o.lr[0].size(); k < ls {
			o = o.lr[0]
		} else {
			k -= o.dupCnt + ls
			if k < 0 {
				return
			}
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 2e9

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		l, r := -inf, inf
		t := newTreap()
		t.put(b[0])
		for i := 1; i < n; i++ {
			v := b[i]
			if v < l || v > r {
				Fprintln(out, "NO")
				return
			}
			if v == b[i-1] {
				t.put(l)
				t.put(r)
			} else if v < b[i-1] {
				if v == l {
					x := -inf
					o := t.prev(l)
					if o != nil {
						x = o.key
					}
					t.put(x)
					t.put(x)
				} else {
					t.put(v)
					t.put(l)
				}
			} else {
				if v == r {
					x := inf
					o := t.next(r)
					if o != nil {
						x = o.key
					}
					t.put(x)
					t.put(x)
				} else {
					t.put(v)
					t.put(r)
				}
			}

			//lo := t.lowerBound(v)
			//if lo == nil {
			//	t.put(v)
			//	t.put(inf)
			//} else if lo.key == v {
			//	if v == l {
			//		x := -inf
			//		o := t.prev(l)
			//		if o != nil {
			//			x = o.key
			//		}
			//		t.put(x)
			//		t.put(x)
			//	} else if v == r {
			//		x := inf
			//		o := t.next(r)
			//		if o != nil {
			//			x = o.key
			//		}
			//		t.put(x)
			//		t.put(x)
			//	} else {
			//		t.put(l)
			//		t.put(r)
			//	}
			//
			//} else {
			//	t.put(l)
			//	t.put(v)
			//}
			lo := t.kth(i - 1)
			if lo == nil {
				l = -inf
			} else {
				l = lo.key
			}
			ro := t.kth(i + 1)
			if ro == nil {
				r = inf
			} else {
				r = ro.key
			}
		}
		Fprintln(out, "YES")
	}

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

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority uint
	key      int
	dupCnt   int
	sz       int
}

func (o *node) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) size() int {
	if o != nil {
		return o.sz
	}
	return 0
}

func (o *node) maintain() { o.sz = o.dupCnt + o.lr[0].size() + o.lr[1].size() }

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	o.maintain()
	x.maintain()
	return x
}

type treap struct {
	rd   uint
	root *node
}

func (t *treap) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: t.fastRand(), key: key, dupCnt: 1, sz: 1}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.dupCnt++
	}
	o.maintain()
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._delete(o.lr[d], key)
	} else {
		if o.dupCnt > 1 {
			o.dupCnt--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			d = 0
			if o.lr[0].priority > o.lr[1].priority {
				d = 1
			}
			o = o.rotate(d)
			o.lr[d] = t._delete(o.lr[d], key)
		}
	}
	o.maintain()
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func newTreap() *treap { return &treap{rd: uint(time.Now().UnixNano())/2 + 1} }

func (t *treap) lowerBound(key int) (lb *node) {
	for o := t.root; o != nil; {
		switch c := o.cmp(key); {
		case c == 0:
			lb = o
			o = o.lr[0]
		case c > 0:
			o = o.lr[1]
		default:
			return o
		}
	}
	return // NOTE: check nil
}

func (t *treap) prev(key int) (prev *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) <= 0 {
			o = o.lr[0]
		} else {
			prev = o
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func (t *treap) next(key int) (next *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) == 0 {
			next = o
			o = o.lr[0]
		} else {
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

// 有 k 个元素小于 o.key
func (t *treap) kth(k int) (o *node) {
	for o = t.root; o != nil; {
		if ls := o.lr[0].size(); k < ls {
			o = o.lr[0]
		} else {
			k -= o.dupCnt + ls
			if k < 0 {
				return
			}
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 2e9
	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		if n <= 2 {
			Fprintln(out, "YES")
			return
		}
		l, r := -inf, inf
		//if b[0] < b[1] {
		//	l = b[0]
		//} else if b[0] > b[1] {
		//	r = b[0]
		//}
		t := newTreap()
		//t.put(-inf)
		//t.put(inf)
		t.put(b[0])
		//t.put(b[1])
		//l,r := -inf

		for i := 1; i < n; i++ {
			v := b[i]
			if v < l || v > r {
				Fprintln(out, "NO")
				return
			}

			lo := t.lowerBound(v)
			if lo == nil {
				t.put(v)
				t.put(inf)
			} else if lo.key == v {
				if v == l {
					x := -inf
					o := t.prev(l)
					if o != nil {
						x= o.key
					}
					t.put(x)
					t.put(x)
				} else if v == r {
					x := inf
					o := t.next(r)
					if o != nil {
						x= o.key
					}
					t.put(x)
					t.put(x)
				} else {
					t.put(l)
					t.put(r)
				}

			} else {
				t.put(l)
				t.put(v)
			}
			l = t.kth(i-1).key
				r=t.kth(i+1).key
		}

		//for i := 2; i < n; i++ {
		//	v := b[i]
		//	if v < l || v > r {
		//		Fprintln(out, "NO")
		//		return
		//	}
		//
		//	lo := t.lowerBound(v)
		//	if lo.key == v {
		//
		//		if
		//
		//		l = t.prev(v).key
		//		r = t.next(v).key
		//		continue
		//	}
		//
		//	r = lo.key
		//	l = t.prev(r).key
		//
		//	t.put(v)
		//	t.prev(l)
		//
		//}

		Fprintln(out, "YES")

	}

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

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

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

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"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) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	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 (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	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 InitInts1D(n int, val int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = val
	}
	return res
}
func InitInts2D(n, m int, val int) [][]int {
	res := make([][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts1D(m, val)
	}
	return res
}
func InitInts3D(n, m, k int, val int) [][][]int {
	res := make([][][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts2D(m, k, val)
	}
	return res
}

type StepState struct {
	step, dist int
}
type PriorityQueue []*StepState

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	if pq[i].step != pq[j].step {
		return pq[i].step < pq[j].step
	}
	return pq[i].dist < pq[j].dist
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Push(x interface{}) {
	item := x.(*StepState)
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type AvlNode struct {
	key    int
	height int
	size   int
	left   *AvlNode
	right  *AvlNode
}

func NewAvlNode(key int) *AvlNode {
	return &AvlNode{
		key:    key,
		height: 0,
		size:   1,
		left:   nil,
		right:  nil,
	}
}

type AvlTree struct {
	root *AvlNode
}

func NewAvlTree() *AvlTree {
	return &AvlTree{}
}

func (t *AvlTree) height(node *AvlNode) int {
	if node == nil {
		return -1
	}
	return node.height
}

func (t *AvlTree) size(node *AvlNode) int {
	if node == nil {
		return 0
	}
	return node.size
}

func (t *AvlTree) balanceFactor(node *AvlNode) int {
	return t.height(node.right) - t.height(node.left)
}

func (t *AvlTree) fixHeight(node *AvlNode) {
	hl := t.height(node.left)
	hr := t.height(node.right)
	newHeight := hl + 1
	if newHeight < hr+1 {
		newHeight = hr + 1
	}
	node.height = newHeight
}

func (t *AvlTree) fixSize(node *AvlNode) {
	node.size = t.size(node.left) + t.size(node.right) + 1
}

func (t *AvlTree) fixNode(node *AvlNode) {
	t.fixHeight(node)
	t.fixSize(node)
}

func (t *AvlTree) rotateRight(p *AvlNode) *AvlNode {
	q := p.left
	p.left = q.right
	q.right = p
	t.fixNode(p)
	t.fixNode(q)
	return q
}

func (t *AvlTree) rotateLeft(q *AvlNode) *AvlNode {
	p := q.right
	q.right = p.left
	p.left = q
	t.fixNode(q)
	t.fixNode(p)
	return p
}

func (t *AvlTree) balance(node *AvlNode) *AvlNode {
	t.fixNode(node)
	if t.balanceFactor(node) == 2 {
		if t.balanceFactor(node.right) < 0 {
			node.right = t.rotateRight(node.right)
		}
		return t.rotateLeft(node)
	}
	if t.balanceFactor(node) == -2 {
		if t.balanceFactor(node.left) > 0 {
			node.left = t.rotateLeft(node.left)
		}
		return t.rotateRight(node)
	}
	return node
}

func (t *AvlTree) insert(node *AvlNode, key int) *AvlNode {
	if node == nil {
		return NewAvlNode(key)
	}
	if key < node.key {
		node.left = t.insert(node.left, key)
	} else {
		node.right = t.insert(node.right, key)
	}
	tes := t.balance(node)
	return tes
}

func (t *AvlTree) Insert(key int) {
	t.root = t.insert(t.root, key)
}

func (t *AvlTree) findByOrder(node *AvlNode, order int) int {
	if node == nil {
		return -1
	}
	if order == t.size(node.left) {
		return node.key
	} else if order < t.size(node.left) {
		return t.findByOrder(node.left, order)
	} else {
		return t.findByOrder(node.right, order-t.size(node.left)-1)
	}
}

func (t *AvlTree) FindByOrder(order int) int {
	return t.findByOrder(t.root, order)
}

func (t *AvlTree) orderOfKey(node *AvlNode, key int) int {
	if node == nil {
		return 0
	} else if node.key == key {
		return t.size(node.left)
	} else if key < node.key {
		return t.orderOfKey(node.left, key)
	} else {
		return t.size(node.left) + 1 + t.orderOfKey(node.right, key)
	}
}

func (t *AvlTree) OrderOfKey(key int) int {
	return t.orderOfKey(t.root, key)
}

func (t *AvlTree) keyLessThan(node *AvlNode, key int, curLessMax int) int {
	if node == nil {
		return curLessMax
	}
	if node.key < key {
		return t.keyLessThan(node.right, key, node.key)
	} else {
		return t.keyLessThan(node.left, key, curLessMax)
	}
}

func (t *AvlTree) KeyLessThan(key int) int {
	return t.keyLessThan(t.root, key, -1)
}

func (t *AvlTree) findMin(node *AvlNode) *AvlNode {
	if node.left == nil {
		return node
	}
	return t.findMin(node.left)
}

func (t *AvlTree) removeMin(node *AvlNode) *AvlNode {
	if node.left == nil {
		return node.right
	}
	node.left = t.removeMin(node.left)
	return t.balance(node)
}

func (t *AvlTree) remove(p *AvlNode, key int) *AvlNode {
	if p == nil {
		return nil
	}
	if key < p.key {
		p.left = t.remove(p.left, key)
	} else if key > p.key {
		p.right = t.remove(p.right, key)
	} else {
		q := p.left
		r := p.right
		if r == nil {
			return q
		}
		minRight := t.findMin(r)
		minRight.right = t.removeMin(r)
		minRight.left = q
		return t.balance(minRight)
	}
	return t.balance(p)
}

func (t *AvlTree) Remove(key int) {
	t.root = t.remove(t.root, key)
}

const (
	INF = 1000000000
)

func process(N int, b []int) string {
	avl := NewAvlTree()
	avl.Insert(b[0])
	curSize := 1
	for i := 1; i < N; i++ {
		order := avl.OrderOfKey(b[i])
		// fmt.Println(b[i], order, avl.FindByOrder(order))
		if avl.FindByOrder(order) == b[i] {
			if order == curSize/2-1 {
				avl.Insert(-INF)
				avl.Insert(-INF)
			} else if order == curSize/2 {
				avl.Insert(-INF)
				avl.Insert(INF)
			} else if order == curSize/2+1 {
				avl.Insert(INF)
				avl.Insert(INF)
			} else {
				return "NO"
			}
		} else if order == curSize/2 {
			avl.Insert(b[i])
			avl.Insert(-INF)
		} else if order == curSize/2+1 {
			avl.Insert(b[i])
			avl.Insert(INF)
		} else {
			return "NO"
		}
		curSize += 2
	}
	return "YES"
}

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

	TC := sc.NextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.NextInt()
		b := sc.NextInts(N)

		fmt.Fprintln(wr, process(N, b))
	}

}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF615D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 1e9 + 7
	pow := func(x, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}

	var k, p int
	e := [2e5]int64{}
	for Fscan(in, &k); k > 0; k-- {
		Fscan(in, &p)
		e[p]++
	}
	sq := true
	for _, c := range e {
		if c&1 > 0 {
			sq = false
			break
		}
	}
	var n, m int64 = 1, 1
	if sq {
		for i, c := range e {
			m = m * (c + 1) % (mod - 1)
			e[i] >>= 1
		}
	} else {
		ok := true
		for _, c := range e {
			c++
			if ok && c&1 == 0 {
				c >>= 1
				ok = false
			}
			m = m * c % (mod - 1)
		}
	}
	for p, c := range e {
		n = n * pow(int64(p), c*m%(mod-1)) % mod
	}
	Fprint(out, n)
}

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

package main

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

const (
	MOD = 1000000007
	PHI = MOD - 1
)

func pow(a, s int64) (r int64) {
	r = 1
	for s > 0 {
		if s%2 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		s /= 2
	}
	return
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	const N = 202000
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	var a [N]int
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscanf(buf, "%d", &x)
		a[x]++
	}
	var prod int64 = 1
	allEven := true
	usedOdd := false
	for i := 0; i < N; i++ {
		var cur int64 = int64(a[i]) + 1
		if a[i]%2 == 1 {
			allEven = false
			if !usedOdd {
				usedOdd = true
				cur = int64(a[i]+1) / 2
			}
		}
		prod = prod * cur % PHI
	}
	var res int64 = 1
	for i := 0; i < N; i++ {
		if a[i] == 0 {
			continue
		}
		var exp int64
		if allEven {
			exp = (int64(a[i]) / 2) * prod % PHI
		} else {
			exp = int64(a[i]) * prod % PHI
		}
		res = res * pow(int64(i), exp) % MOD
	}
	fmt.Println(res)
}

package main

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

const (
	MOD = 1000000007
	PHI = MOD - 1
)

func pow(a, s int64) (r int64) {
	r = 1
	for s > 0 {
		if s%2 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		s /= 2
	}
	return
}

func main() {
	const N = 202000
	var n int
	fmt.Scanf("%d", &n)
	var a [N]int
	for i := 0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		a[x]++
	}
	var prod int64 = 1
	allEven := true
	usedOdd := false
	for i := 0; i < N; i++ {
		var cur int64 = int64(a[i]) + 1
		if a[i]%2 == 1 {
			allEven = false
			if !usedOdd {
				usedOdd = true
				cur = int64(a[i]+1) / 2
			}
		}
		prod = prod * cur % PHI
	}
	var res int64 = 1
	for i := 0; i < N; i++ {
		if a[i] == 0 {
			continue
		}
		var exp int64
		if allEven {
			exp = (int64(a[i]) / 2) * prod % PHI
		} else {
			exp = int64(a[i]) * prod % PHI
		}
		res = res * pow(int64(i), exp) % MOD
	}
	fmt.Println(res)
	writer.Flush()
}

func init() {
	// maybe defer writer.Flush() in main

	lineScanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)

	/*
		inputFile, err := os.Open("a.in")
		if err != nil {
			panic(err)
		}
		outputFile, err := os.Create("a.out")
		if err != nil {
			panic(err)
		}
		lineScanner = bufio.NewScanner(inputFile)
		writer = bufio.NewWriter(outputFile)
	*/

	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

var writer *bufio.Writer

func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}