You are a coach of a group consisting of $$$n$$$ students. The $$$i$$$-th student has programming skill $$$a_i$$$. All students have distinct programming skills. You want to divide them into teams in such a way that:  No two students $$$i$$$ and $$$j$$$ such that $$$|a_i - a_j| = 1$$$ belong to the same team (i.e. skills of each pair of students in the same team have the difference strictly greater than $$$1$$$);  the number of teams is the minimum possible. You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of students in the query. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$, all $$$a_i$$$ are distinct), where $$$a_i$$$ is the programming skill of the $$$i$$$-th student.

For each query, print the answer on it — the minimum number of teams you can form if no two students $$$i$$$ and $$$j$$$ such that $$$|a_i - a_j| = 1$$$ may belong to the same team (i.e. skills of each pair of students in the same team has the difference strictly greater than $$$1$$$)

NoteIn the first query of the example, there are $$$n=4$$$ students with the skills $$$a=[2, 10, 1, 20]$$$. There is only one restriction here: the $$$1$$$-st and the $$$3$$$-th students can't be in the same team (because of $$$|a_1 - a_3|=|2-1|=1$$$). It is possible to divide them into $$$2$$$ teams: for example, students $$$1$$$, $$$2$$$ and $$$4$$$ are in the first team and the student $$$3$$$ in the second team.In the second query of the example, there are $$$n=2$$$ students with the skills $$$a=[3, 6]$$$. It is possible to compose just a single team containing both students.

package main

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

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		solveOne()
	}
}

func solveOne() {
	n := readInt()
	a := make([]bool, 102)
	ans := 1
	for i := 0; i < n; i++ {
		v := readInt()
		if a[v-1] || a[v+1] {
			ans = 2
		}
		a[v] = true
	}
	printInt(ans)
}

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

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

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		data := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &data[j])
		}
		sort.Slice(data, func(i, j int) bool {
			return data[i] < data[j]
		})
		ans := 1
		for j := 0; j < n-1; j++ {
			if data[j+1]-data[j] == 1 {
				ans = 2
			}
		}
		fmt.Println(ans)
	}
}

package main
import "fmt"
func main(){
	var q,n,x int
	fmt.Scan(&q)
	for k:=0;k<q;k++{
		num := make([]bool,110)
		ans := 0
		fmt.Scan(&n)
		for i:=0;i<n;i++{
			fmt.Scan(&x)
			num[x] = true;
		}
		for i:=1;i<=100;i++{
			if(num[i] == false){
				continue
			}
			ans++
			tmp := i+1
			for (tmp<=100){
				tmp++
				if (num[tmp] == false){
					continue
				}
				//fmt.Printf("Test %d %d\n",i,tmp)
				num[tmp] = false
				tmp++
			}
		}
		fmt.Println(ans)
	}

}

package main

import (
    "fmt"
    "bufio"
    "os"
    "sort"
)
var input *bufio.Reader

func solve() {
    var N int
    fmt.Fscanf(input, "%d\n", &N)
    skill := make([]int, N)
    for i:=0 ; i<N ; i++ {
        fmt.Fscanf(input, "%d", &skill[i])
    }
    sort.Ints(skill)
    fmt.Fscanf(input, "\n")
    for i:=0 ; i<N-1 ; i++ {
        if skill[i] == skill[i+1] - 1 {
            fmt.Println(2)
            return
        }
    }
    fmt.Println(1)
}

func main () {
    input = bufio.NewReader(os.Stdin)
    var T int
    fmt.Fscanf(input, "%d\n", &T)
    for i:=0; i<T; i++ {
        solve()
    }
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		breakIntoGroups()
	}
}

func breakIntoGroups() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	for i := 1; i < n; i++ {
		if a[i]-a[i-1] == 1 {
			fmt.Println(2)
			return
		}
	}
	fmt.Println(1)
}

package main

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

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

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

	var testCases, n, temp int
	fmt.Fscanf(reader, "%d\n", &testCases)
	for tCase:= 1; tCase <= testCases; tCase++{
		fmt.Fscanf(reader, "%d\n", &n)
		inputArr := make([]int, 0)
		for i := 1; i <= n; i++{
			fmt.Fscanf(reader, "%d", & temp)
			inputArr = append(inputArr, temp)
		}
		fmt.Fscanf(reader, "\n")
		sort.Ints(inputArr)
		answer := 1
		for i := 0; i < len(inputArr) - 1; i++{
			if abs(inputArr[i], inputArr[i+1]) == 1{
				answer = 2
			}
		}
		fmt.Println(answer)
	}

}

package main

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

func solve() {
	q := readInt32()
	for i := 0; i < q; i++ {
		n := readInt32()
		arr := make([]int, n)
		for j := range arr {
			arr[j] = readInt32()
		}
		sort.Ints(arr)
		ans := 1
		prv := -1
		for _, val := range arr {
			if val - prv == 1 {
				ans = 2
			}
			prv = val
		}
		writeString(ans)
	}

}

/*   Helping stuff   */
type pair struct {
	a, b int
}

func newPair(a, b int) pair {
	return pair{a, b}
}

func mod(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

	solve()
}

/*   Scanner   */
var in *bufio.Reader
var out *bufio.Writer
var stringParts []string

func readLine() string {
	str, _, _ := in.ReadLine()
	return string(str)
}

func readNext() string {
	if len(stringParts) == 0 {
		stringParts = strings.Split(readLine(), " ")
	}
	res := stringParts[0]
	stringParts = stringParts[1:]
	return res
}

func readInt32() int {
	res, _ := strconv.ParseInt(readNext(), 10, 32)
	return int(res)
}

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

func readFloat32() float32 {
	res, _ := strconv.ParseFloat(readNext(), 32)
	return float32(res)
}

func readFloat64() float64 {
	res, _ := strconv.ParseFloat(readNext(), 32)
	return res
}

func writeString(s interface{}) {
	out.WriteString(fmt.Sprintf("%v ", s))
	out.Flush()
}

func writeSlice(s interface{}) {
	writeString(strings.Trim(strings.Join(strings.Split(fmt.Sprint(s), " "), " "), "[]"))
}

func ln() {
	out.Write([]byte{'\n'})
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var q int
	for fmt.Scan(&q); q > 0; q-- {
		var n int
		fmt.Scan(&n)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
		}
		sort.Ints(a)
		ans := 1
		for i := 0; i < n - 1; i++ {
			if a[i] == a[i + 1] - 1 {
				ans = 2
			}
		}
		fmt.Println(ans)
	}
}

package main

import "fmt"

func main()  {
	var q int
	fmt.Scanf("%d\n", &q)

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

		numbers := map[int]bool{}
		count := 1

		for j := 0; j < n; j++ {
			var x int
			fmt.Scanf("%d", &x)
			numbers[x] = true

			if _, ok := numbers[x-1]; ok {
				if count != 2 {
					count++
				}
			} else if _, ok := numbers[x+1]; ok {
				if count != 2 {
					count++
				}
			}
		}
		fmt.Scanf("\n")

		fmt.Println(count)
	}
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var q int

