Consider an array $$$a$$$ of $$$n$$$ positive integers.You may perform the following operation:   select two indices $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq n$$$), then  decrease all elements $$$a_l, a_{l + 1}, \dots, a_r$$$ by $$$1$$$. Let's call $$$f(a)$$$ the minimum number of operations needed to change array $$$a$$$ into an array of $$$n$$$ zeros.Determine if for all permutations$$$^\dagger$$$ $$$b$$$ of $$$a$$$, $$$f(a) \leq f(b)$$$ is true. $$$^\dagger$$$ An array $$$b$$$ is a permutation of an array $$$a$$$ if $$$b$$$ consists of the elements of $$$a$$$ in arbitrary order. For example, $$$[4,2,3,4]$$$ is a permutation of $$$[3,2,4,4]$$$ while $$$[1,2,2]$$$ is not a permutation of $$$[1,2,3]$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — description of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print "YES" (without quotes) if for all permutations $$$b$$$ of $$$a$$$, $$$f(a) \leq f(b)$$$ is true, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

NoteIn the first test case, we can change all elements to $$$0$$$ in $$$5$$$ operations. It can be shown that no permutation of $$$[2, 3, 5, 4]$$$ requires less than $$$5$$$ operations to change all elements to $$$0$$$.In the third test case, we need $$$5$$$ operations to change all elements to $$$0$$$, while $$$[2, 3, 3, 1]$$$ only needs $$$3$$$ operations.

// 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"
	"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 (
	"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()
	}
}

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

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

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

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


A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?

Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.

Output the maximum possible length of a regular bracket sequence.

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


You have a string $$$s$$$ consisting of lowercase Latin alphabet letters. You can color some letters in colors from $$$1$$$ to $$$k$$$. It is not necessary to paint all the letters. But for each color, there must be a letter painted in that color.Then you can swap any two symbols painted in the same color as many times as you want. After that, $$$k$$$ strings will be created, $$$i$$$-th of them will contain all the characters colored in the color $$$i$$$, written in the order of their sequence in the string $$$s$$$.Your task is to color the characters of the string so that all the resulting $$$k$$$ strings are palindromes, and the length of the shortest of these $$$k$$$ strings is as large as possible.Read the note for the first test case of the example if you need a clarification.Recall that a string is a palindrome if it reads the same way both from left to right and from right to left. For example, the strings abacaba, cccc, z and dxd are palindromes, but the strings abab and aaabaa — are not.

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input data sets in the test.  The descriptions of the input data sets follow. The first line of the description of each input data set contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the length of the string and the number of colors in which its letters can be painted. The second line of the description of each input data set contains a string $$$s$$$ of length $$$n$$$ consisting of lowercase letters of the Latin alphabet. It is guaranteed that the sum of n over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each set of input data, output a single integer  — the maximum length of the shortest palindrome string that can be obtained.

10

8 2

bxyaxzay

6 3

aaaaaa

6 1

abcdef

6 6

abcdef

3 2

dxd

11 2

abcabcabcac

6 6

sipkic

7 2

eatoohd

3 1

llw

6 2

bfvfbv

Note In the first test case, $$$s$$$="bxyaxzay", $$$k=2$$$. We use indices in the string from $$$1$$$ to $$$8$$$. The following coloring will work: $$$\mathtt{\mathbf{\color{red}{b}\color{blue}{xy}\color{red}{a}\color{blue}{x}z\color{red}{a}\color{blue}{y}}}$$$ (the letter z remained uncolored). After painting:  swap two red characters (with the indices $$$1$$$ and $$$4$$$), we get $$$\mathtt{\mathbf{\color{red}{a}\color{blue}{xy}\color{red}{b}\color{blue}{x}z\color{red}{a}\color{blue}{y}}}$$$;  swap two blue characters (with the indices $$$5$$$ and $$$8$$$), we get $$$\mathtt{\mathbf{\color{red}{a}\color{blue}{xy}\color{red}{b}\color{blue}{y}z\color{red}{a}\color{blue}{x}}}$$$. Now, for each of the two colors we write out the corresponding characters from left to right, we get two strings $$$\mathtt{\mathbf{\color{red}{aba}}}$$$ and $$$\mathtt{\mathbf{\color{blue}{xyyx}}}$$$. Both of them are palindromes, the length of the shortest is $$$3$$$. It can be shown that the greatest length of the shortest palindrome cannot be achieved. In the second set of input data, the following coloring is suitable: $$$[1, 1, 2, 2, 3, 3]$$$. There is no need to swap characters. Both received strings are equal to aa, they are palindromes and their length is $$$2$$$. In the third set of input data, you can color any character and take it into a string. In the fourth set of input data, you can color the $$$i$$$th character in the color $$$i$$$. In the fifth set of input data can be colored in each of the colors of one character. In the sixth set of input data, the following coloring is suitable: $$$[1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0]$$$. Rearrange the characters so as to get the palindromes abcba and acbca.

