package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	pref := [][]int{
		{2, 1},
		{2, 2},
		{2, 0},
		{1, 1},
		{1, 0},
		{0, 0},
		{0, 1},
		{0, 2},
		{1, 2},
	}
	for t := io.NextInt(); t > 0; t-- {
		a, b := io.NextInts(3), io.NextInts(3)
		ans := 0
		for _, r := range pref {
			i, j := r[0], r[1]
			c := min(a[i], b[j])
			a[i] -= c
			b[j] -= c
			if i > j {
				ans += c * i * j
			} else if i < j {
				ans -= c * i * j
			}
		}
		io.Println(ans)
	}
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)

	if err := run(os.Args[1:], s); err != nil {
		fmt.Println(err)
	}
}

type Seq struct {
	x, y, z int
}

func run(args []string, s *bufio.Scanner) error {
	// Problem Logic Here... 😊
	s.Split(bufio.ScanWords)
	s.Scan()
	tc, err := strconv.Atoi(s.Text())
	if err != nil {
		return err
	}

	for tc > 0 && s.Scan() {
		ax, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		ay, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		az, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		bx, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		by, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		bz, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		fmt.Println(solve(int64(ax), int64(ay), int64(az), int64(bx), int64(by), int64(bz), big.NewInt(0)))
		tc--
	}

	return nil
}

func solve(ax, ay, az, bx, by, bz int64, score *big.Int) *big.Int {
	canIncreaseScore := az > 0 && by > 0
	canDecreaseScore := ay > 0 && bz > 0

	if canIncreaseScore {
		if az <= by {
			return solve(ax, ay, 0, bx, by - ax, bz, score.Add(score, big.NewInt(az * 2)))
		}
		return solve(ax, ay, az - by, bx, 0, bz, score.Add(score, big.NewInt(by * 2)))
	}

	haveToDecrease := bz > 0 && bz > ax + az && canDecreaseScore

	if !haveToDecrease {
		return score
	}

	if ax != 0 || az != 0 {
		return solve(0, ay, 0, bx, by, bz - (ax + az), score)
	}

	if canDecreaseScore {
		if bz <= ay {
			return solve(ax, ay - bz, az, bx, by, 0, score.Sub(score, big.NewInt(bz * 2)))
		}
		return solve(ax, 0, az, bx, by, bz - ay, score.Sub(score, big.NewInt(ay * 2)))
	}

	return score
}

package main

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

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(r, &t)
	for tc := 0; tc < t; tc++ {
		var x1, y1, z1 int64
		fmt.Fscan(r, &x1, &y1, &z1)
		var x2, y2, z2 int64
		fmt.Fscan(r, &x2, &y2, &z2)

		tmp := min(z1, y2)
		z1, y2 = z1-tmp, y2-tmp
		rls := 2 * tmp

		tmp = min(x1+z1, z2)
		rls -= 2 * (z2 - tmp)
		fmt.Println(rls)
	}
}

package main

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

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(r, &t)
	for tc := 0; tc < t; tc++ {
		var x1, y1, z1 int64
		fmt.Fscan(r, &x1, &y1, &z1)
		var x2, y2, z2 int64
		fmt.Fscan(r, &x2, &y2, &z2)

		tmp := min(z1, y2)
		rls := 2 * tmp
		z1 -= tmp
		y2 -= tmp

		tmp = min(x1+z1, z2)
		rls -= 2 * (z2 - tmp)
		fmt.Println(rls)
	}
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	nTest := rw.NextInt()
	for i := 0; i < nTest; i++ {
		solveCase()
	}
}

func solveCase() {
	a := rw.NextInts(3)
	b := rw.NextInts(3)
	ans := 2 * Min(a[2], b[1])
	a[2] -= ans / 2
	b[1] -= ans / 2
	a[1] -= b[1]
	a[1] -= b[0]
	if a[1] > 0 {
		ans -= 2 * a[1]
	}
	rw.Println(ans)
}

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

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var x1, x2, y1, y2, z1, z2 int
		fmt.Fscan(in, &x1)
		fmt.Fscan(in, &y1)
		fmt.Fscan(in, &z1)

		fmt.Fscan(in, &x2)
		fmt.Fscan(in, &y2)
		fmt.Fscan(in, &z2)

		if x1 >= z2 {
			x1 -= z2
			z2 = 0
		} else {
			z2 -= x1
			x1 = 0
		}

		if z1 >= z2 {
			z1 -= z2
			z2 = 0
		} else {
			z2 -= z1
			z1 = 0
		}

		ans := 0
		ans += 2 * min(z1, y2)
		ans -= 2 * min(z2, y1)
		fmt.Println(ans)
	}
}

package main

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

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		xyz := MustParseFieldsB(scanner.Text())

		x1 := xyz[0]
		y1 := xyz[1]
		z1 := xyz[2]

		scanner.Scan()

		xyz2 := MustParseFieldsB(scanner.Text())

		x2 := xyz2[0]
		y2 := xyz2[1]
		z2 := xyz2[2]

		ans := solveB(x1, y1, z1, x2, y2, z2)

		fmt.Println(ans)
	}
}

func solveB(x1, y1, z1, x2, y2, z2 int) int {
	if x1 >= z2 {
		return 2 * min(z1, y2)
	}
	second2Left := z2 - x1

	if z1 >= second2Left {
		one2Left := z1 - second2Left
		return 2 * min(one2Left, y2)
	}
	return - 2 * min(second2Left - z1, y1)
}

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

func MustParseFieldsB(str string) []int {
	parts := strings.Fields(str)

	var ints []int

	for i := 0; i < len(parts); i++ {
		v, err := strconv.Atoi(parts[i])

		if err != nil {
			panic(err)
		}
		ints = append(ints, v)
	}
	return ints
}

package main

import (
	"fmt"
)

type Seq struct {
	Zero int
	One  int
	Two  int
}

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

	return b
}

func main() {
	var t int
	if _, err := fmt.Scanf("%d\n", &t); err != nil {
		panic(err)
	}

	for i := 0; i < t; i++ {
		var p1, p2 Seq
		if _, err := fmt.Scanf("%d %d %d\n", &p1.Zero, &p1.One, &p1.Two); err != nil {
			panic(err)
		}

		if _, err := fmt.Scanf("%d %d %d\n", &p2.Zero, &p2.One, &p2.Two); err != nil {
			panic(err)
		}

		c := 0

		{
			count := min(p1.Two, p2.One)
			c += count * 2 // + 2 * 1
			p1.Two -= count
			p2.One -= count
		}

		{
			count := min(p1.Two, p2.Two)
			p1.Two -= count
			p2.Two -= count
		}

		{
			count := min(p1.Two, p2.Zero)
			p1.Two -= count
			p2.Zero -= count
		}

		{
			count := min(p1.Zero, p2.Two)
			p1.Zero -= count
			p2.Two -= count
		}

		{
			count := min(p1.Zero, p2.One)
			p1.Zero -= count
			p2.One -= count
		}

		{
			count := min(p1.Zero, p2.Zero)
			p1.Zero -= count
			p2.Zero -= count
		}

		{
			count := min(p1.One, p2.Zero)
			p1.One -= count
			p2.Zero -= count
		}

		{
			count := min(p1.One, p2.One)
			p1.One -= count
			p2.One -= count
		}

		{
			count := min(p1.One, p2.Two)
			c -= count * 2
			p1.One -= count
			p2.Two -= count
		}

		fmt.Println(c)
	}
}

