// You can edit this code!
// Click here and start typing.
package main

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

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

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

	var n int
	res := true
	pre := int(1e9) + 15
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)
	for i := 1; i <= n; i++ {
		var a, b int
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &a, &b)
		if a < b {
			a, b = b, a
		}
		if pre >= a {
			pre = a
		} else if pre >= b {
			pre = b
		} else {
			res = false
		}
	}
	if res {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
	return result
}

const M int = 1e5 + 5

var (
	n, x, y int
	a, b [M]int
)

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

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

func main() {
	n = readInt()
	for i := 0; i < n; i++ {
		x, y = readInt(), readInt()
		a[i] = max(x, y)
		b[i] = min(x, y)
	}
	last_pick := b[n-1]
	for i := n-1; i > 0; i-- {
		if last_pick <= b[i-1] {
			last_pick = b[i-1]
			continue
		}
		if last_pick <= a[i-1] {
			last_pick = a[i-1]
			continue
		}
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	return
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
	return result
}

func solve() bool {
	n := readInt()
	cur := math.MaxInt32
	for i := 0; i < n; i++ {
		a, b := readInt(), readInt()
		if a < b {
			a, b = b, a
		}
		if cur >= a {
			cur = a
		} else if cur >= b {
			cur = b
		} else {
			return false
		}
	}
	return true
}

func main() {
	if solve() {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	mx := int(1e9)
	for i := 0; i < N; i++ {
		C, D := sc.NextInt(), sc.NextInt()

		Q1 := max(C, D)
		Q2 := min(C, D)
		if mx >= Q1 {
			mx = Q1
		} else if mx >= Q2 {
			mx = Q2
		} else {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	for {
		var n int
		_, err := fmt.Scanln(&n)
		if err != nil {
			break
		}

		last := math.MaxInt32
		res := "YES"
		for i := 0; i < n; i++ {
			var w, h int
			fmt.Fscanf(in, "%d%d\n", &w, &h)
			//fmt.Println(w, h)
			if w <= last && h <= last {
				if w >= h {
					last = w
				} else {
					last = h
				}
			} else if w <= last && h > last {
				last = w
			} else if h <= last && w > last {
				last = h
			} else {
				res = "NO"
			}
		}

		fmt.Println(res)
	}
}

package main

import "fmt"

const M int = 1e5 + 5

var (
	n, x, y int
	a, b [M]int
)

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

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

func main() {
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scanln(&x, &y)
		a[i] = max(x, y)
		b[i] = min(x, y)
	}
	last_pick := b[n-1]
	for i := n-1; i > 0; i-- {
		if last_pick <= b[i-1] {
			last_pick = b[i-1]
			continue
		}
		if last_pick <= a[i-1] {
			last_pick = a[i-1]
			continue
		}
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	return
}

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
)

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

func main() {
	var n int
	res := true
	pre := int(1e9) + 15
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		if a < b {
			a, b = b, a
		}
		if pre >= a {
			pre = a
		} else if pre >= b {
			pre = b
		} else {
			res = false
			return
		}
	}
	if res {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	mx := int(1e6)
	for i := 0; i < N; i++ {
		C, D := sc.NextInt(), sc.NextInt()

		Q1 := max(C, D)
		Q2 := min(C, D)
		if mx >= Q1 {
			mx = Q1
		} else if mx >= Q2 {
			mx = Q2
		} else {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

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

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

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

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int()
		a := make([]int, n)
		for i := range a {
			a[i] = _int()
		}
		res := sol(n, a)
		for _, i := range res {
			printf("%d ", i)
		}
		printf("\n")
	}
}

func sol(n int, a []int) []int {
	ret := make([]int, n)
	for i := range a {
		add := n - a[i]
		if add == 0 {
			add = n
		}
		ret[add-1] = i + 1
	}
	return ret
}

package main

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

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

func solve() {
    var n int
    Fscan(in, &n)
    a := make([]int, n)
    for i := range a {
        Fscan(in, &a[i])
    }
    for i := n - 1; i > 0; i-- {
        a[i] = a[i - 1] - a[i]
    }
    a[0] = n

    b := make([]int, n)
    for i := range b {
        b[i] = i;
    }
    sort.Slice(b, func(i, j int) bool {
        return a[b[i]] < a[b[j]]
    })

    for _, v := range b {
        Fprint(out, v + 1, " ")
    }
    Fprint(out, "\n")
}

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

package main

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

var in = bufio.NewReader(os.Stdin)

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

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

func solve() {
  var n int
  scan(&n)
  a := make([]int, n)
  b := make([]string, n)
  for i := range a {
    scan(&a[i])
    diff := n - a[i]
    if diff == 0 {
      diff = n
    }
    b[diff-1] = fmt.Sprintf("%d", i+1)
  }
  pf("%s\n", strings.Join(b, " "))
}

func main() {
	var T int
	scan(&T)
	for ; T > 0; T-- {
    solve()
	}
}

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

package main

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

const cf = true

type data struct {
	diff int
	ind  int
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	diffs := make([]data, 0, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		if i > 0 && arr[i] < arr[i-1] {
			diffs = append(diffs, data{diff: arr[i-1] - arr[i], ind: i})
		}
	}
	sort.Slice(diffs, func(i, j int) bool {
		return diffs[i].diff < diffs[j].diff
	})
	cur := 0
	for i := 1; i <= n; i++ {
		if cur == len(diffs) {
			fmt.Fprint(out, "1 ")
		} else {
			fmt.Fprint(out, diffs[cur].ind+1, " ")
			diffs[cur].diff -= i
			if diffs[cur].diff <= 0 {
				cur++
			}
		}
	}
	fmt.Fprintln(out)
}

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

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

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

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

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

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

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

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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

package main

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

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

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

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

		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}

		b := make([][]int, 0, n)
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				b = append(b, []int{a[i-1] - a[i], i})
			}
		}
		sort.Slice(b, func(i, j int) bool { return b[i][0] < b[j][0] })

		for i := 0; i < n - len(b); i++ {
			fmt.Fprintf(w, "%d ", n)
		}
		for _, v := range b {
			fmt.Fprintf(w, "%d ", v[1]+1)
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

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

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

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

		for i := 1; i <= n; i++ {
			fmt.Fprintf(out, "%d ", bb[n+1-i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}

		b := make([][]int, 0, n)
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				b = append(b, []int{a[i-1] - a[i], i})
			}
		}
		sort.Slice(b, func(i, j int) bool { return b[i][0] < b[j][0] })

		for _, v := range b {
			fmt.Fprintf(w, "%d ", v[1]+1)
		}

		for i := len(b); i < n; i++ {
			fmt.Fprintf(w, "%d ", n)
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

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

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

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

		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}

		res := n
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				res = i + 1
				break
			}
		}

		for i := 0; i < n-1; i++ {
			fmt.Fprintf(w, "%d ", n)
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, done int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		m := make([]int, n)
		rr := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			if i > 0 {
				m[i] = max(m[i-1], a[i-1])
			}
		}

		for i := range a {
			if i > 0 { m[i] = max(m[i], a[i-1] + done) }

			if d := m[i] - a[i] - done; d > 0 {
				for j := done; j < done + d && j < n; j++ {
					rr[j] = i+1
				}
				done += d
			}
		}

		for _, v := range rr { fmt.Fprintf(w, "%d ", max(v, 1)) }
		fmt.Fprintln(w, "")
	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, done int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		m := make([]int, n)
		rr := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			if i > 0 {
				m[i] = max(m[i-1], a[i-1])
			}
		}

		for i := range a {
			if i > 0 { m[i] = max(m[i], a[i-1] + done) }
			a[i] += done

			if d := m[i] - a[i]; d > 0 {
				for j := done; j < done + d && j < n; j++ {
					rr[j] = i+1
				}
				done += d
			}
		}

		for _, v := range rr { fmt.Fprintf(w, "%d ", max(v, 1)) }
		fmt.Fprintln(w, "")
	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, done int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		m := make([]int, n)
		rr := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			if i > 0 {
				m[i] = max(m[i-1], a[i])
			}
		}

		for i := range a {
			if i > 0 { m[i] = max(m[i], a[i-1] + done) }
			a[i] += done

			if d := m[i] - a[i]; d > 0 {
				for j := done; j < done + d && j < n; j++ {
					rr[j] = i+1
				}
				done += d
			}
		}

		for _, v := range rr { fmt.Fprintf(w, "%d ", max(v, 1)) }
		fmt.Fprintln(w, "")
	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, done int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		m := make([]int, n)
		rr := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			if i > 0 {
				m[i] = max(m[i-1], a[i])
			}
		}

		for i := range a {
			d := m[i] - a[i] - done
			if d > 0 {
				for j := done; j < done + d; j++ {
					rr[j] = i+1
				}
				done += d
			}
		}

		for i := range rr { fmt.Fprintf(w, "%d ", max(rr[i], 1)) }
		fmt.Fprintln(w, "")
	}

}