package main

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

var cf = true

const sz = int('z' - 'a' + 1)

var arr [sz]int

func solve() {
	var n, k int
	var str string
	for i := 0; i < sz; i++ {
		arr[i] = 0
	}
	fmt.Fscan(in, &n, &k, &str)
	var evenPairs, odd int
	for _, elem := range str {
		arr[elem-'a']++
	}
	for _, elem := range arr {
		evenPairs += elem / 2
	}
	if evenPairs%k != 0 {
		evenPairs -= evenPairs % k
	}
	odd = n - evenPairs*2
	ans := (evenPairs / k) * 2
	if odd >= k {
		ans++
	}
	fmt.Fprintln(out, ans)
}

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

type intSet struct {
	itms map[int]struct{}
}

type stringSet struct {
	itms map[string]struct{}
}

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

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

func (s *intSet) remove(item int) *intSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *intSet) size() int {
	s.init()
	return len(s.itms)
}

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

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

func (s *stringSet) remove(item string) *stringSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *stringSet) 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)
}

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

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
}

const float64EqualityThreshold = 1e-9

func almostEqual(a, b float64) bool {
	return math.Abs(a-b) <= float64EqualityThreshold
}

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

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, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)

		m := make([]int, 26)
		for _, ch := range s {
			m[ch-'a']++
		}

		var pairs, z int
		for i, v := range m {
			d := v / 2
			pairs += d
			m[i] -= d * 2

			z += m[i]
		}

		min := pairs / k * 2
		z += (pairs % k) * 2
		if z >= k {
			min++
		}
		fmt.Println(min)
	}
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)
		s, _ := reader.ReadString('\n')
		res := solve(n, k, s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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(n int, k int, s string) int {
	cnt := make([]int, 26)

	for i := 0; i < n; i++ {
		cnt[int(s[i]-'a')]++
	}
	check := func(l int) bool {
		arr := make(IntHeap, 26)

		copy(arr, cnt)

		heap.Init(&arr)

		for j := 0; j < k; j++ {
			var tmp int

			for tmp+1 < l && arr.Len() > 0 {
				x := heap.Pop(&arr).(int)
				y := x / 2 * 2
				if y == 0 {
					break
				}
				// y is atleast 2
				if tmp+y <= l {
					tmp += y
					x -= y
				} else {
					// tmp + y > l
					z := (l - tmp) / 2 * 2
					tmp += z
					x -= z
				}
				if x > 0 {
					heap.Push(&arr, x)
				}
			}
			if tmp+1 < l {
				return false
			}
		}

		if l&1 == 1 {
			var left int
			for i := 0; i < len(arr); i++ {
				left += arr[i]
			}
			return left >= k
		}

		return true
	}

	r := (n+k-1)/k + 1
	l := 1

	for l < r {
		mid := (l + r) / 2
		if !check(mid) {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return r - 1
}

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

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

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

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

package main

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

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

	var T, n, k int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k, &s)
		cnt := [26]int{}
		for _, b := range s {
			cnt[b-'a']++
		}
		pair, odd := 0, 0
		for _, c := range cnt {
			pair += c / 2
			odd += c & 1
		}
		ans := pair / k * 2
		if odd+pair%k*2 >= k {
			ans++
		}
		Fprintln(out, ans)
	}
}

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

