package main

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

func merge(groupgroup [][]int, groupnum []int, n0 int, n1 int) {
	for i := 0; i < len(groupgroup[n1]); i++ {
		k := groupgroup[n1][i]
		groupnum[k] = n0
		groupgroup[n0] = append(groupgroup[n0], k)
	}
	groupgroup[n1] = []int{}
}

func main() {
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)
	var n, m int
	fmt.Fscan(read, &n, &m)
	usergroup := make([][]int, n+1)

	for i := 0; i < m; i++ {
		var k int
		fmt.Fscan(read, &k)
		for j := 0; j < k; j++ {
			var u int
			fmt.Fscan(read, &u)
			usergroup[u] = append(usergroup[u], i)
		}
	}
	//fmt.Print(usergroup)

	groupnum := make([]int, m)
	groupgroup := make([][]int, m)
	for i := 0; i < m; i++ {
		groupnum[i] = i
		groupgroup[i] = append(groupgroup[i], i)
	}

	for i := 1; i < n+1; i++ {
		var gg0, gg1 int
		for j := 0; j < len(usergroup[i]); j++ {
			gg1 = usergroup[i][j]
			if j == 0 {
				gg0 = gg1
				continue
			} else {
				// merge
				n0 := groupnum[gg0]
				n1 := groupnum[gg1]
				if n0 != n1 {

					if len(groupgroup[n0]) < len(groupgroup[n1]) {
						gg0 = gg1
						merge(groupgroup, groupnum, n1, n0)
					} else {
						merge(groupgroup, groupnum, n0, n1)
					}
				}

			}

		}
	}

	grouplen := make([]int, m)
	for i := 1; i < n+1; i++ {
		if len(usergroup[i]) > 0 {
			k := usergroup[i][0]
			nl := groupnum[k]
			grouplen[nl] = grouplen[nl] + 1

		}
	}

	for i := 1; i < n+1; i++ {
		if len(usergroup[i]) == 0 {
			fmt.Fprint(write, 1, " ")
		} else {
			k := usergroup[i][0]
			nl := groupnum[k]
			fmt.Fprint(write, grouplen[nl], " ")
		}
	}

	write.Flush()

}

/*
7 5
3 2 5 4
0
2 1 2
1 1
2 6 7
*/

package main

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

func solve(j Jam) {
	n := uint32(j.Int())
	m := uint32(j.Int())
	uf := UnionFindNew(n)
	for i := uint32(0); i < m; i++ {
		k := uint32(j.Int())
		root := uint32(0)
		for ii := uint32(0); ii < k; ii++ {
			if ii == 0 {
				root = uint32(j.Int() - 1)
			} else {
				uf.Union(root, uint32(j.Int()-1))
			}
		}
	}
	for i := uint32(0); i < n; i++ {
		fmt.Printf("%d ", uf.Size(i))
	}
}

func main() {
	jam, closeFunc := JamNew()
	defer closeFunc()
	solve(jam)
}

type Jam interface {
	Scanner() *bufio.Scanner
	Writer() *bufio.Writer
	Close()

	Str() string
	Int() int64
	Float() float64

	P(format string, values ...interface{})
	PF(format string, values ...interface{})
}

func JamNew() (Jam, func()) {
	if len(os.Args) > 1 {
		panic("running with input file path is not supported")
	}

	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

	var writer = bufio.NewWriter(os.Stdout)
	jam := &jam{scanner, writer}
	return jam, jam.Close
}

type jam struct {
	sc *bufio.Scanner
	wr *bufio.Writer
}

func (j *jam) Close() {
	if err := j.wr.Flush(); err != nil {
		panic(err)
	}
}

func (j *jam) Scanner() *bufio.Scanner {
	return j.sc
}

func (j *jam) Writer() *bufio.Writer {
	return j.wr
}

func (j *jam) Str() string {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	return j.sc.Text()
}

func (j *jam) Int() int64 {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(j.sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}

	return res
}