func main() {
	q = ReadInt()

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

		sort.Sort(sort.IntSlice(A))

		diffNum := 0
		for i := 0; i < n-1; i++ {
			if AbsInt(A[i]-A[i+1]) == 1 {
				diffNum++
			}
		}

		if diffNum > 0 {
			fmt.Println(2)
		} else {
			fmt.Println(1)
		}
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

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

	var q int
	for Fscan(in, &q); q > 0; q-- {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		ans := 1
		for i := 1; i < n; i++ {
			if a[i]-a[i-1] == 1 {
				ans = 2
				break
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	q := readi()
	for i := 0; i < q; i++ {
		n := readi()
		a := make([]int, n)
		for j := range a {
			a[j] = readi()
		}
		println(solve(n, a))
	}
}

func solve(n int, a []int) int {
	sort.Ints(a)
	ans := 1
	for i := 0; i+1 < n; i++ {
		if abs(a[i]-a[i+1]) == 1 {
			ans = 2
		}
	}
	return ans
}

package main

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

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

func main() {
   for t := ScanInt64(); t > 0; t-- {
    n := ScanInt64()
    a := ScanInt64Slice(n)
    sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
    result := 1
    for i := 1; i < len(a); i++ {
        if abs(a[i] - a[i-1]) == 1 {
            result++
            break
        }
    }

    O <- S(result)
   }

   close(O)
   oWg.Wait()
}

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

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

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

func init() {
   Pl = fmt.Println

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

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

   writer := bufio.NewWriterSize(os.Stdout, int(1e5))
   go func(writer *bufio.Writer) {
      defer oWg.Done()
      defer writer.Flush()

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

func ScanWord() string {
   in.Scan()
   return in.Text()
}

func ScanStringSlice(n int64) []string {
   length := int(n)
   s := make([]string, n)
   for i := 0; i < length; i++ {
      s[i] = ScanWord()
   }
   return s
}

func ScanInt64() int64 {
   intStr := ScanWord()
   i, err := strconv.ParseInt(intStr, 10, 64)
   if err != nil {
      panic(err)
   }
   return i
}

func ScanInt() int {
   intStr := ScanWord()
   i, err := strconv.Atoi(intStr)
   if err != nil {
      panic(err)
   }
   return i
}

func ScanInt64Slice(n int64) []int64 {
   length := int(n)
   arr := make([]int64, n)
   for i := 0; i < length; i++ {
      arr[i] = ScanInt64()
   }
   return arr
}

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

func Mx(args ...int64) int64 {
   maxVal := MN_INT
   for _, v := range args {
      if v > maxVal {
         maxVal = v
      }
   }
   return maxVal
}

func Mn(args ...int64) int64 {
   minVal := MX_INT
   for _, v := range args {
      if v < minVal {
         minVal = v
      }
   }
   return minVal
}

func LCM(a, b int64) int64 {
   return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
   if (a == 0) {
      return b
   }
   return GCD(b%a, a)
}

func S(v interface{}) string {
   return fmt.Sprintf("%v", v)
}

package main

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func diff(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}
func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func largest(a, b, c int) (lgst int) {
	if a > b {
		lgst = a
	} else {
		lgst = b
	}
	if c > lgst {
		lgst = c
	}
	return
}
func smallest(a, b, c int) (slst int) {
	if a < b {
		slst = a
	} else {
		slst = b
	}
	if c < slst {
		slst = c
	}
	return
}
func intsMax(a []int) (idx, val int) {
	if len(a) == 0 {
		panic("func max: argument slice length must not be zero")
	}
	val = a[0]
	for i, aa := range a {
		if aa > val {
			idx, val = i, aa
		}
	}
	return
}
func intsMin(a []int) (idx, val int) {
	if len(a) == 0 {
		panic("func min: argument slice length must not be zero")
	}
	val = a[0]
	for i, aa := range a {
		if aa < val {
			idx, val = i, aa
		}
	}
	return
}
func intsSum(a []int) int {
	res := 0
	for _, v := range a {
		res += v
	}
	return res
}
func intsAdd(ints *[]int, x int) { *ints = append(*ints, x) }
func intsJoin(a, b []int) []int  { return append(a, b...) }
func intsClear(a []int) []int    { return a[:0] }
func intsCopy(a []int) []int     { return append([]int(nil), a...) }
func intsSorted(a []int) []int {
	s := intsCopy(a)
	sort.Ints(s)
	return s
}
func intsReverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return
}
func intsFill(a []int, val int) {
	for i := 0; i < len(a); i++ {
		a[i] = val
	}
	return
}
func intsPeekBack(a []int) int {
	if len(a) == 0 {
		panic("func peekBack: zero length slice")
	}
	return a[len(a)-1]
}
func intsPeekFront(a []int) int {
	if len(a) == 0 {
		panic("func peekFront: zero length slice")
	}
	return a[0]
}
func intsPopBack(a []int) (int, []int) {
	if len(a) == 0 {
		panic("func popBack: zero length slice")
	}
	return a[len(a)-1], a[:len(a)-1]
}
func intsPopFront(a []int) (int, []int) {
	if len(a) == 0 {
		panic("func popFront: zero length slice")
	}
	return a[0], a[1:]
}
func intsPushBack(a []int, x int) []int  { return append(a, x) }
func intsPushFront(a []int, x int) []int { return append([]int{x}, a...) }
func intsAppendSentinelHead(a []int, sentinel int) []int {
	return append([]int{sentinel}, a...)
}
func intsAppendSentinelTail(a []int, sentinel int) []int {
	return append(a, sentinel)
}
func intsAppendSentinel(a []int, sentinel int) []int {
	return append(append([]int{sentinel}, a[:len(a):len(a)+2]...), sentinel)
}
func isEven(n int) bool    { return n&1 == 0 }
func isOdd(n int) bool     { return n&1 == 1 }
func ceil(x float64) int   { return int(math.Ceil(x)) }
func ceilDiv(x, y int) int { return (x + y - 1) / y }
func pow(x, y int) int {
	if y < 0 {
		panic("Exponent must be a natural number")
	}
	z := 1
	for i := y; i != 0; i >>= 1 {
		if i&1 == 1 {
			z *= x
		}
		x *= x
	}
	return z
}
func fact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact *= i
	}
	return fact
}
func sigmaK(n int) int  { return n * (n + 1) / 2 }
func sigmaKK(n int) int { return (n * (n + 1) / 2) * (2*n + 1) / 3 }
func euclideanDistance(a, b point) float64 {
	s := diff(a.x, b.x)
	s *= s
	t := diff(a.y, b.y)
	t *= t
	return math.Sqrt(float64(s) + float64(t))
}
func manhattanDistance(a, b point) int {
	s := diff(a.x, b.x)
	t := diff(a.y, b.y)
	return s + t
}
func swap(a, b *int) { *a, *b = *b, *a }
func chmax(a *int, b int) {
	if *a < b {
		*a = b
	}
}
func chmin(a *int, b int) {
	if *a > b {
		*a = b
	}
}
func cumSum(a []int) []int {
	b := append([]int{0}, a...)
	for i := 1; i < len(b); i++ {
		b[i] += b[i-1]
	}
	return b
}
func runesReverse(a []rune) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return
}
func bytesReverse(a []byte) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return
}
func strUpperCase(s string) string { return strings.ToUpper(s) }
func strLowerCase(s string) string { return strings.ToLower(s) }
func strToInt(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}
func intToStr(i int) string  { return strconv.Itoa(i) }
func CalcMod(a, mod int) int { return (a%mod + mod) % mod }
func ModPow(x, y, mod int) int {
	if y < 0 {
		panic("Exponent must be a natural number")
	}
	z := 1
	for i := y; i != 0; i >>= 1 {
		if i&1 == 1 {
			z = (z * x) % mod
		}
		x = (x * x) % mod
	}
	return z
}
func ModFact(x, mod int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % mod
	}
	return fact
}
func ModInv(x, mod int) int { return ModPow(x, mod-2, mod) }
func initMatrixBool(parentSize, childSize int, initialValue bool) *[][]bool {
	res := make([][]bool, parentSize)
	for i := range res {
		res[i] = make([]bool, childSize)
		for j := range res[i] {
			res[i][j] = initialValue
		}
	}
	return &res
}
func initMatrixInt(parentSize, childSize int, initialValue int) *[][]int {
	res := make([][]int, parentSize)
	for i := range res {
		res[i] = make([]int, childSize)
		for j := range res[i] {
			res[i][j] = initialValue
		}
	}
	return &res
}

var (
	sc = bufio.NewScanner(os.Stdin)
	bw = bufio.NewWriterSize(os.Stdout, bwBufSize)
)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1e7), 1e7)
}
func ru() (n int) {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}
func ri() (n int) {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	b := sc.Bytes()
	neg := false
	if b[0] == 45 {
		neg = true
		b = b[1:]
	}
	for _, v := range b {
		n = n*10 + int(v-48)
	}
	if neg {
		n = -n
	}
	return
}
func ri64() (n int64) {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	b := sc.Bytes()
	neg := false
	if b[0] == 45 {
		neg = true
		b = b[1:]
	}
	for _, v := range b {
		n = n*10 + int64(v-48)
	}
	if neg {
		n = -n
	}
	return
}
func rf64() float64 {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}
func rs() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return sc.Text()
}
func rb() []byte {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return sc.Bytes()
}
func rr() []rune {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return []rune(sc.Text())
}
func ris(n int) []int {
	s := make([]int, n)
	for i := range s {
		s[i] = ri()
	}
	return s
}
func risZeroBased(n int) []int {
	s := make([]int, n)
	for i := range s {
		s[i] = ri() - 1
	}
	return s
}
func ri64s(n int) []int64 {
	s := make([]int64, n)
	for i := range s {
		s[i] = ri64()
	}
	return s
}
func rss(n int) []string {
	s := make([]string, n)
	for i := range s {
		s[i] = rs()
	}
	return s
}
func pf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(bw, format, a...); err != nil {
		panic(err)
	}
}
func pln(a ...interface{}) {
	if _, err := fmt.Fprintln(bw, a...); err != nil {
		panic(err)
	}
}
func pints(a []int) {
	for _, v := range a {
		fmt.Fprintln(bw, v)
	}
}
func pintsol(a []int) {
	s := fmt.Sprint(a)
	if _, err := fmt.Fprintln(bw, s[1:len(s)-1]); err != nil {
		panic(err)
	}
}
func dbg(a ...interface{}) {
	if _, err := fmt.Fprintln(os.Stderr, a...); err != nil {
		panic(err)
	}
}
func YESorNO(b bool) string {
	if b {
		return "YES"
	} else {
		return "NO"
	}
}
func YesOrNo(b bool) string {
	if b {
		return "Yes"
	} else {
		return "No"
	}
}
func main() {
	solve()
	bw.Flush()
}

const (
	bwBufSize = 1e6

	alphabetUpper = "abcdefghijklmnopqrstuvwxyz"
	alphabetLower = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	// maxInt64  = 9223372036854775807  // 9e18
	// maxInt32  = 2147483647           // 2e9
	// maxUint64 = 18446744073709551615 // 1e19
	inf = 1 << 60
	mod = 1e9 + 7
)

type pair struct{ fi, se int }
type byFiSe []pair

func (p byFiSe) Len() int      { return len(p) }
func (p byFiSe) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p byFiSe) Less(i, j int) bool {
	if p[i].fi == p[j].fi {
		return p[i].se < p[j].se
	}
	return p[i].fi < p[j].fi
}