package main

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

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

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

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

		bb := make([]int, n)
		var pos int
		z := 1
	Loop:
		for i := 0; i < n-1; i++ {
			if aa[i] > aa[i+1] {
				d := aa[i+1]
				for aa[i] >= d {
					bb[pos] = i + 2
					pos++
					if pos >= n {
						break Loop
					}
					d += z
					z++
				}
			}
		}

		for i := pos; i < n; i++ {
			bb[i] = 1
		}
		for _, v := range bb {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

		bb := make([]int, n)
		var pos int
		z := 1
	Loop:
		for i := 0; i < n-1; i++ {
			if aa[i] > aa[i+1] {
				d := aa[i+1]
				for aa[i] > d {
					bb[pos] = i + 2
					pos++
					if pos >= n {
						break Loop
					}
					d += z
					z++
				}
			} else {
				z++
			}
		}

		for i := pos; i < n; i++ {
			bb[i] = 1
		}
		for _, v := range bb {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

		var c int
	Loop:
		for i := n - 1; i > 0; i-- {
			if c >= n {
				break
			}
			for aa[i] < aa[i-1] {
				aa[i]++
				fmt.Fprintf(out, "%d ", i+1)
				c++
				if c >= n {
					break Loop
				}
			}
		}

		for i := c; i < n; i++ {
			fmt.Fprintf(out, "%d ", 1)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}
		orig := make([]int, n)
		copy(orig, aa)

		var c int
		bb := make([]int, n)
		var pos int
		for i := n - 1; i > 0; i-- {
			if aa[i]+c < aa[i-1]+c {
				d := aa[i-1] - aa[i]
				c += d
				for j := 0; j < d; j++ {
					if pos < n {
						bb[pos] = i + 1
						pos++
					}
				}
			}
		}

		for i := pos; i < n; i++ {
			bb[i] = n
		}
		for _, v := range bb {
			// for i := v - 1; i < n; i++ {
			// 	aa[i]++
			// }
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)

		// if !sort.IsSorted(sort.IntSlice(aa)) {
		// 	fmt.Fprintln(out, "false")
		// 	fmt.Fprintln(out, orig)
		// 	fmt.Fprintln(out, aa)
		// }
	}
}