package main
import (
        "fmt"
        "os"
        "bufio"
)
func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}
func main(){
    var t, x1, y1, z1, x2, y2, z2, ans int
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()

    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &x1, &y1, &z1)
        fmt.Fscan(in, &x2, &y2, &z2)

        ans = min(z1, y2) * 2
        z1 -= min(z1, y2)
        ans += min(z2 - min(z2, x1+z1), y1) * -2
        fmt.Fprintln(out, ans)
    }
}

package main

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

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		xyz := MustParseFieldsB(scanner.Text())

		x1 := xyz[0]
		y1 := xyz[1]
		z1 := xyz[2]

		scanner.Scan()

		xyz2 := MustParseFieldsB(scanner.Text())

		x2 := xyz2[0]
		y2 := xyz2[1]
		z2 := xyz2[2]

		ans := solveB(x1, y1, z1, x2, y2, z2)

		fmt.Println(ans)
	}
}

func solveB(x1, y1, z1, x2, y2, z2 int) int {
	if x1 >= z2 {
		return 2 * min(z1, y2)
	}
	second2Left := z2 - x1

	if z1 >= second2Left {
		one2Left := z1 - second2Left
		return 2 * min(one2Left, y2)
	}
	return - 2 * min(second2Left, y1)
}

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

func MustParseFieldsB(str string) []int {
	parts := strings.Fields(str)

	var ints []int

	for i := 0; i < len(parts); i++ {
		v, err := strconv.Atoi(parts[i])

		if err != nil {
			panic(err)
		}
		ints = append(ints, v)
	}
	return ints
}

package main
import (
        "fmt"
        "os"
        "bufio"
)
func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}
func main(){
    var t, x1, y1, z1, x2, y2, z2, ans int
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()

    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &x1, &y1, &z1)
        fmt.Fscan(in, &x2, &y2, &z2)

        ans = min(z1, y2) * 2
        ans += min(z2 - min(z2, x1), y1) * -2
        fmt.Fprintln(out, ans)
    }
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)

	if err := run(os.Args[1:], s); err != nil {
		fmt.Println(err)
	}
}

type Seq struct {
	x, y, z int
}

func run(args []string, s *bufio.Scanner) error {
	// Problem Logic Here... 😊
	s.Split(bufio.ScanWords)
	s.Scan()
	tc, err := strconv.Atoi(s.Text())
	if err != nil {
		return err
	}

	for tc > 0 && s.Scan() {
		ax, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		ay, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		az, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		bx, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		by, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		bz, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		fmt.Println(solve(int64(ax), int64(ay), int64(az), int64(bx), int64(by), int64(bz), big.NewInt(0)))
		tc--
	}

	return nil
}

func solve(ax, ay, az, bx, by, bz int64, score *big.Int) *big.Int {
	canIncreaseScore := az > 0 && by > 0
	canDecreaseScore := ay > 0 && bz > 0
	if !canIncreaseScore && !canDecreaseScore {
		return score
	}

	haveToDecrease := bz > 0 && ax == 0 && az == 0

	if !haveToDecrease && !canIncreaseScore {
		return score
	}

	if az > 0 && by > 0 {
		if az <= by {
			return solve(ax, ay, 0, bx, by - ax, bz, score.Add(score, big.NewInt(az * 2)))
		}
		return solve(ax, ay, az - by, bx, 0, bz, score.Add(score, big.NewInt(by * 2)))
	}

	if ay > 0 && bz > 0 {
		if bz <= ay {
			return solve(ax, ay - bz, az, bx, by, 0, score.Sub(score, big.NewInt(bz * 2)))
		}
		return solve(ax, 0, az, bx, by, bz - ay, score.Sub(score, big.NewInt(ay * 2)))
	}

	return score
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)

	if err := run(os.Args[1:], s); err != nil {
		fmt.Println(err)
	}
}

type Seq struct {
	x, y, z int
}

func run(args []string, s *bufio.Scanner) error {
	// Problem Logic Here... 😊
	s.Split(bufio.ScanWords)
	s.Scan()
	tc, err := strconv.Atoi(s.Text())
	if err != nil {
		return err
	}

	for tc > 0 && s.Scan() {
		ax, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		ay, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		az, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		bx, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		by, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		bz, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		fmt.Println(solve(int64(ax), int64(ay), int64(az), int64(bx), int64(by), int64(bz), big.NewInt(0)))
		tc--
	}

	return nil
}

func solve(ax, ay, az, bx, by, bz int64, score *big.Int) *big.Int {
	canIncreaseScore := az > 0 && by > 0
	canDecreaseScore := ay > 0 && bz > 0
	if !canIncreaseScore && !canDecreaseScore {
		return score
	}

	//haveToDecrease := bz > 0 && ax == 0 && az == 0
	haveToDecrease := bz > 0 && bz > ax + az

	if !haveToDecrease && !canIncreaseScore {
		return score
	}

	if haveToDecrease && !canIncreaseScore && ax != 0 && az != 0 {
		return solve(0, ay, 0, bx, by, bz - (ax + az), score)
	}

	if canIncreaseScore {
		if az <= by {
			return solve(ax, ay, 0, bx, by - ax, bz, score.Add(score, big.NewInt(az * 2)))
		}
		return solve(ax, ay, az - by, bx, 0, bz, score.Add(score, big.NewInt(by * 2)))
	}

	if canDecreaseScore {
		if bz <= ay {
			return solve(ax, ay - bz, az, bx, by, 0, score.Sub(score, big.NewInt(bz * 2)))
		}
		return solve(ax, 0, az, bx, by, bz - ay, score.Sub(score, big.NewInt(ay * 2)))
	}

	return score
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)

	if err := run(os.Args[1:], s); err != nil {
		fmt.Println(err)
	}
}

type Seq struct {
	x, y, z int
}

func run(args []string, s *bufio.Scanner) error {
	// Problem Logic Here... 😊
	s.Split(bufio.ScanWords)
	s.Scan()
	tc, err := strconv.Atoi(s.Text())
	if err != nil {
		return err
	}

	for tc > 0 && s.Scan() {
		ax, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		ay, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		az, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		bx, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		by, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		s.Scan()
		bz, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		fmt.Println(solve(int64(ax), int64(ay), int64(az), int64(bx), int64(by), int64(bz), big.NewInt(0)))
		tc--
	}

	return nil
}