package main

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

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

var writer = bufio.NewWriter(os.Stdout)

func next() string {
	return reader.next()
}

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

func nextInt() int {
	return int(nextInt64())
}

func nextLine() string {
	return reader.nextLine()
}

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

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

func max(x, y int) int {
	return int(max64(int64(x), int64(y)))
}

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

func min(x, y int) int {
	return int(min64(int64(x), int64(y)))
}

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func abs(x int) int {
	return int(abs64(int64(x)))
}

func joinInt64s(a []int64, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.FormatInt(v, 10)
	}
	return strings.Join(b, sep)
}

func joinInts(a []int, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func divUp64(x, y int64) int64 {
	return (x + y - 1) / y
}

func divUp(x, y int) int {
	return int(divUp64(int64(x), int64(y)))
}

func gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func gcd(x, y int) int {
	return int(gcd64(int64(x), int64(y)))
}

func lcm64(x, y int64) int64 {
	return x * y / gcd64(x, y)
}

func lcm(x, y int) int {
	return int(lcm64(int64(x), int64(y)))
}

func pow64(x, y int64) int64 {
	return int64(math.Pow(float64(x), float64(y)))
}

func pow(x, y int) int {
	return int(pow64(int64(x), int64(y)))
}

func main() {
	solveTC()
	writer.Flush()
}

func solveTC() {
	t := nextInt()
	for tc := 0; tc < t; tc++ {
		solve()
	}
}

func solve() {
	nextInt()
	k := nextInt()

	letterCounts := []int{}
	for i := 0; i < 26; i++ {
		letterCounts = append(letterCounts, 0)
	}
	s := next()
	for _, c := range s {
		letterCounts[c-'a']++
	}
	pairs := 0
	extraLetters := 0
	for _, c := range letterCounts {
		pairs += c / 2
		extraLetters += c % 2
	}
	colorCounts := []int{}
	startCount := pairs / k
	for i := 0; i < k; i++ {
		colorCounts = append(colorCounts, startCount*2)
		pairs -= startCount
	}
	for (extraLetters < k-1) && (pairs > 0) {
		extraLetters += 2
		pairs--
	}
	for i := 0; i < k; i++ {
		if extraLetters > 0 {
			colorCounts[i]++
			extraLetters--
		}
	}
	for i := k - 1; i >= 0; i-- {
		if pairs > 0 {
			colorCounts[i] += 2
			pairs--
		}
	}
	minCount := 1000000
	for _, i := range colorCounts {
		minCount = min(minCount, i)
	}
	out(minCount)
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n,k int
	Fscan(in,&n,&k)
	var s string
	Fscan(in,&s)
	cnt := make([]int,26)
	for _,v := range s{
		cnt[v - 'a']++
	}
	even := 0
	odd := 0
	for _,v := range cnt{
		even += v / 2
		odd += v % 2
	}
	ans := 2 * (even / k)
	odd += 2 * (even % k)
	if odd >= k{
		ans++
	}
	Fprintln(out,ans)
}
func max(a,b int)int{
	if a > b{
		return a
	}
	return b
}
func min(a,b int)int{
	if a > b{
		return b
	}
	return a
}
func gcd(a,b int)int{
	if a % b == 0{
		return b
	}
	return gcd(b,a%b)
}

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

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++ {
		solve()
	}
}

func solve() {
	var n, k int
	scan(&n, &k)
	var s string
	scan(&s)
	var c = [26]int{}
	for i := range s {
		c[s[i]-'a']++
	}
	var pairs, singles int
	for i := 'a'; i <= 'z'; i++ {
		pairs += c[i-'a'] / 2
		if c[i-'a']%2 == 1 {
			singles++
		}
	}
	var (
		l, r  = 1, n + 1
		check = func(x int) bool {
			if x%2 == 1 {
				r, a, b := 0, pairs/(x/2), singles+2*(pairs%(x/2))
				mn := min(a, b)
				r += mn; a -= mn; b -= mn
				if a > 0 {
					r += a - ((a + x - 1) / x)
				}
				return r >= k
			}
			return (pairs / (x / 2)) >= k
		}
	)
	for r-l > 1 {
		m := l + (r-l)/2
		if check(m) {
			l = m
		} else {
			r = m
		}
	}
	printf("%v\n", l)
}

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