package main

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

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

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

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

		var c int
		bb := make([]int, n)
		var pos int
		for i := 0; i < n-1; i++ {
			if aa[i]+c > aa[i+1]+c {
				d := aa[i] - aa[i+1]
				c += d
				for j := 0; j < d; j++ {
					if pos < n {
						bb[pos] = i + 2
						pos++
					}
				}
			}
		}

		for i := pos; i < n; i++ {
			bb[i] = n
		}
		for _, v := range bb {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

		var c int
		for i := 0; i < n-1; i++ {
			if aa[i]+c > aa[i+1]+c {
				d := aa[i] - aa[i+1]
				c += d
				for j := 0; j < d; j++ {
					fmt.Fprintf(out, "%d ", i+2)
				}
			}
		}
		for i := c; i < n; i++ {
			fmt.Fprintf(out, "%d ", n)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func solve() {
    var n int
    Fscan(in, &n)
    a := make([]int, n)
    for i := range a {
        Fscan(in, &a[i])
    }

    op := 1
    ans := make([]int, 0, n)
    for i := n - 1; i > 0; i-- {
        if a[i] < a[i - 1] {
            for ; a[i] < a[i - 1]; op++ {
                ans = append(ans, i + 1)
                a[i] += op
            }
        }
    }

    for ; len(ans) < n; {
        ans = append(ans, 1)
    }

    for i := 0; i < n; i++ {
        Fprint(out, ans[i], " ")
    }
    Fprint(out, "\n")
}

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

package main

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

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

func solve() {
    var n int
    Fscan(in, &n)
    a := make([]int, n)
    for i := range a {
        Fscan(in, &a[i])
    }

    op := 1
    var ans []int
    for i := 1; i < n; i++ {
        if a[i] < a[i - 1] {
            for ; a[i] < a[i - 1]; op++ {
                ans = append(ans, i + 1)
                a[i] += op
            }
        }
    }

    for ; len(ans) < n; {
        ans = append(ans, 1)
    }

    for i := 0; i < n; i++ {
        Fprint(out, ans[i], " ")
    }
    Fprint(out, "\n")
}

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


package main

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

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

	var T, n, m, k, v, w int
t:
	for Fscan(I, &T); T > 0; T-- {
		Fscan(I, &n, &m, &k)
		g := make([]map[int]bool, n)
		for i := range g {
			g[i] = map[int]bool{}
		}
		d := make([]int, n)
		for ; m > 0; m-- {
			Fscan(I, &v, &w)
			v--
			w--
			g[v][w] = true
			g[w][v] = true
			d[v]++
			d[w]++
		}
		left := n
		del := make([]bool, n)
		q := []int{}
		for i, v := range d {
			if v < k {
				del[i] = true
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			left--
			if d[v] == k-1 {
				a := []int{}
				for w := range g[v] {
					if d[w] >= k-1 {
						a = append(a, w)
					}
				}
				if len(a) == k-1 {
					for i, v := range a {
						for _, w := range a[:i] {
							if !g[v][w] {
								goto o
							}
						}
					}
					Fprint(O, "2\n", v+1, " ")
					for _, v := range a {
						Fprint(O, v+1, " ")
					}
					Fprintln(O)
					continue t
				}
			}
		o:
			d[v] = 0
			for w := range g[v] {
				if d[w]--; d[w] < k && !del[w] {
					del[w] = true
					q = append(q, w)
				}
			}
		}
		if left > 0 {
			Fprintln(O, 1, left)
			for i, d := range del {
				if !d {
					Fprint(O, i+1, " ")
				}
			}
			Fprintln(O)
		} else {
			Fprintln(O, -1)
		}
	}
}

package main

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

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

	var T, n, m, k, v, w int
t:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		g := make([]map[int]bool, n)
		for i := range g {
			g[i] = map[int]bool{}
		}
		deg := make([]int, n)
		for ; m > 0; m-- {
			Fscan(in, &v, &w)
			v--
			w--
			g[v][w] = true
			g[w][v] = true
			deg[v]++
			deg[w]++
		}
		left := n
		del := make([]bool, n)
		q := []int{}
		for i, d := range deg {
			if d < k {
				del[i] = true
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			left--
			if deg[v] == k-1 {
				a := []int{}
				for w := range g[v] {
					if deg[w] >= k-1 {
						a = append(a, w)
					}
				}
				if len(a) == k-1 {
					for i, v := range a {
						for _, w := range a[:i] {
							if !g[v][w] {
								goto o
							}
						}
					}
					Fprint(out, "2\n", v+1, " ")
					for _, v := range a {
						Fprint(out, v+1, " ")
					}
					Fprintln(out)
					continue t
				}
			}
		o:
			deg[v] = 0
			for w := range g[v] {
				deg[w]--
				if deg[w] < k && !del[w] {
					del[w] = true
					q = append(q, w)
				}
			}
		}
		if left > 0 {
			Fprintln(out, 1, left)
			for i, d := range del {
				if !d {
					Fprint(out, i+1, " ")
				}
			}
			Fprintln(out)
		} else {
			Fprintln(out, -1)
		}
	}
}

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

package main

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

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

	var T, n, m, k, v, w int
t:
	for Fscan(I, &T); T > 0; T-- {
		Fscan(I, &n, &m, &k)
		g := make([]map[int]bool, n)
		for i := range g {
			g[i] = map[int]bool{}
		}
		d := make([]int, n)
		for ; m > 0; m-- {
			Fscan(I, &v, &w)
			v--
			w--
			g[v][w] = true
			g[w][v] = true
			d[v]++
			d[w]++
		}
		left := n
		del := make([]bool, n)
		q := []int{}
		for i, v := range d {
			if v < k {
				del[i] = true
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			left--
			if d[v] == k-1 {
				a := []int{}
				for w := range g[v] {
					if d[w] >= k-1 {
						a = append(a, w)
					}
				}
				if len(a) == k-1 {
					for i, v := range a {
						for _, w := range a[:i] {
							if !g[v][w] {
								goto o
							}
						}
					}
					Fprint(O, "2\n", v+1, " ")
					for _, v := range a {
						Fprint(O, v+1, " ")
					}
					Fprintln(O)
					continue t
				}
			}
		o:
			for w := range g[v] {
				if d[w]--; d[w] < k && !del[w] {
					del[w] = true
					q = append(q, w)
				}
			}
		}
		if left > 0 {
			Fprintln(O, 1, left)
			for i, d := range del {
				if !d {
					Fprint(O, i+1, " ")
				}
			}
			Fprintln(O)
		} else {
			Fprintln(O, -1)
		}
	}
}

package main

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

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

	solve := func(Case int) {
		var n, m, k int
		Fscan(in, &n, &m, &k)

		g := make([][]int, n)
		has := make([]map[int]bool, n)
		for i := range has {
			has[i] = map[int]bool{}
		}
		for i := 0; i < m; i++ {
			var v, w int
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
			has[v][w] = true
			has[w][v] = true
		}

		if k*(k-1)/2 > m {
			Fprintln(out, -1)
			return
		}

		cntV := 0
		for _, vs := range g {
			if len(vs) >= k-1 {
				cntV++
			}
		}
		if cntV < k {
			Fprintln(out, -1)
			return
		}

		if k == 1 {
			Fprintln(out, 2)
			Fprintln(out, 1)
			return
		}

		calc := func(k int, check bool) []int {
			var ans []int
			vis := make([]bool, n)
			var f func(int) bool
			f = func(v int) bool {
				vis[v] = true
				c := 0
				for _, w := range g[v] {
					if len(g[w]) >= k {
						c++
					}
				}
				if c < k {
					return false
				}

				// todo   暴力即可？
				c = 0
				for _, w := range g[v] {
					if !vis[w] {
						if f(w) {
							c++
						}
					} else {
						c++
					}
				}
				if c >= k {
					ans = append(ans, v)
				}
				return c >= k
			}

			for i, vs := range g {
				if len(vs) == k && !vis[i] {
					ans = nil
					if f(i) {
						if check {
							// remove
							mp := map[int]bool{}
						o2:
							for _, v := range ans {
								for w := range mp {
									if !has[v][w] {
										continue o2
									}
								}
								mp[v] = true
								if len(mp) == k+1 {
									keys := make([]int, 0, len(mp))
									for k := range mp {
										keys = append(keys, k)
									}
									return keys
								}
							}
							if len(mp) < k+1 {
								continue
							}
						}

						return ans
					}
				}
			}
			return nil
		}

		ans := calc(k,false)
		if ans != nil {
			Fprintln(out, 1, len(ans))
			for _, v := range ans {
				Fprint(out, v+1, " ")
			}
			Fprintln(out)
			return
		}

		ans = calc(k - 1,true)
		if len(ans) < k {
			Fprintln(out, -1)
			return
		}

		Fprintln(out, 2)
		for _, v := range ans {
			Fprint(out, v+1, " ")
		}
		Fprintln(out)
	}

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

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


package main

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

const N = 200010
var nt int
var n int
var a [N] int

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

	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d\n", &n)
		for i := 1; i <= n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}
		fmt.Fscanf(reader, "\n")

		var same = true
		for i := 1; i < n; i++ {
			if a[i] != a[i + 1] {
				same = false
				break
			}
		}

		if same {
			fmt.Fprintf(writer, "1\n")
			for i := 1; i <= n; i++ {
				fmt.Fprintf(writer, "1 ")
			}
			fmt.Fprintf(writer, "\n")
			continue
		}

		if n % 2 == 0 {
			fmt.Fprintf(writer, "2\n")
			for i := 1; i <= n; i++ {
				if i % 2 == 0 {
					fmt.Fprintf(writer, "1 ")
				} else {
					fmt.Fprintf(writer, "2 ")
				}
			}
			fmt.Fprintf(writer, "\n")
			continue
		}

		a[n + 1] = a[1]
		var pos = -1
		for i := 1; i <= n; i++ {
			if a[i] == a[i + 1] {
				pos = i
				break
			}
		}

		if pos == -1 {
			fmt.Fprintf(writer, "3\n")
			for i := 1; i < n; i++ {
				if i % 2 == 0 {
					fmt.Fprintf(writer, "1 ")
				} else {
					fmt.Fprintf(writer, "2 ")
				}
			}
			fmt.Fprintf(writer, "3\n")
			continue
		}

		val := 1

		fmt.Fprintf(writer, "2\n1 ")
		for i := 2; i <= n; i++ {
			if i != pos + 1 {
				val = 3 - val
			}
			fmt.Fprintf(writer, "%d ", val)
		}
		fmt.Fprintf(writer, "\n")
	}

}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

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