func solve(ax, ay, az, bx, by, bz int64, score *big.Int) *big.Int {
	canIncreaseScore := az > 0 && by > 0
	canDecreaseScore := ay > 0 && bz > 0

	if canIncreaseScore {
		if az <= by {
			return solve(ax, ay, 0, bx, by - ax, bz, score.Add(score, big.NewInt(az * 2)))
		}
		return solve(ax, ay, az - by, bx, 0, bz, score.Add(score, big.NewInt(by * 2)))
	}

	haveToDecrease := bz > 0 && bz > ax + az && canDecreaseScore

	if !haveToDecrease {
		return score
	}

	if ax != 0 && az != 0 {
		return solve(0, ay, 0, bx, by, bz - (ax + az), score)
	}

	if canDecreaseScore {
		if bz <= ay {
			return solve(ax, ay - bz, az, bx, by, 0, score.Sub(score, big.NewInt(bz * 2)))
		}
		return solve(ax, 0, az, bx, by, bz - ay, score.Sub(score, big.NewInt(ay * 2)))
	}

	return score
}

package main

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

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(r, &t)
	for tc := 0; tc < t; tc++ {
		var x1, y1, z1 int
		fmt.Fscan(r, &x1, &y1, &z1)
		var x2, y2, z2 int
		fmt.Fscan(r, &x2, &y2, &z2)

		tmp := min(z1, y2)
		rls := 2 * tmp

		tmp = min(x1+z1, z2)
		rls -= 2 * (z2 - tmp)
		fmt.Println(rls)
	}
}


package main

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

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

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

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

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

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

/**
Run solve the problem CF1608A
Date: 11/12/21
User: epradere
URL: https://codeforces.com/contest/1608/problem/0
Problem: CF1608A
**/
func (in *CF1608A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		if n == 1 {
			fmt.Println(1)
		} else {
			for i := 2; i < n+2; i++ {
				fmt.Printf("%d ", i)
			}
			fmt.Println()
		}
	}
}

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

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

package main

import (
	"bufio"
	"os"
	"fmt"

)

const MOD int64 = 1000000007

var n int

var r *bufio.Reader

func main() {

	r = bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(r, &n)

		solve()

		fmt.Println()
	}
}

func solve()  {
	for i := 2; i <= n+1; i++ {
		fmt.Print(i)
		fmt.Print(" ")
	}
}

package main

import "fmt"

func main() {
	var T, n int
	fmt.Scan(&T)
	for T > 0 {
		T--
		fmt.Scan(&n)
		if n == 1 {
			fmt.Println(1)
			continue
		}
		var i int
		for i = 2; i < n+1; i++ {
			fmt.Print(i, " ")
		}
		fmt.Println(i)
	}
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    for i := 0; i < n; i++ {
        fmt.Fprint(output, i + 2, " ")
    }
    fmt.Fprintln(output)
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = i + 2
		}

		for _, ch := range arr {
			fmt.Fprintf(out, "%d ", ch)
		}
		fmt.Fprintln(out)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		for j := 0; j < n; j++ {
			fmt.Fprint(w, j+2, " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var num int
		fmt.Scanf("%d\n", &num)
		for j := 0; j < num; j++ {
			fmt.Printf("%d ", 2+j)
		}
		fmt.Println()
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

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

func solve(n int) string {
	var s []string
	for i := 0; i < n; i++ {
		s = append(s, fmt.Sprint(i+2))
	}
	return strings.Join(s, " ")
}

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

// Online IDE - Code Editor, Compiler, Interpreter

package main

import "fmt"

func main() {
   t := 1
   fmt.Scanln(&t)
   for x := 0; x < t; x++ {
      n := 1
      fmt.Scanln(&n)
      for i := 2; i <= (n + 1); i++ {
         fmt.Print(i)
         fmt.Print(" ")
      }
      fmt.Print("\n")
   }

}

package main

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

/*
1
5
---
2 3 5 7 11
 */

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

	bld := strings.Builder{}

	primes := make([]int, 1_000)
	j := 0

	for i := 2; i < 8000 && j < len(primes); i++ {
		if isPrime(i) {
			primes[j] = i
			j++
		}
	}

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		for i := 0; i < n; i++ {
			fmt.Fprintf(&bld, "%d ", primes[i])
		}
		fmt.Fprintln(&bld)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

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

	return true
}

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

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

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

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

package main

import (
	"fmt"
)

func main() {
	var t int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		_, _ = fmt.Scanln(&n)
		if n == 1 {
			fmt.Println(1)
		} else {
			fmt.Print("2")
			for j, k := 0, 3; j < n-1; j, k = j+1, k+1 {
				fmt.Printf(" %d", k)
			}
			fmt.Println()
		}
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"

)

const MOD int64 = 1000000007

var n int

var r *bufio.Reader

func main() {

	r = bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(r, &n)

		solve()

		fmt.Println()
	}
}

func solve()  {
	for i := 1; i <= n; i++ {
		fmt.Print(i)
		fmt.Print(" ")
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"

)

const MOD int64 = 1000000007

var n int

var r *bufio.Reader

func main() {

	r = bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(r, &n)

		solve()

		fmt.Println()
	}
}

func solve()  {
	for i := 1; i < n; i++ {
		fmt.Print(i)
		fmt.Print(" ")
	}
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    for i := 0; i < n; i++ {
        fmt.Fprint(output, i + 1, " ")
    }
    fmt.Fprintln(output)
}


