package main

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

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for t > 0 {
		t--
		var n int
		fmt.Scanf("%d ", &n)
		var s string
		fmt.Scanf("%s ", &s)
		if n > 2 || s[0] < s[1] {
			fmt.Println("YES\n2")
			s = s[0:1] + " "  + s[1:]
			fmt.Println(s)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var q int
	scan(&q)
	for ; q > 0; q-- {
		var l int
		var s string
		scan(&l,&s)

		if l == 1 {
			print("NO\n")
		}else if l == 2 {
			if s[0] < s[1] {
				print("YES\n")
				print("2\n")
				print(s[:1]," ", s[1:],"\n")
			}else{
				print("NO\n")
			}

		}else if l > 2 {
			print("YES\n")
			print("2\n")
			print(s[:1], " ",s[1:] ,"\n")
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var q, n int
	var s string

	scanf("%d\n", &q)

	for i := 0; i < q; i++ {
		scanf("%d\n", &n)
		scanf("%s\n", &s)

		if n == 1 {
			printf("NO\n")
		} else if n == 2 {
			if s[0] >= s[1] {
				printf("NO\n")
			} else {
				printf("YES\n2\n")
				printf("%s %s\n", string(s[0]), string(s[1]))
			}
		} else {
			printf("YES\n2\n")
			printf("%s %s\n", string(s[0]), string(s[1:]))
		}

	}
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++{
		var n int
		var b []byte
		fmt.Scan(&n, &b)
		if n == 2 && b[0] >= b[1]{
			fmt.Println("NO")
		}else{
			fmt.Println("YES")
			if n == 1{
				fmt.Println(1)
				fmt.Println(string(b))
			}else{
				//eee
				fmt.Println(2)
				fmt.Println(string(b[0]), string(b[1:]))
			}
		}
	}
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++{
		var n int
		var b []byte
		fmt.Scan(&n, &b)
		if n == 2 && b[0] >= b[1]{
			fmt.Println("NO")
		}else{
			fmt.Println("YES")
			if n == 1{
				fmt.Println(1)
				fmt.Println(string(b))
			}else{
				fmt.Println(2)
				fmt.Println(string(b[0]), string(b[1:]))
			}
		}
	}
}

package main

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

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

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

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	var n, len, num int
	var d string
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d\n", &len)
		scanf("%s\n", &d)
		// printf("len: %v, data: %v\n", len, d)
		if len > 2 {
			printf("YES\n")
			printf("2\n")
			printf("%v %v\n", d[:1], d[1:])
			continue
		}
		num, _ = strconv.Atoi(d)
		if num / 10 >= num % 10 {
			printf("NO\n")
			continue
		}
		printf("YES\n")
		printf("2\n")
		printf("%v %v\n", d[:1], d[1:])
	}
	// printf("%d\n", a+b)
}

package main

import (
	"fmt"
	//"strconv"
)

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		//var k int64

		var s string
		fmt.Scanf("%s ", &s)
		fmt.Scanf("%s ", &s)
		//fmt.Println(string('#'), s)
		if len(s) == 2 && s[0] >= s[1] {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			fmt.Println("2")
			s = s[0:1] + string(' ') + s[1:]
			fmt.Println(s)
		}
	}

}

package main

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

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

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

func main() {
	defer writer.Flush()

	var q int64
	scanf("%d\n", &q)

	for q>0 {
		q--

		var n int64
		var s string

		scanf("%v\n", &n)
		scanf("%v\n", &s)

		if(n==int64(2)) {
			if(int(s[0]) < int(s[1])) {
				printf("YES\n")
				printf("2\n")
				printf("%c %c\n", s[0], s[1])
			} else {
				printf("NO\n")
			}
		} else {
			printf("YES\n")
			printf("2\n")
			printf("%c %s\n", s[0], s[1:])
		}
	}
}

package main

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

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

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

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	var n, len, num int
	var d string
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d\n", &len)
		scanf("%s\n", &d)
		// printf("len: %v, data: %v\n", len, d)
		if len > 2 {
			printf("YES\n")
			printf("%v %v\n", d[:1], d[1:])
			continue
		}
		num, _ = strconv.Atoi(d)
		if num / 10 >= num % 10 {
			printf("NO\n")
			continue
		}
		printf("YES\n")
		printf("%v %v\n", d[:1], d[1:])
	}
	// printf("%d\n", a+b)
}

package main

import (
	"fmt"
	//"strconv"
)

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		//var k int64

		var s string
		fmt.Scanf("%s ", &s)
		fmt.Scanf("%s ", &s)
		//fmt.Println(string('#'), s)
		if len(s) == 2 && s[0] == s[1] {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			fmt.Println("2")
			s = s[0:1] + string(' ') + s[1:]
			fmt.Println(s)
		}
	}

}

package main

import (
	"fmt"
	//"strconv"
)

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		//var k int64
		var s string
		fmt.Scanf("%s ", &s)
		if len(s) == 2 && s[0] == s[1] {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			fmt.Println("2")
			s = s[0:1] + string(' ') + s[1:]
			fmt.Println(s)
		}
	}

}

package main

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

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

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