func (j *jam) Float() float64 {
	j.sc.Scan()
	res, err := strconv.ParseFloat(j.sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (j *jam) P(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
}

func (j *jam) PF(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
	if err = j.wr.Flush(); err != nil {
		panic(err)
	}
}

type UnionFind struct {
	parent []uint32
	size   []uint32
	count  uint32
}

func UnionFindNew(count uint32) *UnionFind {
	parent := make([]uint32, count, count)
	size := make([]uint32, count, count)
	lim := count
	for i := uint32(0); i < lim; i++ {
		parent[i], size[i] = i, 1
	}
	return &UnionFind{parent, size, lim}
}

func (ufp *UnionFind) Reset() {
	lim := uint32(len(ufp.parent))
	for i := uint32(0); i < lim; i++ {
		ufp.parent[i], ufp.size[i] = i, 1
	}
	ufp.count = lim
}

func (ufp *UnionFind) validate(p uint32) {
	n := uint32(len(ufp.parent))
	if p >= n {
		panic(fmt.Sprintf("index %d is not between 0 and %d", p, n-1))
	}
}

func (ufp *UnionFind) Count() uint32 {
	return ufp.count
}

func (ufp *UnionFind) Find(p uint32) uint32 {
	// ufp.validate(p)

	root := p
	for root != ufp.parent[root] {
		root = ufp.parent[root]
	}
	for p != root {
		newp := ufp.parent[p]
		ufp.parent[p] = root
		p = newp
	}

	return root
}

func (ufp *UnionFind) Size(p uint32) uint32 {
	return ufp.size[ufp.Find(p)]
}

func (ufp *UnionFind) Connected(p, q uint32) bool {
	return ufp.Find(p) == ufp.Find(q)
}

func (ufp *UnionFind) Union(p, q uint32) {
	rootP := ufp.Find(p)
	rootQ := ufp.Find(q)

	if rootP == rootQ {
		return
	}

	if ufp.size[rootP] < ufp.size[rootQ] {
		ufp.parent[rootP] = rootQ
		ufp.size[rootQ] += ufp.size[rootP]
	} else {
		ufp.parent[rootQ] = rootP
		ufp.size[rootP] += ufp.size[rootQ]
	}

	ufp.count -= 1
}

package main

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

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

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

var (
	mm []int
	size []int
)

func main(){
	defer writer.Flush();

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

	mm = make([]int, n+1);
	size = make([]int, n+1);

	for i := 1; i <= n; i++ {
		mm[i] = i;
		size[i] = 1;
	}

	for ; m > 0; m-- {
		var k int;
		scanf("%d", &k);
		root := -1;
		for ; k > 0; k-- {
			var v int;
			scanf("%d", &v);
			if root == -1 {
				root = v;
			} else {
				merge(v, root);
			}
		}
		scanf("\n");
	}

	for i := 1; i <= n; i++ {
		printf("%d ", size[find(i)]);
	}
}

//	finds the root of the union
func find(x int) int {
	if mm[x] == x {
		return x;
	}
	mm[x] = find(mm[x]);
	return mm[x];
}

func merge(x, y int) {
	x, y = find(x), find(y);
	if x != y {
		mm[x] = y;
		size[y] += size[x];
	}
}

package main

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

func solve() {
	n := readInt()
	m := readInt()
	g := make([][]int, n+m)
	for i := 0; i < n+m; i++ {
		g[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		k := readInt()
		a := readIntArray(k)
		for _, u := range a {
			u--
			g[n+i] = append(g[n+i], u)
			g[u] = append(g[u], n+i)
		}
	}
	vis := make([]bool, len(g))
	colors := make([]int, len(g))
	colorsSize := make([]int, len(g))
	color := 0
	for i := 0; i < n; i++ {
		if !vis[i] {
			color++
			colorsSize[color] = dfs(g, vis, i, n, colors, color)
		}
	}
	a := make([]string, n)
	for i := 0; i < n; i++ {
		if !vis[i] {
			a[i] = "1"
		} else {
			a[i] = strconv.Itoa(colorsSize[colors[i]])
		}
	}

	fmt.Println(strings.Join(a, " "))
}

func dfs(g [][]int, vis []bool, u int, n int, colors []int, color int) int {
	vis[u] = true
	colors[u] = color
	ans := 0
	if u < n {
		ans++
	}
	for _, v := range g[u] {
		if !vis[v] {
			ans += dfs(g, vis, v, n, colors, color)
		}
	}
	return ans

}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

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

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

var mm []int
var size []int

func main() {
	defer writer.Flush()

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

	mm = make([]int, n+1)
	size = make([]int, n+1)

	for i := 1; i <= n; i++ {
		mm[i] = i
		size[i] = 1
	}

	for ; m > 0; m-- {
		var k int
		scanf("%d", &k)

		root := -1
		for ; k > 0; k-- {
			var v int
			scanf("%d", &v)

			if root == -1 {
				root = v
			} else {
				merge(v, root)
			}

		}
		scanf("\n")
	}

	for i := 1; i <= n; i++ {
		printf("%d ", size[find(i)])
	}
}

func find(x int) int {
	if mm[x] == x {
		return x
	}
	mm[x] = find(mm[x])
	return mm[x]
}

func merge(x, y int) {
	x, y = find(x), find(y)
	if x != y {
		mm[x] = y
		size[y] += size[x]
	}
}

package main

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

func dsuGet(p []int, v int) int {
	if v == p[v] {
		return v
	}
	p[v] = dsuGet(p, p[v])
	return p[v]
}

func dsuUnite(p, s []int, a, b int) {
	a = dsuGet(p, a)
	b = dsuGet(p, b)
	if a != b {
		if s[a] < s[b] {
			a, b = b, a
		}
		p[b] = a
		s[a] += s[b]
	}
}

func main() {

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

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

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

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

	for i := 0; i < n; i++ {
		p[i] = i
		s[i] = 1
	}

	for i := 0; i < m; i++ {
		var k int
		fmt.Fscanf(reader, "%d", &k)
		var f int
		for j := 0; j < k; j++ {
			var c int
			fmt.Fscanf(reader, "%d", &c)
			c--
			if j == 0 {
				f = c
			}
			dsuUnite(p, s, f, c)
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%d ", s[dsuGet(p, i)])
	}

	writer.Flush()
}

package main

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

func initt(parent []int, count []int) {
	for i := 0; i < len(parent); i++ {
		parent[i] = i
	}
	for i := 0; i < len(count); i++ {
		count[i] = 1
	}
}

func find(parent []int, c int) int {
	if c == parent[c] {
		return c
	}
	parent[c] = find(parent, parent[c])
	return parent[c]
}

func merge(parent []int, count []int, x int, y int) {
	px := find(parent, x)
	py := find(parent, y)

	if px != py {
		parent[px] = py
		count[py] = count[py] + count[px]
	}
}

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

func main() {
	defer writer.Flush()

	n := 0
	m := 0

	// os.Stdin = os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")

	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	parent := make([]int, n+1)
	count := make([]int, n+1)

	initt(parent, count)

	for ; m != 0; m-- {
		k := 0
		first := 0
		fmt.Fscanf(reader, "%d", &k)

		for i := 0; i < k; i++ {
			ki := 0
			fmt.Fscanf(reader, "%d", &ki)
			if i == 0 {
				first = ki
			} else {
				merge(parent, count, first, ki)
			}
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 1; i <= n; i++ {
		str := ""
		if i == n {
			str = "%d\n"
		} else {
			str = "%d "
		}
		fmt.Fprintf(writer, str, count[find(parent, i)])
	}
}

package main

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

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

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

var mm []map[int]struct{}

func main() {
	defer writer.Flush()

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

	mm = make([]map[int]struct{}, 0)

	for ; m > 0; m-- {
		var k int
		scanf("%d", &k)

		x := make(map[int]struct{})
		for ; k > 0; k-- {
			var v int
			scanf("%d", &v)

			x[v] = struct{}{}
		}
		scanf("\n")

		found := false
		for k, em := range mm {
			for v := range x {
				if _, ok := em[v]; ok {
					for v := range x {
						mm[k][v] = struct{}{}
					}
					found = true
					break
				}
			}
		}

		if !found {
			mm = append(mm, x)
		}
	}

	for i := 1; i <= n; i++ {
		found := false
		for _, v := range mm {
			if _, ok := v[i]; ok {
				found = true
				printf("%d ", len(v))
				break
			}
		}

		if !found {
			printf("0 ")
		}
	}
	printf("\n")
}

package main

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

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

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

var mm map[int]int

func main() {
	defer writer.Flush()

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

	mm = make(map[int]int)
	ans := make(map[int]map[int]struct{})

	for ; m > 0; m-- {
		var k int
		scanf("%d", &k)

		root := -1
		for ; k > 0; k-- {
			var v int
			scanf("%d", &v)

			if root == -1 {
				root = v
			}
			mm[v] = root
		}
		scanf("\n")
	}

	for k := range mm {
		if _, ok := ans[find(k)]; !ok {
			ans[find(k)] = map[int]struct{}{}
		}
		ans[find(k)][k] = struct{}{}
	}

	for i := 1; i <= n; i++ {
		if _, ok := ans[find(i)]; ok {
			printf("%d ", len(ans[find(i)]))
			continue
		}
		printf("1 ")
	}
	printf("\n")
}

func find(x int) int {
	if mm[x] == x {
		return x
	}
	mm[x] = find(mm[x])
	return mm[x]
}

package main

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

func dsuGet(p []int, v int) int {
	if v == p[v] {
		return v
	}
	p[v] = dsuGet(p, p[v])
	return p[v]
}

func dsuUnite(p, s []int, a, b int) {
	a = dsuGet(p, a)
	b = dsuGet(p, b)
	if a < b {
		if s[a] < s[b] {
			a, b = b, a
		}
		p[b] = a
		s[a] += s[b]
	}
}

func main() {

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

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

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

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

	for i := 0; i < n; i++ {
		p[i] = i
		s[i] = 1
	}

	for i := 0; i < m; i++ {
		var k int
		fmt.Fscanf(reader, "%d", &k)
		var f int
		for j := 0; j < k; j++ {
			var c int
			fmt.Fscanf(reader, "%d", &c)
			c--
			if j == 0 {
				f = c
			}
			dsuUnite(p, s, f, c)
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%d ", s[dsuGet(p, i)])
	}

	writer.Flush()
}

package main

import (
	"fmt"
)

func initt(parent []int, count []int) {
	for i := 0; i < len(parent); i++ {
		parent[i] = i
	}
	for i := 0; i < len(count); i++ {
		count[i] = 1
	}
}

func find(parent []int, c int) int {
	cp := parent[c]
	if cp != c {
		ca := find(parent, cp)
		parent[cp] = ca
	}
	return parent[cp]
}

func merge(parent []int, count []int, x int, y int) {
	px := find(parent, x)
	py := find(parent, y)

	if px != py {
		parent[px] = py
		count[py] = count[py] + count[px]
	}
}

func main() {
	n := 0
	m := 0
	fmt.Scanf("%d %d\n", &n, &m)
	parent := make([]int, n+1)
	count := make([]int, n+1)

	initt(parent, count)

	for ; m != 0; m-- {
		k := 0
		first := 0
		fmt.Scanf("%d", &k)
		for i := 0; i < k; i++ {
			ki := 0
			fmt.Scanf("%d", &ki)
			if i == 0 {
				first = ki
			} else {
				merge(parent, count, first, ki)
			}
		}
	}

	for i := 1; i <= n; i++ {
		str := ""
		if i == n {
			str = "%d\n"
		} else {
			str = "%d "
		}
		fmt.Printf(str, count[find(parent, i)])
	}
}

package main

import (
	"fmt"
	"os"
	"syscall"
)

func initt(parent []int, count []int) {
	for i := 0; i < len(parent); i++ {
		parent[i] = i
	}
	for i := 0; i < len(count); i++ {
		count[i] = 1
	}
}

func find(parent []int, c int) int {
	cp := parent[c]
	if cp != c {
		ca := find(parent, cp)
		parent[cp] = ca
	}
	return parent[cp]
}

func merge(parent []int, count []int, x int, y int) {
	px := find(parent, x)
	py := find(parent, y)

	if px != py {
		parent[px] = py
		count[py] = count[py] + count[px]
	}
}

func main() {
	n := 0
	m := 0

	os.Stdin = os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")

	fmt.Scanf("%d %d\n", &n, &m)
	parent := make([]int, n+1)
	count := make([]int, n+1)

	initt(parent, count)

	for ; m != 0; m-- {
		k := 0
		first := 0
		fmt.Scanf("%d", &k)
		for i := 0; i < k; i++ {
			ki := 0
			if i == k-1 {
				fmt.Scanf("%d\n", &ki)
			} else {
				fmt.Scanf("%d", &ki)
			}
			if i == 0 {
				first = ki
			} else {
				merge(parent, count, first, ki)
			}
		}
	}

	for i := 1; i <= n; i++ {
		str := ""
		if i == n {
			str = "%d\n"
		} else {
			str = "%d "
		}
		fmt.Printf(str, count[find(parent, i)])
	}
}


package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		a, b := readTwoNums(reader)
		res := solve(a, b)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(a, b int) int {
	x := a & b
	return a ^ x + b ^ x
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func solve(a, b int) int {
  res := 0.0
  for i := 0; i < 32; i++ {
    mask := 1 << i
    if a & mask != 0 && b & mask != 0 {
      res += math.Pow(2, float64(i))
    }
  }
  return a^int(res) + b^int(res)
}

func main() {
  defer writer.Flush()
  var test int
  scanf("%d\n", &test)
  for t := 0; t < test; t++ {
    var a, b int
    scanf("%d %d\n", &a, &b)
    printf("%d\n", solve(a, b))
  }
}

package main

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

func main() {
	var a, b, t int

	scanner := bufio.NewScanner(os.Stdin)

	if scanner.Scan() {
		line := scanner.Text()
		if len(line) > 0 {
			fmt.Sscanf(line, "%d", &t)
		}
	}

	for scanner.Scan() && t > 0 {
		line := scanner.Text()
		if len(line) >  0 {
			fmt.Sscanf(line, "%d %d", &a, &b)
			fmt.Println(a ^ b)
			t -= 1
		}
	}

}

package main

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

var _r = bufio.NewReader(os.Stdin)
var _w = bufio.NewWriter(os.Stdout)

var T, a, b int

func check(x int, pos int) bool {
	return (x & (1 << pos)) > 0
}
func main() {
	for _, _ = fmt.Fscan(_r, &T); T > 0; T-- {
		_, _ = fmt.Fscan(_r, &a, &b)
		ans := 0
		for i := 0; i <= 30; i++ {
			if check(a, i) && check(b, i) {
				ans = ans | (1 << i)
			}
		}
		_, _ = fmt.Fprintln(_w, (ans^a)+(ans^b))
		_ = _w.Flush()
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		a, b := ReadInt(), ReadInt()
		println(a ^ b)
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

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, a, b int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b)
		Fprintln(out, (a^a&b)+(b^a&b))
	}
}

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, a, b int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b)
		Fprintln(out, a^b)
	}
}

package main

import "fmt"

func main() {
	var a, b, t, ret int
	ret, err := fmt.Scanf("%d", &t)

	if err != nil || ret != 1 {
		fmt.Println("Error:", err)
	}

	for i := 0; i < t; i++ {
		ret, err = fmt.Scanf("%d %d", &a, &b)
		if err == nil && ret == 2 {
			fmt.Println(a ^ b)
		} else {
			fmt.Println("Error:", err)
		}
	}
}


package main

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

var (
	idToC = []rune{rune('S'), rune('R'), rune('G'), rune('B')}
	cToId = map[rune]int{rune('R'): 1, rune('G'): 2, rune('B'): 3}
)

func gotXor(a rune, b rune) rune {
	aid := cToId[a]
	bid := cToId[b]
	return idToC[aid^bid]
}

func gotNext(a rune) rune {
	aid := cToId[a]
	naid := aid + 1
	if naid > 3 {
		naid = 1
	}
	return idToC[naid]
}

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

	var n int
	fmt.Fscanln(reader, &n)
	rs, _ := reader.ReadString('\n')
	s := []rune(rs)

	m := 0
	i := 0
	for i < n-1 {
		if s[i] == s[i+1] {
			m++
			if i < n-2 {
				if s[i] != s[i+2] {
					s[i+1] = gotXor(s[i], s[i+2])
				} else {
					s[i+1] = gotNext(s[i])
				}
				i += 2
			} else {
				s[i+1] = gotNext(s[i])
				break
			}
		} else {
			i++
		}
	}
	fmt.Println(m)
	fmt.Println(string(s))
}

package main

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

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	var s [2e5 + 10]int
	var ss string
	//t := time.Now()
	//fmt.Println(t)
	//fmt.Scanf("%s", &ss)
	ss, _ = ReadLine()

	for i := 0; i < T; i++ {
		//var c int
		//fmt.Scanf("%c", &c)
		c := ss[i]
		if c == 'R' {
			s[i] = 0
		} else if c == 'G' {
			s[i] = 1
		} else if c == 'B' {
			s[i] = 2
		}
	}
	//t = time.Now()
	//fmt.Println(t)
	ans := 0
	for e := range ss {
		if e == 0 {
			continue
		}

		if s[e] == s[e-1] {
			ans ++
			s[e] = change(&s, e, T)
		}
	}

	fmt.Printf("%d\n", ans)
	for i := 0; i < T; i++ {
		if s[i] == 0 {
			fmt.Printf("R")
		}
		if s[i] == 1 {
			fmt.Printf("G")
		}
		if s[i] == 2 {
			fmt.Printf("B")
		}
	}
	fmt.Printf("\n")
	//t = time.Now()
	//fmt.Println(t)
}

func ReadLine() (string, error) {
	line, err := bufio.NewReader(os.Stdin).ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimSpace(string(line)), nil
}

func change(s *[2e5 + 10]int, e int, leng int) int {
	cc := []int{0, 0, 0}
	cc[s[e-1]] = 1
	if e+1 < leng {
		cc[s[e+1]]=1
	}
	for e := range cc {
		if cc[e] == 0{
			return e
		}
	}
	return 0
}

package main

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

var (

)

func to(t byte) int {
	if t == 'R' {
		return 0
	} else if t == 'B' {
		return 1
	} else {
		return 2
	}
}
func next(v int) {

}
func solveD(s []byte, n int,dp,from [][]int) {
	dp[0][0] = 1
	dp[0][1] = 1
	dp[0][2] = 1
	dp[0][to(s[0])] = 0;
	for i := 1; i < n; i++ {
		for j := 0; j < 3; j++ {
			add := 0
			if j != to(s[i]) {
				add++
			}
			pre1 := (j + 1) % 3
			pre2 := (pre1 + 1) % 3
			if dp[i-1][pre1] < dp[i-1][pre2] {
				dp[i][j] = dp[i-1][pre1] + add
				from[i][j] = pre1
			} else {
				dp[i][j] = dp[i-1][pre2] + add
				from[i][j] = pre2
			}
		}
	}
}
func toC(v int)byte  {
	if v == 0{
		return 'R'
	}else if v==1{
		return 'B'
	}else {
		return 'G'
	}
}
func anstr(pre,n int,from [][]int) []byte {
	res := make([]byte,n)
	for i:= n-1;i >= 0;i--{
		res[i] = toC(pre)
		pre = from[i][pre]
	}
	return res
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	str := make([]byte, n+1)
	fmt.Fscanf(buf, "%s\n", &str)

	dp :=make([][]int,n)
	from := make([][]int,n)
	for i:= 0;i < n;i++{
		dp[i] = make([]int,3)
		from[i] = make([]int,3)
	}

	solveD(str,n,dp,from)
	end := 0
	for i:= 1;i < 3;i++{
		if dp[n-1][end] > dp[n-1][i]{
			end = i
		}
	}
	fmt.Printf("%d\n", dp[n-1][end])
	fmt.Printf("%s\n", anstr(end,n,from))
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)
var st = [3]byte{'R', 'G', 'B'}

func main() {
	var n int
	fmt.Fscan(in, &n)
	var ans = make([]byte, n, n)
	fmt.Fscan(in, &ans)
	cnt := 0
	for i := 0; i < len(ans)-1; i++ {
		if ans[i] == ans[i+1] {
			for _, ch := range st {
				if ch != ans[i] && ((i != len(ans)-2 && ch != ans[i+2]) || i == len(ans)-2) {
					ans[i+1] = ch
					cnt++
					break
				}
			}
		}
	}
	fmt.Printf("%d\n%s\n", cnt, ans)
}


package main
import (
    "fmt"
)

func getResult(vec []string, c chan string) {
    str := fmt.Sprintln(len(vec))
    for _, a := range(vec) {
        str += fmt.Sprintln(a)
    }
    c <- str
}

func main() {
    var H1, a1, c1 int
    fmt.Scan(&H1, &a1, &c1);
    var H2, a2 int;
    fmt.Scan(&H2, &a2);

    h1 := H1
    h2 := H2
    vec := make([]string, 0)
    for {
        switch {
            case a1 >= h2: // last attack
                vec = append(vec, "STRIKE")
                c := make(chan string)
                go getResult(vec, c)
                fmt.Println(<-c)
                return;
            case a2 >= h1: // heal
                vec = append(vec, "HEAL")
                h1 += c1
                h1 -= a2; // be attacked
            default: // normal attack
                vec = append(vec, "STRIKE");
                h2 -= a1;
                h1 -= a2;
        }
    }

}

package main

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

func solve() {
	h1 := readInt()
	a1 := readInt()
	c1 := readInt()
	h2 := readInt()
	a2 := readInt()

	for i := 0; ; i++ {
		a, v := runGame(h1, a1, c1, h2, a2, i)
		if !v {
			continue
		}
		fmt.Println(len(a))
		for _, isattack := range a {
			if isattack {
				fmt.Println("STRIKE")
			} else {
				fmt.Println("HEAL")
			}
		}
		break
	}
}

func runGame(h1, a1, c1, h2, a2, nheals int) (attacks []bool, success bool) {
	attacks = make([]bool, 0, 1000)
	for {
		if nheals > 0 {
			// Heal
			h1 += c1
			attacks = append(attacks, false)
			nheals--
		} else {
			// Attack
			h2 -= a1
			attacks = append(attacks, true)
		}

		// monster dies
		if h2 <= 0 {
			return attacks, true
		}

		// monster attacks
		h1 -= a2
		if h1 <= 0 {
			return attacks, false
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"fmt"
)

func main() {
	var h1, a1, c1, h2, a2 int
	fmt.Scan(&h1, &a1, &c1)
	fmt.Scan(&h2, &a2)
	var ans []string
	for h2 > 0 {
		if h1 <= a2 && h2 > a1 {
			h1 += c1
			h1 -= a2
			ans = append(ans, "HEAL")
		} else {
			h2 -= a1
			h1 -= a2
			ans = append(ans, "STRIKE")
		}
	}
	fmt.Println(len(ans))
	for _, val := range ans {
		fmt.Println(val)
	}
}

package main

import "fmt"

var ans []string
var h1, a1, c1, h2, a2, ret int

func main() {
  fmt.Scan(&h1)
  fmt.Scan(&a1)
  fmt.Scan(&c1)
  fmt.Scan(&h2)
  fmt.Scan(&a2)
  for true {
    ret++
    if a1 >= h2 {
      ans = append(ans, "STRIKE")
      break
    }
    if a2 >= h1 {
      ans = append(ans, "HEAL")
      h1 += c1 - a2
    } else {
      ans = append(ans, "STRIKE")
      h1 -= a2
      h2 -= a1
    }
  }
  fmt.Println(ret)
  for i := 0; i < ret; i++ {
    fmt.Println(ans[i])
  }
}

package main
import (
    "fmt"
)

func printResult(vec []string) {
    fmt.Println(len(vec))
    for _, a := range(vec) {
        fmt.Println(a)
    }
}

func main() {
    var H1, a1, c1 int
    fmt.Scan(&H1, &a1, &c1);
    var H2, a2 int;
    fmt.Scan(&H2, &a2);

    h1 := H1
    h2 := H2
    vec := make([]string, 0)
    for {
        switch {
            case a1 >= h2: // last attack
                vec = append(vec, "STRIKE")
                printResult(vec)
                return;
            case a2 >= h1: // heal
                vec = append(vec, "HEAL")
                h1 += c1
                h1 -= a2; // be attacked
            default: // normal attack
                vec = append(vec, "STRIKE");
                h2 -= a1;
                h1 -= a2;
        }
    }

}

package main
import (
    "fmt"
    "bytes"
)

func getResult(vec []string, c chan string) {
    var buf bytes.Buffer
    buf.WriteString(fmt.Sprintln(len(vec)))
    for _, a := range(vec) {
        buf.WriteString(fmt.Sprintln(a))
    }
    //c <- string(buf.Bytes())
    c <- buf.String()
}

func main() {
    var H1, a1, c1 int
    fmt.Scan(&H1, &a1, &c1);
    var H2, a2 int;
    fmt.Scan(&H2, &a2);

    h1 := H1
    h2 := H2
    vec := make([]string, 0)
    for {
        switch {
            case a1 >= h2: // last attack
                vec = append(vec, "STRIKE")
                c := make(chan string)
                go getResult(vec, c)
                fmt.Println(<-c)
                return;
            case a2 >= h1: // heal
                vec = append(vec, "HEAL")
                h1 += c1
                h1 -= a2; // be attacked
            default: // normal attack
                vec = append(vec, "STRIKE");
                h2 -= a1;
                h1 -= a2;
        }
    }

}

//  URL: http://codeforces.com/contest/903/problem/B
//  ~ Greedy Implementation Problem

package main

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

func solve(h1 int, a1 int, c1 int, h2 int, a2 int) []string {
	var actions = []string{}
	for h2 > 0 {
		if h1 <= a2 && h2 > a1 {
			actions = append(actions, "HEAL")
			h1 += c1
		} else {
			actions = append(actions, "STRIKE")
			h2 -= a1
		}
		h1 -= a2
	}
	return actions
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var h1, a1, c1 int
	fmt.Fscanf(reader, "%d %d %d\n", &h1, &a1, &c1)
	var h2, a2 int
	fmt.Fscanf(reader, "%d %d\n", &h2, &a2)
	actions := solve(h1, a1, c1, h2, a2)
	fmt.Fprintf(writer, "%d\n", len(actions))
	for i := 0; i < len(actions); i++ {
		fmt.Fprintf(writer, "%s\n", actions[i])
	}
}

package main
import "fmt"

func main(){
	var h1,a1,c1,h2,a2 int
	fmt.Scan(&h1, &a1, &c1, &h2, &a2)
	save:= make([]string,10000)
	var c int

	for h2>0 {
		if h1>a2 {
			save[c]="STRIKE"
			c++
			h2-=a1
			h1-=a2
		} else {
			if a1>=h2 {
				save[c]="STRIKE"
				c++
				h2-=a1
				h1-=a2
				break
			} else {
				save[c]="HEAL"
				c++
				h1+=c1
				h1-=a2
			}
		}
	}
	fmt.Println(c)
	for i:=0;i<c;i++ {
		fmt.Println(save[i])
	}
}

package main
import "fmt"

func main(){
	var h1,a1,c1,h2,a2 int
	fmt.Scan(&h1, &a1, &c1, &h2, &a2)
	save:= make([]string,100)
	var c int
	h:=h1

	for h2>0 {
		if h1>a2 {
			save[c]="STRIKE"
			c++
			h2-=a1
			h1-=a2
		} else if h1<=a2 {
			if a1>=h2 {
				save[c]="STRIKE"
				c++
				break
			} else {
				save[c]="HEAL"
				c++
				if h1+c1>=h {
					h1=h
				} else {h1+=c1}
			}
		}
	}
	fmt.Println(c)
	for i:=0;i<c;i++ {
		fmt.Println(save[i])
	}
}

package main

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

func solve() {
	h1 := readInt()
	a1 := readInt()
	c1 := readInt()
	h2 := readInt()
	a2 := readInt()

	for i := 0; ; i++ {
		a, v := runGame(h1, a1, c1, h2, a2, i)
		if !v {
			continue
		}
		for _, isattack := range a {
			if isattack {
				fmt.Println("STRIKE")
			} else {
				fmt.Println("HEAL")
			}
		}
		break
	}
}

func runGame(h1, a1, c1, h2, a2, nheals int) (attacks []bool, success bool) {
	attacks = make([]bool, 0, 1000)
	for {
		if nheals > 0 {
			// Heal
			h1 += c1
			attacks = append(attacks, false)
			nheals--
		} else {
			// Attack
			h2 -= a1
			attacks = append(attacks, true)
		}

		// monster dies
		if h2 <= 0 {
			return attacks, true
		}

		// monster attacks
		h1 -= a2
		if h1 <= 0 {
			return attacks, false
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"fmt"
)

func main() {
	var h1, a1, c1, h2, a2 int
	fmt.Scan(&h1, &a1, &c1)
	fmt.Scan(&h2, &a2)
	var ans []string
	for h2 >= 0 {
		if h1 <= a2 {
			h1 += c1
			h1 -= a2
			ans = append(ans, "HEAL")
		} else {
			h2 -= a1
			h1 -= a2
			ans = append(ans, "STRIKE")
		}
	}
	fmt.Println(len(ans))
	for _, val := range ans {
		fmt.Println(val)
	}
}

package main

import (
	"fmt"
)

func main() {
	var h1, a1, c1, h2, a2 int
	fmt.Scan(&h1, &a1, &c1)
	fmt.Scan(&h2, &a2)
	var ans []string
	for h2 > 0 {
		if h1 <= a2 {
			h1 += c1
			h1 -= a2
			ans = append(ans, "HEAL")
		} else {
			h2 -= a1
			h1 -= a2
			ans = append(ans, "STRIKE")
		}
	}
	fmt.Println(len(ans))
	for _, val := range ans {
		fmt.Println(val)
	}
}


package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var odd, even []int

		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				odd = append(odd, x)
			} else {
				even = append(even, x)
			}
		}

		if ok(odd) && ok(even) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func ok(a []int) bool {
	for i := 1; i < len(a); i++ {
		if a[i] < a[i-1] {
			return false
		}
	}
	return true
}

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var odd, even []int

		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				odd = append(odd, x)
			} else {
				even = append(even, x)
			}
		}

		if ok(odd) && ok(even) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

func ok(a []int) bool {
	for i := 1; i < len(a); i++ {
		if a[i] < a[i-1] {
			return false
		}
	}
	return true
}

package main

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

var a [1e5 + 5]int

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	var t, n int
	var flag bool
	var Odd, Even int
	for t = read(); t > 0; t-- {
		n = read()
		flag = false
		Odd, Even = 0, 0
		for i := 1; i <= n; i++ {
			a[i] = read()
		}
		for i := 1; i <= n; i++ {
			if a[i]&1 == 1 {
				if a[i] < Odd {
					flag = true
					break
				}
				Odd = a[i]
			} else {
				if a[i] < Even {
					flag = true
					break
				}
				Even = a[i]
			}
		}
		if flag {
			Fprintln(out, "No")
		} else {
			Fprintln(out, "Yes")
		}
	}
}

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

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		flag := true
		odd := 0
		even := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if !flag {
				continue
			}

			if x&1 == 1 {
				if odd > x {
					flag = false
				} else {
					odd = x
				}
			} else {
				if even > x {
					flag = false
				} else {
					even = x
				}
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		flag := true
		odd := 0
		even := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				if odd > x {
					flag = false
				} else {
					odd = x
				}
			} else {
				if even > x {
					flag = false
				} else {
					even = x
				}
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

//nolint
package main

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

func Main() {
	var t, n, tp int
	scan(&t)
	for ; t > 0; t-- {
		maxOdd, maxEven := 0, 0
		scan(&n)
		possible := true
		for ; n > 0; n-- {
			scan(&tp)
			if tp%2 == 1 {
				if tp >= maxOdd {
					maxOdd = tp
				} else {
					possible = false
				}
				continue
			}
			if tp >= maxEven {
				maxEven = tp
			} else {
				possible = false
			}
		}
		if possible {
			println("yes")
		} else {
			println("no")
		}
	}
}

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

package main

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

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

1 2 4 5 5

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

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

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

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

		a := make([]int, n)

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

		ans := "YES"

		prevOdd := -1
		prevEven := -1

		for _, num := range a {
			if (num%2 != 0 && num < prevOdd) || (num%2 == 0 && num < prevEven) {
				ans = "NO"
				break
			}

			if num%2 != 0 {
				prevOdd = num
			}

			if num%2 == 0 {
				prevEven = num
			}
		}

		fmt.Fprintln(writer, ans)
	}
}

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 int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