package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		one := false
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
			if nums[i] == 1 {
				one = true
			}
		}
		sort.Ints(nums)
		min := nums[0]
		if min > 1 {
			fmt.Fprintln(out, "YES")
			continue
		}
		if min == 0 {
			if one {
				fmt.Fprintln(out, "NO")
			} else {
				fmt.Fprintln(out, "YES")
			}
			continue
		}
		find := true
		for i := n - 2; i >= 0; i-- {
			if nums[i]+1 == nums[i+1] {
				find = false
				break
			}
			if nums[i] == min {
				break
			}
		}
		if find {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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 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 main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		_ = readInt(ip)
		tmp := readArrInt(ip)
		sort.Ints(tmp)
		c1, c2 := 0, 0
		f := true
		for i := range tmp {
			if tmp[i] == 1 {
				c1++
			}
			if i < len(tmp)-1 && tmp[i]+1 == tmp[i+1] {
				c2++
			}
			if c1 > 0 && c2 > 0 {
				f = false
				break
			}
		}
		if f {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

// https://codeforces.com/problemset/problem/1656/C

// 1656C - Make Equal With Mod

// You are given an array of n non-negative integers a1,a2,…,an. You can make the following operation: choose an integer x≥2 and replace each number of the array by the remainder when dividing that number by x, that is, for all 1≤i≤n set ai to aimodx.
// Determine if it is possible to make all the elements of the array equal by applying the operation zero or more times.

// Input
// The input consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. Description of the test cases follows.
// The first line of each test case contains an integer n (1≤n≤105) — the length of the array.
// The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) where ai is the i-th element of the array.
// The sum of n for all test cases is at most 2⋅105.

// Output
// For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO.
// You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

// Example
// input
// 4
// 4
// 2 5 6 8
// 3
// 1 1 1
// 5
// 4 1 7 0 8
// 4
// 5 9 17 5
// output
// YES
// YES
// NO
// YES

// Note

// In the first test case, one can apply the operation with x=3 to obtain the array [2,2,0,2], and then apply the operation with x=2 to obtain [0,0,0,0].
// In the second test case, all numbers are already equal.
// In the fourth test case, applying the operation with x=4 results in the array [1,1,1,1].

// Tutorial

// Note that, if 1 is not present in the array, we can always make all elements equal to 0 by repeatedly applying the operation with x=max(ai) until all elements become 0, as this operation will set the elements equal to the maximum to 0, while maintaining the others intact. So the answer is YES.
// If 1 is present and there are no two consecutive numbers in the array, we can similarly apply repeatedly the operation with x=max(ai)−1 until all elements become 1, as this operation will set the elements equal to the maximum to 1, while maintaining the others intact. So the answer is again YES.
// If 1 is present in the array, and there are two consecutive numbers m,m+1 in the array, the answer is NO. Note that if we have a 0 and a 1 in the array, we won't be able to make them equal after any number of operations, and so we cannot have any operation with an x that divides one of the ai's. The rest of operations will cause that m,m+1 remain consecutive (and thus different), meaning that it is impossible to make all the array equal.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, i uint
	var a []uint
	var one, consec bool

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)
			a = make([]uint, n)
			one = false
			consec = false

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

				if a[i] == 1 {
					one = true
				}
			}

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

			for i = 1; i < n && !consec; i++ {
				if a[i] == a[i-1]+1 {
					consec = true
				}
			}

			if one && consec {
				fmt.Fprintln(writer, "NO")
			} else {
				fmt.Fprintln(writer, "YES")
			}
		}
	}

	writer.Flush()
}

// https://codeforces.com/problemset/problem/1656/C

// 1656C - Make Equal With Mod

// You are given an array of n non-negative integers a1,a2,…,an. You can make the following operation: choose an integer x≥2 and replace each number of the array by the remainder when dividing that number by x, that is, for all 1≤i≤n set ai to aimodx.
// Determine if it is possible to make all the elements of the array equal by applying the operation zero or more times.

// Input
// The input consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. Description of the test cases follows.
// The first line of each test case contains an integer n (1≤n≤105) — the length of the array.
// The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) where ai is the i-th element of the array.
// The sum of n for all test cases is at most 2⋅105.

// Output
// For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO.
// You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

// Example
// input
// 4
// 4
// 2 5 6 8
// 3
// 1 1 1
// 5
// 4 1 7 0 8
// 4
// 5 9 17 5
// output
// YES
// YES
// NO
// YES

// Note

// In the first test case, one can apply the operation with x=3 to obtain the array [2,2,0,2], and then apply the operation with x=2 to obtain [0,0,0,0].
// In the second test case, all numbers are already equal.
// In the fourth test case, applying the operation with x=4 results in the array [1,1,1,1].

// Tutorial

// Note that, if 1 is not present in the array, we can always make all elements equal to 0 by repeatedly applying the operation with x=max(ai) until all elements become 0, as this operation will set the elements equal to the maximum to 0, while maintaining the others intact. So the answer is YES.
// If 1 is present and there are no two consecutive numbers in the array, we can similarly apply repeatedly the operation with x=max(ai)−1 until all elements become 1, as this operation will set the elements equal to the maximum to 1, while maintaining the others intact. So the answer is again YES.
// If 1 is present in the array, and there are two consecutive numbers m,m+1 in the array, the answer is NO. Note that if we have a 0 and a 1 in the array, we won't be able to make them equal after any number of operations, and so we cannot have any operation with an x that divides one of the ai's. The rest of operations will cause that m,m+1 remain consecutive (and thus different), meaning that it is impossible to make all the array equal.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, i uint
	var a []uint
	var one, consec bool

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)
			a = make([]uint, n)
			one = false
			consec = false

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

				if a[i] == 1 {
					one = true
				}
			}

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

			for i = 1; i < n; i++ {
				if a[i] == a[i-1]+1 {
					consec = true
				}
			}

			if one && consec {
				fmt.Fprintln(writer, "NO")
			} else {
				fmt.Fprintln(writer, "YES")
			}
		}
	}

	writer.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, n, v int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		c := map[int]int{}
		for ; n > 0; n-- {
			Fscan(in, &v)
			c[v]++
		}
		if c[1] > 0 {
			for v := range c {
				if c[v-1] > 0 {
					Fprintln(out, "NO")
					continue o
				}
			}
		}
		Fprintln(out, "YES")
	}
}

package main

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