func main() {
	defer writer.Flush()

	var q int64
	scanf("%d\n", &q)

	for q>0 {
		q--

		var n int64
		var s string

		scanf("%v\n", &n)
		scanf("%v\n", &s)

		if(n==int64(2)) {
			if(int(s[0]) < int(s[1])) {
				printf("YES\n")
				printf("2\n")
				printf("%v %v\n", s[0], s[1])
			} else {
				printf("NO\n")
			}
		} else {
			printf("YES\n")
			printf("2\n")
			printf("%v %v\n", s[:1], s[1:])
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var q int64
	scanf("%d\n", &q)

	for q>0 {
		q--

		var n int64
		var s string

		scanf("%v\n", &n)
		scanf("%v\n", &s)

		if(n==int64(2)) {
			if(int(s[0]) < int(s[1])) {
				printf("YES\n")
				printf("2\n")
				printf("%v %v\n", s[0], s[1])
			} else {
				printf("NO\n")
			}
		} else {
			printf("YES\n")
			printf("2\n")
			printf("%v %v\n", s[:1], s[1:])
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var q int
	scan(&q)
	for ; q > 0; q-- {
		var l int
		var s string
		scan(&l,&s)

		if l == 1 {
			print("NO\n")
		}else if l == 2 {
			if s[0] < s[1] {
				print("YES\n")
				print(s[0]," ", s[1],"\n")
			}else{
				print("NO\n")
			}

		}else if l > 2 {
			print("YES\n")
			print(s[:1], " ",s[1:] ,"\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var q int
	scan(&q)
	for ; q > 0; q-- {
		var l int
		var s string
		scan(&l,&s)

		if l == 1 {
			print("NO\n")
		}else if l == 2 {
			if s[0] < s[1] {
				print("YES\n")
				print("2\n")
				print(s[0]," ", s[1],"\n")
			}else{
				print("NO\n")
			}

		}else if l > 2 {
			print("YES\n")
			print("2\n")
			print(s[:1], " ",s[1:] ,"\n")
		}
	}
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++{
		var n int
		var b []byte
		fmt.Scan(&n, &b)
		if n == 2 && b[0] >= b[1]{
			fmt.Println("NO")
		}else{
			fmt.Println("YES")
			if n == 1{
				fmt.Println(string(b))
			}else{
				fmt.Println(string(b[0]), string(b[1:]))
			}
		}
	}
}


// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		i := 1
		for i < len(s) {
			if s[i] == '1' && s[i-1] == '1' {
				break
			}
			i++
		}
		for i < len(s) {
			if s[i] == '0' && s[i-1] == '0' {
				break
			}
			i++
		}
		if i == len(s) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import (
	. "fmt"
	. "strings"
)
func main() {
	T, s := 0, ""
	for Scan(&T); T > 0; T-- {
		Scan(&s)
		if i := Index(s, "11"); i >= 0 && i < LastIndex(s, "00") {
			Println("NO");
		} else {
			Println("YES");
		}
	}
}

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

func main() {
	T, s := 0, ""
	for Scan(&T); T > 0; T-- {
		Scan(&s)
		if i := Index(s, "11"); i >= 0 && i < LastIndex(s, "00") {
			Println("NO")
		} else {
			Println("YES")
		}
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		s, _ := reader.ReadString('\n')
		res := solve(len(s)-1, s)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}
func solve(n int, s string) bool {
	var one bool

	for i := 1; i < n; i++ {
		if s[i] == s[i-1] && s[i] == '0' {
			if one {
				return false
			}
		}
		one = one || s[i] == '1' && s[i-1] == '1'
	}
	return true
}
func solve1(n int, s string) bool {
	// if position i is kept
	// if s[i] = 0, then all '1' before it should be removed,
	// if s[i] = 1, then all '0' after it should be removed
	// let dp[i] means if there are continues 1 before i,
	dp := make([]bool, n)
	for i := 1; i < n; i++ {
		dp[i] = dp[i-1] || s[i] == '1' && s[i-1] == '1'
	}
	if !dp[n-1] {
		// remove all ones
		return true
	}
	// fp means there are continues 0 so far
	var fp bool
	for i := n - 2; i >= 0; i-- {
		if s[i] == '0' {
			if !dp[i] && !fp {
				// remove all ones before, and all zeros after
				return true
			}
		}
		fp = fp || s[i] == '0' && s[i+1] == '0'
	}
	if !fp {
		// return all zeros
		return true
	}
	return false
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		s, _ := reader.ReadString('\n')
		res := solve(len(s)-1, s)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, s string) bool {
	// if position i is kept
	// if s[i] = 0, then all '1' before it should be removed,
	// if s[i] = 1, then all '0' after it should be removed
	// let dp[i] means if there are continues 1 before i,
	dp := make([]bool, n)
	for i := 1; i < n; i++ {
		dp[i] = dp[i-1] || s[i] == '1' && s[i-1] == '1'
	}
	if !dp[n-1] {
		// remove all ones
		return true
	}
	// fp means there are continues 0 so far
	var fp bool
	for i := n - 2; i >= 0; i-- {
		if s[i] == '0' {
			if !dp[i] && !fp {
				// remove all ones before, and all zeros after
				return true
			}
		}
		fp = fp || s[i] == '0' && s[i+1] == '0'
	}
	if !fp {
		// return all zeros
		return true
	}
	return false
}

package main

import (
	"fmt"
	"strings"
)

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

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

		ones := strings.Index(s, "11")
		zeroes := strings.LastIndex(s, "00")

		if ones != -1 && zeroes != -1 && ones < zeroes {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

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

// github.com/EndlessCheng/codeforces-go
func main() {
	T, s := 0, ""
	for Scan(&T); T > 0; T-- {
		Scan(&s)
		if i := Index(s, "11"); i >= 0 && i < LastIndex(s, "00") {
			Println("NO")
		} else {
			Println("YES")
		}
	}
}

package main

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

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

	solve := func(Case int) bool {
		var s string
		Fscan(in, &s)
	o:
		for i := range s {
			ps := []int{}
			for j, b := range s[:i] {
				if b == '1' {
					ps = append(ps, j)
				}
			}
			for j := i; j < len(s); j++ {
				if s[j] == '0' {
					ps = append(ps, j)
				}
			}
			for i := 1; i < len(ps); i++ {
				if ps[i]-ps[i-1] == 1 {
					continue o
				}
			}
			return true
		}
		return false
		//cnt := []int{}
		//for i, n := 0, len(s); i < n; {
		//	st := i
		//	v := s[st]
		//	for ; i < n && s[i] == v; i++ {
		//	}
		//	cnt = append(cnt, i-st)
		//}
		//if len(cnt) == 1 {
		//	return true
		//}
		//
		//	Println(cnt)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		Fprintln(out, map[bool]string{true: "YES", false: "NO"}[solve(Case)])
	}

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

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

package main
import "fmt"
func main(){
	var t int
	fmt.Scan(&t);
	for i:=0;i<t;i++ {
		var s string
		flag:=0
		f:=0
		fmt.Scan(&s);
		for j:=0;j<len(s)-1;j++ {
			if s[j]=='0' && s[j+1]=='0' && flag==1 {
				f=1;
				break;
			}
			if s[j]=='1' && s[j+1]=='1' {
				flag=1;
			}

		}
		if f==0 {
		    fmt.Println("YES")
		} else {
		    fmt.Println("NO")
		}

	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	s := getS()

	var lastZero int
	firstOne := len(s)

	for i := 0; i < len(s)-1; i++ {
		if s[i] == '1' && s[i+1] == '1' && firstOne == len(s) {
			firstOne = i
		}

		if s[i] == '0' && s[i+1] == '0' {
			lastZero = i
		}
	}

	if lastZero <= firstOne {
		out("YES")
	} else {
		out("NO")
	}
}

// http://github.com/KadoBOT (me@ricardoambrogi.com)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!
func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func ceil(n, d int64) int64 {
	return (n + d - 1) / d
}

func nsort(data ...int64) []int64 {
	sort.SliceStable(data, func(i, j int) bool { return data[i] < data[j] })
	return data
}

func nsorti(data ...int64) []int64 {
	idxs := make([]int64, len(data))
	for i := 0; i < len(data); i++ {
		idxs[i] = int64(i)
	}

	sort.SliceStable(idxs, func(i, j int) bool { return data[idxs[i]] < data[idxs[j]] })
	return idxs
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

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

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// !------- FORMULAS -------!
func gcd(a, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func lcm(a, b int64, integers ...int64) int64 {
	result := a * b / gcd(a, b)

	for i := 0; i < len(integers); i++ {
		result = lcm(result, integers[i])
	}

	return result
}

func sieve(n int64) []int64 {
	integers := make([]bool, n+1)
	for i := int64(2); i < n+1; i++ {
		integers[i] = true
	}

	for p := int64(2); p*p <= n; p++ {
		if integers[p] == true {
			for i := p * 2; i <= n; i += p {
				integers[i] = false
			}
		}
	}

	var primes []int64
	for p := int64(2); p <= n; p++ {
		if integers[p] == true {
			primes = append(primes, p)
		}
	}

	return primes
}

package main
import (
    "fmt"
)

func main() {
    var T int
    fmt.Scanf("%d\n", &T)
    for t := 1; t <= T; t++ {
        var s string
        fmt.Scanf("%s\n", &s)
        res := false
        for i := 0; i < len(s); i++ {
            flag := true
            last := -10000
            for j := 0; j < len(s); j++ {
                if j <= i {
                    if s[j] == '1' {
                        if j == last + 1 {
                            flag = false
                            break
                        }
                        last = j
                    }
                } else {
                    if s[j] == '0' {
                        if j == last + 1 {
                            flag = false
                            break
                        }
                        last = j
                    }
                }
            }
            if flag {
                res = true
                break
            }
        }
        if res {
            fmt.Printf("YES\n")
        } else {
            fmt.Printf("NO\n")
        }
    }
}

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 int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

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

func MAX(x, y int) int {
	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 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 o := 0; o < t; o++ {

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

		k := len(STRING)
		one := make([]int, 0)
		zero := make([]int, 0)

		for i := 0; i < k-1; i++ {
			if string(STRING[i]) == "1" && string(STRING[i+1]) == "1" {
				one = append(one, i)
			}
			if string(STRING[i]) == "0" && string(STRING[i+1]) == "0" {
				zero = append(zero, i)
			}

		}
		if len(zero)*len(one) == 0 {
			fmt.Println("YES")
		} else {
			k := len(zero)
			if zero[k-1] > one[0] {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}
		}

	}

}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		if solve() {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

type ll = int64

func solve() bool {
	var s string
	scan(&s)
	a := []int{}
	for i := range s {
		if s[i] == '1' {
			a = append(a, i)
		}
		b := []int{}
		for j := i + 1; j < len(s); j++ {
			if s[j] == '0' {
				b = append(b, j)
			}
		}
		if check(a, b) {
			return true
		}
	}
	return false
}

func check(a, b []int) bool {
	x := append(append(([]int)(nil), a...), b...)
	for i := 1; i < len(x); i++ {
		if x[i]-x[i-1] == 1 {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.LastIndex(s, "00")
		if ltind > ind && ind >= 0 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.LastIndex(s, "00")
		if ind != -1 && ltind != -1 && ltind > ind {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"bufio"
	"fmt"
	"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 t := 0; t < T; t++ {
		var s string
		fmt.Fscan(in, &s)

		zeroIdx := strings.LastIndex(s, "00")
		oneIdx := strings.Index(s, "11")
		if oneIdx >= 0 && oneIdx < zeroIdx {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"fmt"
	"math/big"
)

var ret *big.Int

func isPrime(x int) bool {
	for i := 2; i < x; i++ {
		if x % i == 0 {
			return false
		}
	}
	return true
}

func dfs(dep, maxDep, n int, a, primeArr []int32, used []bool) {
	if dep == maxDep {
		cur := big.NewInt(1)
		for i := 0; i < n; i++ {
			curFlag := false
			for j := 0; j < maxDep; j++ {
				if used[j] && a[i] % primeArr[j] == 0 {
					curFlag = true
				}
			}
			if !curFlag {
				return
			}
		}
		for i := 0; i < maxDep; i++ {
			if used[i] {
				cur.Mul(cur, big.NewInt(int64(primeArr[i])))
			}
		}
		//fmt.Println(cur)
		if ret.Cmp(big.NewInt(0)) == 0 || -1 == cur.Cmp(ret) {
			ret = cur
		}
		return
	}
	used[dep] = true
	dfs(dep + 1, maxDep, n, a, primeArr, used)
	used[dep] = false
	dfs(dep + 1, maxDep, n, a, primeArr, used)
}

func main() {
	input()
}

func input() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Println(answer(s))
	}
}

func answer(s string) string {
	flag := false
	for i := 0; i < len(s); i++ {
		if !flag {
			if s[i] == '1' {
				if i + 1 < len(s) && s[i + 1] == '1' {
					flag = true
				}
			}
		} else {
			if s[i] == '0' {
				if i + 1 < len(s) && s[i + 1] == '0' {
					return "NO"
				}
			}
		}
	}
	return "YES"
}

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
}

package main

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

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

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

// --------------------------------------------------------------------- //

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	ok := true
	for i := 1; i < len(s); i++ {
		if s[i-1] > s[i] {
			ok = false
		}
	}
	if ok {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	cnt = make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	for i := len(s) - 1; i >= 0; i-- {
		if cnt['1'] == 0 {
			if check(s, i+1, len(s), '0') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

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

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

// --------------------------------------------------------------------- //

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}

	ok := true
	for i := 1; i < len(s); i++ {
		if s[i-1] > s[i] {
			ok = false
		}
	}
	if ok {
		printf("yes\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

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

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

// --------------------------------------------------------------------- //

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}

	ok := true
	for i := 1; i < len(s); i++ {
		if s[i-1] >= s[i] {
			ok = false
		}
	}
	if ok {
		printf("yes\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

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

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

// --------------------------------------------------------------------- //

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	if cnt['0'] == 0 || cnt['1'] == 0 {
		printf("yes\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

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

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

// --------------------------------------------------------------------- //

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	if cnt['0'] == 0 || cnt['1'] == 0 {
		printf("no\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

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

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

// --------------------------------------------------------------------- //

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	if cnt['0'] == 0 || cnt['1'] == 0 {
		printf("yes\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

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

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

// --------------------------------------------------------------------- //

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	for i := range s {
		if cnt['0'] > 0 {
			cnt[s[i]]--
			continue
		}
		cnt[s[i]]--
		if check(s, 0, i, '1') {
			printf("yes\n")
			return
		}
	}

	printf("no\n")
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.Index(s, "00")
		if ind != -1 && ltind != -1 && ltind > ind {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.Index(s, "00")
		if ind >= 0 && ltind >= 0 && ltind > ind {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.Index(s, "00")
		if ltind > ind && ind >= 0 && ltind >= 0 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.Index(s, "00")
		if ltind > ind && ind >= 0 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"bufio"
	"fmt"
	"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 t := 0; t < T; t++ {
		var s string
		fmt.Fscan(in, &s)

		zeroIdx := strings.Index(s, "00")
		oneIdx := strings.Index(s, "11")
		if zeroIdx >= 0 && oneIdx >= 0 && oneIdx < zeroIdx {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"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 t := 0; t < T; t++ {
		var s string
		fmt.Fscan(in, &s)

		zeroIdx := strings.Index(s, "00")
		oneIdx := strings.Index(s, "11")
		if oneIdx >= 0 && zeroIdx > oneIdx {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"fmt"
	"math/big"
)

var ret *big.Int

func isPrime(x int) bool {
	for i := 2; i < x; i++ {
		if x % i == 0 {
			return false
		}
	}
	return true
}

func dfs(dep, maxDep, n int, a, primeArr []int32, used []bool) {
	if dep == maxDep {
		cur := big.NewInt(1)
		for i := 0; i < n; i++ {
			curFlag := false
			for j := 0; j < maxDep; j++ {
				if used[j] && a[i] % primeArr[j] == 0 {
					curFlag = true
				}
			}
			if !curFlag {
				return
			}
		}
		for i := 0; i < maxDep; i++ {
			if used[i] {
				cur.Mul(cur, big.NewInt(int64(primeArr[i])))
			}
		}
		//fmt.Println(cur)
		if ret.Cmp(big.NewInt(0)) == 0 || -1 == cur.Cmp(ret) {
			ret = cur
		}
		return
	}
	used[dep] = true
	dfs(dep + 1, maxDep, n, a, primeArr, used)
	used[dep] = false
	dfs(dep + 1, maxDep, n, a, primeArr, used)
}

func main() {
	input()
}

func input() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Println(answer(s))
	}
}

func answer(s string) string {
	newS := ""
	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			newS = s[i + 1:]
			break
		}
	}
	if len(newS) == 0 {
		return "YES"
	}
	for i := len(newS) - 1; i >= 0; i-- {
		if newS[i] == '0' {
			if i > 0 {
				if newS[i - 1] == '0' {
					return "NO"
				}
			}
		}
	}
	return "YES"
}

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
}

package main

import (
	"fmt"
	"math/big"
)

var ret *big.Int

func isPrime(x int) bool {
	for i := 2; i < x; i++ {
		if x % i == 0 {
			return false
		}
	}
	return true
}

func dfs(dep, maxDep, n int, a, primeArr []int32, used []bool) {
	if dep == maxDep {
		cur := big.NewInt(1)
		for i := 0; i < n; i++ {
			curFlag := false
			for j := 0; j < maxDep; j++ {
				if used[j] && a[i] % primeArr[j] == 0 {
					curFlag = true
				}
			}
			if !curFlag {
				return
			}
		}
		for i := 0; i < maxDep; i++ {
			if used[i] {
				cur.Mul(cur, big.NewInt(int64(primeArr[i])))
			}
		}
		//fmt.Println(cur)
		if ret.Cmp(big.NewInt(0)) == 0 || -1 == cur.Cmp(ret) {
			ret = cur
		}
		return
	}
	used[dep] = true
	dfs(dep + 1, maxDep, n, a, primeArr, used)
	used[dep] = false
	dfs(dep + 1, maxDep, n, a, primeArr, used)
}

func main() {
	input()
}

func input() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Println(answer(s))
	}
}

func answer(s string) string {
	newS := ""
	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			newS = s[i:]
			break
		}
	}
	if len(newS) == 0 {
		return "YES"
	}
	for i := len(newS) - 1; i >= 0; i-- {
		if newS[i] == '0' {
			if i > 0 {
				if newS[i - 1] == '0' {
					return "NO"
				}
			}
		}
	}
	return "YES"
}

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
}

package main

import (
	"fmt"
	"strings"
)

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

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

		ones := strings.Index(s, "11")
		zeroes := strings.Index(s, "00")

		if ones != -1 && zeroes != -1 && ones < zeroes {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}


package main

import "fmt"

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

	sum := n * (n + 1) / 2

	ans := 0

	for gcd := 2; gcd < n; gcd++ {
		cmp := sum - gcd
		if cmp > 0 && cmp%gcd == 0 {
			ans = gcd
			break
		}
	}

	if ans == 0 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
		fmt.Printf("%d", n-1)
		for i := 1; i <= n; i++ {
			if i == ans {
				continue
			}
			fmt.Printf(" %d", i)
		}
		fmt.Printf("\n1 %d\n", ans)
	}
}

package main

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

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

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

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

func main() {
	defer writer.Flush()
	var n, tot, t1 int
	scanf("%d", &n)
	tot = n * (n + 1) / 2
	for i := 1; i <= n; i++ {
		t1 = tot - i
		if gcd(t1, i) > 1 {
			printf("Yes\n%d %d\n%d ", 1, i, n-1)
			for j := 1; j <= n; j++ {
				if j == i {
					continue
				}
				printf("%d ", j)
			}

			return
		}
	}
	printf("No")
}

// Find the answer by looking at n(n + 1)/2
package main

import (
	"fmt"
	"os"
)

func main() {
	n := 0
	fmt.Scan(&n)
	if n <= 2 {
		fmt.Println("No")
		os.Exit(0)
	} else {
		fmt.Println("Yes")
	}

	choice := 0
	if n%2 == 0 {
		choice = n / 2
	} else {
		choice = (n + 1) / 2
	}

	fmt.Println("1", choice)
	fmt.Print(n - 1)
	for i := 1; i <= n; i++ {
		if i == choice {
			continue
		}
		fmt.Printf(" %d", i)
	}
	fmt.Println()
}

// Find the answer by looking at n(n + 1)/2
package main

import (
	"fmt"
	"os"
)

func main() {
	n := 0
	fmt.Scan(&n)
	if n == 1 {
		fmt.Println("No")
		os.Exit(0)
	} else {
		fmt.Println("Yes")
	}

	choice := 0
	if n%2 == 0 {
		choice = n / 2
	} else {
		choice = (n + 1) / 2
	}

	fmt.Println("1", choice)
	fmt.Print("2")
	for i := 1; i <= n; i++ {
		if i == choice {
			continue
		}
		fmt.Printf(" %d", i)
	}
	fmt.Println()
}

// Find the answer by looking at n(n + 1)/2
package main

import (
	"fmt"
	"os"
)

func main() {
	n := 0
	fmt.Scan(&n)
	if n == 1 {
		fmt.Println("No")
		os.Exit(0)
	} else {
		fmt.Println("Yes")
	}

	choice := 0
	if n%2 == 0 {
		choice = n / 2
	} else {
		choice = (n + 1) / 2
	}

	fmt.Println("1", choice)
	fmt.Print(n - 1)
	for i := 1; i <= n; i++ {
		if i == choice {
			continue
		}
		fmt.Printf(" %d", i)
	}
	fmt.Println()
}


package main

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

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

	var n int64
	Fscan(in, &n)
	a := make([]int64, n+1)
	for i := int64(2); i <= n; i++ {
		Fscan(in, &a[i])
	}
	dp := make([][2]int64, n+1)
	var f func(int64, int8) int64
	f = func(p int64, d int8) (res int64) {
		if p > 1 {
			dv := &dp[p][d]
			if *dv != 0 {
				return *dv
			}
			*dv = -1
			defer func() { *dv = res }()
		}
		res = a[p]
		if d == 0 {
			p -= a[p]
		} else {
			p += a[p]
		}
		if p == 1 {
			return -1
		}
		if p <= 0 || p > n {
			return
		}
		v := f(p, d^1)
		if v == -1 {
			return -1
		}
		return res + v
	}
	for a[1] = 1; a[1] < n; a[1]++ {
		Fprintln(out, f(1, 1))
	}
}

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

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int, n+1)
	for i := 2; i <= n; i++ {
		Fscan(in, &a[i])
	}
	dp := make([][2]int64, n+1)
	var f func(int, int8) int64
	f = func(p int, d int8) (res int64) {
		if p > 1 {
			dv := &dp[p][d]
			if *dv != 0 {
				return *dv
			}
			*dv = -1
			defer func() { *dv = res }()
		}
		res = int64(a[p])
		if d == 0 {
			p -= a[p]
		} else {
			p += a[p]
		}
		if p == 1 {
			return -1
		}
		if p <= 0 || p > n {
			return
		}
		v := f(p, d^1)
		if v == -1 {
			return -1
		}
		return res + v
	}
	for a[1] = 1; a[1] < n; a[1]++ {
		Fprintln(out, f(1, 1))
	}
}

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


package main

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

func solve() {
	n := get()
	a := geta(n)
	i := 1
	for i < n && a[i-1] <= a[i] {
		i++
	}
	for i < n && a[i-1] >= a[i] {
		i++
	}
	yn(i == n)
}

const (
	once       = false
	useBuf     = false
	maxBufSize = 10_000_000
	YES        = "YES"
	NO         = "NO"
)

var (
	splitFunc = bufio.ScanWords
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	if useBuf {
		in.Buffer(make([]byte, maxBufSize), maxBufSize)
	}

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

	if once {
		solve()
		return
	}

	for t := get(); t > 0; t-- {
		solve()
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func line() {
	putc('\n')
}

func space() {
	putc(' ')
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts(YES)
	line()
}

func no() {
	puts(NO)
	line()
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

type IntTp interface {
	int | int64
}

type Tp interface {
	IntTp | float64
}

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

func fabs(x float64) float64 {
	return math.Abs(x)
}

func max1[T Tp](x T, y T) T {
	if x > y {
		return x
	}
	return y
}

func max[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = max1(r, x)
	}
	return r
}

func maxa[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] <= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func min1[T Tp](x T, y T) T {
	if x < y {
		return x
	}
	return y
}

func min[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = min1(r, x)
	}
	return r
}

func mina[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] >= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func L(i int) int64 {
	return int64(i)
}

func F(i int) float64 {
	return float64(i)
}

func ints(n int, val int) (a []int) {
	a = make([]int, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func int64s(n int, val int64) (a []int64) {
	a = make([]int64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func floats(n int, val float64) (a []float64) {
	a = make([]float64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

const heapBase = 4

func children(i int) (int, int) {
	start := heapBase * i
	return start + 1, start + (1 + heapBase)
}

func parent(i int) int {
	return (i - 1) / heapBase
}

package main

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

func main() {
	var t int
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n, _ = strconv.Atoi(getString(reader))
		var a = getIntln(reader)
		var prelen, suflen = 0, 1
		for prelen < n-1 && a[prelen] <= a[prelen+1] {
			prelen++
		}
		for suflen < n && a[n-suflen-1] >= a[n-suflen] {
			suflen++
		}
		if prelen+suflen+1 >= n {
			writer.WriteString("YES\n")
		} else {
			writer.WriteString("NO\n")
		}
	}
	writer.Flush()
}

func getIntln(in *bufio.Reader) []int {
	var x = strings.Split(getString(in), " ")
	var res = make([]int, len(x))
	for k, v := range x {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}

func getString(in *bufio.Reader) string {
	var s, _ = in.ReadString('\n')
	s = strings.TrimSpace(s)
	return s
}

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)

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

		if n == 1 {
			fmt.Fprintln(out, "YES")
			continue
		}
		f := true
		var d bool
		for i := 1; i < n; i++ {
			if aa[i-1] < aa[i] {
				if d {
					f = false
					break
				}
			}

			if aa[i-1] > aa[i] {
				d = true
			}
		}

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

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		u := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if i == 0 || i > 0 && a[i] != a[i-1] {
				u = append(u, a[i])
			}
		}

		ok := true

		inf := 0
		for i := 0; i < len(u); i++ {
			if i > 0 && i < len(u)-1 {
				if u[i] < u[i-1] && u[i] < u[i+1] {
					inf++
				}
			}
		}
		if inf > 0 {
			ok = false
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}

	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		n := readInt(input)
		arr := readArrInt(input)
		fmt.Println(solve(n, arr))
	}
}

func solve(n int, arr []int) string {
	if n == 1 {
		return "YES"
	}
	top := 0
	index := 0
	flag := true
	for i := 0; i < n; i++ {
		if top <= arr[i] {
			top = arr[i]
			index = i
		}
	}
	for i := 1; i <= index; i++ {
		if arr[i-1] > arr[i] {
			flag = false
		}
	}
	for i := index; i < n-1; i++ {
		if arr[i] < arr[i+1] {
			flag = false
		}
	}
	if flag {
		return "YES"
	}
	return "NO"
}

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 readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	maxL := make([]int, n)
	maxR := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		maxL[i], maxR[i] = arr[i], arr[i]
	}
	for i := 1; i < n; i++ {
		maxL[i] = max(maxL[i], maxL[i-1])
	}
	for i := n - 2; i >= 0; i-- {
		maxR[i] = max(maxR[i], maxR[i+1])
	}
	for i := 1; i < n-1; i++ {
		if arr[i] < maxL[i-1] && arr[i] < maxR[i+1] {
			fmt.Fprintln(out, "NO")
			return
		}
	}
	fmt.Fprintln(out, "YES")
}

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

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 := []rune(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"
)

func readLine() string {
	s, err := in.ReadString('\n')
	if err != nil {
		panic(err)
	}
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return s
}

func readLines(n int) []string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = readLine()
	}
	return res
}

func readInt() int {
	n, err := strconv.ParseInt(readLine(), 10, 32)
	if err != nil {
		panic(err)
	}
	return int(n)
}

func readInt2() (int, int) {
	as := readInts(2)
	return as[0], as[1]
}

func readInt3() (int, int, int) {
	as := readInts(3)
	return as[0], as[1], as[2]
}

func readUint() uint64 {
	n, err := strconv.ParseUint(readLine(), 10, 64)
	if err != nil {
		panic(err)
	}
	return n
}

func readInts(n int) []int {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	arr := make([]int, n)
	for k, a := range as {
		x, _ := strconv.ParseInt(a, 10, 64)
		arr[k] = int(x)
	}
	return arr
}

func readStrings(n int) []string {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	return as
}

func arr(n, m int) [][]int {
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	return a
}

var in = bufio.NewReader(os.Stdin)

func main() {
	t := readInt()

	for i := 0; i < t; i++ {
		n := readInt()
		a := readInts(n)
		c := a[0]
		up := true
		no := false
		for _, v := range a {
			if up && v >= c {
				c = v
			} else if up && v < c {
				up = false
				c = v
			} else if !up && v > c {
				no = true
				c = v
			} else {
				c = v
			}
		}
		if no {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--

		n := readNum(reader)
		A := readNNums(reader, n)

		res := solve(A)

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

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func solve(A []int) bool {
	n := len(A)

	var i int

	for i+1 < n && A[i+1] >= A[i] {
		i++
	}

	if i+1 == n {
		return true
	}
	// A[i] is the peek
	for j := i + 1; j < n; j++ {
		if A[j] > A[j-1] {
			return false
		}
	}

	return true
}

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

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

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() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)

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

		var (

			n, before int
			less = false
			ans = true
		)
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {

			var x int
			fmt.Fscan(in, &x)
			if j > 0 {

				if less == true && x > before {

					ans = false
				}
				if x < before {

					less = true
				}
			}
			before = x
		}
		if ans {

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

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

package main

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

var a_arr [100_002]int

func Solve(testCaseIdx int, reader io.Reader) {
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscan(reader, &n)
	a := a_arr[0:0]
	a = append(a, 0)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		if ak != a[len(a) - 1] {
			a = append(a, ak)
		}
	}
	a = append(a, 0)
	hill_count := 0
	for k := 1; k < len(a) - 1; k++ {
		if a[k - 1] < a[k] && a[k] > a[k + 1] {
			hill_count++
		}
	}

	if hill_count <= 1 {
		fmt.Fprintln(writer, "YES")
	} else {
		fmt.Fprintln(writer, "NO")
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for k := 0; k < testCaseCount; k++ {
		Solve(k, reader)
	}
}

package main

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

const MAXN int = 2e5 + 7

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	a := make([]int, MAXN)
	defer out.Flush()
	var t, n, maxVal, refPos, flag int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		fmt.Fscan(in, &n)
		maxVal, refPos, flag = -1, -1, 0
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
			if maxVal < a[i] {
				maxVal = a[i]
				refPos = i
			}
		}
		for i, cur := refPos, maxVal; i > 0; i-- {
			if a[i] > cur {
				flag = 1
				break
			}
			cur = a[i]
		}
		if flag == 1 {
			fmt.Fprintln(out, "NO")
			continue
		}
		for i, cur := refPos, maxVal; i <= n; i++ {
			if a[i] > cur {
				flag = 1
				break
			}
			cur = a[i]
		}
		if flag == 1 {
			fmt.Fprintln(out, "NO")
			continue
		}
		fmt.Fprintln(out, "YES")
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var tc int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		var n int
		var a, b int
		ok, inc := true, true
		for fmt.Fscan(in, &n); n > 0; n-- {
			a = b
			fmt.Fscan(in, &b)
			if inc {
				if a > b {
					inc = false
				}
			} else {
				if a < b {
					ok = false
				}
			}
		}
		if ok {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()

	var t, n int

	Fscan(in, &t)
	for ; t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}

		l, r := 1, n
		for ; l < n && a[l] <= a[l+1]; l++ {
		}

		for ; r > 1 && a[r] <= a[r-1]; r-- {
		}

		if r <= l {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
	_, _ = in, out
}

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

package main

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
outer:
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		var prev int
		fmt.Fscan(in, &prev)

		if n == 1 {
			fmt.Fprintln(out, "YES")
			continue outer
		} else {
			cangoup := true
			for i := 0; i < n-1; i++ {
				var el int
				fmt.Fscan(in, &el)
				if el > prev {
					if !cangoup {
						for tm := i + 1; tm < n-1; tm++ {
							fmt.Fscan(in, &el)
						}
						fmt.Fprintln(out, "NO")
						continue outer
					}
				}
				if el < prev {
					cangoup = false
				}
				prev = el
			}
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n int
	scan(&n)
	a := make([]int, n)
	b := [4]float64{float64(n), float64(n), -1, -1}
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	for i := 0; i+1 < n; i++ {
		d := a[i+1] - a[i]
		if d > 0 {
			b[0] = math.Min(float64(i), b[0])
			b[2] = math.Max(float64(i), b[2])
		} else if d < 0 {
			b[1] = math.Min(float64(i), b[1])
			b[3] = math.Max(float64(i), b[3])
		}
	}
	// printf("%f %f %f %f\n", b[0], b[1], b[2], b[3])
	if b[2] == -1 || b[3] == -1 {
		printf("YES\n")
	} else if b[2] > b[1] || b[0] > b[3] {
		printf("NO\n")
	} else {
		printf("YES\n")
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		u := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if i > 0 && a[i] != a[i-1] {
				u = append(u, a[i])
			}
		}

		ok := true

		inf := 0
		for i := 0; i < len(u); i++ {
			if i > 0 && i < len(u)-1 {
				if u[i] < u[i-1] && u[i] < u[i+1] {
					inf++
				}
			}
		}
		if inf > 0 {
			ok = false
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		u := a

		ok := true

		inf := 0
		for i := 0; i < len(u); i++ {
			if i > 0 && i < len(u)-1 {
				if u[i] < u[i-1] && u[i] < u[i+1] {
					inf++
				}
			}
		}
		if inf > 0 {
			ok = false
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		m := make(map[int]int)
		u := make([]int, 0)
		m[a[0]]++
		u = append(u, a[0])
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				m[a[i]]++
				u = append(u, a[i])
			}
		}
		ok := true
		for _, v := range m {
			if v > 1 {
				ok = false
				break
			}
		}
		inf := 0
		for i := 0; i < len(u); i++ {
			if i > 0 && i < len(u)-1 {
				if u[i] < u[i-1] && u[i] < u[i+1] {
					inf++
				}
			}
		}
		if inf > 0 {
			ok = false
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
		if t == 23 {
			write(f, a)
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		m := make(map[int]int)
		u := make([]int, 0)
		m[a[0]]++
		u = append(u, a[0])
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				m[a[i]]++
				u = append(u, a[i])
			}
		}
		ok := true
		for _, v := range m {
			if v > 1 {
				ok = false
				break
			}
		}
		inf := 0
		for i := 0; i < len(u); i++ {
			if i > 0 && i < len(u)-1 {
				if u[i] < u[i-1] && u[i] < u[i+1] {
					inf++
				}
			}
		}
		if inf > 0 {
			ok = false
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		m := make(map[int]int)
		u := make([]int, 0)
		m[a[0]]++
		u = append(u, a[0])
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				m[a[i]]++
				u = append(u, a[i])
			}
		}
		ok := true
		for _, v := range m {
			if v > 1 {
				ok = false
				break
			}
		}
		inf := 0
		for i := 0; i < len(u); i++ {
			if i > 0 && i < len(u)-1 {
				if (u[i] > u[i-1] && u[i] > u[i+1]) || (u[i] < u[i-1] && u[i] < u[i+1]) {
					inf++
				}
			}
		}
		if inf > 1 {
			ok = false
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		m := make(map[int]int)
		u := make([]int, 0)
		m[a[0]]++
		u = append(u, a[0])
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				m[a[i]]++
				u = append(u, a[i])
			}
		}
		ok := true
		for _, v := range m {
			if v > 1 {
				ok = false
				break
			}
		}
		inf := 0
		for i := 0; i < len(u); i++ {
			if i > 0 && i < len(u)-1 {
				if (a[i] > a[i-1] && a[i] > a[i+1]) || (a[i] < a[i-1] && a[i] < a[i+1]) {
					inf++
				}
			}
		}
		if inf > 1 {
			ok = false
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		m := make(map[int]int)
		m[a[0]]++
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				m[a[i]]++
			}
		}
		ok := true
		for _, v := range m {
			if v > 1 {
				ok = false
				break
			}
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

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

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() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)

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

		var (

			n, first int
			change = 0
			sub = 0
			firstsub = 0
			have = false
			ff = 0
		)
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {

			var x int
			fmt.Fscan(in, &x)
			if j > 0 {

				if !have {

					if x != first {

						ff = x - first
						have = true
					}
				}
				if j == 1 {

					firstsub = x - first
					change += 1
				} else {

					sub = x - first
					if sub * firstsub < 0 {

						change += 1
					}
					if sub != 0 {

						firstsub = sub
					}
				}
			}
			first = x
		}
		if change > 2 {

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

			if n > 2 && have && change == 2 && ff < 0 {

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

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

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

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

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() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)

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

		var (

			n, first int
			change = 0
			sub = 0
			firstsub = 0
			have = false
			ff = 0
		)
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {

			var x int
			fmt.Fscan(in, &x)
			if j > 0 {

				if !have {

					if x != first {

						ff = x - first
						have = true
					}
				}
				if j == 1 {

					firstsub = x - first
					change += 1
				} else {

					sub = x - first
					if sub * firstsub < 0 {

						change += 1
					}
					firstsub = sub
				}
			}
			first = x
		}
		if change > 2 {

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

			if n > 2 && have && change == 2 && ff < 0 {

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

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

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

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

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() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)

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

		var (

			n, first int
			change = 0
			sub = 0
			firstsub = 0
		)
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {

			var x int
			fmt.Fscan(in, &x)
			if j > 0 {

				if j == 1 {

					firstsub = x - first
					change += 1
				} else {

					sub = x - first
					if sub * firstsub < 0 {

						change += 1
					}
					firstsub = sub
				}
			}
			first = x
		}
		if change > 2 {

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

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

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

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

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() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)

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

		var (

			n, pos int
			a []int
			mx = 0
			less = false
		)
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {

			var x int
			fmt.Fscan(in, &x)
			a = append(a, x)
			if x > mx {

				pos = j
				mx = x
			}
		}
		if n < 3 {

			fmt.Fprintln(out, "YES")
			continue
		}
		if pos == 0 {

			var ans = false
			if a[pos] < a[pos + 1] {

				less = true
			}
			for j := pos + 1; j < n; j++ {

				if less {

					if a[j - 1] > a[j] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				} else {

					if a[j - 1] < a[j] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				}
			}
			if !ans {

				fmt.Fprintln(out, "YES")
			}
			continue
		}
		if pos == n - 1 {

			var ans = false
			if a[pos] < a[pos - 1] {

				less = true
			}
			for j := pos; j > 0; j-- {

				if less {

					if a[j] > a[j - 1] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				} else {

					if a[j] < a[j - 1] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				}
			}
			if !ans {

				fmt.Fprintln(out, "YES")
			}
			continue
		}
		var ans = false
		if a[pos] > a[pos + 1] {

			less = true
		}
		for j := pos + 1; j < n; j++ {

			if less {

				if a[j - 1] < a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			} else {

				if a[j - 1] > a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			}
		}
		if ans {

			continue
		}
		less = false
		if a[pos] < a[pos - 1] {

			less = true
		}
		for j := pos - 1; j >= 0; j-- {

			if less {

				if a[j + 1] > a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			} else {

				if a[j + 1] < a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			}
		}
		if !ans {

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

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

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

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() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)

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

		var (

			n, pos int
			a []int
			mx = 0
			less = false
		)
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {

			var x int
			fmt.Fscan(in, &x)
			a = append(a, x)
			if x > mx {

				pos = j
				mx = x
			}
		}
		if n < 3 {

			fmt.Fprintln(out, "YES")
			continue
		}
		if pos == 0 {

			var ans = false
			if a[pos] < a[pos + 1] {

				less = true
			}
			for j := pos + 1; j < n; j++ {

				if less {

					if a[j - 1] > a[j] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				} else {

					if a[j - 1] < a[j] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				}
			}
			if !ans {

				fmt.Fprintln(out, "YES")
			}
			continue
		}
		if pos == n - 1 {

			var ans = false
			if a[pos] < a[pos - 1] {

				less = true
			}
			for j := pos; j > 0; j-- {

				if less {

					if a[j] > a[j - 1] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				} else {

					if a[j] < a[j - 1] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				}
			}
			if !ans {

				fmt.Fprintln(out, "YES")
			}
			continue
		}
		var ans = false
		if a[pos] > a[pos + 1] {

			less = true
		}
		for j := pos + 1; j < n; j++ {

			if less {

				if a[j - 1] < a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			} else {

				if a[j - 1] > a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			}
		}
		if ans {

			continue
		}
		less = false
		if a[pos] < a[pos - 1] {

			less = true
		}
		for j := pos - 1; j > 0; j-- {

			if less {

				if a[j + 1] > a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			} else {

				if a[j + 1] < a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			}
		}
		if !ans {

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

package main

import (

	"bufio"
	"os"
	"fmt"
)

var (

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

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() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)

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

		var (

			n, pos int
			a []int
			mx = 0
			less = false
		)
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {

			var x int
			fmt.Fscan(in, &x)
			a = append(a, x)
			if x > mx {

				pos = j
				mx = x
			}
		}
		if n < 3 {

			fmt.Fprintln(out, "YES")
			continue
		}
		if pos == 0 {

			var ans = false
			if a[pos] < a[pos + 1] {

				less = true
			}
			for j := pos + 1; j < n; j++ {

				if less {

					if a[j - 1] > a[j] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				} else {

					if a[j - 1] < a[j] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				}
			}
			if !ans {

				fmt.Fprintln(out, "YES")
			}
			continue
		}
		if pos == n - 1 {

			var ans = false
			if a[pos] < a[pos - 1] {

				less = true
			}
			for j := pos; j > 0; j-- {

				if less {

					if a[j] > a[j - 1] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				} else {

					if a[j] < a[j - 1] {

						fmt.Fprintln(out, "NO")
						ans = true
						break
					}
				}
			}
			if !ans {

				fmt.Fprintln(out, "YES")
			}
			continue
		}
		var ans = false
		if a[pos] > a[pos + 1] {

			less = true
		}
		for j := pos + 1; j < n; j++ {

			if less {

				if a[j - 1] < a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			} else {

				if a[j - 1] > a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			}
		}
		less = false
		if a[pos] < a[pos - 1] {

			less = true
		}
		for j := pos - 1; j > 0; j-- {

			if less {

				if a[j + 1] > a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			} else {

				if a[j + 1] < a[j] {

					fmt.Fprintln(out, "NO")
					ans = true
					break
				}
			}
		}
		if !ans {

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

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()

	var t, n int

	Fscan(in, &t)
	for ; t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}

		l, r := 1, n
		for ; l < n && a[l] <= a[l+1]; l++ {
		}

		for ; r > 1 && a[r] <= a[r-1]; r-- {
		}

		if r <= l {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
	_, _ = in, out
}

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

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()

	var t, n int

	Fscan(in, &t)
	for ; t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}

		var op int = a[1]

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

		sort.Ints(a)

		minOp := a[n]

		if minOp == op {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
	_, _ = in, out
}

func min(x, y int) int { if x < y { return x } else { return y } }
func max(x, y int) int { if x > y { return x } else { return y } }
func main() { Solve(os.Stdin, os.Stdout) }

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()

	var t, n int

	Fscan(in, &t)
	for ; t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}

		s := "YES"
		for i := 2; i <= n-1; i++ {
			if a[i] < a[i-1] && a[i] < a[i+1] {
				s = "NO"
				break
			}
		}
		Fprintln(out, s)
	}
	_, _ = in, out
}

func min(x, y int) int { if x < y { return x } else { return y } }
func max(x, y int) int { if x > y { return x } else { return y } }
func main() { Solve(os.Stdin, os.Stdout) }

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()

	var t, n int

	Fscan(in, &t)
	for ; t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}

		var op int
		for i, j := 1, 1; i <=n; i = j {
			if a[i] == a[j] {
				op++
			}
			for ; j <= n && a[i] == a[j]; j++ {
			}
		}

		sort.Ints(a)

		var minOp int
		for i, j := 1, 1; i <=n; i = j {
			if a[i] == a[j] {
				minOp++
			}
			for ; j <= n && a[i] == a[j]; j++ {
			}
		}

		if minOp == op {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
	_, _ = in, out
}

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

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()

	var t, n int

	Fscan(in, &t)
	for ; t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		var op int
		for i, j := 1, 1; i <=n; i = j {
			Fscan(in, &a[i])
			if a[i] == a[j] {
				op++
			}
			for ; j <= n && a[i] == a[j]; j++ {
			}
		}

		sort.Ints(a)

		var minOp int
		for i, j := 1, 1; i <=n; i = j {
			if a[i] == a[j] {
				minOp++
			}
			for ; j <= n && a[i] == a[j]; j++ {
			}
		}

		if minOp == op {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
	_, _ = in, out
}

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

package main

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
outer:
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		var prev int
		fmt.Fscan(in, &prev)

		if n == 1 {
			fmt.Fprintln(out, "YES")
			continue outer
		} else {
			cangoup := true
			for i := 0; i < n-1; i++ {
				var el int
				fmt.Fscan(in, &el)
				if el > prev {
					if !cangoup {
						for tm := n - 1 - i; tm < n-1; tm++ {
							fmt.Fscan(in, &el)
						}
						fmt.Fprintln(out, "NO")
						continue outer
					}
				}
				if el < prev {
					cangoup = false
				}
				prev = el
			}
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
outer:
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		var prev int
		fmt.Fscan(in, &prev)

		if n == 1 {
			fmt.Fprintln(out, "YES")
			continue outer
		} else {
			cangoup := true
			for i := 0; i < n-1; i++ {
				var el int

				fmt.Fscan(in, &el)
				if el > prev {
					if !cangoup {
						fmt.Fprintln(out, "NO")
						continue outer
					}
				}
				if el < prev {
					cangoup = false
				}
				prev = el
			}
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
outer:
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		var prev int
		fmt.Fscan(in, &prev)
		up := false
		down := false
		state := 2 // 1 up; 0 down
		if n == 1 {
			fmt.Fprintln(out, "YES")
			continue outer
		} else {
			for i := 0; i < n-1; i++ {
				var el int
				fmt.Fscan(in, &el)
				if el > prev {
					switch state {
					case 0:
						if up {
							fmt.Fprintln(out, "NO")
							continue outer
						} else {
							up = true
						}
						state = 1
					case 1:
					case 2:
						up = true
						state = 1
					}
				}
				if el < prev {
					switch state {
					case 0:
					case 1:
						if down {
							fmt.Fprintln(out, "NO")
							continue outer
						} else {
							down = true
						}
						state = 0
					case 2:
						down = true
						state = 0
					}
				}
				prev = el
			}
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		max := 0
		cmax := 0
		for i := 0; i < n; i++ {
			var el int
			fmt.Fscan(in, &el)
			if el == max {
				cmax++
			}
			if el > max {
				max = el
				cmax = 1
			}
		}
		if cmax == 1 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n int
	scan(&n)
	a := make([]int, n)
	b := [4]float64{float64(n), float64(n), 0, 0}
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	for i := 0; i+1 < n; i++ {
		d := a[i+1] - a[i]
		if d > 0 {
			b[0] = math.Min(float64(i), b[0])
			b[2] = math.Max(float64(i), b[2])
		} else if d < 0 {
			b[1] = math.Min(float64(i), b[1])
			b[3] = math.Max(float64(i), b[3])
		}
	}
	// printf("%f %f %f %f\n", b[0], b[1], b[2], b[3])
	if b[2] > b[1] || b[0] > b[3] {
		printf("NO\n")
	} else {
		printf("YES\n")
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n int
	var x, y float64
	scan(&n)
	arr := [4]float64{0, 0, 0, 0}
	for i := 0; i < n; i++ {
		scan(&x, &y)
		arr[0] = math.Min(arr[0], x)
		arr[1] = math.Min(arr[1], y)

		arr[2] = math.Max(arr[2], x)
		arr[3] = math.Max(arr[3], y)
	}
	a := arr[2] - arr[0]
	b := arr[3] - arr[1]
	printf("%d\n", int64(a+b)*2)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

func main() {
	var t int
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n, _ = strconv.Atoi(getString(reader))
		var a = getIntln(reader)
		var lowest = true
		for i := 1; i < n-1; i++ {
			if a[i] < a[i-1] && a[i] < a[i+1] {
				lowest = false
				break
			}
		}
		if lowest {
			writer.WriteString("YES\n")
		} else {
			writer.WriteString("NO\n")
		}
	}
	writer.Flush()
}

func getIntln(in *bufio.Reader) []int {
	var x = strings.Split(getString(in), " ")
	var res = make([]int, len(x))
	for k, v := range x {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}

func getString(in *bufio.Reader) string {
	var s, _ = in.ReadString('\n')
	s = strings.TrimSpace(s)
	return s
}

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)

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

		if n == 1 {
			fmt.Fprintln(out, "YES")
			continue
		}
		f := true
		var u, d bool
		for i := 1; i < n; i++ {
			if aa[i-1] < aa[i] {
				if d {
					f = false
					break
				}
				u = true
			}

			if aa[i-1] > aa[i] {
				if u && d {
					f = false
					break
				}
				d = true
			}
		}

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

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		n := readInt(input)
		arr := readArrInt(input)
		fmt.Println(solve(n, arr))
	}
}

func solve(n int, arr []int) string {
	if n == 1 {
		return "YES"
	}
	top := 0
	index := 0
	flag := true
	for i := 0; i < n; i++ {
		if top <= arr[i] {
			top = arr[i]
			index = i
		}
	}
	for i := 1; i <= index; i++ {
		if arr[i-1] > arr[i] {
			flag = false
		}
	}
	for i := index; i < n-1; i++ {
		if arr[i] < arr[i+1] {
			flag = false
		}
	}
	if flag {
		return "YES"
	}
	flag = true
	bottom := 2147483647
	index = 0
	for i := 0; i < n; i++ {
		if bottom >= arr[i] {
			bottom = arr[i]
			index = i
		}
	}
	for i := 1; i <= index; i++ {
		if arr[i-1] < arr[i] {
			flag = false
		}
	}
	for i := index; i < n-1; i++ {
		if arr[i] > arr[i+1] {
			flag = false
		}
	}
	if flag {
		return "YES"
	}
	return "NO"
}

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 readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	for i := 1; i < n-1; i++ {
		if arr[i] < arr[i-1] && arr[i] < arr[i+1] {
			fmt.Fprintln(out, "NO")
			return
		}
	}
	fmt.Fprintln(out, "YES")
}

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

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 := []rune(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"
)

func readLine() string {
	s, err := in.ReadString('\n')
	if err != nil {
		panic(err)
	}
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return s
}

func readLines(n int) []string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = readLine()
	}
	return res
}

func readInt() int {
	n, err := strconv.ParseInt(readLine(), 10, 32)
	if err != nil {
		panic(err)
	}
	return int(n)
}

func readInt2() (int, int) {
	as := readInts(2)
	return as[0], as[1]
}

func readInt3() (int, int, int) {
	as := readInts(3)
	return as[0], as[1], as[2]
}

func readUint() uint64 {
	n, err := strconv.ParseUint(readLine(), 10, 64)
	if err != nil {
		panic(err)
	}
	return n
}

func readInts(n int) []int {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	arr := make([]int, n)
	for k, a := range as {
		x, _ := strconv.ParseInt(a, 10, 64)
		arr[k] = int(x)
	}
	return arr
}

func readStrings(n int) []string {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	return as
}

func arr(n, m int) [][]int {
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	return a
}

var in = bufio.NewReader(os.Stdin)

func main() {
	t := readInt()

	for i := 0; i < t; i++ {
		n := readInt()
		a := readInts(n)
		c := a[0]
		up := true
		no := false
		for _, v := range a {
			if up && v < c {
				up = false
				c = v
			} else if !up && v > c {
				no = true
			}
		}
		if no {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}


package main

import (
	"bytes"
	"os"
	"io/ioutil"
	"fmt"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var s string
	fmt.Fscanf(reader, "%s\n", &s)

	chars := []byte(s)
	left, result := 0, 0
	for i := 0;i < len(chars);i ++ {
		if chars[i] == '(' {
			left ++
			result ++
		} else if chars[i] == ')' && left > 0 {
			result ++
			left --
		}
	}
	fmt.Printf("%d", result - left)
}

package main

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

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

  line, _ := reader.ReadString('\n')
  s := strings.TrimSpace(line)
  result := len(s)
  depth := 0
  for _, ch := range s {
    if ch == ')' {
      if depth == 0 {
        result--
      } else {
        depth--
      }
    } else {
      depth++
    }
  }
  result -= depth
  writer.WriteString(fmt.Sprintf("%d\n", result))
}