// generated by 1e9y at 10-01-2022
// template version: 2022-01

package main

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

// 0000.A
func solve(n, k int, str string) int {
	index := map[rune]int{}
	for _, s := range str {
		index[s]++
	}
	var pairs, singles int
	for _, v := range index {
		pairs += v / 2
		singles += v % 2
	}

	// Println(str, pairs, singles)
	res := pairs / k * 2
	if (pairs%k*2 + singles) >= k {
		res++
	}

	return res
}

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

	t := ReadInt(in)
	for i := 0; i < t; i++ {
		line := ReadIntSlice(in)
		n, k := line[0], line[1]
		str := ReadLine(in)
		Println(solve(n, k, str))
	}
}

// helpers for convenient input reading

func ReadInt(in *bufio.Reader) int {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	n, _ := strconv.Atoi(line)
	return n
}

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

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

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

package main

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

var cf = true

const sz = int('z' - 'a' + 1)

var arr [sz]int

func solve() {
	var n, k int
	var str string
	for i := 0; i < sz; i++ {
		arr[i] = 0
	}
	fmt.Fscan(in, &n, &k, &str)
	var evenPairs, odd int
	for _, elem := range str {
		arr[elem-'a']++
	}
	for _, elem := range arr {
		evenPairs += elem / 2
	}
	fmt.Println(evenPairs)
	if evenPairs%k != 0 {
		evenPairs -= evenPairs % k
	}
	odd = n - evenPairs*2
	fmt.Println(evenPairs, odd)
	fmt.Println()
	ans := (evenPairs / k) * 2
	if odd >= k {
		ans++
	}
	fmt.Fprintln(out, ans)
}

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

type intSet struct {
	itms map[int]struct{}
}

type stringSet struct {
	itms map[string]struct{}
}

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

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

func (s *intSet) remove(item int) *intSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *intSet) size() int {
	s.init()
	return len(s.itms)
}

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

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

func (s *stringSet) remove(item string) *stringSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *stringSet) 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)
}

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

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
}

const float64EqualityThreshold = 1e-9

func almostEqual(a, b float64) bool {
	return math.Abs(a-b) <= float64EqualityThreshold
}

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"
	"math"
	"os"
	"sort"
)

var cf = true

var z = int('z' - 'a' + 1)
var arr ['z' - 'a' + 1]int