type point struct{ x, y int }

func solve() {
	q := ri()
	for i := 0; i < q; i++ {
		n := ri()
		as := ris(n)

		sort.Ints(as)
		ok := true
		for i := 0; i < n-1; i++ {
			if as[i+1]-as[i] == 1 {
				ok = false
				break
			}
		}
		if ok {
			pln(1)
		} else {
			pln(2)
		}
	}
}

package main

import (
    "fmt"
    "bufio"
    "os"
)
var input *bufio.Reader

func solve() {
    var n int
    fmt.Fscanf(input, "%d\n", &n)
    a := make([]bool, 101)
    for i:=0; i<n; i++ {
        var x int
        fmt.Fscanf(input, "%d", &x)
        a[x] = true
    }
    fmt.Fscanf(input, "\n")
    for i:=1; i<=99; i++ {
        if(a[i] && a[i+1]){
            fmt.Println(2)
            return
        }
    }
    fmt.Println(1)
}

func main(){
    input = bufio.NewReader(os.Stdin)
    var T int
    fmt.Fscanf(input, "%d\n", &T)
    for i:=0; i<T; i++ {
        solve()
    }
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var(
        n int
        m int
        x [1010]int
        f bool
    )
    fmt.Scanf("%d\n",&n)
    for i:=0 ; i<n ; i++ {
        fmt.Scanf("%d\n", &m)
        for j:=0 ; j<m ; j++ {
            fmt.Scanf("%d", &x[j])
        }
        var b []int = x[0:m]
        sort.Ints(b)
        f=true
        for j:=1 ; j<m ; j++ {
            if b[j-1]+1==b[j]{
                f=false
            }
        }
        if f == true {
            fmt.Println("1")
        }else{
            fmt.Println("2")
        }
        fmt.Scanf("\n")
    }
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, q, t int
	fmt.Fscanf(reader, "%d\n", &q)

	for ; q > 0; q-- {
		fmt.Fscanf(reader, "%d\n", &n)

		a := make([]bool, 102)

		for i := 1; i <= n; i++ {
			if i == n {
				fmt.Fscanf(reader, "%d\n", &t)
			} else {
				fmt.Fscanf(reader, "%d ", &t)
			}

			a[t] = true
		}

		team := 1
		for i := 1; i < 101; i++ {
			if a[i] && a[i-1] {
				team = 2
				break
			}
		}
		fmt.Printf("%d\n", team)

	}

}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, q, t int
	fmt.Scanf("%d\n", &q)

	res := make([]int, q)
	for j := 0; j < q; j++ {
		fmt.Scanf("%d\n", &n)

		a := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &t)
			a[i] = t
		}

		res[j] = 1
		sort.Ints(a)
		for z := 1; z < len(a); z++ {
			if (a[z] - a[z-1]) == 1 {
				res[j] = 2
				break
			}
		}

		fmt.Scanf("\n")
	}

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

package main

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

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

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

	var numCases, n, temp int
	fmt.Fscanf(reader, "%d\n", &numCases)
	for tcase := 1; tcase <= numCases; tcase++ {
		fmt.Fscanf(reader, "%d\n", &n)
		arr := make([]int, 0)
		for i := 1; i <= n; i++ {
			fmt.Fscanf(reader, "%d", &temp)
			arr = append(arr, temp)
		}
		fmt.Fscanf(reader, "\n")
		sort.Ints(arr)
		found := false
		for i := 1; i < len(arr); i++ {
			if abs(arr[i], arr[i-1]) == 1 {
				found = true
				break
			}
		}
		if found {
			fmt.Fprintf(writer, "2\n")
		} else {
			fmt.Fprintf(writer, "1\n")
		}
	}

}

// Author: sighduck
// URL: https://codeforces.com/contest/1249/problem/A

package main

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

func Solve(a []int) int {
	sort.Ints(a)
	for i := 1; i < len(a); i++ {
		if a[i] == a[i-1]+1 {
			return 2
		}
	}
	return 1
}

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)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%d\n", Solve(a))
	}
}

package main

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

type WordScanner struct {
	*bufio.Scanner
}

func NewWordScanner() *WordScanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &WordScanner{Scanner: s}
}

func (s *WordScanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *WordScanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *WordScanner) NextString() string {
	s.Scan()
	return s.Text()
}

func main() {
	ws := NewWordScanner()
	q := ws.NextInt()
	for i := 0; i < q; i++ {
		n := ws.NextInt()
		sl := []int{}
		for j := 0; j < n; j++ {
			sl = append(sl, ws.NextInt())
		}
		fmt.Println(sol(sl))
	}
}

func sol(sl []int) int {
    if len(sl) == 0 {
        return 0 // should not happen
    }
    sort.Ints(sl)
    prev := sl[0]
    for _, v := range sl[1:] {
        if v - prev <= 1 {
            return 2
        }
        prev = v
    }
	return 1
}

package main
import "fmt"
func main(){
	var q,n,x int
	fmt.Scan(&q)
	for k:=0;k<q;k++{
		num := make([]bool,110)
		ans := 0
		fmt.Scan(&n)
		for i:=0;i<n;i++{
			fmt.Scan(&x)
			num[x] = true;
		}
		for i:=1;i<=100;i++{
			if(num[i] == false){
				continue
			}
			ans++
			tmp := i+1
			cnt := 1
			for (tmp<=100 && cnt<3){
				tmp++
				if (num[tmp] == false){
					continue
				}
				num[tmp] = false
				cnt++
			}
		}
		fmt.Println(ans)
	}

}

package main
import "fmt"
func main(){
	var q,n,x int
	fmt.Scan(&q)
	for k:=0;k<q;k++{
		num := make([]bool,110)
		ans := 0
		fmt.Scan(&n)
		for i:=0;i<n;i++{
			fmt.Scan(&x)
			num[x] = true;
		}
		for i:=1;i<=100;i++{
			if(num[i] == false){
				continue
			}
			ans++
			tmp := i+1
			cnt := 1
			for (tmp<=100 && cnt<3){
				tmp++
				if (num[tmp] == false){
					continue
				}
				//fmt.Printf("Test %d %d\n",i,tmp)
				num[tmp] = false
				tmp++
				cnt++
			}
		}
		fmt.Println(ans)
	}

}

package main

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

func solve() {
	q := readInt32()
	for i := 0; i < q; i++ {
		n := readInt32()
		arr := make([]int, n)
		for j := range arr {
			arr[j] = readInt32()
		}
		sort.Ints(arr)
		ans := 1
		prv := -1
		wasSplited := false
		for _, val := range arr {
			if mod(ans-prv) == 1 && !wasSplited {
				ans++
				wasSplited = true
			} else {
				wasSplited = false
			}
			prv = val
		}
		writeString(ans)
	}

}

/*   Helping stuff   */
type pair struct {
	a, b int
}

func newPair(a, b int) pair {
	return pair{a, b}
}

func mod(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

	solve()
}

/*   Scanner   */
var in *bufio.Reader
var out *bufio.Writer
var stringParts []string

func readLine() string {
	str, _, _ := in.ReadLine()
	return string(str)
}

func readNext() string {
	if len(stringParts) == 0 {
		stringParts = strings.Split(readLine(), " ")
	}
	res := stringParts[0]
	stringParts = stringParts[1:]
	return res
}

func readInt32() int {
	res, _ := strconv.ParseInt(readNext(), 10, 32)
	return int(res)
}

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

func readFloat32() float32 {
	res, _ := strconv.ParseFloat(readNext(), 32)
	return float32(res)
}

func readFloat64() float64 {
	res, _ := strconv.ParseFloat(readNext(), 32)
	return res
}

func writeString(s interface{}) {
	out.WriteString(fmt.Sprintf("%v ", s))
	out.Flush()
}

func writeSlice(s interface{}) {
	writeString(strings.Trim(strings.Join(strings.Split(fmt.Sprint(s), " "), " "), "[]"))
}

func ln() {
	out.Write([]byte{'\n'})
}

package main

import "fmt"

func main()  {
	var q int
	fmt.Scanf("%d", &q)

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

		numbers := map[int]bool{}
		count := 1

		for j := 0; j < n; j++ {
			var x int
			fmt.Scanf("%d", &x)
			numbers[x] = true

			if _, ok := numbers[x-1]; ok {
				if count != 2 {
					count++
				}
			}

			if _, ok := numbers[x+1]; ok {
				if count != 2 {
					count++
				}
			}
		}

		fmt.Println(count)
	}
}

package main

import "fmt"

func main()  {
	var q int
	fmt.Scanf("%d\n", &q)

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

		numbers := map[int]bool{}
		count := 1

		for j := 0; j < n; j++ {
			var x int
			fmt.Scanf("%d", &x)
			numbers[x] = true

			if _, ok := numbers[x-1]; ok {
				if count != 2 {
					count++
				}
			} else if _, ok := numbers[x+1]; ok {
				if count != 2 {
					count++
				}
			}
		}

		fmt.Println(count)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, q, t int
	fmt.Scanf("%d\n", &q)

	res := make([]int, q)
	for j := 0; j < q; j++ {
		fmt.Scanf("%d\n", &n)

		a := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &t)
			a[i] = t
		}

		res[j] = 1
		sort.Ints(a)
		fmt.Println(a)
		for z := 1; z < len(a); z++ {
			if (a[z] - a[z-1]) == 1 {
				res[j] = 2
				break
			}
		}

		fmt.Scanf("\n")
	}

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