/*
3
1
0
1
1
2
0 1
---
YES
YES
NO
========

1
5
4 6 7 0 8
---
YES
---
4 6 7 0 8 mod 4
0 2 3 0 0 mod 3
0 2 0 0 0 mod 2
0 0 0 0 0
=======
1
7
2 1 3 2 1 4 3
---
NO
========
2
2
4 5
2
1 6
---
YES
YES
=======
1
7
4 9 3 5 1 4 3
---
NO?
4 9 3 5 1 4 3 mod 8
4 1 3 5 1 4 3 mod
======
1
3
1 7 8
---
NO
1 2 3

*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	hasZero := false
	hasOne := false
	hasOneDiff := false

	for i, num := range a {
		if a[i] == 0 {
			hasZero = true
		} else if a[i] == 1 {
			hasOne = true
		}

		if i == 0 {
			continue
		}

		if num == a[i-1]+1 {
			hasOneDiff = true
		}
	}

	if hasOne && hasZero || hasOne && hasOneDiff {
		fmt.Fprintln(writer, "NO")
	} else {
		fmt.Fprintln(writer, "YES")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return minNumIdx
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

func main(){
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)

	defer write.Flush()

	var tc int

	for Fscan (read, &tc); tc > 0; tc -- {
		var n int

		Fscan (read, &n)

		isOne := false

		vals := map[int]bool{}

		for i := 1; i <= n; i++ {
		    var val int
		    Fscan (read, &val)
		    if val == 1{
		        isOne = true
		    }
		    vals[val] = true
		}

		if !isOne {
		    Fprintln (write, "YES")
		} else{
		    ok := true
		    for key, _ := range vals {
		        if vals[key + 1] {
		            ok = false
		        }
		    }
		    if ok {
		        Fprintln (write, "YES")
		    } else {
		        Fprintln (write, "NO")
		    }
		}
	}
}

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

type IntSlice []int

func (s IntSlice) Len() int { return len(s) }
func (s IntSlice) Swap(i, j int){ s[i], s[j] = s[j], s[i] }

const N int =1e5+10
var a [N]int
func main(){
	in:=bufio.NewReader(os.Stdin)
	out:=bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T int
	Fscan(in,&T)
	for i:=1;i<=T;i++{
		var n int
		Fscan(in,&n)
		p := make([]int, n)
		var flag,is1 bool=false,false
		for i:=range p{
           var x int
		   Fscan(in,&x)

		   if x==1{
			   is1=true
		   }
		   p[i]=x
		}

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

		for i:=0;i<n-1;i++{
			if p[i]+1==p[i+1]{
				flag=true
			}
		}
		if is1 && flag{
			Println("NO")
		}else{
			Println("YES")
		}
	}
}

package main

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

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)

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

			if arr[i] == 1 {
				hasOne = true
			}
		}

		sort.Ints(arr)
		var f bool
		for i := 1; i < n; i++ {
			if arr[i]-arr[i-1] == 1 {
				f = true
				break
			}
		}

		if !hasOne || (hasOne && !f) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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)

		tally := [3]int{}
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			if v <= 2 {
				tally[v]++
			}
		}

		if tally[1] == n || (tally[1] > 0 && tally[0] == 0 && tally[2] == 0) || tally[1] == 0 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

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)

		tally := [3]int{}
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v <= 2 {
				tally[v]++
			}
		}

		if tally[1] == n || (tally[1] > 0 && tally[0] == 0 && tally[2] == 0) || tally[1] == 0 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

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)

		var odds, evens int
		var ones int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v%3 == 1 {
				ones++
			}

			if v%2 == 0 {
				evens++
			} else {
				odds++
			}
		}

		if ones == 0 || ones == n || evens == n || odds == n {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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)

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

			if v%3 == 1 {
				ones++
			}
		}

		if ones == 0 || ones == n {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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 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 main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		_ = readInt(ip)
		tmp := readArrInt(ip)
		sort.Ints(tmp)
		c1, c2 := 0, 0
		f := true
		for i := range tmp {
			if tmp[i] == 1 {
				c1++
			}
			if i < len(tmp)-1 && tmp[i] == tmp[i+1] {
				c2++
			}
			if c1 > 0 && c2 > 0 {
				f = false
				break
			}
		}
		if f {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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 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 main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		_ = readInt(ip)
		tmp := readArrInt(ip)
		sort.Ints(tmp)
		c1, c2 := 0, 0
		f := true
		for i := range tmp {
			if tmp[i] == 1 {
				c1++
			}
			if i < len(tmp)-1 && tmp[i] == tmp[i+1] {
				c2++
			}
			if c1 > 0 && c2 > 0 {
				f = false
				break
			}
		}
		if f {
			fmt.Println("Yes")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		c := [3]int{}
		for i := 0; i < n; i++ {
			if Fscan(in, &v); v < 3 {
				c[v]++
			}
		}
		if 0 < c[1] && c[1] < n && c[0]+c[2] > 0 {
			Println("NO")
		} else {
			Println("YES")
		}
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		var one, zero, two bool
		for i := 0; i < n; i++ {
			num := 0
			fmt.Fscan(in, &num)
			if num == 0 {
				zero = true
			}
			if num == 1 {
				one = true
			}
			if num == 2 {
				two = true
			}
		}
		if !one {
			fmt.Fprintln(out, "YES")
		} else if two || zero {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

/*
3
1
0
1
1
2
0 1
---
YES
YES
NO
========

1
5
4 6 7 0 8
---
YES
---
4 6 7 0 8 mod 4
0 2 3 0 0 mod 3
0 2 0 0 0 mod 2
0 0 0 0 0
=======
1
7
2 1 3 2 1 4 3
---
NO
========
2
2
4 5
2
1 6
---
YES
YES
*/

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

	a := make([]int64, n)

	hasZero := false
	hasOne := false
	hasTwo := false

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

		if a[i] == 0 {
			hasZero = true
		} else if a[i] == 1 {
			hasOne = true
		} else if a[i] == 2 {
			hasTwo = true
		}
	}
	scanf("\n")

	if hasOne && hasZero || hasOne && hasTwo {
		fmt.Fprintln(writer, "NO")
	} else {
		fmt.Fprintln(writer, "YES")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return minNumIdx
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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


package main

import (
  "fmt"
)

func main(){
  var n,m,q int
  var b [501][501]int
  var largest [501]int
  fmt.Scan(&n,&m,&q)
  for i:=0;i<n;i++ {
    t := 0
    for j:=0;j<m;j++ {
      fmt.Scan(&b[i][j])
      if b[i][j] == 1 {
        t++
      }else{
        t=0
      }
      if t > largest[i] {
        largest[i] = t
      }
    }
  }
  for i:=0;i<q;i++ {
    var x,y,t int
    fmt.Scan(&x,&y)
    x--;y--;
    b[x][y] = 1 - b[x][y]
    largest[x] = 0
    for j:=0;j<m;j++ {
      if b[x][j] == 1 {
        t++
      }else{
        t=0
      }
      if t>largest[x] {
        largest[x] = t
      }
    }
    t = 0
    for j:=0;j<n;j++ {
      if largest[j]>t {
        t=largest[j]
      }
    }
    fmt.Println(t)
  }
}

package main

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

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

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func getLine2Int3() (a, b, c int) {
	scanf("%d %d %d\n", &a, &b, &c)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n-1; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}
func getLines2Ints(n, m int) [][]int {
	ans := make([][]int, n)
	for i := 0; i < n; i++ {
		ans[i] = getLine2Ints(m)
	}
	return ans
}
func updateMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func getMaxC(a []int) int {
	max, now := 0, 0
	for i := 0; i < len(a); i++ {
		if a[i] == 1 {
			now++
		} else {
			max = updateMax(max, now)
			now = 0
		}
	}
	max = updateMax(max, now)
	return max
}
func getMax(a []int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		max = updateMax(max, a[i])
	}
	return max
}
func main() {
	defer writer.Flush()

	n, m, q := getLine2Int3()
	a := getLines2Ints(n, m)
	b := getLines2Ints(q, 2)
	cnt := make([]int, n)
	for i := 0; i < n; i++ {
		cnt[i] = getMaxC(a[i])
	}
	for i := 0; i < q; i++ {
		x, y := b[i][0]-1, b[i][1]-1
		a[x][y] = 1 - a[x][y]
		cnt[x] = getMaxC(a[x])
		printf("%d\n", getMax(cnt))
	}
}

package main

import (
	"fmt"
)

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