var sc = newScanner()

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

	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		f := make([]int, n)
		m := make(map[int]bool)
		r := -1
		for i := 0; i < n; i++ {
			f[i] = scanInt()
			m[f[i]] = true
			if r == -1 && i > 0 && f[i] == f[i-1] {
				r = i
			}
		}

		cnt := 0
		res := make([]int, n)
		if len(m) == 1 {
			cnt = 1
			for i := 0; i < n; i++ {
				res[i] = 1
			}

		} else if n&1 == 0 || f[0] == f[n-1] {
			cnt = 2
			res[0] = 1
			for i := 1; i < n; i++ {
				res[i] = res[i-1] ^ 3
			}
		} else if r > 0 {
			cnt = 2
			res[0] = 1
			for i := 1; i < n; i++ {
				res[i] = res[i-1] ^ 3
				if i == r {
					res[i] = res[i-1]
				}
			}
		} else {
			cnt = 3
			res[0], res[n-1] = 1, 3
			for i := 1; i < n-1; i++ {
				res[i] = res[i-1] ^ 3
			}
		}

		fmt.Println(cnt)
		fmt.Println(strings.Trim(fmt.Sprint(res), "[]"))
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1328/problem/D

package main

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

type Answer struct {
	min   int
	array []int
}

func Solve(n int, t []int) Answer {
	allSame := true
	for i := 1; i < n; i++ {
		if t[i] != t[0] {
			allSame = false
		}
	}
	ans := Answer{}
	ans.array = make([]int, n)
	if allSame {
		ans.min = 1
		for i := 0; i < n; i++ {
			ans.array[i] = 1
		}
		return ans
	}
	if n%2 == 0 {
		ans.min = 2
		for i := 0; i < n; i++ {
			ans.array[i] = i%2 + 1
		}
		return ans
	}
	l := -1
	r := -1
	if n%2 == 1 {
		for i := 0; i < n; i++ {
			if t[i] == t[(i+1)%n] {
				l = i
				r = (i + 1)%n
			}
		}
	}
	if l == -1 && r == -1 {
		for i := 0; i < n; i++ {
			ans.array[i] = i%2 + 1
		}
		ans.array[n-1] = 3
		ans.min = 3
		return ans
	}
	ans.min = 2
	ans.array[l] = 1
	ans.array[r] = 1
	for i := 0; i < l; i++ {
		ans.array[i] = (l-i)%2 + 1
	}
	for i := r + 1; i < n; i++ {
		ans.array[i] = (i-r)%2 + 1
	}
	return ans
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		t := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &t[i])
		}
		fmt.Fscanf(reader, "\n")
		ans := Solve(n, t)
		fmt.Fprintf(writer, "%d\n", ans.min)
		for _, elem := range ans.array {
			fmt.Fprintf(writer, "%d ", elem)
		}
		fmt.Fprintf(writer, "\n")
	}
}

package main

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

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewWriter(os.Stdout)

func main() {
	defer writer.Flush()
	q := reader.NextInt64()
	for ; q > 0; q-- {
		n := reader.NextInt64()
		vals := []int64{}
		for ; n > 0; n-- {
			vals = append(vals, reader.NextInt64())
		}
        res, resVals := sol(vals)
        writer.Printf("%d\n", res)
        for _, v := range resVals {
            writer.Printf("%d ", v)
        }
        writer.Printf("\n")
	}
}

func sol(vals []int64) (int64, []int64) {
    maxSoFar := int64(1)
    res := []int64{1}
    for i := 1; i < len(vals); i++ {
        prev := vals[i-1]
        curr := vals[i]
        if curr == prev {
            res = append(res, res[i-1])
        } else {
            res = append(res, alt(res[i-1]))
            maxSoFar = 2
        }
    }
    if vals[0] != vals[len(vals)-1] && res[0] == res[len(res)-1] {
        res[0] = 2
        for i := 1; i < len(vals); i++ {
            if vals[i] != vals[i-1] {
                res[i] = alt(res[i-1])
            } else {
                break
            }
        }
    }
    if vals[0] != vals[len(vals)-1] && res[0] == res[len(res)-1] {
        res[0] = 3
        return 3, res
    }
    return maxSoFar, res
}

func alt(i int64) int64 {
    if i == 1 {
        return 2
    }
    return 1
}

package main

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

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

func  main()  {
	defer writer.Flush()
	var t int
	scanf("%d\n",&t)
	const N int = 2e5+5
	var arr [N]int
	var ans [N]int
	for t>0 {
		t--
		var n int
		scanf("%d\n",&n)
		sing := false
		for i:=0; i<n ;i++ {
			if i<n-1{
				scanf("%d",&arr[i])
			}else{
				scanf("%d\n",&arr[i])
			}
			if i>0 && arr[i]!=arr[i-1]{
				sing=true
			}
		}
		if sing==false{
			printf("1\n")
			for i:=0; i<n; i++{
				printf("1 ")
			}
			printf("\n")
		}else if n%2==0{
			printf("2\n")
			for i:=0 ; i<n ;i++{
				printf("%d ",(i%2)+1)
			}
			printf("\n")
		}else{
			var check bool = false
			var tmp bool =false
			for i:=0; i<n; i++{
				if arr[i]==arr[(i+1)%n]{
					check = true
					tmp=true
				}
			}
			if check{
				printf("2\n")
			}else{
				printf("3\n")
			}
			ans[0]=1
			for i:=1; i<n ;i++{
				if(check && arr[i]==arr[i-1]){
					ans[i]=ans[i-1]
					check=false
				}else{
					if ans[i-1]==1{
						ans[i]=2
					}else{
						ans[i]=1
					}
				}
			}
			if tmp==false{
				ans[n-1]=3
			}
			for i:=0; i<n; i++{
				printf("%d ",ans[i])
			}
			printf("\n")
		}
	}
}