package main

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

type WordScanner struct {
	*bufio.Scanner
}

func NewWordScanner() *WordScanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &WordScanner{Scanner: s}
}

func (s *WordScanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *WordScanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *WordScanner) NextString() string {
	s.Scan()
	return s.Text()
}

func main() {
	ws := NewWordScanner()
	q := ws.NextInt()
	for i := 0; i < q; i++ {
		n := ws.NextInt()
		sl := []int{}
		for j := 0; j < n; j++ {
			sl = append(sl, ws.NextInt())
		}
		fmt.Println(sol(sl))
	}
}

func sol(sl []int) int {
    if len(sl) == 0 {
        return 0 // should not happen
    }
    sort.Ints(sl)
    prev := sl[0]
    for _, v := range sl[1:] {
        if v - prev <= 1 {
            return 2
        }
    }
	return 1
}


Polycarp has invited $$$n$$$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side.Each friend is characterized by two values $$$h_i$$$ (their height) and $$$w_i$$$ (their width). On the photo the $$$i$$$-th friend will occupy a rectangle $$$h_i \times w_i$$$ (if they are standing) or $$$w_i \times h_i$$$ (if they are lying on the side).The $$$j$$$-th friend can be placed in front of the $$$i$$$-th friend on the photo if his rectangle is lower and narrower than the rectangle of the $$$i$$$-th friend. Formally, at least one of the following conditions must be fulfilled:  $$$h_j < h_i$$$ and $$$w_j < w_i$$$ (both friends are standing or both are lying);  $$$w_j < h_i$$$ and $$$h_j < w_i$$$ (one of the friends is standing and the other is lying). For example, if $$$n = 3$$$, $$$h=[3,5,3]$$$ and $$$w=[4,4,3]$$$, then:  the first friend can be placed in front of the second: $$$w_1 < h_2$$$ and $$$h_1 < w_2$$$ (one of the them is standing and the other one is lying);  the third friend can be placed in front of the second: $$$h_3 < h_2$$$ and $$$w_3 < w_2$$$ (both friends are standing or both are lying). In other cases, the person in the foreground will overlap the person in the background.Help Polycarp for each $$$i$$$ find any $$$j$$$, such that the $$$j$$$-th friend can be located in front of the $$$i$$$-th friend (i.e. at least one of the conditions above is fulfilled).Please note that you do not need to find the arrangement of all people for a group photo. You just need to find for each friend $$$i$$$ any other friend $$$j$$$ who can be located in front of him. Think about it as you need to solve $$$n$$$ separate independent subproblems.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of friends. This is followed by $$$n$$$ lines, each of which contains a description of the corresponding friend. Each friend is described by two integers $$$h_i$$$ and $$$w_i$$$ ($$$1 \leq h_i, w_i \leq 10^9$$$) — height and width of the $$$i$$$-th friend, respectively. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output $$$n$$$ integers on a separate line, where the $$$i$$$-th number is the index of a friend that can be placed in front of the $$$i$$$-th. If there is no such friend, then output -1. If there are several answers, output any.

NoteThe first test case is described in the statement.In the third test case, the following answers are also correct:   $$$[-1, -1, 1, 2]$$$;  $$$[-1, -1, 1, 1]$$$;  $$$[-1, -1, 2, 1]$$$.

package main

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

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

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

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

type Friend struct {
	i   int64
	h   int64
	w   int64
	res int64
}

type Solver struct {
	n       int64
	friends map[int64]*Friend
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		friends := map[int64]*Friend{}
		for i := int64(1); i <= n; i++ {
			h, w := sint64(), sint64()
			if h > w {
				friends[i] = &Friend{
					i:   i,
					h:   h,
					w:   w,
					res: -1,
				}
			} else {
				friends[i] = &Friend{
					i:   i,
					h:   w,
					w:   h,
					res: -1,
				}
			}
		}
		(&Solver{n, friends}).Solve()
	}
}

func (s *Solver) Solve() {
	sorted := s.sortFriendsByHeight()
	minw := make([]int64, len(sorted))
	minwRes := make([]int64, len(sorted))
	for i := range sorted {
		if i == 0 {
			minw[i] = sorted[i].w
			minwRes[i] = sorted[i].i
		} else {
			if sorted[i].w < minw[i-1] {
				minw[i] = sorted[i].w
				minwRes[i] = sorted[i].i
			} else {
				minw[i] = minw[i-1]
				minwRes[i] = minwRes[i-1]
			}
		}
	}
	prevIdx := -1
	for i := range sorted {
		if i > 0 && sorted[i-1].h < sorted[i].h {
			prevIdx = i - 1
		}
		if prevIdx != -1 && minw[prevIdx] < sorted[i].w {
			sorted[i].res = minwRes[prevIdx]
		}
	}
	s.output()
}

func (s *Solver) sortFriendsByHeight() []*Friend {
	ret := []*Friend{}
	for _, f := range s.friends {
		ret = append(ret, f)
	}
	sort.Slice(ret, func(il, ir int) bool {
		if ret[il].h == ret[ir].h {
			return ret[il].w < ret[ir].w
		}
		return ret[il].h < ret[ir].h
	})
	return ret
}

func (s *Solver) output() {
	for i := int64(1); i <= s.n; i++ {
		printf("%d ", s.friends[i].res)
	}
	printf("\n")
}

package main

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

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

// var file, _ = os.Open("input")
// var reader *bufio.Reader = bufio.NewReader(file)

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

type person struct {
	w        int
	h        int
	rawIndex int
}

func main() {
	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)
		process(reader, int(n))
		fmt.Println()
	}
}

func process(reader *bufio.Reader, n int) {
	a := make([]person, n)
	var i int
	for i = 0; i < n; i++ {
		scanf("%d %d\n", &a[i].h, &a[i].w)
		if a[i].h < a[i].w {
			a[i].h, a[i].w = a[i].w, a[i].h
		}
		a[i].rawIndex = i
	}
	sort.Slice(a, func(i, j int) bool {
		if a[i].h < a[j].h {
			return true
		}
		if a[i].h > a[j].h {
			return false
		}
		return a[i].w < a[j].w
	})
	fmt.Println()
	minIndex := int(-1)
	currentMinIndex := int(-1)
	result := make([]int, n)
	for i = 0; i < n; i++ {
		if currentMinIndex == -1 {
			result[a[i].rawIndex] = -1
			currentMinIndex = 0
			continue
		}
		if a[i].h != a[i-1].h {
			minIndex = currentMinIndex
		}
		if a[currentMinIndex].w > a[i].w {
			currentMinIndex = i
		}
		if minIndex == -1 {
			result[a[i].rawIndex] = -1
			continue
		}
		if a[minIndex].w < a[i].w {
			result[a[i].rawIndex] = a[minIndex].rawIndex + 1
		} else {
			result[a[i].rawIndex] = -1
		}
	}
	for _, rs := range result {
		fmt.Printf("%d ", rs)
	}
}

package main

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

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

// var file, _ = os.Open("input")
// var reader *bufio.Reader = bufio.NewReader(file)

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

type person struct {
	w        int64
	h        int64
	rawIndex int64
}

func main() {
	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)
		process(reader, int64(n))
		fmt.Println()
	}
}