func main() {
	var n, m, q int
	fmt.Scan(&n, &m, &q)
	var bears = make([][]int, n)
	for i := range bears {
		bears[i] = make([]int, m)
	}
	var count = make([]int, n)
	for i := range bears {
		count[i] = 0
		total := 0
		for j := range bears[i] {
			fmt.Scan(&bears[i][j])
			if bears[i][j] == 1 {
				total++
			} else {
				count[i] = max(count[i], total)
				total = 0
			}
		}
		if total != 0 {
			count[i] = max(count[i], total)
		}
	}
	for i := 0; i < q; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a = a - 1
		b = b - 1
		if bears[a][b] == 1 {
			bears[a][b] = 0
		} else {
			bears[a][b] = 1
		}
		kount := 0
		maxim := 0
		for j := 0; j < m; j++ {
			if bears[a][j] == 1 {
				maxim = maxim + 1
			} else {
				kount = max(maxim, kount)
				maxim = 0
			}
		}
		if maxim != 0 {
			kount = max(kount, maxim)
		}
		count[a] = kount
		x := 0
		for t := range count {
			x = max(x, count[t])
		}
		fmt.Println(x)
	}

}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m, q := nextInt()+1, nextInt()+1, nextInt()
	grid := make([][]int, n)
	rowScores := make([]int, n)
	maxScoreIndex := 0

	for i := 1; i < n; i++ {
		grid[i] = make([]int, m)

		for j := 1; j < m; j++ {
			grid[i][j] = nextInt()
		}

		rowScores[i] = scoreRow(grid[i])
		if rowScores[i] > rowScores[maxScoreIndex] {
			maxScoreIndex = i
		}
		// println(maxScoreIndex, rowScores)
	}

	for ; q > 0; q-- {
		n, m = nextInt(), nextInt()
		grid[n][m] = 1 - grid[n][m]
		rowScores[n] = scoreRow(grid[n])

		if maxScoreIndex == n {
			for i := range rowScores {
				if rowScores[i] > rowScores[maxScoreIndex] {
					maxScoreIndex = i
				}
			}
		} else if rowScores[n] >= rowScores[maxScoreIndex] {
			maxScoreIndex = n
		}

		// println(rowScores[maxScoreIndex], maxScoreIndex, rowScores)
		println(rowScores[maxScoreIndex])
	}
}

func scoreRow(a []int) int {
	cnt := 0
	score := 0

	for i := 0; i < len(a); i++ {
		if a[i] == 1 {
			cnt++
		} else if cnt > 0 {
			score = max(score, cnt)
			cnt = 0
		}
	}

	if cnt > 0 {
		score = max(score, cnt)
	}

	return score
}

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

	return b
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Row struct {
  Data []int
  Key int
}

func maxSpan(data []int) int {
  max := 0
  span := data[0]
  m := len(data)
  for c := 1; c < m; c++ {
    if data[c] == 1 {
      span++
    } else {
      if span > max {
        max = span
      }
      span = 0
    }
  }
  if span > max {
    max = span
  }
  return max
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m, q := getI(), getI(), getI()
  rows := make([]*Row, n)
  for r := range rows {
    row := &Row{ make([]int, m), 0 }
    for c := range row.Data {
      row.Data[c] = getI()
    }
    row.Key = maxSpan(row.Data)
    rows[r] = row
  }
  for qi := 0; qi < q; qi++ {
    r, c := getI()-1, getI()-1
    row := rows[r]
    row.Data[c] ^= 1
    row.Key = maxSpan(row.Data)
    best := 0
    for _, row := range rows {
      if row.Key > best {
        best = row.Key
      }
    }
    writer.WriteString(fmt.Sprintf("%d\n", best))
  }
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m, q := nextInt()+1, nextInt()+1, nextInt()
	grid := make([][]int, n)
	rowScores := make([]int, n)
	maxScoreIndex := 0

	for i := 1; i < n; i++ {
		grid[i] = make([]int, m)

		for j := 1; j < m; j++ {
			grid[i][j] = nextInt()
		}

		rowScores[i] = scoreRow(grid[i])
		if rowScores[i] > rowScores[maxScoreIndex] {
			maxScoreIndex = i
		}
		// println(maxScoreIndex, rowScores)
	}

	for ; q > 0; q-- {
		n, m = nextInt(), nextInt()
		grid[n][m] = 1 - grid[n][m]
		rowScores[n] = scoreRow(grid[n])

		if rowScores[n] >= rowScores[maxScoreIndex] {
			maxScoreIndex = n
		} else if maxScoreIndex == n {
			for i := range rowScores {
				if rowScores[i] > rowScores[maxScoreIndex] {
					maxScoreIndex = i
				}
			}
		}

		// println(rowScores[maxScoreIndex], maxScoreIndex, rowScores)
		println(rowScores[maxScoreIndex])
	}
}

func scoreRow(a []int) int {
	cnt := 0
	score := 0

	for i := 0; i < len(a); i++ {
		if a[i] == 1 {
			cnt++
		} else if cnt > 0 {
			score = max(score, cnt)
			cnt = 0
		}
	}

	if cnt > 0 {
		score = max(score, cnt)
	}

	return score
}

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

	return b
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Mask struct {
  Values []int
  Count int
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m, q := getI(), getI(), getI()
  masks := make([]*Mask, n)
  for r := range masks {
    mask := &Mask{ make([]int, m), 0 }
    for c := range mask.Values {
      x := getI()
      if x == 1 {
        mask.Count++
      }
      mask.Values[c] = x
    }
    masks[r] = mask
  }
  for qi := 0; qi < q; qi++ {
    r, c := getI()-1, getI()-1
    x := masks[r].Values[c] ^ 1
    masks[r].Values[c] = x
    if x == 0 {
      masks[r].Count--
    } else {
      masks[r].Count++
    }
    best := 0
    for _, mask := range masks {
      if mask.Count > best {
        best = mask.Count
      }
    }
    writer.WriteString(fmt.Sprintf("%d\n", best))
  }
}

package main

import (
	"fmt"
)

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

func main() {
	var n, m, q int
	fmt.Scan(&n, &m, &q)
	var bears = make([][]int, n)
	for i := range bears {
		bears[i] = make([]int, m)
	}
	var count = make([]int, n)
	for i := range bears {
		count[i] = 0
		total := 0
		for j := range bears[i] {
			fmt.Scan(&bears[i][j])
			if bears[i][j] == 1 {
				total++
			} else {
				count[i] = max(count[i], total)
				total = 0
			}
		}
		if total != 0 {
			count[i] = max(count[i], total)
		}
	}
	for i := 0; i < q; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a = a - 1
		b = b - 1
		if bears[a][b] == 1 {
			bears[a][b] = 0
		} else {
			bears[a][b] = 1
		}
		kount := 0
		maxim := 0
		for j := 0; j < m; j++ {
			if bears[a][j] == 1 {
				maxim = maxim + 1
			} else {
				kount = max(maxim, kount)
				maxim = 0
			}
		}
		if maxim != 0 {
			kount = maxim
		}
		count[a] = kount
		x := 0
		for t := range count {
			x = max(x, count[t])
		}
		fmt.Println(x)
	}

}


package main
import "fmt"