package main

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

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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var figuresNumb int
	scanf("%d\n", &figuresNumb)

	animals, err := scanIntArr()
	if err != nil {
		fmt.Println(err.Error())
		panic(err)
	}

	colors := make([]string, figuresNumb)
	colorsNumb := 2
	colors[0] = "1"

	isEqual := true
	if figuresNumb%2 == 0 {
		for i := 1; i < figuresNumb; i++ {
			if isEqual && animals[i] != animals[i-1] {
				isEqual = false
			}

			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"
		}
		if isEqual {
			printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
			return
		}
		printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
		return
	}

	isNormalized := false
	for i := 1; i < figuresNumb; i++ {
		if !isNormalized {
			if animals[i-1] == animals[i] {
				isNormalized = true
				colors[i] = colors[i-1]
				continue
			}
			if isEqual {
				isEqual = false
			}
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"
		}
		if isEqual && animals[i] != animals[i-1] {
				isEqual = false
		}
		if colors[i-1] == "1" {
			colors[i] = "2"
			continue
		}
		colors[i] = "1"
	}
	if isEqual {
		printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
		return
	}

	if !isNormalized {
		if animals[0] != animals[figuresNumb-1] {
			colorsNumb = 3
			colors[figuresNumb-1] = "3"
		}
	}

	printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
}

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 NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(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 Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(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 reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

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

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

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

func main() {
	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, 1000010)
	T := NextInt()
	a := make([]int, 200000)
	c := make([]int, 200000)

	for t := 0; t < T; t++ {
		n := NextInt()
		since := 0
		for i := 0; i < n; i++ {
			a[i] = NextInt()
			c[i] = -1
			if i > 0 && since == 0 && a[i] == a[i-1] {
				since = i
			}
		}
		mc := 0
		if since == 0 {
			for i := 0; i < n; i++ {
				c[i] = i & 1
				mc = max(mc, c[i])
			}
			if n >= 2 && c[n-1] == c[0] && a[n-1] != a[0] {
				c[n-1] += 2
				mc = max(mc, c[n-1])
			}
		} else {
			c[since] = 0
			pr := since
			for i := 1; i < n; i++ {
				cur := pr + 1
				if cur == n {
					cur = 0
				}
				if a[pr] != a[cur] {
					c[cur] = c[pr] ^ 1
				} else {
					c[cur] = 0
				}
				mc = max(mc, c[cur])
				pr = cur
			}
		}
		fmt.Fprintln(out, mc+1)
		for i := 0; i < n; i++ {
			fmt.Fprint(out, c[i]+1, " ")
		}
		fmt.Fprintln(out)
	}

}

/*
URL:
https://codeforces.com/problemset/problem/1328/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	q int

	n int
	A []int
)

func main() {
	q = ReadInt()

	for i := 0; i < q; i++ {
		n = ReadInt()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	comp, _ := RunLengthEncoding(A)
	if len(comp) == 1 {
		B := make([]int, n)
		for i := 0; i < n; i++ {
			B[i] = 1
		}
		fmt.Println(1)
		fmt.Println(PrintIntsLine(B...))
		return
	}

	if n%2 == 0 || A[0] == A[n-1] {
		B := make([]int, n)
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				B[i] = 1
			} else {
				B[i] = 2
			}
		}

		fmt.Println(2)
		fmt.Println(PrintIntsLine(B...))
		return
	}

	sid := -1
	for i := 0; i < n-1; i++ {
		if A[i] == A[i+1] {
			sid = i
			break
		}
	}

	if sid == -1 {
		B := make([]int, n)
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				B[i] = 1
			} else {
				B[i] = 2
			}
		}
		B[n-1] = 3

		fmt.Println(3)
		fmt.Println(PrintIntsLine(B...))
		return
	}

	B := make([]int, n)
	B[sid], B[sid+1] = 2, 2
	for i := sid - 1; i >= 0; i-- {
		if B[i+1] == 2 {
			B[i] = 1
		} else {
			B[i] = 2
		}
	}
	for i := sid + 2; i < n; i++ {
		if B[i-1] == 2 {
			B[i] = 1
		} else {
			B[i] = 2
		}
	}
	fmt.Println(2)
	fmt.Println(PrintIntsLine(B...))
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

/*******************************************************************/

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

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

	var t, n int
o:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		same := true
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			if i > 0 && a[i] != a[i-1] {
				same = false
			}
		}
		if same {
			Fprintln(out, 1)
			Fprintln(out, strings.Repeat("1 ", n))
			continue o
		}
		if n&1 == 0 {
			Fprintln(out, 2)
			Fprintln(out, strings.Repeat("1 2 ", n/2))
			continue o
		}
		for i, v := range a {
			if v == a[(i+1)%n] {
				ans := make([]interface{}, n)
				for j, c := i, 1; j >= 0; j-- {
					ans[j] = c
					c = 3 - c
				}
				for j, c := i+1, 1; j < n; j++ {
					ans[j] = c
					c = 3 - c
				}
				Fprintln(out, 2)
				Fprintln(out, ans...)
				continue o
			}
		}
		Fprintln(out, 3)
		Fprintln(out, strings.Repeat("1 2 ", n/2)+"3")
	}
}

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

package main

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

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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var figuresNumb int
	scanf("%d\n", &figuresNumb)

	animals, err := scanIntArr()
	if err != nil {
		fmt.Println(err.Error())
		panic(err)
	}

	colors := make([]string, figuresNumb)
	colorsNumb := 2
	colors[0] = "1"

	isEqual := true
	if figuresNumb%2 == 0 {
		for i := 1; i < figuresNumb; i++ {
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"

			if isEqual && colors[i] != colors[i-1] {
				isEqual = false
			}
		}
		if isEqual {
			printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
			return
		}
		printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
		return
	}

	isNormalized := false
	for i := 1; i < figuresNumb; i++ {
		if !isNormalized {
			if animals[i-1] == animals[i] {
				isNormalized = true
				colors[i] = colors[i-1]
				continue
			}
			if isEqual {
				isEqual = false
			}
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"
		}
		if isEqual && animals[i] != animals[i-1] {
				isEqual = false
		}
		if colors[i-1] == "1" {
			colors[i] = "2"
			continue
		}
		colors[i] = "1"
	}
	if isEqual {
		printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
		return
	}

	if !isNormalized {
		if animals[0] != animals[figuresNumb-1] {
			colorsNumb = 3
			colors[figuresNumb-1] = "3"
		}
	}

	printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
}

package main

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

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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var figuresNumb int
	scanf("%d\n", &figuresNumb)

	animals, err := scanIntArr()
	if err != nil {
		fmt.Println(err.Error())
		panic(err)
	}

	colors := make([]string, figuresNumb)
	colorsNumb := 1
	colors[0] = "1"
	for i := 1; i < figuresNumb; i++{
		if animals[i] != animals[i-1] {
			colors[i] = "1"
			if colorsNumb == 1 || colors[i-1] == "1"{
				colors[i] = "2"
				colorsNumb = 2
			}
			continue
		}
		colors[i] = colors[i-1]
	}
	if animals[figuresNumb-1] != animals[0] && colors[figuresNumb-1] == "1" {
		if colorsNumb == 2 {
			colorsNumb = 3
			colors[figuresNumb-1] = "3"
		}
	}

	printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
}