func process(reader *bufio.Reader, n int64) {
	a := make([]person, n)
	var i int64
	for i = 0; i < n; i++ {
		scanf("%d %d\n", &a[i].h, &a[i].w)
		if a[i].h < a[i].w {
			a[i].h, a[i].w = a[i].w, a[i].h
		}
		a[i].rawIndex = i
	}
	sort.Slice(a, func(i, j int) bool {
		if a[i].h < a[j].h {
			return true
		}
		if a[i].h > a[j].h {
			return false
		}
		return a[i].w < a[j].w
	})
	fmt.Println()
	minIndex := int64(-1)
	currentMinIndex := int64(-1)
	result := make([]int64, n)
	for i = 0; i < n; i++ {
		if currentMinIndex == -1 {
			result[a[i].rawIndex] = -1
			currentMinIndex = 0
			continue
		}
		if a[i].h != a[i-1].h {
			minIndex = currentMinIndex
		}
		if a[currentMinIndex].w > a[i].w {
			currentMinIndex = i
		}
		if minIndex == -1 {
			result[a[i].rawIndex] = -1
			continue
		}
		if a[minIndex].w < a[i].w {
			result[a[i].rawIndex] = a[minIndex].rawIndex + 1
		} else {
			result[a[i].rawIndex] = -1
		}
	}
	for _, rs := range result {
		fmt.Printf("%d ", rs)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

type friend struct {
    index, w, h int
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    friends := make([]friend, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &friends[i].h, &friends[i].w)
        friends[i].index = i
    }
    sort.Slice(friends, func(i, j int) bool { return friends[i].w < friends[j].w })
    sfx := make([]int, n) // min h up to [i]
    minh := friends[0].h
    for i := 1; i < n; i++ {
        if friends[i].h < minh {
            minh = friends[i].h
            sfx[i] = i
        } else {
            sfx[i] = sfx[i - 1]
        }
    }

    ans := make([]int, n)
    //fmt.Println(friends)
    //fmt.Println(sfx)
    for _, v := range friends {
        if pos := getbyw(friends, v.w); pos >= 0 {
            if friends[sfx[pos]].h < v.h {
                ans[v.index] = friends[sfx[pos]].index + 1
                continue
            }
        }

        if pos := getbyw(friends, v.h); pos >= 0 {
            if friends[sfx[pos]].h < v.w {
                ans[v.index] = friends[sfx[pos]].index + 1
                continue
            }
        }

        ans[v.index] = -1
    }
    for i := 0; i < n; i++ {
        if i > 0 { fmt.Fprint(output, " ") }
        fmt.Fprint(output, ans[i])
    }

    fmt.Fprintln(output, "")
}

func getbyw(all []friend, v int) int {
    l, r := -1, len(all)
    for r - l > 1 {
        m := (l + r) >> 1
        if all[m].w < v {
            l = m
        } else {
            r = m
        }
    }

    return l
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y, i int }

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]pair, n)
		for i := range a {
			Fscan(in, &a[i].x, &a[i].y)
			if a[i].x > a[i].y {
				a[i].x, a[i].y = a[i].y, a[i].x
			}
			a[i].i = i
		}
		sort.Slice(a, func(i, j int) bool { return a[i].x < a[j].x })

		ans := make([]int, n)
		mi := -1
		for i := 0; i < n; {
			st := i
			v := a[st]
			for ; i < n && a[i].x == v.x; i++ {
				if mi >= 0 && a[i].y > a[mi].y {
					ans[a[i].i] = a[mi].i + 1
				} else {
					ans[a[i].i] = -1
				}
			}
			for j := st; j < i; j++ {
				if mi == -1 || a[j].y < a[mi].y {
					mi = j
				}
			}
		}

		for _, v := range ans {
			Fprint(out, v, " ")
		}
		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"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// github.com/EndlessCheng/codeforces-go

type node struct {
	lr       [2]*node
	priority uint
	key      int
	val      int
	sz       int // JUST IGNORE
}

func (o *node) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) size() int {
	if o != nil {
		return o.sz
	}
	return 0
}

func (o *node) maintain() { o.sz = 1 + o.lr[0].size() + o.lr[1].size() }

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	o.maintain()
	x.maintain()
	return x
}

type treap struct {
	rd   uint
	root *node
}

func (t *treap) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap) _put(o *node, key, val int) *node {
	if o == nil {
		return &node{priority: t.fastRand(), key: key, val: val, sz: 1}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key, val)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	}
	o.maintain()
	return o
}

func (t *treap) put(key, val int) { t.root = t._put(t.root, key, val) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._delete(o.lr[d], key)
	} else {
		if o.lr[1] == nil {
			return o.lr[0]
		}
		if o.lr[0] == nil {
			return o.lr[1]
		}
		d = 0
		if o.lr[0].priority > o.lr[1].priority {
			d = 1
		}
		o = o.rotate(d)
		o.lr[d] = t._delete(o.lr[d], key)
	}
	o.maintain()
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) get(key int) *node {
	for o := t.root; o != nil; {
		if d := o.cmp(key); d >= 0 {
			o = o.lr[d]
		} else {
			return o
		}
	}
	return nil
}

func newTreap() *treap { return &treap{rd: 1} }

func (t *treap) prev(key int) (prev *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) <= 0 {
			o = o.lr[0]
		} else {
			prev = o
			o = o.lr[1]
		}
	}
	return // NOTE: check nil
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y, i int }
	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]pair, n)
		for i := range a {
			Fscan(in, &a[i].x, &a[i].y)
			if a[i].x > a[i].y {
				a[i].x, a[i].y = a[i].y, a[i].x
			}
			a[i].i = i
		}
		sort.Slice(a, func(i, j int) bool { return a[i].x < a[j].x })

		ans := make([]int, n)
		for _i := range ans {
			ans[_i] = -1
		}
		t := newTreap()
		for i, n := 0, len(a); i < n; {
			st := i
			v := a[st]
			for ; i < n && a[i].x == v.x; i++ {
				o := t.prev(a[i].y)
				if o != nil {
					ans[a[i].i] = o.val + 1
				}
			}
			for j := st; j < i; j++ {
				t.put(a[j].y, a[j].i)
			}
		}

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

	}

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

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

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

package main

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

func unique(a []int) []int {
	var b []int
	b = append(b, a[0])
	for i := 1; i < len(a); i++ {
		if a[i] != a[i-1] {
			b = append(b, a[i])
		}
	}
	return b
}

func valSet(a []int, k int) {
	for i, _ := range a {
		a[i] = k
	}
}

func Solve() {
	n := ri()
	type pair struct{ x, y int }
	var p []pair
	var a []int
	for i := 0; i < n; i++ {
		x, y := ri(), ri()
		p = append(p, pair{x, y})
		a = append(a, x, y)
	}
	sort.Ints(a)
	a = unique(a)
	for i := 0; i < n; i++ {
		p[i].x = lowerBound(a, p[i].x)
		p[i].y = lowerBound(a, p[i].y)
		//println(p[i])
	}
	m := len(a)
	mn := make([]int, m)
	valSet(mn, -1)
	for i := 0; i < n; i++ {
		if mn[p[i].x] == -1 || p[i].y < p[mn[p[i].x]].y {
			mn[p[i].x] = i
		}
	}
	for i := 1; i < m; i++ {
		if (mn[i] == -1) || (mn[i-1] != -1 && p[mn[i-1]].y < p[mn[i]].y) {
			mn[i] = mn[i-1]
		}
	}
	ans := make([]int, n)
	valSet(ans, -1)
	for i := 0; i < n; i++ {
		if p[i].x != 0 && ans[i] == -1 && mn[p[i].x-1] != -1 && p[mn[p[i].x-1]].y < p[i].y {
			ans[i] = mn[p[i].x-1]
		}
	}
	//println(ans)
	valSet(mn, -1)
	for i := 0; i < n; i++ {
		if mn[p[i].y] == -1 || p[i].x < p[mn[p[i].y]].x {
			mn[p[i].y] = i
		}
	}
	for i := 1; i < m; i++ {
		if (mn[i] == -1) || (mn[i-1] != -1 && p[mn[i-1]].x < p[mn[i]].x) {
			mn[i] = mn[i-1]
		}
	}
	for i := 0; i < n; i++ {
		if p[i].x != 0 && ans[i] == -1 && mn[p[i].x-1] != -1 && p[mn[p[i].x-1]].x < p[i].y {
			ans[i] = mn[p[i].x-1]
		}
	}
	for _, x := range ans {
		if x != -1 {
			print(x+1, " ")
		} else {
			print("-1 ")
		}

	}
	println()
}

func main() {
	T := 0 // 如果是多组样例，请讲 T := 1 改为 T := 0
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

var in *bufio.Reader
var out *bufio.Writer

// ri 将直接读入并返回一个 int
func ri() (x int) {
	scan(&x)
	return x
}

// ri64 将直接读入并返回一个 int64
func ri64() (x int64) {
	scan(&x)
	return x
}

//rs 将直接读入并返回一个 string
func rs() (s string) {
	scan(&s)
	return s
}

//scan 用法与 fmt.scan() 相似，可以传入多个变量的地址进行读入操作
func scan(a ...interface{}) { Fscan(in, a...) }

//print 用法与 fmt.print() 相似，可以传入多个变量进行输出。
//注意，这个函数不会换行，多个变量之间有空格
func print(a ...interface{}) { Fprint(out, a...) }

//println 用法与 fmt.println() 相似，可以传入多个变量进行输出。
//这个函数会换行，多个变量之间有空格
func println(a ...interface{}) { Fprintln(out, a...) }

//min 可以传入多个 int 变量，求出这些变量的最小值
func min(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//min64 可以传入多个 int64 变量，求出这些变量的最小值
func min64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//max 可以传入多个 int 变量，求出这些变量的最大值
func max(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//max64 可以传入多个 int64 变量，求出这些变量的最大值
func max64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//sum 可以传入多个 int 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum(a ...int) int {
	ans := 0
	for _, x := range a {
		ans += x
	}
	return ans
}

//sum64 可以传入多个 int64 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum64(a ...int64) int64 {
	ans := int64(0)
	for _, x := range a {
		ans += x
	}
	return ans
}

//reverse 用于翻转 int 切片，所有元素将会变成原切片的倒序
func reverse(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]
	}
}

//reverse64 用于翻转 int64 切片，所有元素将会变成原切片的倒序
func reverse64(a []int64) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//lowerBound 类似于 C++ 中的 lower_bound。
//用于二分查找 int 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int 切片必须升序。
func lowerBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//lowerBound64 类似于 C++ 中的 lower_bound。
//用于二分查找 int64 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int64 切片必须升序。
func lowerBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound 类似于 C++ 中的 upper_bound。
//用于二分查找 int 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int 切片必须升序。
func upperBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound64 类似于 C++ 中的 upper_bound。
//用于二分查找 int64 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int64 切片必须升序。
func upperBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

type Stack struct {
	s []int
}