func solve() {
	for i := 0; i < z; i++ {
		arr[i] = 0
	}
	var n, k int
	var str string
	fmt.Fscan(in, &n, &k, &str)
	for _, elem := range str {
		arr[elem-'a']++
	}
	even := make([]int, 0, z)
	odd := make([]int, 0, z)
	for i := 0; i < z; i++ {
		if arr[i] == 0 {
			continue
		}
		if arr[i]%2 == 0 {
			even = append(even, i)
		} else {
			odd = append(odd, i)
		}
	}
	sort.Slice(even, func(i, j int) bool {
		return arr[even[i]] < arr[even[j]]
	})
	sort.Slice(odd, func(i, j int) bool {
		return arr[odd[i]] < arr[odd[j]]
	})
	ptr1, ptr2 := len(even)-1, len(odd)-1
	limit := n / k
	avail := n - limit*k
	ans := MaxInt
	for ; k > 0; k-- {
		cur := 0
		oddUsed := false
		for cur < limit {
			begCur := cur
			needed := limit - cur
			if !oddUsed && ptr2 >= 0 {
				if arr[odd[ptr2]] > needed {
					//fmt.Println("used odd ", odd[ptr2], " ", needed)
					arr[odd[ptr2]] -= needed
					cur += needed
					if needed%2 == 1 {
						oddUsed = true
					}
					if arr[odd[ptr2]]%2 == 0 {
						even = append(even, odd[ptr2])
						sort.Slice(even, func(i, j int) bool {
							return arr[even[i]] < arr[even[j]]
						})
						ptr1++
						odd = odd[:len(odd)-1]
						ptr2--
					} else {
						sort.Slice(odd, func(i, j int) bool {
							return arr[odd[i]] < arr[odd[j]]
						})
					}
				} else {
					//fmt.Println("used odd ", odd[ptr2], " ", arr[odd[ptr2]])
					cur += arr[odd[ptr2]]
					ptr2--
					oddUsed = true
				}
				continue
			}
			if oddUsed && needed%2 == 1 {
				if avail > 0 {
					avail--
				} else {
					needed--
				}
			}
			if ptr1 >= 0 {
				if arr[even[ptr1]] > needed {
					//fmt.Println("used even ", even[ptr1], " ", needed)
					arr[even[ptr1]] -= needed
					cur += needed
					if needed%2 == 1 {
						oddUsed = true
					}
					if arr[even[ptr1]]%2 == 1 {
						odd = append(odd, even[ptr1])
						sort.Slice(odd, func(i, j int) bool {
							return arr[odd[i]] < arr[odd[j]]
						})
						ptr2++
						even = even[:len(even)-1]
						ptr1--
					} else {
						sort.Slice(even, func(i, j int) bool {
							return arr[even[i]] < arr[even[j]]
						})
					}
				} else {
					//fmt.Println("used even ", even[ptr1], " ", arr[even[ptr1]])
					cur += arr[even[ptr1]]
					ptr1--
				}
			}
			if begCur == cur {
				break
			}
		}
		//fmt.Println(cur)
		ans = min(ans, cur)
	}
	//fmt.Println("------")
	fmt.Fprintln(out, ans)
}

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

type intSet struct {
	itms map[int]struct{}
}

type stringSet struct {
	itms map[string]struct{}
}

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

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

func (s *intSet) remove(item int) *intSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *intSet) size() int {
	s.init()
	return len(s.itms)
}

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

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

func (s *stringSet) remove(item string) *stringSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *stringSet) 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)
}

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

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
}

const float64EqualityThreshold = 1e-9

func almostEqual(a, b float64) bool {
	return math.Abs(a-b) <= float64EqualityThreshold
}

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"
	"math"
	"os"
	"sort"
)

var cf = true

var z = int('z' - 'a' + 1)
var arr ['z' - 'a' + 1]int