//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
    Fscanf(read, "%d\n", &tc)

    for tt := 0; tt < tc; tt++ {
        var n int
        Fscanf(read, "%d\n", &n)

        ok := true
        last_odd, last_even := 0, 0
        for i := 0; i < n; i++ {
            var val int
            Fscanf (read, "%d", &val)
            if val % 2 == 1 {
                if val < last_odd {
                    ok = false
                } else {
                    last_odd = val
                }
            } else{
                if val < last_even {
                    ok = false
                } else {
                    last_even = val
                }
            }
        }
        Fscanf(read, "\n")
        if ok {
            Fprintln(write, "Yes")
        } else{
            Fprintln(write, "No")
        }
    }

}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	t := readInt(in)
	for ; t != 0; t-- {
		solve()
	}
}

func solve() {
	n := readInt(in)
	a := readArrInt(in)
	last := 0
	flag := true
	for i := 0; i < n; i++ {
		if a[i]%2 == 0 {
			if a[i] >= last {
				last = a[i]
			} else {
				flag = false
			}
		}
	}
	last = 0
	for i := 0; i < n; i++ {
		if a[i]%2 == 1 {
			if a[i] >= last {
				last = a[i]
			} else {
				flag = false
			}
		}
	}
	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

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

	var n, t int
	arr := make([]int, int(1e5))
Outer:
	for Fscan(in, &t); t > 0; t-- {
		odd, even := -1, -1
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
		}
		for i := 0; i < n; i++ {
			if arr[i]&1 == 1 {
				if arr[i] < odd {
					Fprintln(out, "No")
					continue Outer
				}
				odd = arr[i]
			} else {
				if arr[i] < even {
					Fprintln(out, "No")
					continue Outer
				}
				even = arr[i]
			}
		}
		Fprintln(out, "Yes")
	}
}

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