func (st *Stack) top() int   { return st.s[len(st.s)-1] }
func (st *Stack) size() int  { return len(st.s) }
func (st *Stack) pop()       { st.s = st.s[:len(st.s)-1] }
func (st *Stack) push(x int) { st.s = append(st.s, x) }

type Queue struct {
	que chan int
}

func MakeQueue(size int) Queue {
	var q Queue
	q.que = make(chan int, size)
	return q
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

type Point struct {
	X, Y, I int
}

func solve() {
	n := ReadInt()
	points := make([]Point, n)
	for i := 0; i < n; i++ {
		h, w := ReadInt(), ReadInt()
		if h > w {
			h, w = w, h
		}
		points[i] = Point{h, w, i}
	}

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

	m := make(map[int]int)
	xx := 0
	for _, point := range points {
		if _, ok := m[point.X]; !ok {
			m[point.X] = xx
			xx++
		}
	}

	ans := make([]int, n)
	v := make([]Point, xx)
	for x := 0; x < xx; x++ {
		v[x].I = -1
	}
	seg := NewSegtree(
		v,
		func(x, y S) S {
			if x.I == -1 {
				return y
			}
			if y.I == -1 {
				return x
			}
			if x.Y < y.Y {
				return x
			}
			return y
		},
		func() S { return Point{0, 0, -1} },
	)
	for _, point := range points {
		p := seg.Prod(0, m[point.X])
		if p.I == -1 || p.Y >= point.Y {
			ans[point.I] = -1
		} else {
			ans[point.I] = p.I + 1
		}
		p = seg.Get(m[point.X])
		if p.I == -1 || p.Y > point.Y {
			seg.Set(m[point.X], point)
		}
	}
	printInts(ans...)
}

type S = Point

type E func() S
type Merger func(x, y S) S
type Compare func(x S) bool
type Segtree struct {
	n      int
	size   int
	log    int
	d      []S
	e      E
	merger Merger
}

func NewSegtree(v []S, op Merger, e E) *Segtree {
	seg := new(Segtree)
	seg.n = len(v)
	seg.log = seg.ceilPow2(seg.n)
	seg.size = 1 << uint(seg.log)
	seg.d = make([]S, 2*seg.size)
	seg.e = e
	seg.merger = op
	for i, _ := range seg.d {
		seg.d[i] = seg.e()
	}
	for i := 0; i < seg.n; i++ {
		seg.d[seg.size+i] = v[i]
	}
	for i := seg.size - 1; i >= 1; i-- {
		seg._update(i)
	}
	return seg
}
func (seg *Segtree) _update(k int) {
	seg.d[k] = seg.merger(seg.d[2*k], seg.d[2*k+1])
}
func (seg *Segtree) Set(p int, x S) {
	p += seg.size
	seg.d[p] = x
	for i := 1; i <= seg.log; i++ {
		seg._update(p >> uint(i))
	}
}
func (seg *Segtree) Get(p int) S {
	return seg.d[p+seg.size]
}
func (seg *Segtree) Prod(l, r int) S {
	sml, smr := seg.e(), seg.e()
	l += seg.size
	r += seg.size
	for l < r {
		if (l & 1) == 1 {
			sml = seg.merger(sml, seg.d[l])
			l++
		}
		if (r & 1) == 1 {
			r--
			smr = seg.merger(seg.d[r], smr)
		}
		l >>= 1
		r >>= 1
	}
	return seg.merger(sml, smr)
}
func (seg *Segtree) AllProd() S {
	return seg.d[1]
}
func (seg *Segtree) MaxRight(l int, cmp Compare) int {
	if l == seg.n {
		return seg.n
	}
	l += seg.size
	sm := seg.e()
	for {
		for l%2 == 0 {
			l >>= 1
		}
		if !cmp(seg.merger(sm, seg.d[l])) {
			for l < seg.size {
				l = 2 * l
				if cmp(seg.merger(sm, seg.d[l])) {
					sm = seg.merger(sm, seg.d[l])
					l++
				}
			}
			return l - seg.size
		}
		sm = seg.merger(sm, seg.d[l])
		l++
		if l&-l == l {
			break
		}
	}
	return seg.n
}
func (seg *Segtree) MinLeft(r int, cmp Compare) int {
	if r == 0 {
		return 0
	}
	r += seg.size
	sm := seg.e()
	for {
		r--
		for r > 1 && r%2 != 0 {
			r >>= 1
		}
		if !cmp(seg.merger(seg.d[r], sm)) {
			for r < seg.size {
				r = 2*r + 1
				if cmp(seg.merger(seg.d[r], sm)) {
					sm = seg.merger(seg.d[r], sm)
					r--
				}
			}
			return r + 1 - seg.size
		}
		sm = seg.merger(seg.d[r], sm)
		if r&-r == r {
			break
		}
	}
	return 0
}
func (seg *Segtree) ceilPow2(n int) int {
	x := 0
	for (1 << uint(x)) < n {
		x++
	}
	return x
}

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

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

package main

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

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

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

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

type Friend struct {
	i   int64
	h   int64
	w   int64
	res int64
}

type Solver struct {
	n       int64
	friends map[int64]*Friend
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		friends := map[int64]*Friend{}
		for i := int64(1); i <= n; i++ {
			h, w := sint64(), sint64()
			friends[i] = &Friend{
				i:   i,
				h:   h,
				w:   w,
				res: -1,
			}
		}
		(&Solver{n, friends}).Solve()
	}
}

func (s *Solver) Solve() {
	sorted := s.sortFriendsByHeight()
	minw := make([]int64, len(sorted))
	minwRes := make([]int64, len(sorted))
	for i := range sorted {
		if i == 0 {
			minw[i] = sorted[i].w
			minwRes[i] = sorted[i].i
		} else {
			if sorted[i].w < minw[i-1] {
				minw[i] = sorted[i].w
				minwRes[i] = sorted[i].i
			} else {
				minw[i] = minw[i-1]
				minwRes[i] = minwRes[i-1]
			}
		}
	}
	prevIdx := -1
	for i := range sorted {
		if i > 0 && sorted[i-1].h < sorted[i].h {
			prevIdx = i - 1
		}
		if prevIdx != -1 && minw[prevIdx] < sorted[i].w {
			sorted[i].res = minwRes[prevIdx]
		}
	}
	s.output()
}

func (s *Solver) sortFriendsByHeight() []*Friend {
	ret := []*Friend{}
	for _, f := range s.friends {
		ret = append(ret, f)
	}
	sort.Slice(ret, func(il, ir int) bool {
		return ret[il].h < ret[ir].h
	})
	return ret
}

func (s *Solver) output() {
	for i := int64(1); i <= s.n; i++ {
		printf("%d ", s.friends[i].res)
	}
	printf("\n")
}

package main

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

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

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

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

type Friend struct {
	i   int64
	h   int64
	w   int64
	res int64
}

type Solver struct {
	n       int64
	friends map[int64]*Friend
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		friends := map[int64]*Friend{}
		for i := int64(1); i <= n; i++ {
			h, w := sint64(), sint64()
			friends[i] = &Friend{
				i:   i,
				h:   h,
				w:   w,
				res: -1,
			}
		}
		(&Solver{n, friends}).Solve()
	}
}

func (s *Solver) Solve() {
	sortedFriends := s.sortFriends()
	minw := make([]int64, len(sortedFriends))
	minwRes := make([]int64, len(sortedFriends))
	for i := range sortedFriends {
		if i == 0 {
			minw[i] = sortedFriends[i].w
			minwRes[i] = sortedFriends[i].i
		} else {
			if sortedFriends[i].w < minw[i-1] {
				minw[i] = sortedFriends[i].w
				minwRes[i] = sortedFriends[i].i
			} else {
				minw[i] = minw[i-1]
				minwRes[i] = minwRes[i-1]
			}
		}
	}
	prevIdx := -1
	for i := range sortedFriends {
		if i > 0 && sortedFriends[i-1].h != sortedFriends[i].h {
			prevIdx = i - 1
		}
		if prevIdx != -1 && minw[prevIdx] < sortedFriends[i].w {
			sortedFriends[i].res = minwRes[prevIdx]
		}
	}
	s.output()
}

func (s *Solver) sortFriends() []*Friend {
	ret := []*Friend{}
	for _, f := range s.friends {
		ret = append(ret, f)
	}
	sort.Slice(ret, func(il, ir int) bool {
		return ret[il].h < ret[ir].h
	})
	return ret
}

func (s *Solver) output() {
	for i := int64(1); i <= s.n; i++ {
		printf("%d ", s.friends[i].res)
	}
	printf("\n")
}

package main

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

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

var file, _ = os.Open("input")
var reader *bufio.Reader = bufio.NewReader(file)

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

type person struct {
	w        int64
	h        int64
	rawIndex int64
}

func main() {
	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)
		process(reader, int64(n))
		fmt.Println()
	}
}