func solve() {
	for i := 0; i < z; i++ {
		arr[i] = 0
	}
	var n, k int
	var str string
	fmt.Fscan(in, &n, &k, &str)
	for _, elem := range str {
		arr[elem-'a']++
	}
	even := make([]int, 0, z)
	odd := make([]int, 0, z)
	for i := 0; i < z; i++ {
		if arr[i] == 0 {
			continue
		}
		if arr[i]%2 == 0 {
			even = append(even, i)
		} else {
			odd = append(odd, i)
		}
	}
	sort.Slice(even, func(i, j int) bool {
		return arr[even[i]] > arr[even[j]]
	})
	sort.Slice(odd, func(i, j int) bool {
		return arr[odd[i]] > arr[odd[j]]
	})
	ptr1, ptr2 := len(even)-1, len(odd)-1
	limit := n / k
	avail := n - limit*k
	ans := MaxInt
	for ; k > 0; k-- {
		cur := 0
		oddUsed := false
		for cur < limit {
			begCur := cur
			needed := limit - cur
			if !oddUsed && ptr2 >= 0 {
				if arr[odd[ptr2]] > needed {
					//fmt.Println("used odd ", odd[ptr2], " ", needed)
					arr[odd[ptr2]] -= needed
					cur += needed
					if needed%2 == 1 {
						oddUsed = true
					}
					if arr[odd[ptr2]]%2 == 0 {
						even = append(even, odd[ptr2])
						sort.Slice(even, func(i, j int) bool {
							return arr[even[i]] > arr[even[j]]
						})
						ptr1++
						odd = odd[:len(odd)-1]
						ptr2--
					} else {
						sort.Slice(odd, func(i, j int) bool {
							return arr[odd[i]] > arr[odd[j]]
						})
					}
				} else {
					//fmt.Println("used odd ", odd[ptr2], " ", arr[odd[ptr2]])
					cur += arr[odd[ptr2]]
					ptr2--
					oddUsed = true
				}
				continue
			}
			if oddUsed && needed%2 == 1 {
				if avail > 0 {
					avail--
				} else {
					needed--
				}
			}
			if ptr1 >= 0 {
				if arr[even[ptr1]] > needed {
					//fmt.Println("used even ", even[ptr1], " ", needed)
					arr[even[ptr1]] -= needed
					cur += needed
					if needed%2 == 1 {
						oddUsed = true
					}
					if arr[even[ptr1]]%2 == 1 {
						odd = append(odd, even[ptr1])
						sort.Slice(odd, func(i, j int) bool {
							return arr[odd[i]] > arr[odd[j]]
						})
						ptr2++
						even = even[:len(even)-1]
						ptr1--
					} else {
						sort.Slice(even, func(i, j int) bool {
							return arr[even[i]] > arr[even[j]]
						})
					}
				} else {
					//fmt.Println("used even ", even[ptr1], " ", arr[even[ptr1]])
					cur += arr[even[ptr1]]
					ptr1--
				}
			}
			if begCur == cur {
				break
			}
		}
		//fmt.Println(cur)
		ans = min(ans, cur)
	}
	//fmt.Println("------")
	fmt.Fprintln(out, ans)
}

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

type intSet struct {
	itms map[int]struct{}
}

type stringSet struct {
	itms map[string]struct{}
}

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

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

func (s *intSet) remove(item int) *intSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *intSet) size() int {
	s.init()
	return len(s.itms)
}

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

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

func (s *stringSet) remove(item string) *stringSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *stringSet) 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)
}

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

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
}

const float64EqualityThreshold = 1e-9

func almostEqual(a, b float64) bool {
	return math.Abs(a-b) <= float64EqualityThreshold
}

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

var cf = true

var z = int('z' - 'a' + 1)
var arr ['z' - 'a' + 1]int