func check(x []int, n int, d int) bool {
	for i:=1; i<n; i++ {
		if x[i]==x[i-1]+d {
			continue
		}
		return false
	}
	return true
}

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

func main(){

	var T int
	fmt.Scan(&T)
	for i:=1; i<=T; i++ {
		solve()
	}

}

package main

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

func isOrder(sts *[]int) bool {
	var g bool
	stsT := *sts

	if stsT[1] > stsT[0] {
		g = true
	} else {
		g = false
	}

	for i := 1; i < len(*sts); i += 1 {
		if g && stsT[i]-stsT[i-1] != 1 {
			return false
		}
		if !g && stsT[i-1]-stsT[i] != 1 {
			return false
		}
	}
	return true
}

func offset(sts *[]int) *[]int {
	stsT := *sts
	tmp := stsT[len(stsT)-1]
	for i := len(stsT) - 1; i > 0; i -= 1 {
		stsT[i] = stsT[i-1]
	}
	stsT[0] = tmp
	return &stsT
}

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

	var (
		total int
		n     int
	)

	_, _ = fmt.Fscan(input, &total)

	for t := 0; t < total; t += 1 {
		_, _ = fmt.Fscan(input, &n)

		sts := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &sts[i])
		}

		if n < 2 {
			fmt.Println("YES")
			continue
		}

		isCW := false
		for i := 0; i < n; i += 1 {
			if isOrder(offset(&sts)) {
				isCW = true
				break
			}
		}
		if isCW {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscanf(input, "%d\n", &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var n int
		_, err := fmt.Fscanf(input, "%d\n", &n)
		if err != nil {
		}

		var p = make([]int, n)
		for i := 0; i < n; i++ {
			_, err := fmt.Fscanf(input, "%d", &p[i])
			if err != nil {
			}
		}
		_, err = fmt.Fscanf(input, "\n")
		if err != nil {
		}
		if checkClockwise(n, p) || checkCounterclockwise(n, p) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func checkClockwise(len int, positions []int) bool {
	reset := 0
	for i := 1; i < len; i++ {
		if positions[i] != positions[i - 1] + 1 {
			reset++
			if reset > 1 {
				return false
			}
		}
	}
	return true
}

func checkCounterclockwise(len int, positions []int) bool {
	reset := 0
	for i := 1; i < len; i++ {
		if positions[i] != positions[i - 1] - 1 {
			reset++
			if reset > 1 {
				return false
			}
		}
	}
	return true
}

package main

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

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

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

	var Q int
	fmt.Fscanf(input, "%d\n", &Q)
	for q := 0; q < Q; q++ {
		var N int
		fmt.Fscanf(input, "%d\n", &N)
		P := make([]int, N)
		for n := 0; n < N; n++ {
			fmt.Fscanf(input, "%d", &P[n])
		}
		fmt.Fscanf(input, "\n")

		cw := true
		ccw := true
		for n := 0; n < N; n++ {
			if (P[(n+1)%N]-P[n]+N)%N != 1 {
				cw = false
			}
			if (P[(n+1)%N]-P[n]+N)%N != N-1 {
				ccw = false
			}
		}
		if cw || ccw {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func roundDance(students []int, count int) string {
	if count == 1 {
		return "YES"
	}

	var iPos int
	for i, v := range students {
		if v == 1 {
			iPos = i
		}
	}
	okl := true
	okr := true
	for i := 1; i < count; i++ {
		okl = okl && students[(iPos-i+count)%count] == i+1
	}
	for i := 1; i < count; i++ {
		okr = okr && students[(iPos+i+count)%count] == i+1
	}
	if okl || okr {
		return "YES"
	} else {
		return "NO"
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	var studentCount int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &studentCount)
		students := make([]int, studentCount)
		for j := 0; j < studentCount; j++ {
			fmt.Fscan(r, &students[j])
		}
		fmt.Println(roundDance(students, studentCount))
	}
}

package main

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

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	q, i := 0, 0
	fmt.Scan(&q)

	for ;q > 0; q-- {
		fmt.Scan(&i)
		a := make([]int, i)
		for n := 0; n < i; n++ {
			fmt.Scan(&a[n])
		}

		ok := true
		for n := 1; n < i; n++ {
			k := math.Abs(float64(a[n] - a[n - 1]))
			if k != 1 && k != float64(i - 1) {
				ok = false
				fmt.Println("NO")
				break
			}
		}

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

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscanf(input, "%d\n", &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var n int
		_, err := fmt.Fscan(input, &n)
		if err != nil {
		}

		var p = make([]int, n)

		for i := 0; i < n; i++ {
			_, err := fmt.Fscan(input, &p[i])
			if err != nil {
			}
		}

		if n == 1 {
			fmt.Println("YES")
			continue
		}

		//fmt.Println(n)
		//var ins = -1
		//var result = true
		//if p[0] == p[1]-1 || (p[0] == n && p[1] == 1) {
		//	// 判断升序
		//	ins = 1
		//}
		//for i := 1; i < n; i++ {
		//	if p[i-1] == n && ins == 1 {
		//		if p[i] != 1 {
		//			result = false
		//			break
		//		}
		//		continue
		//	}
		//	if p[i-1] == 1 && ins == -1 {
		//		if p[i] != n {
		//			result = false
		//			break
		//		}
		//		continue
		//	}
		//	if p[i] != p[i-1]+ins {
		//		result = false
		//		break
		//	}
		//}
		var rresult = true
		var iresult = true
		for i := 1; i < n; i++ {
			if p[i-1] == n {
				if p[i] != 1 {
					rresult = false
					break
				}
				continue
			}
			if p[i] != p[i-1]+1 {
				rresult = false
				break
			}
		}
		for i := 1; i < n; i++ {
			if p[i-1] == 1 {
				if p[i] != n {
					iresult = false
					break
				}
				continue
			}
			if p[i] != p[i-1]-1 {
				iresult = false
				break
			}
		}
		if iresult == false && rresult == false {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}

}

package main

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

func main() {

	//stdin, err := os.Open("in.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var q int
	fmt.Fscanf(reader, "%d\n", &q)

	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)

		a := make([]int, n, n)
		l, r := 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d", &a[j])
			if j > 0 {
				if a[j] > a[j-1] {
					r++
				} else {
					l++
				}
			}
			if j == n-1 {
				if a[j] < a[0] {
					r++
				} else {
					l++
				}
			}
		}
		if l <= 1 || r <= 1 {
			fmt.Fprintf(writer, "YES\n")
		} else {
			fmt.Fprintf(writer, "NO\n")
		}
		fmt.Fscanf(reader, "\n")
	}

	writer.Flush()
}

package main

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

/* solution */

func solve() {

	t := readInt()
	for i := 0; i < t; i++ {
		solveOne()
	}

}

func solveOne() {
	n := readInt()
	a := readInt()
	ok := true
	for i := 1; i < n; i++ {
		b := readInt()
		d := b - a
		ok = ok && (d == -1 || d == 1 || d == n-1 || d == 1-n)
		a = b
	}
	if ok {
		print("YES")
	} else {
		print("NO")
	}
}

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

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

package main

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

func isValid(max, current, next int, clockwise bool) bool {
	if clockwise {
		switch current {
		case max:
			if next != 1 {
				return false
			}
		default:
			if next != current+1 {
				return false
			}
		}
	} else {
		switch current {
		case 1:
			if next != max {
				return false
			}
		default:
			if next != current-1 {
				return false
			}
		}
	}

	return true
}

func evaluatePermutation(studentCount int, students []int) bool {
	if studentCount == 1 {
		return true
	}

	var clockwise bool
	if students[0]+1 == students[1] ||
		(students[0] == studentCount && students[1] == 1) {
		clockwise = true
	}

	current := students[0]
	for _, v := range students[1:] {
		status := isValid(studentCount, current, v, clockwise)
		//fmt.Printf("students: %v previous ID: %d curr ID: %d clockwise: %t status: %t\n",
		//	students, current, v, clockwise, status)
		if !status {
			return false
		}
		current = v
	}

	return true
}

func main() {
	var queryCount int
	_, err := fmt.Scanf("%d\n", &queryCount)
	if err != nil {
		panic(fmt.Sprintf("failed to get query count input, err: %v", err))
	}

	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < queryCount; i++ {
		studentInp, _, err := reader.ReadLine()
		if err != nil {
			panic(fmt.Sprintf("failed to get student count input, err: %v", err))
		}

		studentCount, err := strconv.Atoi(string(studentInp))
		if err != nil {
			panic(fmt.Sprintf("strconv: failed to get student count input, err: %v", err))
		}

		studentList, _,err := reader.ReadLine()
		if err != nil {
			panic(fmt.Sprintf("failed to get student list input, err: %v", err))
		}

		students := strings.Split(string(studentList), " ")
		if len(students) != studentCount {
			panic("input student count doesn't align with student list")
		}

		var inputStudents []int
		for _, v:= range students {
			inp, _ := strconv.Atoi(v)
			inputStudents = append(inputStudents, inp)
		}

		result := evaluatePermutation(studentCount, inputStudents)
		//fmt.Printf("Query #: %d student count: %d student-list: %#v result: %t\n",
		//	i+1, studentCount, students, result)
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

/* solution */

func solve() {

	t := readInt()
	for i := 0; i < t; i++ {
		solveOne()
	}

}

func solveOne() {
	n := readInt()
	a := readInt()
	ok := true
	d := 0
	for i := 1; i < n; i++ {
		b := readInt()
		if d == 0 {
			d = b - a
			if d == n-1 || d == 1-n {
				d /= 1 - n
			}
			if d != 1 && d != -1 {
				ok = false
				break
			}
		}
		ok = ok && ((b-a == d) || (d == 1 && a == n && b == 1) || (d == -1 && a == 1 && b == n))
		a = b
	}
	if ok {
		print("YES")
	} else {
		print("NO")
	}
}

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

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

package main

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

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

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

	var Q int
	fmt.Fscanf(input, "%d\n", &Q)
	for q := 0; q < Q; q++ {
		var N int
		fmt.Fscanf(input, "%d\n", &N)
		P := make([]int, N)
		for n := 0; n < N; n++ {
			fmt.Fscanf(input, "%d", &P[n])
		}
		fmt.Fscanf(input, "\n")

		diff := make(map[int]int)
		for n := 0; n < N; n++ {
			diff[abs(P[n%N]-P[(n+1)%N])]++
		}
		if diff[1] == N-1 && diff[N-1] == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func roundDance(students []int, count int) string {
	if count == 1 {
		return "YES"
	}

	var iPos int
	for i, v := range students {
		if v == 1 {
			iPos = i
		}
	}
	okl := true
	okr := true
	for i := 1; i < count; i++ {
		okl = okl && students[(iPos-i+count)%count] == i+1
	}
	for i := 1; i < count; i++ {
		okr = okr && students[(iPos+i+count)%count] == i+1
	}
	if okl || okr {
		return "YES"
	} else {
		return "NO"
	}
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var studentCount int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d\n", &studentCount)
		students := make([]int, studentCount)
		for j := 0; j < studentCount; j++ {
			fmt.Scanf("%d", &students[j])
		}
		fmt.Println(roundDance(students, studentCount))
	}
}

package main

import "fmt"

func roundDance(students []int, count int) string {
	if count == 1 {
		return "YES"
	}
	direction := students[0] - students[1]
	if direction == -2 {
		direction = 1

	}
	// decreasing, clockwise
	var diff int
	if direction < 0 {
		for i := 1; i < count; i++ {
			diff = students[i] - students[i-1]
			if diff > 0 && diff != 1 {
				return "NO"
			}
		}
	} else {
		for i := 1; i < count; i++ {
			diff = students[i] - students[i-1]
			if diff < 0 && diff != -1 {
				return "NO"
			}
		}
	}
	return "YES"
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var studentCount int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d\n", &studentCount)
		students := make([]int, studentCount)
		for j := 0; j < studentCount; j++ {
			fmt.Scanf("%d", &students[j])
		}
		fmt.Println(roundDance(students, studentCount))
	}
}

package main

import (
	"fmt"
	"os"
)

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	q, i := 0, 0
	fmt.Scan(&q)

	for ;q > 0; q-- {
		fmt.Scan(&i)
		a := make([]int, i)
		for n := 0; n < i; n++ {
			fmt.Scan(&a[n])
		}

		ar := true
		br := true

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

			if br && a[n] < a[n + 1] {
				if !(a[n] == 1 && a[n + 1] == i) {
					br = false
				}
			}

			if !ar && !br {
				break
			}
		}

		if ar || br {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	q, i := 0, 0
	fmt.Scan(&q)

	for ;q > 0; q-- {
		fmt.Scan(&i)
		a := make([]int, i)
		for n := 0; n < i; n++ {
			fmt.Scan(&a[n])
		}

		ar := true
		br := true

		for n := 1; n < i; n++ {
			if ar && !(a[n] != a[n - 1] + 1) {
				ar = false
			}

			if br {
				if !((n == 1 && a[n] == 1) || (a[n] != a[n - 1] - 1)) {
					br = false
				}
			}

			if !ar && !br {
				break
			}
		}

		if ar || br {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	q, i := 0, 0
	fmt.Scan(&q)

	for ;q > 0; q-- {
		fmt.Scan(&i)
		a := make([]int, i)
		for n := 0; n < i; n++ {
			fmt.Scan(&a[n])
		}

		ar := true
		br := true

		for n := 1; n < i; n++ {
			if ar && a[n] < a[n - 1] {
				ar = false
			}

			if br {
				if n != 2 && a[n - 1] > a[n] {
					br = false
				}
			}

			if !ar && !br {
				break
			}
		}

		if ar || br {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}