package main

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

var rdr *bufio.Reader = bufio.NewReader(os.Stdin)
var wr *bufio.Writer = bufio.NewWriter(os.Stdout)

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

func Scanf(f string, a ...interface{}) {
	fmt.Fscanf(rdr, f, a...)
}

func Flush() {
	wr.Flush()
}

func main() {
	defer Flush()

	var t, n, ib, pb, x int;
	var able bool;
	Scanf("%d\n", &t);

	for ab := 0; ab < t; ab++{
		Scanf("%d\n", &n);
		ib, pb = -1, -1;
		able = true;

		for i := 0; i < n - 1; i++{
			Scanf("%d ", &x);
			if((x & 1) == 1){
				if(ib > x){
					able = false;
				}
				ib = x;
			}else{
				if(pb > x){
					able = false;
				}
				pb = x;
			}
		}

		Scanf("%d\n", &x);
		if((x & 1) == 1){
			if(ib > x){
				able = false;
			}
			ib = x;
		}else{
			if(pb > x){
				able = false;
			}
			pb = x;
		}

		if(able){
			Printf("yes\n");
		} else{
			Printf("no\n");
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a, b := make([]int, n), make([]int, n)
		for i := 0; i < n; i++{
			var x int
			Fscan(r, &x)
			if x%2 != 0 {
				a = append(a, x)
			} else {
				b = append(b, x)
			}
		}
		if sort.IntsAreSorted(a) && sort.IntsAreSorted(b) {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

//B.

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-- {
		var n int
		fmt.Fscan(in, &n)
		numsA := make([]int, n)
		var curMaxOdd, curMaxEven int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &numsA[i])
		}
		var isNo bool
		for i := 0; i < n; i++ {
			if numsA[i]&1 == 1 {
				if numsA[i] < curMaxOdd {
					fmt.Fprintln(out, "No")
					isNo = true
					break
				}
				curMaxOdd = max(curMaxOdd, numsA[i])
			} else {
				if numsA[i] < curMaxEven {
					fmt.Fprintln(out, "No")
					isNo = true
					break
				}
				curMaxEven = max(curMaxEven, numsA[i])
			}
		}
		if isNo == false {
			fmt.Fprintln(out, "Yes")
		}
	}
}

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

package main

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

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

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

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

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

		var f bool
		var maxE, maxO int
		for i := 0; i < n; i++ {
			if arr[i]%2 == 0 {
				if arr[i] < maxE {
					f = false
					break
				}

				maxE = arr[i]
			}

			if arr[i]%2 != 0 {
				if arr[i] < maxO {
					f = false
					break
				}

				maxO = arr[i]
			}
			f = true
		}

		if !f {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
}

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var odd, even []int

		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				odd = append(odd, x)
			} else {
				even = append(even, x)
			}
		}

		if ok(odd) && ok(even) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func ok(a []int) bool {
	for i := 1; i < len(a); i++ {
		if a[i] > a[i-1] {
			return false
		}
	}
	return true
}

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		flag := true
		odd := 0
		even := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				if odd > x {
					flag = false
				} else {
					odd = x
				}
			} else {
				if even > x {
					flag = false
				} else {
					even = x
				}
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var q, n int
	fmt.Scanf("%d", &q)
	for i := 0; i < q; i++ {
		fmt.Scanf("%d", &n)
		var x int
		var odd []int
		var even []int
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &x)
			if x%2 == 0 {
				even = append(even, x)
			} else {
				odd = append(odd, x)
			}
		}

		if check(odd) && check(even) {
			fmt.Println("YES")
		} else {
			fmt.Println("No")
		}
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var q, n int
	var a [100001]int

	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[j])
		}

		flag := true
		odd := -1
		even := -2
		for j := 0; j < n && flag; j++ {
			if a[j]&1 == 1 {
				if even > a[j] {
					flag = false
				} else {
					odd = a[j]
				}
			} else {
				if odd > a[j] {
					flag = false
				} else {
					even = a[j]
				}
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		f := true
		s := make([]bool, n)
		for i := 1; i < n; i++ {
			if a[i-1] > a[i] {
				if (a[i-1]+a[i])%2 == 0 {
					f = false
					break
				} else {
					if s[i-1] {
						f = false
						break
					}
					a[i-1], a[i] = a[i], a[i-1]
					if i >= 2 && a[i-2] > a[i-1] {
						f = false
						break
					}
					s[i] = true
				}
			}
		}
		if f {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		//if n == 2 {
		//	if  a[0] > a[1] {
		//		if (a[0]+a[1])%2 == 0{
		//			Fprintln(w, "No")
		//		} else {
		//			Fprintln(w, "Yes")
		//		}
		//		continue
		//	}
		//	if a[0] <= a[1] {
		//		Fprintln(w, "Yes")
		//		continue
		//	}
		//}
		f := true
		s := make([]bool, n)
		for i := 1; i < n; i++ {
			if a[i-1] > a[i] {
				if (a[i-1]+a[i])%2 == 0 {
					f = false
					break
				} else {
					if s[i-1] {
						f = false
						break
					}
					a[i-1], a[i] = a[i], a[i-1]
					s[i] = true
				}
			}
		}
		if f {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		if n == 2 {
			if (a[0]+a[1])%2 == 0 && a[0] > a[1] {
				Fprintln(w, "No")
				continue
			}
			if a[0] <= a[1] {
				Fprintln(w, "Yes")
				continue
			}
		}
		f := true
		s := make([]bool, n)
		for i := 1; i < n; i++ {
			if a[i-1] > a[i] {
				if (a[i-1]+a[i])%2 == 0 {
					f = false
					break
				} else {
					if s[i-1] {
						f = false
						break
					}
					a[i-1], a[i] = a[i], a[i-1]
					s[i] = true
				}
			}
		}
		if f {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		if n == 1 {
			Fprintln(w, "Yes")
			continue
		}
		if n == 2 {
			if (a[0]+a[1])%2 == 0 && a[0] > a[1] {
				Fprintln(w, "No")
				continue
			}
			if a[0] <= a[1] {
				Fprintln(w, "Yes")
				continue
			}
		}
		f := true
		s := make([]bool, n)
		for i := 1; i < n; i++ {
			if a[i-1] > a[i] {
				if (a[i-1]+a[i])%2 == 0 {
					f = false
					break
				} else {
					if s[i-1] {

						f = false
						break
					}
					a[i-1], a[i] = a[i], a[i-1]
					s[i] = true
				}
			}
		}
		if f {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		if n == 1 {
			Fprintln(w, "Yes")
			continue
		}
		if n == 2 {
			if (a[0]+a[1])%2 == 0 && a[0] > a[1] {
				Fprintln(w, "No")
				continue
			}
			if a[0] <= a[1] {
				Fprintln(w, "Yes")
				continue
			}
		}
		f1 := true
		//f2 := true
		//for i := 0; i < n; i+=2 {
		//	if i + 1 < n {
		//		if a[i] > a[i+1] && (a[i] + a[i+1]) %2 == 0 {
		//			f1 = false
		//			break
		//		}
		//	}
		//}
		//
		//for i := 1; i < n; i+=2 {
		//	if i + 1 < n {
		//		if a[i] > a[i+1] && (a[i] + a[i+1]) %2 == 0 {
		//			f2 = false
		//			break
		//		}
		//	}
		//}
		for i := 1; i <= n-2; i++ {
			if a[i] < a[i-1] && a[i] < a[i + 1] && a[i-1] > a[i+1] {
				f1 = false
				break
			}
			if a[i] < a[i-1] && (a[i] + a[i-1])%2==0{

				f1 = false
			}
			if a[i] > a[i+1] && (a[i] + a[i+1])%2==0{
				f1 = false
			}
		}
		if f1  {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

//B.

//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-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		evenCnt := make([]int, n+1)
//		oddCnt := make([]int, n+1)
//		copy(numsB, numsA)
//		sort.Ints(numsB)
//		for i := 0; i < n; i++ {
//			evenCnt[i+1] = evenCnt[i]
//			oddCnt[i+1] = oddCnt[i]
//			if numsB[i]&1 == 0 {
//				evenCnt[i+1]++
//			} else {
//				oddCnt[i+1]++
//			}
//		}
//		var flag bool
//		for i:=0;i<n;i++{
//			if numsA[i] == numsB[i] {
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					break
//				}
//				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "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-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		copy(numsB, numsA)
//		sort.Ints(numsB)
//		var a, b int
//		var flag bool
//		for ; a < n && flag == false; a++ {
//			if numsA[a] == numsB[b] {
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					break
//				}
//				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "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-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		copy(numsB, numsA)
//		visB := make([]bool, n)
//		sort.Ints(numsB)
//		var a, b int
//		var flag bool
//		for ; a < n && flag == false; a++ {
//			if numsA[a] == numsB[b] {
//				visB[b] = true
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					visB[p] = true
//					break
//				}
//				if visB[p] == false && numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "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-- {
		var n int
		fmt.Fscan(in, &n)
		numsA := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &numsA[i])
		}
		numsB := make([]int, n)
		copy(numsB, numsA)
		visB := make([]bool, n)
		sort.Ints(numsB)
		var a, b int
		var flag bool
		for ; a < n && flag == false; a++ {
			if numsA[a] == numsB[b] {
				visB[b] = true
				for b < n && visB[b] == true {
					b++
				}
				continue
			}
			p := sort.SearchInts(numsB, numsA[a]) - 1
			visB[p+1] = true
			for ; p >= b; p-- {
				if visB[p] == true {
					continue
				}
				if (numsB[p]+numsA[a])&1 == 0 {
					fmt.Fprintln(out, "No")
					flag = true
					break
				}
			}
		}
		if flag == false {
			fmt.Fprintln(out, "Yes")
		}
	}
}

//B.

//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-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		evenCnt := make([]int, n+1)
//		oddCnt := make([]int, n+1)
//		copy(numsB, numsA)
//		sort.Ints(numsB)
//		for i := 0; i < n; i++ {
//			evenCnt[i+1] = evenCnt[i]
//			oddCnt[i+1] = oddCnt[i]
//			if numsB[i]&1 == 0 {
//				evenCnt[i+1]++
//			} else {
//				oddCnt[i+1]++
//			}
//		}
//		var flag bool
//		for i:=0;i<n;i++{
//			if numsA[i] == numsB[i] {
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					break
//				}
//				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "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-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		copy(numsB, numsA)
//		sort.Ints(numsB)
//		var a, b int
//		var flag bool
//		for ; a < n && flag == false; a++ {
//			if numsA[a] == numsB[b] {
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					break
//				}
//				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "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-- {
		var n int
		fmt.Fscan(in, &n)
		numsA := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &numsA[i])
		}
		numsB := make([]int, n)
		copy(numsB, numsA)
		visB := make([]bool, n)
		sort.Ints(numsB)
		var a, b int
		var flag bool
		for ; a < n && flag == false; a++ {
			if numsA[a] == numsB[b] {
				visB[b] = true
				b++
				continue
			}
			for p := b; p < n; p++ {
				if numsB[p] == numsA[a] {
					visB[p] = true
					break
				}
				if visB[p] == false && numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
					fmt.Fprintln(out, "No")
					flag = true
					break
				}
			}
		}
		if flag == false {
			fmt.Fprintln(out, "Yes")
		}
	}
}