func process(reader *bufio.Reader, n int64) {
	a := make([]person, n)
	var i int64
	for i = 0; i < n; i++ {
		scanf("%d %d\n", &a[i].h, &a[i].w)
		if a[i].h < a[i].w {
			a[i].h, a[i].w = a[i].w, a[i].h
		}
		a[i].rawIndex = i
	}
	sort.Slice(a, func(i, j int) bool {
		if a[i].h < a[j].h {
			return true
		}
		if a[i].h > a[j].h {
			return false
		}
		return a[i].w < a[j].w
	})
	fmt.Println()
	minIndex := int64(-1)
	currentMinIndex := int64(-1)
	result := make([]int64, n)
	for i = 0; i < n; i++ {
		if currentMinIndex == -1 {
			result[a[i].rawIndex] = -1
			currentMinIndex = 0
			continue
		}
		if a[i].h != a[i-1].h {
			minIndex = currentMinIndex
		}
		if a[currentMinIndex].w > a[i].w {
			currentMinIndex = i
		}
		if minIndex == -1 {
			result[a[i].rawIndex] = -1
			continue
		}
		if a[minIndex].w < a[i].w {
			result[a[i].rawIndex] = a[minIndex].rawIndex + 1
		} else {
			result[a[i].rawIndex] = -1
		}
	}
	for _, rs := range result {
		fmt.Printf("%d ", rs)
	}
}

package main

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

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

// var file, _ = os.Open("input")
// var reader *bufio.Reader = bufio.NewReader(file)
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...) }

type person struct {
	w        int64
	h        int64
	rawIndex int64
}

func main() {
	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)
		process(reader, int64(n))
		fmt.Println()
	}
}

func process(reader *bufio.Reader, n int64) {
	a := make([]person, n)
	var i int64
	for i = 0; i < n; i++ {
		scanf("%d %d\n", &a[i].h, &a[i].w)
		if a[i].h < a[i].w {
			a[i].h, a[i].w = a[i].w, a[i].h
		}
		a[i].rawIndex = i
	}
	sort.Slice(a, func(i, j int) bool {
		if a[i].h < a[j].h {
			return true
		}
		return a[i].w < a[j].w
	})
	minIndex := int64(-1)
	currentMinIndex := int64(-1)
	result := make([]int64, n)
	for i = 0; i < n; i++ {
		if currentMinIndex == -1 {
			result[a[i].rawIndex] = -1
			currentMinIndex = 0
			continue
		}
		if a[i].h != a[i-1].h {
			minIndex = currentMinIndex
		}
		if a[currentMinIndex].w > a[i].w {
			currentMinIndex = i
		}
		if minIndex == -1 {
			result[a[i].rawIndex] = -1
			continue
		}
		if a[minIndex].w < a[i].w {
			result[a[i].rawIndex] = a[minIndex].rawIndex + 1
		} else {
			result[a[i].rawIndex] = -1
		}
	}
	for _, rs := range result {
		fmt.Printf("%d ", rs)
	}
}

package main

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

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

// var file, _ = os.Open("input")
// var reader *bufio.Reader = bufio.NewReader(file)
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...) }

type person struct {
	w        int64
	h        int64
	rawIndex int64
}

func main() {
	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)
		process(reader, int64(n))
		fmt.Println()
	}
}

func process(reader *bufio.Reader, n int64) {
	a := make([]person, n)
	var i int64
	for i = 0; i < n; i++ {
		scanf("%d %d\n", &a[i].h, &a[i].w)
		if a[i].h < a[i].w {
			a[i].h, a[i].w = a[i].w, a[i].h
		}
		a[i].rawIndex = i + 1
	}
	sort.Slice(a, func(i, j int) bool {
		if a[i].h < a[j].h {
			return true
		}
		return a[i].w < a[j].w
	})
	minIndex := int64(-1)
	currentMinIndex := int64(-1)
	for i = 0; i < n; i++ {
		if currentMinIndex == -1 {
			fmt.Printf("%d ", -1)
			currentMinIndex = 0
			continue
		}
		if a[i].h != a[i-1].h {
			minIndex = currentMinIndex
		}
		if a[currentMinIndex].w > a[i].w {
			currentMinIndex = i
		}
		if minIndex == -1 {
			fmt.Printf("%d ", -1)
			continue
		}
		if a[minIndex].w < a[i].w {
			fmt.Printf("%d ", a[minIndex].rawIndex)
		} else {
			fmt.Printf("%d ", -1)
		}
	}
}

package main

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

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

var file, _ = os.Open("input")
var reader *bufio.Reader = bufio.NewReader(file)
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...) }

type person struct {
	w        int64
	h        int64
	rawIndex int64
}

func main() {
	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)
		process(reader, int64(n))
		fmt.Println()
	}
}