package main

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

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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var figuresNumb int
	scanf("%d\n", &figuresNumb)

	animals, err := scanIntArr()
	if err != nil {
		fmt.Println(err.Error())
		panic(err)
	}

	colors := make([]string, figuresNumb)
	colorsNumb := 1
	colors[0] = "1"

	isEqual := true
	if figuresNumb%2 == 0 {
		for i := 1; i < figuresNumb; i++ {
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"

			if isEqual && colors[i] != colors[i-1] {
				isEqual = false
			}
		}
		if isEqual {
			printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
			return
		}
		printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
		return
	}

	isNormalized := false
	for i := 1; i < figuresNumb; i++ {
		if !isNormalized {
			if animals[i-1] == animals[i] {
				isNormalized = true
				colors[i] = colors[i-1]
				continue
			}
			if isEqual {
				isEqual = false
			}
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"
		}
		if isEqual && animals[i] != animals[i-1] {
				isEqual = false
		}
		if colors[i-1] == "1" {
			colors[i] = "2"
			continue
		}
		colors[i] = "1"
	}
	if isEqual {
		printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
		return
	}

	if !isNormalized {
		if animals[figuresNumb-2] != animals[figuresNumb-1] {
			colors[figuresNumb-1] = "3"
		}
	}

	printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
}

package main

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

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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var figuresNumb int
	scanf("%d\n", &figuresNumb)

	animals, err := scanIntArr()
	if err != nil {
		fmt.Println(err.Error())
		panic(err)
	}

	colors := make([]string, figuresNumb)
	colorsNumb := 2
	colors[0] = "1"

	isEqual := true
	if figuresNumb%2 == 0 {
		for i := 1; i < figuresNumb; i++ {
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"

			if isEqual && animals[i] != animals[i-1] {
				isEqual = false
			}
		}
		if isEqual {
			printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
			return
		}
		printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
		return
	}

	isNormalized := false
	for i := 1; i < figuresNumb; i++ {
		if !isNormalized {
			if animals[i-1] == animals[i] {
				isNormalized = true
				colors[i] = colors[i-1]
				continue
			}
			if isEqual {
				isEqual = false
			}
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"
		}
		if isEqual && animals[i] != animals[i-1] {
				isEqual = false
		}
		if colors[i-1] == "1" {
			colors[i] = "2"
			continue
		}
		colors[i] = "1"
	}
	if isEqual {
		printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
		return
	}

	if !isNormalized {
		if animals[0] != animals[figuresNumb-1] {
			colorsNumb = 3
			colors[figuresNumb-1] = "3"
		}
	}

	printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
}

package main

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

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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var figuresNumb int
	scanf("%d\n", &figuresNumb)

	animals, err := scanIntArr()
	if err != nil {
		fmt.Println(err.Error())
		panic(err)
	}

	colors := make([]byte, figuresNumb)
	colorsNumb := 1
	colors[0] = '1'
	for i := 1; i < figuresNumb; i++{
		if animals[i] != animals[i-1] {
			colors[i] = '1'
			if colorsNumb == 1 || colors[i-1] == '1'{
				colors[i] = '2'
				colorsNumb = 2
			}
			continue
		}
		colors[i] = colors[i-1]
	}
	if animals[figuresNumb-1] != animals[0] && colors[figuresNumb-1] == '1' {
		if colorsNumb == 2 {
			colorsNumb = 3
			colors[figuresNumb-1] = '3'
		}
	}

	printf("%d\n%s\n", colorsNumb, colors)
}

package main

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

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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var figuresNumb int
	scanf("%d\n", &figuresNumb)

	animals, err := scanIntArr()
	if err != nil {
		fmt.Println(err.Error())
		panic(err)
	}

	colors := make([]string, figuresNumb)
	colorsNumb := 2
	colors[0] = "1"

	isEqual := true
	if figuresNumb%2 == 0 {
		for i := 1; i < figuresNumb; i++ {
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"

			if isEqual && colors[i] != colors[i-1] {
				isEqual = false
			}
		}
		if isEqual {
			printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
			return
		}
		printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
		return
	}

	isNormalized := false
	for i := 1; i < figuresNumb; i++ {
		if !isNormalized {
			if animals[i-1] == animals[i] {
				isNormalized = true
				colors[i] = colors[i-1]
				continue
			}
			if isEqual {
				isEqual = false
			}
			if i%2 == 0 {
				colors[i] = "1"
				continue
			}
			colors[i] = "2"
		}
		if isEqual && animals[i] != animals[i-1] {
				isEqual = false
		}
		if colors[i-1] == "1" {
			colors[i] = "2"
			continue
		}
		colors[i] = "1"
	}
	if isEqual {
		printf("%d\n%s\n", 1, strings.TrimSpace(strings.Repeat("1 ", figuresNumb)))
		return
	}

	if !isNormalized {
		if animals[figuresNumb-2] != animals[figuresNumb-1] {
			colorsNumb = 3
			colors[figuresNumb-1] = "3"
		}
	}

	printf("%d\n%s\n", colorsNumb, strings.Join(colors, " "))
}

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 NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(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 Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(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 reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

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

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

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

func main() {
	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, 1000010)
	T := NextInt()
	a := make([]int, 200000)
	c := make([]int, 200000)

	for t := 0; t < T; t++ {
		n := NextInt()
		since := 0
		for i := 0; i < n; i++ {
			a[i] = NextInt()
			c[i] = -1
			if i > 0 && since == 0 && a[i] == a[i-1] {
				since = i
			}
		}
		mc := 0
		if since == 0 {
			for i := 0; i < n; i++ {
				c[i] = i & 1
				mc = max(mc, c[i])
			}
			if n >= 2 && c[n-1] == c[0] {
				c[n-1] += 2
				mc = max(mc, c[n-1])
			}
		} else {
			c[since] = 0
			pr := since
			for i := 1; i < n; i++ {
				cur := pr + 1
				if cur == n {
					cur = 0
				}
				if a[pr] != a[cur] {
					c[cur] = c[pr] ^ 1
				} else {
					c[cur] = 0
				}
				mc = max(mc, c[cur])
				pr = cur
			}
		}
		fmt.Fprintln(out, mc+1)
		for i := 0; i < n; i++ {
			fmt.Fprint(out, c[i]+1, " ")
		}
		fmt.Fprintln(out)
	}

}

/*
URL:
https://codeforces.com/problemset/problem/1328/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	q int

	n int
	A []int
)

func main() {
	q = ReadInt()

	for i := 0; i < q; i++ {
		n = ReadInt()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	comp, _ := RunLengthEncoding(A)
	if len(comp) == 1 {
		B := make([]int, n)
		for i := 0; i < n; i++ {
			B[i] = 1
		}
		fmt.Println(1)
		fmt.Println(PrintIntsLine(B...))
		return
	}

	if n%2 == 0 {
		B := make([]int, n)
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				B[i] = 1
			} else {
				B[i] = 2
			}
		}

		fmt.Println(2)
		fmt.Println(PrintIntsLine(B...))
		return
	}

	sid := -1
	for i := 0; i < n-1; i++ {
		if A[i] == A[i+1] {
			sid = i
			break
		}
	}

	if sid == -1 {
		B := make([]int, n)
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				B[i] = 1
			} else {
				B[i] = 2
			}
		}
		B[n-1] = 3

		fmt.Println(3)
		fmt.Println(PrintIntsLine(B...))
		return
	}

	B := make([]int, n)
	B[sid], B[sid+1] = 2, 2
	for i := sid - 1; i >= 0; i-- {
		if B[i+1] == 2 {
			B[i] = 1
		} else {
			B[i] = 2
		}
	}
	for i := sid + 2; i < n; i++ {
		if B[i-1] == 2 {
			B[i] = 1
		} else {
			B[i] = 2
		}
	}
	fmt.Println(2)
	fmt.Println(PrintIntsLine(B...))
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

/*******************************************************************/

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		segCnt := 1
		samePos := -1
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			if i > 0 {
				if a[i] != a[i-1] {
					segCnt++
				} else {
					samePos = i
				}
			}
		}
		if segCnt == 1 {
			Fprintln(out, 1)
			Fprintln(out, strings.Repeat("1 ", n))
		} else if samePos == -1 && segCnt&1 == 1 {
			Fprintln(out, 3)
			Fprintln(out, strings.Repeat("1 2 ", n/2)+"3")
		} else {
			Fprintln(out, 2)
			c := 1
			Fprint(out, 1, " ")
			if samePos == -1 || segCnt&1 == 0 {
				for i := 1; i < n; i++ {
					if a[i] != a[i-1] {
						c = 3 - c
					}
					Fprint(out, c, " ")
				}
			} else {
				for i := 1; i < n; i++ {
					if i == samePos || a[i] != a[i-1] {
						c = 3 - c
					}
					Fprint(out, c, " ")
				}
			}
			Fprintln(out)
		}
	}
}

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