//B.

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-- {
		var n int
		fmt.Fscan(in, &n)
		numsA := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &numsA[i])
		}
		numsB := make([]int, n)
		copy(numsB, numsA)
		sort.Ints(numsB)
		var a, b int
		var flag bool
		for ; a < n && flag == false; a++ {
			if numsA[a] == numsB[b] {
				b++
				continue
			}
			for p := b; p < n; p++ {
				if numsB[p] == numsA[a] {
					break
				}
				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
					fmt.Fprintln(out, "No")
					flag = true
					break
				}
			}
		}
		if flag == false {
			fmt.Fprintln(out, "Yes")
		}
	}
}

package main

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

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

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

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

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

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

			if arr[i]%2 != 0 && arr[i+1]%2 != 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

			if arr[i] > arr[i+1] && (arr[i]+arr[i+1])%2 != 0 {
				arr[i], arr[i+1] = arr[i+1], arr[i]

				if i > 0 && arr[i] < arr[i-1] {
					f = false
					break
				}
			}

			f = true
		}

		if !f {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
}

package main

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

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

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

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

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

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

			if arr[i]%2 != 0 && arr[i+1]%2 != 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

			if arr[i] > arr[i+1] && (arr[i]+arr[i+1])%2 != 0 {
				arr[i], arr[i+1] = arr[i+1], arr[i]
			}

			f = true
		}

		if !f {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
}