func process(reader *bufio.Reader, n int64) {
	a := make([]person, n)
	var i int64
	for i = 0; i < n; i++ {
		scanf("%d %d\n", &a[i].h, &a[i].w)
		if a[i].h < a[i].w {
			a[i].h, a[i].w = a[i].w, a[i].h
		}
		a[i].rawIndex = i + 1
	}
	sort.Slice(a, func(i, j int) bool {
		if a[i].h < a[j].h {
			return true
		}
		return a[i].w < a[j].w
	})
	minIndex := int64(-1)
	currentMinIndex := int64(-1)
	for i = 0; i < n; i++ {
		if currentMinIndex == -1 {
			fmt.Printf("%d ", -1)
			currentMinIndex = 0
			continue
		}
		if a[i].h != a[i-1].h {
			minIndex = currentMinIndex
		}
		if a[currentMinIndex].w > a[i].w {
			currentMinIndex = i
		}
		if minIndex == -1 {
			fmt.Printf("%d ", -1)
			continue
		}
		if a[minIndex].w < a[i].w {
			fmt.Printf("%d ", a[minIndex].rawIndex)
		} else {
			fmt.Printf("%d ", -1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

type friend struct {
    index, w, h int
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    friends := make([]friend, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &friends[i].h, &friends[i].w)
        friends[i].index = i
    }
    sort.Slice(friends, func(i, j int) bool { return friends[i].w < friends[j].w })
    sfx := make([]int, n)
    sfx[0] = friends[0].h
    for i := 1; i < n; i++ {
        sfx[i] = min(sfx[i - 1], friends[i].h)
    }

    ans := make([]int, n)
    for _, v := range friends {
        if pos := getbyw(friends, v.w); pos >= 0 {
            if sfx[pos] < v.h {
                ans[v.index] = friends[pos].index + 1
                continue
            }
        }

        if pos := getbyw(friends, v.h); pos >= 0 {
            if sfx[pos] < v.w {
                ans[v.index] = friends[pos].index + 1
                continue
            }
        }

        ans[v.index] = -1
    }
    for i := 0; i < n; i++ {
        if i > 0 { fmt.Fprint(output, " ") }
        fmt.Fprint(output, ans[i])
    }

    fmt.Fprintln(output, "")
}

func getbyw(all []friend, v int) int {
    l, r := -1, len(all)
    for r - l > 1 {
        m := (l + r) >> 1
        if all[m].w < v {
            l = m
        } else {
            r = m
        }
    }

    return l
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

type friend struct {
    index, w, h int
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    friends := make([]friend, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &friends[i].h, &friends[i].w)
        friends[i].index = i
    }
    sort.Slice(friends, func(i, j int) bool { return friends[i].w < friends[j].w })
    sfx := make([]int, n)
    sfx[0] = friends[0].h
    for i := 1; i < n; i++ {
        sfx[i] = min(sfx[i - 1], friends[i].h)
    }

    ans := make([]int, n)
    for _, v := range friends {
        if pos := getbyw(friends, v.w); pos >= 0 {
            if sfx[pos] < v.h {
                ans[v.index] = friends[pos].index
                continue
            }
        }

        if pos := getbyw(friends, v.h); pos >= 0 {
            if sfx[pos] < v.w {
                ans[v.index] = friends[pos].index
                continue
            }
        }

        ans[v.index] = -1
    }
    for i := 0; i < n; i++ {
        if i > 0 { fmt.Fprint(output, " ") }
        fmt.Fprint(output, ans[i])
    }

    fmt.Fprintln(output, "")
}

func getbyw(all []friend, v int) int {
    l, r := -1, len(all)
    for r - l > 1 {
        m := (l + r) >> 1
        if all[m].w < v {
            l = m
        } else {
            r = m
        }
    }

    return l
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

type friend struct {
    index, w, h int
    s int64
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a, b := make([]friend, n), make([]friend, n)
    for i := 0; i < len(a); i++ {
        fmt.Fscan(input, &a[i].h, &a[i].w)
        a[i].index = i
        a[i].s = int64(a[i].w) * int64(a[i].h)
        b[i].w, b[i].h = a[i].w, a[i].h
        b[i].index = i
        b[i].s = a[i].s
        //c[i].w, c[i].h = a[i].w, a[i].h
        //c[i].index = i
        //c[i].s = a[i].s
    }
    sort.Slice(a, func(i, j int) bool { return a[i].w < a[j].w && a[i].s < a[j].s})
    sort.Slice(b, func(i, j int) bool { return b[i].h < b[j].h && b[i].s < b[j].s})
    //sort.Slice(b, func(i, j int) bool { return c[i].h < c[j].h && c[i].s < c[j].s})

    ans := make([]int, n)
    for _, v := range a {
        if pos := getw(a, v); pos >= 0 {
            ans[v.index] = pos + 1
            continue
        }
        if pos := geth(b, v); pos >= 0 {
            ans[v.index] = pos + 1
            continue
        }
        ans[v.index] = -1
    }

    for i := 0; i < n; i++ {
        if i > 0 { fmt.Fprint(output, " ") }
        fmt.Fprint(output, ans[i])
    }
    fmt.Fprintln(output, "")
}

// returns index of less
func getw(a []friend, fr friend) int {
    l, r := -1, len(a)
    for r - l > 1 {
        m := (l + r) >> 1
        if a[m].w < fr.w && a[m].s < fr.s && a[m].h < fr.h {
            l = m
        } else {
            r = m
        }
    }
    return l
}

func geth(b []friend, fr friend) int {
    l, r := -1, len(b)
    for r - l > 1 {
        m := (l + r) >> 1
        if b[m].h < fr.w && b[m].s < fr.s && b[m].w < fr.h {
            l = m
        } else {
            r = m
        }
    }
    return l
}

func getc(b []friend, fr friend) int {
    l, r := -1, len(b)
    for r - l > 1 {
        m := (l + r) >> 1
        if b[m].w < fr.h && b[m].s < fr.s && b[m].h < fr.w {
            l = m
        } else {
            r = m
        }
    }
    return l
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

type friend struct {
    index, w, h int
    s int64
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a, b, c := make([]friend, n), make([]friend, n), make([]friend, n)
    for i := 0; i < len(a); i++ {
        fmt.Fscan(input, &a[i].h, &a[i].w)
        a[i].index = i
        a[i].s = int64(a[i].w) * int64(a[i].h)
        b[i].w, b[i].h = a[i].w, a[i].h
        b[i].index = i
        b[i].s = a[i].s
        c[i].w, c[i].h = a[i].w, a[i].h
        c[i].index = i
        c[i].s = a[i].s
    }
    sort.Slice(a, func(i, j int) bool { return a[i].w < a[j].w && a[i].s < a[j].s})
    sort.Slice(b, func(i, j int) bool { return b[i].h < b[j].h && b[i].s < b[j].s})
    sort.Slice(b, func(i, j int) bool { return c[i].h < c[j].h && c[i].s < c[j].s})

    ans := make([]int, n)
    for _, v := range a {
        if pos := getw(a, v); pos >= 0 {
            ans[v.index] = pos + 1
            continue
        }
        if pos := geth(b, v); pos >= 0 {
            ans[v.index] = pos + 1
            continue
        }
        if pos := getc(c, v); pos >= 0 {
            ans[v.index] = pos + 1
            continue
        }
        ans[v.index] = -1
    }

    for i := 0; i < n; i++ {
        if i > 0 { fmt.Fprint(output, " ") }
        fmt.Fprint(output, ans[i])
    }
    fmt.Fprintln(output, "")
}

// returns index of less
func getw(a []friend, fr friend) int {
    l, r := -1, len(a)
    for r - l > 1 {
        m := (l + r) >> 1
        if a[m].w < fr.w && a[m].s < fr.s && a[m].h < fr.h {
            l = m
        } else {
            r = m
        }
    }
    return l
}

func geth(b []friend, fr friend) int {
    l, r := -1, len(b)
    for r - l > 1 {
        m := (l + r) >> 1
        if b[m].h < fr.w && b[m].s < fr.s && b[m].w < fr.h {
            l = m
        } else {
            r = m
        }
    }
    return l
}

func getc(b []friend, fr friend) int {
    l, r := -1, len(b)
    for r - l > 1 {
        m := (l + r) >> 1
        if b[m].w < fr.h && b[m].s < fr.s && b[m].h < fr.w {
            l = m
        } else {
            r = m
        }
    }
    return l
}


The only difference between the two versions is that this version asks the maximal possible answer.Homer likes arrays a lot. Today he is painting an array $$$a_1, a_2, \dots, a_n$$$ with two kinds of colors, white and black. A painting assignment for $$$a_1, a_2, \dots, a_n$$$ is described by an array $$$b_1, b_2, \dots, b_n$$$ that $$$b_i$$$ indicates the color of $$$a_i$$$ ($$$0$$$ for white and $$$1$$$ for black).According to a painting assignment $$$b_1, b_2, \dots, b_n$$$, the array $$$a$$$ is split into two new arrays $$$a^{(0)}$$$ and $$$a^{(1)}$$$, where $$$a^{(0)}$$$ is the sub-sequence of all white elements in $$$a$$$ and $$$a^{(1)}$$$ is the sub-sequence of all black elements in $$$a$$$. For example, if $$$a = [1,2,3,4,5,6]$$$ and $$$b = [0,1,0,1,0,0]$$$, then $$$a^{(0)} = [1,3,5,6]$$$ and $$$a^{(1)} = [2,4]$$$.The number of segments in an array $$$c_1, c_2, \dots, c_k$$$, denoted $$$\mathit{seg}(c)$$$, is the number of elements if we merge all adjacent elements with the same value in $$$c$$$. For example, the number of segments in $$$[1,1,2,2,3,3,3,2]$$$ is $$$4$$$, because the array will become $$$[1,2,3,2]$$$ after merging adjacent elements with the same value. Especially, the number of segments in an empty array is $$$0$$$.Homer wants to find a painting assignment $$$b$$$, according to which the number of segments in both $$$a^{(0)}$$$ and $$$a^{(1)}$$$, i.e. $$$\mathit{seg}(a^{(0)})+\mathit{seg}(a^{(1)})$$$, is as large as possible. Find this number.

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$).

Output a single integer, indicating the maximal possible total number of segments.

package main

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

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

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

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

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

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

func solve() {
	var n int
	scan(&n)

	var elems = make([]int, n)
	for i := range elems {
		scan(&elems[i])
	}

	var (
		i    int
		b, w []int
	)
	for i < len(elems) {
		j, ci := i, 0
		for ; j < len(elems) && elems[i] == elems[j]; j++ {
			ci++
		}
		if ci > 1 {
			b = append(b, elems[i])
			w = append(w, elems[i])
			goto nextGroup
		}
		if j >= len(elems) {
			if len(b) == 0 || b[len(b)-1] == elems[i] {
				w = append(w, elems[i])
			} else {
				b = append(b, elems[i])
			}
			goto nextGroup
		}
		if len(b) > 0 && b[len(b)-1] == elems[j] {
			b = append(b, elems[i])
		} else if len(w) > 0 && w[len(w)-1] == elems[j] {
			w = append(w, elems[i])
		} else { // we don'c care where to put this element
			b = append(b, elems[i])
		}
	nextGroup:
		i = j
	}

	printf("%v\n", calc(b)+calc(w))
}

func calc(s []int) (r int) {
	last := -1
	for i := range s {
		if s[i] != last {
			r++
			last = s[i]
		}
	}
	return
}

package main

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

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

	n := readNum(reader)

	A := readNNums(reader, n)

	res := solve(n, A)

	fmt.Printf("%d\n", res)
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, a []int) int {
	A := make([]int, n+1)
	copy(A[1:], a)
	pos := make([]int, n+1)
	for i := 0; i <= n; i++ {
		pos[i] = n + 1
	}

	next := make([]int, n+1)

	for i := n; i >= 0; i-- {
		next[i] = pos[A[i]]
		pos[A[i]] = i
	}

	var x, y int
	var res int
	for i := 1; i <= n; i++ {
		if A[x] == A[i] {
			res += boolValue(A[i] != A[y])
			y = i
		} else if A[y] == A[i] {
			res += boolValue(A[x] != A[i])
			x = i
		} else if next[x] < next[y] {
			res += boolValue(A[x] != A[i])
			x = i
		} else {
			res += boolValue(A[y] != A[i])
			y = i
		}
	}
	return res
}

func boolValue(v bool) int {
	if v {
		return 1
	}
	return 0
}

package main

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

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

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

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

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

	T := 1
	//scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)
		a := make([]int, n)
		for i := range a {
			scan(&a[i])
		}
		solveB1(a)
	}
}

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

func solveB1(a []int) {
	res := 0
	last := [2]int{}
	for _, x := range a {
		if x == last[0] {
			if last[1] != x {
				res++
			}
			last[1] = x
		} else if x == last[1] {
			if last[0] != x {
				res++
			}
			last[0] = x
		} else {
			res++
			last[0] = x
		}
	}
	printf("%d\n", res)
}

package main

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

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

	n := readNum(reader)

	A := readNNums(reader, n)

	res := solve(n, A)

	fmt.Printf("%d\n", res)
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, a []int) int {
	A := make([]int, n+1)
	copy(A[1:], a)
	pos := make([]int, n+1)
	for i := 0; i <= n; i++ {
		pos[i] = n + 1
	}

	next := make([]int, n+1)

	for i := n; i > 0; i-- {
		next[i] = pos[A[i]]
		pos[A[i]] = i
	}

	var x, y int
	var res int
	for i := 1; i <= n; i++ {
		if A[x] == A[i] {
			res += boolValue(A[i] != A[y])
			y = i
		} else if A[y] == A[i] {
			res += boolValue(A[x] != A[i])
			x = i
		} else if next[x] < next[y] {
			res += boolValue(A[x] != A[i])
			x = i
		} else {
			res += boolValue(A[y] != A[i])
			y = i
		}
	}
	return res
}

func boolValue(v bool) int {
	if v {
		return 1
	}
	return 0
}