func solve() {
	for i := 0; i < z; i++ {
		arr[i] = 0
	}
	var n, k int
	var str string
	fmt.Fscan(in, &n, &k, &str)
	for _, elem := range str {
		arr[elem-'a']++
	}
	even := make([]int, 0, z)
	odd := make([]int, 0, z)
	for i := 0; i < z; i++ {
		if arr[i] == 0 {
			continue
		}
		if arr[i]%2 == 0 {
			even = append(even, i)
		} else {
			odd = append(odd, i)
		}
	}
	for i := 0; i < len(even); i++ {
		for j := i + 1; j < len(even); j++ {
			if arr[even[i]] < arr[even[j]] {
				even[i], even[j] = even[j], even[i]
			}
		}
	}
	for i := 0; i < len(odd); i++ {
		for j := i + 1; j < len(odd); j++ {
			if arr[odd[i]] < arr[odd[j]] {
				odd[i], odd[j] = odd[j], odd[i]
			}
		}
	}
	ptr1, ptr2 := 0, 0
	limit := n / k
	ans := MaxInt
	for ; k > 0; k-- {
		cur := 0
		oddUsed := false
		for cur < limit {
			begCur := cur
			needed := limit - cur
			if !oddUsed && ptr2 < len(odd) {
				if arr[odd[ptr2]] > needed {
					//fmt.Println("used odd ", odd[ptr2], " ", needed)
					arr[odd[ptr2]] -= needed
					cur += needed
					if needed%2 == 1 {
						oddUsed = true
					}
					if arr[odd[ptr2]]%2 == 0 {
						even = append(even, odd[ptr2])
						for ind := len(even) - 1; ind > ptr1 && arr[even[ind]] > arr[even[ind-1]]; ind-- {
							even[ind], even[ind-1] = even[ind-1], even[ind]
						}
						ptr2++
					} else {
						for ind := ptr2; ind < len(odd)-1 && arr[odd[ind]] < arr[odd[ind+1]]; ind++ {
							odd[ind], odd[ind+1] = odd[ind+1], odd[ind]
						}
					}
					continue
				} else {
					//fmt.Println("used odd ", odd[ptr2], " ", arr[odd[ptr2]])
					cur += arr[odd[ptr2]]
					ptr2++
					oddUsed = true
				}
			}
			needed = limit - cur
			if needed%2 == 1 && oddUsed {
				needed--
				if needed == 0 {
					break
				}
			}
			if ptr1 < len(even) {
				if arr[even[ptr1]] > needed {
					//fmt.Println("used even ", even[ptr1], " ", needed)
					arr[even[ptr1]] -= needed
					cur += needed
					if needed%2 == 1 {
						oddUsed = true
					}
					if arr[even[ptr1]]%2 == 1 {
						odd = append(odd, even[ptr1])
						for ind := len(odd) - 1; ind > ptr2 && arr[odd[ind]] > arr[odd[ind-1]]; ind-- {
							odd[ind], odd[ind-1] = odd[ind-1], odd[ind]
						}
						ptr1++
					} else {
						for ind := ptr1; ind < len(even)-1 && arr[even[ind]] < arr[even[ind+1]]; ind++ {
							even[ind], even[ind+1] = even[ind+1], even[ind]
						}
					}
				} else {
					//fmt.Println("used even ", even[ptr1], " ", arr[even[ptr1]])
					cur += arr[even[ptr1]]
					ptr1++
				}
			}
			if begCur == cur {
				break
			}
		}
		//fmt.Println(cur)
		ans = min(ans, cur)
	}
	//fmt.Println("------")
	fmt.Fprintln(out, ans)
}

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

type intSet struct {
	itms map[int]struct{}
}

type stringSet struct {
	itms map[string]struct{}
}

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

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

func (s *intSet) remove(item int) *intSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *intSet) size() int {
	s.init()
	return len(s.itms)
}

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

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

func (s *stringSet) remove(item string) *stringSet {
	s.init()
	delete(s.itms, item)
	return s
}

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

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

func (s *stringSet) 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)
}

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

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
}

const float64EqualityThreshold = 1e-9

func almostEqual(a, b float64) bool {
	return math.Abs(a-b) <= float64EqualityThreshold
}

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

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, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)

		m := make([]int, 26)
		z := make([]int, k)
		var pos int
		for _, ch := range s {
			if m[ch-'a'] == 0 {
				m[ch-'a']++
			} else {
				z[pos] += 2
				m[ch-'a'] = 0
				pos++
				if pos >= k {
					pos = 0
				}
			}
		}

		for _, v := range m {
			if v > 0 && z[pos]%2 == 0 {
				z[pos]++
				pos++
				if pos == k {
					pos = 0
				}
			}
		}

		for i := k - 1; i >= 0; i-- {
			if z[i]%2 != 0 {
				continue
			}

			j := i - 1
			for j >= 0 {
				if z[j]-z[i] == 2 {
					z[i]++
					z[j]--
					break
				}
				j--
			}

			if j == 0 {
				break
			}
		}

		fmt.Fprintln(out, z[k-1])
	}
}

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, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)

		m := make([]int, 26)
		z := make([]int, k)
		var pos int
		for _, ch := range s {
			if m[ch-'a'] == 0 {
				m[ch-'a']++
			} else {
				z[pos] += 2
				m[ch-'a'] = 0
				pos++
				if pos >= k {
					pos = 0
				}
			}
		}

		for _, v := range m {
			if v > 0 && z[pos]%2 == 0 {
				z[pos]++
				pos++
				if pos == k {
					pos = 0
				}
			}
		}

		if k > 1 && z[k-1]%2 == 0 && z[k-2]-z[k-1] == 2 {
			z[k-1]++
		}

		if z[k-1] == 0 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, z[k-1])
		}
	}
}