package main

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

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

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

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

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

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

			if arr[i]%2 != 0 && arr[i+1]%2 != 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

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

			f = true
		}

		if !f {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
}

package main

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

var a [1e5 + 5]int

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	var t, n int
	var flag bool
	Odd, Even := 0, 0
	for t = read(); t > 0; t-- {
		n = read()
		flag = false
		for i := 1; i <= n; i++ {
			a[i] = read()
		}
		for i := 1; i <= n; i++ {
			if a[i]&1 == 1 {
				if a[i] < Odd {
					flag = true
					break
				}
				Odd = a[i]
			} else {
				if a[i] < Even {
					flag = true
					break
				}
				Even = a[i]
			}
		}
		if flag {
			Fprintln(out, "No")
		} else {
			Fprintln(out, "Yes")
		}
	}
}

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

package main

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

var a [1e5 + 5]int

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	var t, n int
	flag := false
	Odd, Even := 0, 0
	for t = read(); t > 0; t-- {
		n = read()
		for i := 1; i <= n; i++ {
			a[i] = read()
		}
		for i := 1; i <= n; i++ {
			if a[i]&1 == 1 {
				if a[i] < Odd {
					flag = true
					break
				}
				Odd = a[i]
			} else {
				if a[i] < Even {
					flag = true
					break
				}
				Even = a[i]
			}
		}
		if flag {
			Fprintln(out, "No")
		} else {
			Fprintln(out, "Yes")
		}
	}
}

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

//nolint
package main

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

// main execution here...
func do() {
	var t, n, tp int
	scan(&t)
	for ; t > 0; t-- {
		maxOdd, maxEven := 0, 0
		scan(&n)
		for i := 0; i < n; i++ {
			scan(&tp)
			if tp%2 == 0 {
				if tp >= maxOdd {
					maxOdd = tp
				} else {
					println("no")
					break
				}
				continue
			}
			if tp >= maxEven {
				maxEven = tp
			} else {
				println("no")
				break
			}
		}
		println("yes")
	}
}

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	do()
}

package main

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

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

1 2 4 5 5

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

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

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

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

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

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

		sort.Ints(sa)

		ans := "YES"

		l := 0
		for ; l < n; l++ {
			if a[l] != sa[l] {
				break
			}
		}

		r := n - 1
		for ; r >= 0; r-- {
			if a[r] != sa[r] {
				break
			}
		}

		for i := l + 1; i <= r; i++ {
			if (a[l]+a[i])%2 == 0 {
				ans = "NO"
			}
		}

		fmt.Fprintln(writer, ans)
	}
}

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 int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