package main

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

const N = 200010
var nt int
var n int
var a [N] int

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

	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d\n", &n)
		for i := 1; i <= n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}
		fmt.Fscanf(reader, "\n")

		var same = true
		for i := 1; i < n; i++ {
			if a[i] != a[i + 1] {
				same = false
				break
			}
		}

		if same {
			fmt.Fprintf(writer, "1\n")
			for i := 1; i <= n; i++ {
				fmt.Fprintf(writer, "1 ")
			}
			fmt.Fprintf(writer, "\n")
			continue
		}

		if n % 2 == 0 {
			fmt.Fprintf(writer, "2\n")
			for i := 1; i <= n; i++ {
				if i % 2 == 0 {
					fmt.Fprintf(writer, "1 ")
				} else {
					fmt.Fprintf(writer, "2 ")
				}
			}
			fmt.Fprintf(writer, "\n")
			continue
		}

		a[n + 1] = a[1]
		var pos = -1
		for i := 1; i <= n; i++ {
			if a[i] == a[i + 1] {
				pos = i
				break
			}
		}

		if pos == -1 {
			fmt.Fprintf(writer, "3\n")
			for i := 1; i < n; i++ {
				if i % 2 == 0 {
					fmt.Fprintf(writer, "1 ")
				} else {
					fmt.Fprintf(writer, "2 ")
				}
			}
			fmt.Fprintf(writer, "3\n")
			continue
		}

		val := 1

		fmt.Fprintf(writer, "2\n")
		for i := 2; i <= n; i++ {
			if i != pos + 1 {
				val = 3 - val
			}
			fmt.Fprintf(writer, "%d ", val)
		}
		fmt.Fprintf(writer, "\n")
	}

}

package main

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

const N = 200010
var nt int
var n int
var a [N] int
var b [N] int

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

	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d\n", &n)
		for i := 1; i <= n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}

		a[n + 1] = a[1]
		b[1] = 1
		cnt := 1

		for i := 2; i <= n; i++ {
			if a[i] == a[i - 1] {
				b[i] = b[i - 1]
			} else {
				b[i] = 3 - b[i - 1]
			}

			if b[i] == 2 && cnt == 1 {
				cnt++
			}
		}

		if a[1] != a[n] && b[n] == b[1] {
			cnt++
			b[n] = cnt
		}

		fmt.Fscanf(reader, "\n")

		fmt.Fprintf(writer, "%d\n", cnt)

		for i:= 1; i <= n; i++ {
			fmt.Fprintf(writer, "%d ", b[i])
		}

		fmt.Fprintf(writer, "\n")
	}

}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

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

var sc = newScanner()

func main() {
	t := scanInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	n := scanInt()
	m := make(map[int]int)
	res := make([]int, n)
	max := 1
	for i := 0; i < n; i++ {
		f := scanInt()
		if _, ok := m[f]; ok {
			res[i] = m[f]
		} else {
			res[i] = max
			m[f] = max
			max++
		}
	}
	fmt.Println(len(m))
	fmt.Println(strings.Trim(fmt.Sprint(res), "[]"))
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

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

var sc = newScanner()

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		f := scanInts(n)
		res := make([]int, n)
		m := 1
		res[0] = 1
		for i := 1; i < n; i++ {
			if f[i] == f[i-1] {
				res[i] = res[i-1]
			} else {
				res[i] = res[i-1] ^ 3
				m = 2
			}
			if i == n-1 && f[i] != f[0] && res[i] == res[0] {
				res[i] = 3
				m = 3
			}
		}
		fmt.Println(m)
		fmt.Println(strings.Trim(fmt.Sprint(res), "[]"))
	}
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

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

var sc = newScanner()

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

	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		f := make([]int, n)
		m := make(map[int]bool)
		r := -1
		for i := 0; i < n; i++ {
			x := scanInt()
			f[i] = x
			m[x] = true
			if i > 0 && r == -1 && f[i] == f[i-1] {
				r = i
			}
		}

		cnt := 0
		res := make([]int, n)
		if len(m) == 1 {
			cnt = 1
			for i := 0; i < n; i++ {
				res[i] = 1
			}

		} else if n&1 == 0 {
			cnt = 2
			res[0] = 1
			for i := 1; i < n; i++ {
				res[i] = res[i-1] ^ 3
			}
		} else if r > 0 {
			cnt = 2
			res[0] = 1
			for i := 1; i < n; i++ {
				res[i] = res[i-1] ^ 3
				if i == r {
					res[i] = res[i-1]
				}
			}
		} else {
			cnt = 3
			res[0], res[n-1] = 1, 3
			for i := 1; i < n-1; i++ {
				res[i] = res[i-1] ^ 3
			}
		}

		fmt.Println(cnt)
		fmt.Println(strings.Trim(fmt.Sprint(res), "[]"))
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1328/problem/D

package main

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

type Answer struct {
	min   int
	array []int
}