//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 (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1010)

	T := NextInt()
	a := make([][3]int, 0)
	for i := 0; i <= 1; i++ {
		for j := 0; j <= 1; j++ {
			for k := 0; k <= 1; k++ {
				if i+j+k > 0 {
					a = append(a, [3]int{i, j, k})
				}
			}
		}
	}
	dp := make([][][][]int, 11)
	for i := 0; i <= 10; i++ {
		dp[i] = make([][][]int, 11)
		for j := 0; j <= 10; j++ {
			dp[i][j] = make([][]int, 11)
			for k := 0; k <= 10; k++ {
				dp[i][j][k] = make([]int, len(a))
				for l := 0; l < len(a); l++ {
					res := 0
					if l > 0 {
						res = dp[i][j][k][l-1]
					}

					if a[l][0] <= i && a[l][1] <= j && a[l][2] <= k {
						prev := 1
						if l > 0 {
							prev = dp[i-a[l][0]][j-a[l][1]][k-a[l][2]][l-1] + 1
						}
						if res == -1 || prev > res {
							res = prev
						}
					}
					dp[i][j][k][l] = res
				}
			}
		}
	}

	for t := 0; t < T; t++ {
		aa := NextInt()
		bb := NextInt()
		cc := NextInt()
		fmt.Fprintln(out, dp[aa][bb][cc][len(a)-1])
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		t int
		a = make([]int, 3)
	)
	fmt.Scanf("%d\n", &t)
	for t != 0 {
		fmt.Scanf("%d %d %d\n", &a[0], &a[1], &a[2])
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		res := 0
		for i := 0; i < 3; i++ {
			if a[i] != 0 {
				res++
				a[i]--
			}
		}
		for i := 0; i < 3; i++ {
			for j := i + 1; j < 3; j++ {
				if a[i] != 0 && a[j] != 0 {
					res++
					a[i]--
					a[j]--
				}
			}
		}
		if a[0] != 0 && a[1] != 0 && a[2] != 0 {
			res++
		}
		//
		fmt.Println(res)
		t--
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		ans := 0
		arr := []int{a, b, c}
		sort.Sort(sort.IntSlice(arr))
		a = arr[2]
		b = arr[1]
		c = arr[0]
		if a > 0 {
			a--
			ans++
		}
		if b > 0 {
			b--
			ans++
		}
		if c > 0 {
			c--
			ans++
		}
		if a > 0 && b > 0 {
			a--
			b--
			ans++
		}
		if a > 0 && c > 0 {
			a--
			c--
			ans++
		}
		if c > 0 && b > 0 {
			c--
			b--
			ans++
		}
		if a > 0 && b > 0 && c > 0 {
			ans++
		}
		fmt.Println(ans)

	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		a, b, c := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
		if a < b {
			a, b = b, a
		}
		if a < c {
			a, c = c, a
		}
		if b < c {
			b, c = c, b
		}
		ans := 0
		if a > 0 {
			a--
			ans++
		}
		if b > 0 {
			b--
			ans++
		}
		if c > 0 {
			c--
			ans++
		}
		if a > 0 && c > 0 {
			a--
			c--
			ans++
		}
		if a > 0 && b > 0 {
			a--
			b--
			ans++
		}
		if b > 0 && c > 0 {
			b--
			c--
			ans++
		}
		if a > 0 && b > 0 && c > 0 {
			a--
			b--
			c--
			ans++
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

func main() {
	var n, a, b, c, cnt int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%v\n", &n)
	exit := make([]int, n, n)
	for i:= 0; i<n; i++ {
		cnt = 0
		fmt.Fscanf(in, "%v %v %v\n", &a, &b, &c)
		if a < b {
			a, b = b, a
		}
		if a < c {
			b, c = c, b
		}
		if a < b {
			a, b = b, a
		}
		if a>0 {
			a--
			cnt++
		}
		if b>0 {
			b--
			cnt++
		}
		if c>0 {
			c--
			cnt++
		}
		if a>0 && b>0 {
			a--
			b--
			cnt++
		}
		if a>0 && c>0 {
			a--
			c--
			cnt++
		}
		if b>0 && c>0 {
			b--
			c--
			cnt++
		}
		if a>0 && b>0 && c>0 {
			cnt++
		}
		exit[i] = cnt

	}
	for i:=0; i<n; i++ {
		fmt.Println(exit[i])
	}

}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a, b, c int
		result := 0
		fmt.Scanf("%d %d %d\n", &a, &b, &c)
		arr := []int{a,b,c}
		sort.Ints(arr)
		if arr[2] > 0 {
			arr[2]--
			result++
		}
		if arr[1] > 0 {
			arr[1]--
			result++
		}
		if arr[0] > 0 {
			arr[0]--
			result++
		}
		if arr[2]>0&&arr[1]>0 {
			arr[2]--
			arr[1]--
			result++
		}
		if arr[2]>0 && arr[0]>0 {
			arr[2]--
			arr[0]--
			result++
		}
		if arr[1]>0&&arr[0]>0 {
			arr[1]--
			arr[0]--
			result++
		}
		if arr[2]>0&&arr[1]>0&&arr[0]>0 {
			arr[2]--
			arr[1]--
			arr[0]--
			result++
		}
		fmt.Println(result)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var testCases int
	fmt.Scanf("%d\n", &testCases)
	d, c, p := 0, 0, 0
	for i:=0; i<testCases; i++ {
		fmt.Scanf("%d %d %d\n", &d, &c, &p)
		res :=solution(d,c,p)
		fmt.Println(res)
	}
}

func solution(d int,c int, p int) int  {
	var res = 0
	dishes := []int{d,c,p}
	sort.Ints(dishes)

	d,c,p = dishes[2],dishes[1],dishes[0]

	if d ==0 && c==0 && p==0 {
		return res
	}
	if d > 0 {
		res +=1
		d -=1
	}
	if c > 0 {
		res +=1
		c -=1
	}
	if p > 0 {
		res +=1
		p -=1
	}

	if d > 0 && c > 0 {
		res +=1
		d -=1
		c -=1
	}
	if d > 0 && p > 0 {
		res +=1
		d -=1
		p -=1
	}

	if c > 0 && p > 0 {
		res +=1
		c -=1
		p -=1
	}

	if d > 0 && c > 0 && p > 0 {
		res +=1
		c -=1
		p -=1
	}

	return res

}

package main

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

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

	solve := func() (ans int) {
		a := make([]int, 3)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		if a[2] == 0 {
			return
		}
		if a[1] == 0 {
			return 1
		}
		if a[0] == 0 {
			if a[1] == 1 {
				return 2
			}
			return 3
		}
		if a[0] == 1 {
			if a[1] == 1 {
				return 3
			}
			return 4
		}
		if a[0] == 2 {
			if a[1] == 2 {
				if a[2] == 2 {
					return 4
				}
			}
			return 5
		}
		if a[0] == 3 {
			return 6
		}

		return 7
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fprintln(out, solve())
	}
}

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

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
    for t := ScanInt(); t > 0; t-- {
        a, b, c := ScanInt(), ScanInt(), ScanInt()
		arr := []int{a, b, c}
		sort.Ints(arr)
		a = arr[2]
		b = arr[1]
		c = arr[0]

        count := 0

        if a > 0 {
			count++
			a--
		}
		if b > 0 {
			count++
			b--
		}
		if c > 0 {
			count++
			c--
		}

		if a > 0 && b > 0 {
			count++
			a--
			b--
		}

		if a > 0 && c > 0 {
			count++
			a--
			c--
		}
		if b>0 && c > 0 {
			count++
			b--
			c--
		}

		if a > 0 && b > 0 && c > 0 {
			count++
		}

        P(count)
    }

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string {in.Scan(); return in.Text() }
func ScanInt() int {i, _ := strconv.Atoi(ScanWord()); return i}
func ScanInt64() int64 {i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i}
func ScanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = ScanWord()}; return s}
func ScanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = ScanInt64()}; return arr}

/*********************** Utils ***********************/

func S(v interface{}) string {return fmt.Sprintf("%v", v)}
func SArr(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func MnMx(args ...int64) (int64, int64) {minVal, maxVal := MX_INT, MN_INT; for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64 {return a / GCD(a, b) * b}
func GCD(a, b int64) int64 {if (a == 0) {return b}; return GCD(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func abs(x int64) int64 {if x < 0 {return -x}; return x}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scan(&t)
	for tc := 0; tc < t; tc++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		rls := solve(a, b, c)
		fmt.Println(rls)
	}
}

func solve(a, b, c int) int {
	arr := []int{a, b, c}
	sort.Sort(sort.Reverse(sort.IntSlice(arr)))
	rls := 0
	for i := 0; i < 3; i++ {
		if arr[i] > 0 {
			rls += 1
			arr[i] -= 1
		}
	}
	for i := 0; i < 3; i++ {
		for j := i + 1; j < 3; j++ {
			if arr[i] > 0 && arr[j] > 0 {
				rls += 1
				arr[i] -= 1
				arr[j] -= 1
			}
		}
	}
	if arr[0] > 0 && arr[1] > 0 && arr[2] > 0 {
		rls += 1
	}
	return rls
}

//многогранники
package main

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

func MySort (str []string) (out []int){
	out = make([]int, 0, 3)
	var new int
	for _, j := range str{
		new, _ = strconv.Atoi(j)
		if new > 4{
			new = 4
		}
		out = append(out, new)
	}
	sort.Ints(out)
	return
}
func MyCounter(in []int)(out [3]int){
	if in[0] == in[1] && in[1] == 0{
		if in[2] == 0{
			out = [3]int{0, 0, 0}
		}else{
			out = [3]int{0, 0, 1}
		}
	}else if in[0] == 0{
		if in[1] > 1{
			out = [3]int{1, 1, 1}
		}else {
			out = [3]int{0, 1, 1}
		}
	}else if in[0] == 1{
		if in[1] == 1{
			out = [3]int{1, 1, 1}
		}else {
			out = [3]int{1, 2, 2}
		}
	}else if in[0] == 2{
		if in[2] >= 3{
			out = [3]int{2, 2, 3}
		} else{
			out = [3]int{1, 2, 2}
		}
	}else if in[0] == 3{
		out = [3]int{3, 3, 3}
	} else{
		out = [3]int{4, 4, 4}
	}
	return
 }
func main() {
	var dict map [[3]int]int = map[[3]int]int{
		{0, 0, 0}: 0,
		{0, 0, 1}: 1,
		{0, 1, 1}: 2,
		{1, 1, 1}: 3,
		{1, 2, 2}: 4,
		{2, 2, 3}: 5,
		{3, 3, 3}: 6,
		{4, 4, 4}: 7,
	}
	var line string
	var q int
	fmt.Scanln(&q)
	answer := make([]int, q, q)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < q; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		answer[i] = dict[MyCounter(MySort(strings.Split(line, " ")))]

	}
	for i:= 0; i < q; i++{
		fmt.Println(answer[i])
	}
}

/*
4
Icosahedron
Cube
Tetrahedron
Dodecahedron
42
*/

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

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

	var t int
	fmt.Fscan(r, &t)
	for i := 0; i < t; i++ {
		var a [3]int
		fmt.Fscan(r, &a[0], &a[1], &a[2])
		if a[1] > a[0] {
			a[0], a[1] = a[1], a[0]
		}
		if a[2] > a[1] {
			a[2], a[1] = a[1], a[2]
		}
		if a[1] > a[0] {
			a[0], a[1] = a[1], a[0]
		}
		cnt := 0
		for j := 1; j <= 7; j++ {
			flag := true
			for x := 0; x < 3; x++ {
				if j&(1<<x) > 0 {
					if a[x] == 0 {
						flag = false
						break
					}
				}
			}
			if flag {
				for x := 0; x < 3; x++ {
					if j&(1<<x) > 0 {
						a[x]--
					}
				}
				cnt++
			}

		}
		fmt.Fprintln(w, cnt)

	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		t int
		a = make([]int, 3)
	)
	fmt.Scanf("%d\n", &t)
	for t != 0 {
		fmt.Scanf("%d %d %d\n", &a[0], &a[1], &a[2])
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		res := 0
		for i := 0; i < 3; i++ {
			if a[i] != 0 {
				res++
				a[i]--
			}
		}
		for i := 0; i < 3; i++ {
			for j := i + 1; j < 3; j++ {
				if a[i] != 0 && a[j] != 0 {
					res++
					a[i]--
					a[j]--
				}
			}
		}
		if a[0] != 0 && a[1] != 0 && a[2] != 0 {
			res++
		}
		//
		println(res)
		t--
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		ans := 0
		if a > 0 {
			a--
			ans++
		}
		if b > 0 {
			b--
			ans++
		}
		if c > 0 {
			c--
			ans++
		}
		if a > 0 && b > 0 {
			a--
			b--
			ans++
		}
		if c > 0 && b > 0 {
			c--
			b--
			ans++
		}
		if a > 0 && c > 0 {
			a--
			c--
			ans++
		}
		if a > 0 && b > 0 && c > 0 {
			ans++
		}
		fmt.Println(ans)

	}
}

package main

import "fmt"

func main() {
	var testCases int
	fmt.Scanf("%d\n", &testCases)
	d, c, p := 0, 0, 0
	for i:=0; i<testCases; i++ {
		fmt.Scanf("%d %d %d\n", &d, &c, &p)
		res :=solution(d,c,p)
		fmt.Println(res)
	}
}

func solution(d int,c int, p int) int  {
	var res = 0
	if d ==0 && c==0 && p==0 {
		return res
	}
	if d > 0 {
		res +=1
		d -=1
	}
	if c > 0 {
		res +=1
		c -=1
	}
	if p > 0 {
		res +=1
		p -=1
	}

	if d > 0 && c > 0 {
		res +=1
		d -=1
		c -=1
	}
	if d > 0 && p > 0 {
		res +=1
		d -=1
		p -=1
	}

	if c > 0 && p > 0 {
		res +=1
		c -=1
		p -=1
	}

	if d > 0 && c > 0 && p > 0 {
		res +=1
		c -=1
		p -=1
	}

	return res

}

//многогранники
package main

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

func MySort (str []string) (out []int){
	out = make([]int, 0, 3)
	var new int
	for _, j := range str{
		new, _ = strconv.Atoi(j)
		if new > 4{
			new = 4
		}
		out = append(out, new)
	}
	sort.Ints(out)
	return
}
func MyCounter(in []int)(out [3]int){
	if in[0] == in[1] && in[1] == 0{
		if in[2] == 0{
			out = [3]int{0, 0, 0}
		}else{
			out = [3]int{0, 0, 1}
		}
	}else if in[0] == 0{
		if in[1] > 1{
			out = [3]int{1, 1, 1}
		}else {
			out = [3]int{0, 1, 1}
		}
	}else if in[0] == 1{
		if in[1] == 1{
			out = [3]int{1, 1, 1}
		}else {
			out = [3]int{1, 2, 2}
		}
	}else if in[0] == 2{
		if in[2] == 3{
			out = [3]int{2, 2, 3}
		} else{
			out = [3]int{1, 2, 2}
		}
	}else if in[2] == 3{
		out = [3]int{3, 3, 3}
	} else{
		out = [3]int{4, 4, 4}
	}
	return
 }
func main() {
	var dict map [[3]int]int = map[[3]int]int{
		{0, 0, 0}: 0,
		{0, 0, 1}: 1,
		{0, 1, 1}: 2,
		{1, 1, 1}: 3,
		{1, 2, 2}: 4,
		{2, 2, 3}: 5,
		{3, 3, 3}: 6,
		{4, 4, 4}: 7,
	}
	var line string
	var q int
	fmt.Scanln(&q)
	answer := make([]int, q, q)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < q; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		answer[i] = dict[MyCounter(MySort(strings.Split(line, " ")))]

	}
	for i:= 0; i < q; i++{
		fmt.Println(answer[i])
	}
}

/*
4
Icosahedron
Cube
Tetrahedron
Dodecahedron
42
*/

//многогранники
package main

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

func MySort (str []string) (out []int){
	out = make([]int, 0, 3)
	var new int
	for _, j := range str{
		new, _ = strconv.Atoi(j)
		if new > 4{
			new = 4
		}
		out = append(out, new)
	}
	sort.Ints(out)
	return
}
func MyCounter(in []int)(out [3]int){
	if in[0] == in[1] && in[1] == 0{
		if in[2] == 0{
			out = [3]int{0, 0, 0}
		}else{
			out = [3]int{0, 0, 1}
		}
	}else if in[0] == 0{
		if in[1] > 1{
			out = [3]int{1, 1, 1}
		}else {
			out = [3]int{0, 1, 1}
		}
	}else if in[0] == 1{
		if in[1] == 1{
			out = [3]int{1, 1, 1}
		}else {
			out = [3]int{1, 2, 2}
		}
	}else if in[0] == 2{
		if in[2] >= 3{
			out = [3]int{2, 2, 3}
		} else{
			out = [3]int{1, 2, 2}
		}
	}else if in[2] == 3{
		out = [3]int{3, 3, 3}
	} else{
		out = [3]int{4, 4, 4}
	}
	return
 }
func main() {
	var dict map [[3]int]int = map[[3]int]int{
		{0, 0, 0}: 0,
		{0, 0, 1}: 1,
		{0, 1, 1}: 2,
		{1, 1, 1}: 3,
		{1, 2, 2}: 4,
		{2, 2, 3}: 5,
		{3, 3, 3}: 6,
		{4, 4, 4}: 7,
	}
	var line string
	var q int
	fmt.Scanln(&q)
	answer := make([]int, q, q)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < q; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		answer[i] = dict[MyCounter(MySort(strings.Split(line, " ")))]

	}
	for i:= 0; i < q; i++{
		fmt.Println(answer[i])
	}
}

/*
4
Icosahedron
Cube
Tetrahedron
Dodecahedron
42
*/

//многогранники
package main

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

func MySort (str []string) (out []int){
	out = make([]int, 0, 3)
	var new int
	for _, j := range str{
		new, _ = strconv.Atoi(j)
		if new > 4{
			new = 4
		}
		out = append(out, new)
	}
	sort.Ints(out)
	return
}
func MyCounter(in []int)(out [3]int){
	if in[0] == in[1] && in[1] == 0{
		out = [3]int{0, 0, in[2]}
	}else if in[0] == 0{
		if in[1] > 1{
			out = [3]int{1, 1, 1}
		}else {
			out = [3]int{0, 1, 1}
		}
	}else if in[0] == 1{
		if in[1] == 1{
			out = [3]int{1, 1, 1}
		}else {
			out = [3]int{1, 2, 2}
		}
	}else if in[0] == 2{
		if in[2] == 3{
			out = [3]int{2, 2, 3}
		} else{
			out = [3]int{1, 2, 2}
		}
	}else if in[2] == 3{
		out = [3]int{3, 3, 3}
	} else{
		out = [3]int{4, 4, 4}
	}
	return
 }
func main() {
	var dict map [[3]int]int = map[[3]int]int{
		{0, 0, 0}: 0,
		{0, 0, 1}: 1,
		{0, 1, 1}: 2,
		{1, 1, 1}: 3,
		{1, 2, 2}: 4,
		{2, 2, 3}: 5,
		{3, 3, 3}: 6,
		{4, 4, 4}: 7,
	}
	var line string
	var q int
	fmt.Scanln(&q)
	answer := make([]int, q, q)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < q; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		answer[i] = dict[MyCounter(MySort(strings.Split(line, " ")))]

	}
	for i:= 0; i < q; i++{
		fmt.Println(answer[i])
	}
}

/*
4
Icosahedron
Cube
Tetrahedron
Dodecahedron
42
*/


package main

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

type SubArr struct {
    l, r int
}

type ByL []SubArr
func (a ByL) Len() int           { return len(a) }
func (a ByL) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByL) Less(i, j int) bool { return a[i].l < a[j].l }

func solve() {
    n, m := readInt(), readInt()
    sl, mn, ans := make([]SubArr, m), n, make([]int, n)
    for i := range sl {
        sl[i] = SubArr{readInt()-1, readInt()-1}
        if dist := sl[i].r-sl[i].l+1; dist < mn {
            mn = dist
        }
    }
    for i := range sl {
        sl[i].r = sl[i].l+mn
    }
    sort.Sort(ByL(sl))

    l, r := 0, mn
    for i := l; i < r; i++ {
        ans[i] = i
    }

    for _, pr := range sl {

        toAdd := []int{}
        for l < pr.l {
            if l < r {
                toAdd = append(toAdd, ans[l])
            }
            l++
        }
        for i, v := range toAdd {
            ans[pr.r-i-1] = v
        }
        r = pr.r
    }

    fmt.Println(mn)
    for _, v := range ans {
        fmt.Print(v, " ")
    }
    fmt.Println()
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

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

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

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1<<13)
	writer := bufio.NewWriterSize(os.Stdout, 1<<13)
	n, m := ReadInt(reader), ReadInt(reader)
	l, r := make([]int, m), make([]int, m)
	for i := 0; i < m; i++ {
		l[i], r[i] = ReadInt(reader)-1, ReadInt(reader)-1
	}
	ans := minMex(l, r, n)
	fmt.Fprintln(writer, ans)
	for i := 0; i < n; i++ {
		fmt.Fprint(writer, i%ans, " ")
	}
	writer.Flush()
}

func minMex(l, r []int, n int) int {
	ans := n
	for i := 0; i < len(l); i++ {
		ans = min(ans, r[i]-l[i]+1)
	}
	return ans
}

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

func ReadInt(reader *bufio.Reader) int {
	return int(ReadInt64(reader))
}

func ReadInt64(reader *bufio.Reader) int64 {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	var res int64
	for isValid(b, err) {
		res = res*10 + int64(b-'0')
		b, err = reader.ReadByte()
	}
	return res
}

func isValid(b byte, err error) bool {
	return err == nil && '0' <= b && b <= '9'
}