func Solve(n int, t []int) Answer {
	allSame := true
	for i := 1; i < n; i++ {
		if t[i] != t[0] {
			allSame = false
		}
	}
	ans := Answer{}
	ans.array = make([]int, n)
	if allSame {
		ans.min = 1
		for i := 0; i < n; i++ {
			ans.array[i] = 1
		}
		return ans
	}
	if n%2 == 0 {
		ans.min = 2
		for i := 0; i < n; i++ {
			ans.array[i] = i%2 + 1
		}
		return ans
	}
	l := -1
	r := -1
	if n%2 == 1 {
		for i := 0; i < n-1; i++ {
			if t[i] == t[i+1] {
				l = i
				r = i + 1
			}
		}
	}
	if l == -1 && r == -1 {
		for i := 0; i < n; i++ {
			ans.array[i] = i%2 + 1
		}
		ans.array[n-1] = 3
		ans.min = 3
		return ans
	}
	ans.min = 2
	ans.array[l] = 1
	ans.array[r] = 1
	for i := 0; i < l; i++ {
		ans.array[i] = (l-i)%2 + 1
	}
	for i := r + 1; i < n; i++ {
		ans.array[i] = (i-r)%2 + 1
	}
	return ans
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		t := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &t[i])
		}
		fmt.Fscanf(reader, "\n")
		ans := Solve(n, t)
		fmt.Fprintf(writer, "%d\n", ans.min)
		for _, elem := range ans.array {
			fmt.Fprintf(writer, "%d ", elem)
		}
		fmt.Fprintf(writer, "\n")
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1328/problem/D

package main

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

type Answer struct {
	min   int
	array []int
}

func Solve(n int, t []int) Answer {
	ans := Answer{}
	ans.array = make([]int, n)
	ans.array[0] = 1
	ans.min = 1
	for i := 1; i < n; i++ {
		if t[i] == t[i-1] {
			ans.array[i] = ans.array[i-1]
		} else {
			ans.array[i] = -ans.array[i-1] + 3
		}
	}
	if ans.array[n-1] == ans.array[0] && t[n-1] != t[0] {
		ans.array[n-1] = 3
	}
	for _, elem := range ans.array {
		if elem > ans.min {
			ans.min = elem
		}
	}
	return ans
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		t := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &t[i])
		}
		fmt.Fscanf(reader, "\n")
		ans := Solve(n, t)
		fmt.Fprintf(writer, "%d\n", ans.min)
		for _, elem := range ans.array {
			fmt.Fprintf(writer, "%d ", elem)
		}
		fmt.Fprintf(writer, "\n")
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1328/problem/D

package main

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

type Answer struct {
	min   int
	array []int
}

func Solve(n int, t []int) Answer {
	allSame := true
	for i := 1; i < n; i++ {
		if t[i] != t[0] {
			allSame = false
		}
	}
	ans := Answer{}
	ans.array = make([]int, n)
	if allSame {
		ans.min = 1
		for i := 0; i < n; i++ {
			ans.array[i] = 1
		}
		return ans
	}
	if n%2 == 0 {
		ans.min = 2
		for i := 0; i < n; i++ {
			ans.array[i] = i%2 + 1
		}
		return ans
	}
	ans.array[0] = 1
	ans.min = 1
	for i := 1; i < n; i++ {
		if t[i] == t[i-1] {
			ans.array[i] = ans.array[i-1]
		} else {
			ans.array[i] = -ans.array[i-1] + 3
		}
	}
	if ans.array[n-1] == ans.array[0] && t[n-1] != t[0] {
		ans.array[n-1] = 3
	}
	for _, elem := range ans.array {
		if elem > ans.min {
			ans.min = elem
		}
	}
	return ans
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		t := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &t[i])
		}
		fmt.Fscanf(reader, "\n")
		ans := Solve(n, t)
		fmt.Fprintf(writer, "%d\n", ans.min)
		for _, elem := range ans.array {
			fmt.Fprintf(writer, "%d ", elem)
		}
		fmt.Fprintf(writer, "\n")
	}
}

package main

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

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewWriter(os.Stdout)

func main() {
	defer writer.Flush()
	q := reader.NextInt64()
	for ; q > 0; q-- {
		n := reader.NextInt64()
		vals := []int64{}
		for ; n > 0; n-- {
			vals = append(vals, reader.NextInt64())
		}
        res, resVals := sol(vals)
        writer.Printf("%d\n", res)
        for _, v := range resVals {
            writer.Printf("%d ", v)
        }
        writer.Printf("\n")
	}
}

func sol(vals []int64) (int64, []int64) {
    maxSoFar := int64(1)
    res := []int64{1}
    for i := 1; i < len(vals); i++ {
        prev := vals[i-1]
        curr := vals[i]
        if curr == prev {
            res = append(res, res[i-1])
        } else {
            res = append(res, alt(res[i-1]))
            maxSoFar = 2
        }
    }
    if vals[0] != vals[len(vals)-1] && res[0] == res[len(res)-1] {
        for i := 1; i < len(vals); i++ {
            if vals[i] == vals[i-1] {
                res[i-1] = alt(res[i-1])
                return maxSoFar, res
            }
        }
    }
    if vals[0] != vals[len(vals)-1] && res[0] == res[len(res)-1] {
        res[0] = 3
        return 3, res
    }
    return maxSoFar, res
}

func alt(i int64) int64 {
    if i == 1 {
        return 2
    }
    return 1
}

package main

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

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewWriter(os.Stdout)

func main() {
	defer writer.Flush()
	q := reader.NextInt64()
	for ; q > 0; q-- {
		n := reader.NextInt64()
		dll := &DLL{Nodes: []*Node{}}
		for ; n > 0; n-- {
			dll.Add(reader.NextInt64())
		}
		dll.Build()
		dll.Solve()
		res := dll.GetRes()
		for _, num := range res {
			writer.Printf("%d ", num)
		}
		writer.Printf("\n")
	}
}

// DLL is a doubly linked list
type DLL struct {
	Nodes []*Node
}

type Node struct {
	Val   int64 // fill on init
	Left  *Node // fill on build
	Right *Node // fill on build
	Res   int64 // fill on solve
}

func (dll *DLL) Add(v int64) {
	dll.Nodes = append(dll.Nodes, &Node{Val: v})
}

func (dll *DLL) Build() {
	for i := range dll.Nodes {
		left := i - 1
		if i-1 < 0 {
			left = len(dll.Nodes) - 1
		}
		right := i + 1
		if i+1 > len(dll.Nodes)-1 {
			right = 0
		}
		dll.Nodes[i].Left = dll.Nodes[left]
		dll.Nodes[i].Right = dll.Nodes[right]
	}
}

func (dll *DLL) Solve() {
	u := 1
	dll.Nodes[0].Res = int64(1)
	for i := 1; i < len(dll.Nodes); i++ {
		node := dll.Nodes[i]
		if node.Val == node.Left.Val {
			node.Res = node.Left.Res
		} else {
			node.Res = alt(node.Left.Res)
			u = 2
		}
	}
	if dll.Nodes[0].Val != dll.Nodes[0].Left.Val {
		if dll.Nodes[0].Left.Res == dll.Nodes[0].Res {
			if dll.Nodes[0].Right.Val == dll.Nodes[0].Val {
				dll.Nodes[0].Res = 2
			} else {
				dll.Nodes[0].Res = 3
				u = 3
			}
		}
	}
	writer.Printf("%d\n", u)
}

func alt(color int64) int64 {
	if color == 1 {
		return 2
	}
	return 1
}

func (dll *DLL) GetRes() []int64 {
	ret := []int64{}
	for _, node := range dll.Nodes {
		ret = append(ret, node.Res)
	}
	return ret
}