package main

import "fmt"

func solve() {
	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)

	m := n - k
	i := 1
	for ; i < k-m; i++ {
		fmt.Printf("%d ", i)
	}
	for j := k; j >= i; j-- {
		fmt.Printf("%d ", j)
	}
	fmt.Println()
}

func main() {
	var t int
	fmt.Scan(&t)

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

package main

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

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

func main() {
	defer writer.Flush()

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

	for i := 0; i < t; i++ {
		var n, k int
		fmt.Fscan(reader, &n, &k)

		m := n - k
		for j := 0; j < k-m-1; j++ {
			fmt.Fprintf(writer, "%d ", j+1)
		}

		for j := k; j >= k-m; j-- {
			fmt.Fprintf(writer, "%d ", j)
		}

		fmt.Fprintln(writer)
	}
}

package main
import (
	"bufio"
	"fmt"
	"os"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
	q := 0
	fmt.Fscan(rd, &q)
	for t := 0; t < q; t++ {
		n, k := 0, 0
		fmt.Fscan(rd, &n, &k)
		for i := 1; i < 2 * k - n; i++ {
			fmt.Print(i, " ")
		}
		for i := k; i >= 2 * k - n; i-- {
			fmt.Print(i, " ")
		}
		fmt.Println()
	}
}

package main

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

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

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

func solve() {
	var n, k int
	scanf("%d %d\n", &n, &k)
	for i := 1; i < 2 * k - n; i++ {
		printf("%d ", i)
	}
	for i := 2 * k - n; i <= k; i++ {
		printf("%d ", k - (i - 2 * k + n))
	}
	/*for i := k; i >= 2 * k - n; i-- {
		printf("%d ", i)
	}*/
	printf("\n")
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 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()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		k := sint64()
		for _, r := range sol(n, k) {
			printf("%d ", r)
		}
		printf("\n")
	}
}

func sol(n, k int64) []int64 {
	ret := []int64{}
	for i := int64(1); i < 2*k-n; i++ {
		ret = append(ret, i)
	}
	for i := k; i >= 2*k-n; i-- {
		ret = append(ret, i)
	}
	return ret
}

/*
URL:
https://codeforces.com/contest/1473/problem/C
*/

package main

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

var (
	println = fmt.Println

	tc   int
	n, k int
)

func main() {
	defer stdout.Flush()

	tc = readi()
	for i := 0; i < tc; i++ {
		n, k = readi2()

		solve()
	}
}

func solve() {
	P := make([]int, k)
	for i := 0; i < k; i++ {
		P[i] = i + 1
	}

	r := n - k

	A := []int{}
	for i := 0; i < k-r-1; i++ {
		A = append(A, P[i])
	}
	rev := Reverse(P[k-r-1:])
	for _, a := range rev {
		A = append(A, a)
	}
	printf("%s\n", PrintIntsLine(A...))
}

func Reverse(A []int) []int {
	res := []int{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

// func solve() {
// 	P := make([]int, k)
// 	for i := 0; i < k; i++ {
// 		P[i] = i + 1
// 	}

// 	if n-k == 0 {
// 		printf("%s\n", PrintIntsLine(P...))
// 		return
// 	}

// 	if n == 3 && k == 2 {
// 		printf("2 1\n")
// 		return
// 	}

// 	if n-k == k-1 {
// 		M := []int{}
// 		for i := k - 1; i >= 1; i-- {
// 			M = append(M, i)
// 		}
// 		M = append(M, k)
// 		printf("%s\n", PrintIntsLine(M...))
// 		return
// 	}

// 	// a >= 1
// 	a := n - k
// 	i, j := k-a, k-a-1
// 	P[i], P[j] = P[j], P[i]
// 	printf("%s\n", PrintIntsLine(P...))
// }

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

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

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

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

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

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

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(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 := pow(a, halfE)
		return half * half
	}

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

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

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

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

package main

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

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

	var T, n, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		for i := 1; i < k*2-n; i++ {
			Fprint(out, i, " ")
		}
		for i := k; i >= k*2-n; i-- {
			Fprint(out, i, " ")
		}
		Fprintln(out)
	}
}

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

/*
URL:
https://codeforces.com/contest/1473/problem/C
*/

package main

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

var (
	println = fmt.Println

	tc   int
	n, k int
)

func main() {
	defer stdout.Flush()

	tc = readi()
	for i := 0; i < tc; i++ {
		n, k = readi2()

		solve()
	}
}

func solve() {
	P := make([]int, k)
	for i := 0; i < k; i++ {
		P[i] = i + 1
	}

	if n-k == 0 {
		printf("%s\n", PrintIntsLine(P...))
		return
	}

	if n == 3 && k == 2 {
		printf("2 1\n")
		return
	}

	if n-k == k-1 {
		M := []int{}
		for i := k - 1; i >= 1; i-- {
			M = append(M, i)
		}
		M = append(M, k)
		printf("%s\n", PrintIntsLine(M...))
		return
	}

	// a >= 1
	a := n - k
	i, j := k-a, k-a-1
	P[i], P[j] = P[j], P[i]
	printf("%s\n", PrintIntsLine(P...))
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

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

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

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

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

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

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(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 := pow(a, halfE)
		return half * half
	}

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

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

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

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

/*
URL:
https://codeforces.com/contest/1473/problem/C
*/

package main

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

var (
	println = fmt.Println

	tc   int
	n, k int
)

func main() {
	defer stdout.Flush()

	tc = readi()
	for i := 0; i < tc; i++ {
		n, k = readi2()

		solve()
	}
}

func solve() {
	P := make([]int, k)
	for i := 0; i < k; i++ {
		P[i] = i + 1
	}

	if n-k == 0 {
		printf("%s\n", PrintIntsLine(P...))
		return
	}

	// a >= 1
	a := n - k
	i, j := k-a, k-a-1
	P[i], P[j] = P[j], P[i]
	printf("%s\n", PrintIntsLine(P...))
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

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

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

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

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

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

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(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 := pow(a, halfE)
		return half * half
	}

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

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

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

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)

	for tc > 0 {
		tc--
		L := readNNums(reader, 3)
		res := solve(L)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}
	fmt.Print(buf.String())
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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

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

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

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

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

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

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

	return i
}

func solve(L []int) bool {
	sort.Ints(L)
	// a, b, c
	// c = a + b
	if L[2] == L[1]+L[0] {
		return true
	}
	if L[0] == L[1] {
		return L[2]%2 == 0
	}

	if L[1] == L[2] {
		return L[0]%2 == 0
	}
	return false
}

package main
import(
    "fmt"
    "sort"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var list []int = make([]int,3)
		for j:=0;j<3;j++{
			fmt.Scan(&list[j])
		}
		sort.Ints(list)
		if list[0] == list[1] {
			if list[2] % 2 != 0 {
				fmt.Println("NO")
				continue
			}
		} else if list[1] == list[2] {
			if list[0] % 2 != 0 {
				fmt.Println("NO")
				continue
			}
		} else if list[0] == list[2] {
			if list[1] % 2 !=0 {
				fmt.Println("NO")
				continue
			}
		} else {
			if list[0] + list[1] != list[2] {
				fmt.Println("NO")
				continue
			}
		}
		fmt.Println("YES")
	}
}

package main

import "fmt"

func main() {

	t := 0
	fmt.Scan(&t)

	for t > 0 {

		l1, l2, l3 := 0, 0, 0

		fmt.Scan(&l1, &l2, &l3)
		fmt.Println(solve(l1, l2, l3))

		t--
	}

	//fmt.Println(solve(4, 1, 1))
}

func solve(l1, l2, l3 int) string {

	array := []int{l1, l2, l3}
	big := max(l1, l2, l3)
	count := 0

	for i := range array {
		if array[i] == big {
			count++
		}
	}

	if count == 3 {
		if big%2 == 0 {
			return "YES"
		} else {
			return "NO"
		}
	}

	if count == 2 {
		for i := range array {
			if array[i] != big {
				if array[i]%2 == 0 {
					return "YES"
				} else {
					return "NO"
				}
			}
		}
	}

	temp := []int{}
	for i := range array {
		if array[i] != big {
			temp = append(temp, array[i])
		}
	}

	if temp[0] == temp[1] && big%2 == 0 {
		return "YES"
	}

	if big-temp[0] == temp[1] {
		return "YES"
	} else {
		return "NO"
	}

}

func max(a, b, c int) int {
	max := a

	if b > max {
		max = b
	}

	if c > max {
		max = c
	}

	return max
}

package main

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

func main() {
	n := 0

	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	s1, s2, s3 := "", "", ""
	fmt.Fscan(f, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(f, &s1)
		fmt.Fscan(f, &s2)
		fmt.Fscan(f, &s3)

		if match(s1, s2, s3) {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func match(s1, s2, s3 string) bool {
	n1, _ := strconv.Atoi(s1)
	n2, _ := strconv.Atoi(s2)
	n3, _ := strconv.Atoi(s3)
	if n1 == n2 && n3%2 == 0 {
		return true
	}
	if n1 == n3 && n2%2 == 0 {
		return true
	}
	if n2 == n3 && n1%2 == 0 {
		return true
	}
	if n1 == n2+n3 || n2 == n1+n3 || n3 == n1+n2 {
		return true
	}
	return false

}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		l1, l2, l3 := readThreeInt(reader)

		if l1 == l2 && l3%2 == 0 ||
			l2 == l3 && l1%2 == 0 ||
			l1 == l3 && l2%2 == 0 ||
			l1 + l2 == l3 || l1 + l3 == l2 || l2 + l3 == l1 {

			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}

			t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		ls := strings.Split(scanner.Text(), " ")
		var l []int
		for j := 0; j < 3; j++ {
			ti, _ := strconv.Atoi(ls[j])
			l = append(l, ti)
		}
		sort.Ints(l)
		if l[0] == l[1] && l[2]%2 == 0 {
			fmt.Println("YES")
		} else if l[1] == l[2] && l[0]%2 == 0 {
			fmt.Println("YES")
		} else if l[0]+l[1] == l[2] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func CF1622A(rawIn io.Reader, rawOut io.Writer) {
	in := bufio.NewReader(rawIn)
	out := bufio.NewWriter(rawOut)
	defer out.Flush()

	var cases int
	fmt.Fscan(in, &cases)
	for cc := 0; cc < cases; cc++ {
		var a, b, c int
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &c)
		if pairAndEven(a, b, c) || pairAndEven(a, c, b) || pairAndEven(b, c, a) {
			fmt.Fprintln(out, "YES")
			continue
		}
		if isSumOf(a, b, c) || isSumOf(b, a, c) || isSumOf(c, a, b) {
			fmt.Fprintln(out, "YES")
			continue
		}
		fmt.Fprintln(out, "NO")
	}
}

func pairAndEven(n1, n2, n3 int) bool {
	if n1 == n2 && n3%2 == 0 {
		return true
	}
	return false
}

func isSumOf(s, n1, n2 int) bool {
	return s == n1+n2
}

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

package main

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

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

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

		s := "NO"
		if a > b && a > c && a-b == c {
			s = "YES"
		} else if b > a && b > c && b-a == c {
			s = "YES"
		} else if c > a && c > b && c-a == b {
			s = "YES"
		} else if a == b && c%2 == 0 {
			s = "YES"
		} else if a == c && b%2 == 0 {
			s = "YES"
		} else if b == c && a%2 == 0 {
			s = "YES"
		}

		fmt.Fprintln(out, s)
	}
}

package main

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

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

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

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

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

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

/**
TO SEND
Run solve the problem CF1622A
Date: 3/01/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1622/A
Problem: CF1622A
**/
func (in *CF1622A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		arr := []int{in.NextInt(), in.NextInt(), in.NextInt()}
		sort.Ints(arr)
		ws := false
		if (arr[0] == arr[1] && arr[2]%2 == 0) || (arr[1] == arr[2] && arr[0]%2 == 0) {
			ws = true
		} else if arr[2]-arr[1]-arr[0] == 0 {
			ws = true
		}

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

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

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

package main

import (
	"fmt"
)

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

func main() {
	var t, a, b, c int
	fmt.Scanln(&t)
	for i := 1; i <= t; i++ {
		fmt.Scanln(&a, &b, &c)
		if a == b {
			if c%2 == 0 {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		} else if a == c {
			if b%2 == 0 {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		} else if b == c {
			if a%2 == 0 {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		} else {
			maxx := max(max(a, b), c)
			if maxx == a+b || maxx == a+c || maxx == b+c {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

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

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

func solve(l []int) string {
	sort.Ints(l)
	if l[0]+l[1] == l[2] {
		return "YES"
	}
	if l[0] == l[1] && l[2]%2 == 0 {
		return "YES"
	}
	if l[2] == l[1] && l[0]%2 == 0 {
		return "YES"
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		l := make([]int, 3)
		for i := 0; i < 3; i++ {
			fmt.Fscan(reader, &l[i])
		}
		fmt.Println(solve(l))
	}
}

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 l [3]int64
	for i := range l {
		scan(&l[i])
	}
	if l[0]+l[1] == l[2] || (l[0] == l[1] && l[2]%2 == 0) {
		printf("YES\n")
		return
	}
	if l[0]+l[2] == l[1] || (l[0] == l[2] && l[1]%2 == 0) {
		printf("YES\n")
		return
	}
	if l[1]+l[2] == l[0] || (l[1] == l[2] && l[0]%2 == 0) {
		printf("YES\n")
		return
	}
	printf("NO\n")
}

package main

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

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

func check(a, b, c int) bool {
	if a%2 == 0 && b == c || a == b+c {
		return true
	}
	return false
}

func solve(t int) {
	a, b, c := readInt(), readInt(), readInt()
	result := check(a, b, c) || check(b, a, c) || check(c, a, b)
	if result {
		println("YES")
	} else {
		println("NO")
	}
}

func main() {
	var t int
	fmt.Fscan(in, &t)

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	arr := make([]int, 3)
	Fscan(in, &arr[0], &arr[1], &arr[2])
	sort.Ints(arr)
	if arr[0] == arr[1] && arr[2]%2 == 0 {
		Fprintln(out, "YES")
		return
	}
	if arr[1] == arr[2] && arr[0]%2 == 0 {
		Fprintln(out, "YES")
		return
	}
	if arr[0]+arr[1] == arr[2] {
		Fprintln(out, "YES")
	} else {
		Fprintln(out, "NO")
	}
}

func main() {

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

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, a, b, c := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &a, &b, &c)
		ok := (a%2 == 0 && (a/2)+b == (a/2)+c) || (b%2 == 0 && (b/2)+a == (b/2)+c) || (c%2 == 0 && (c/2)+a == (c/2)+b)
		if a == b+c || b == a+c || c == a+b || ok {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func canSolve(a [3]int) bool {
	if a[0] == a[1] {
		return a[2]%2 == 0
	}
	if a[1] == a[2] {
		return a[0]%2 == 0
	}
	return a[2] == a[0]+a[1]
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		var a [3]int
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Ints(a[:])
		if canSolve(a) {
			fmt.Fprintf(out, "YES\n")
		} else {
			fmt.Fprintf(out, "NO\n")
		}
	}
	out.Flush()
}

package main

import (
	"fmt"
)

type palki struct {
	a, b, c int
}

func main() {
	var n int
	fmt.Scanln(&n)
	var arr []palki
	for i := 0; i < n; i++ {
		var new palki
		fmt.Scanln(&new.a, &new.b, &new.c)
		arr = append(arr, new)
	}

	//2 4 1
	for _,v := range arr {
		if v.a == v.b {
			answer(v.c)
		} else if v.c == v.b {
			answer(v.a)
		}  else if v.c == v.a {
			answer(v.b)
		} else if v.c-v.b == v.a || v.b-v.c == v.a {
			fmt.Println("yes")
		} else if v.b-v.a == v.c || v.a-v.b == v.c {
			fmt.Println("yes")
		}else if v.c-v.a == v.b || v.a-v.c == v.b {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

//ab cd
//ac bd
//ad cd
//bc ad

func answer(a int) {
	if a & 1 == 0 {
		fmt.Println("yes")
	} else {
		fmt.Println("no")
	}
}

package main

import (
	"fmt"
)

type palki struct {
	a, b, c int
}

func main() {
	var n int
	fmt.Scanln(&n)
	var arr []palki
	for i := 0; i < n; i++ {
		var new palki
		fmt.Scanln(&new.a, &new.b, &new.c)
		arr = append(arr, new)
	}

	//2 4 1
	for _,v := range arr {
		if v.a == v.b {
			answer(v.c)
		} else if v.c == v.b {
			answer(v.a)
		}  else if v.c == v.a {
			answer(v.b)
		} else if v.c-v.b == v.a || v.b-v.c == v.a {
			fmt.Println(v.a ,(v.b-v.c), "test1")
			fmt.Println("yes")
		} else if v.b-v.a == v.c || v.a-v.b == v.c {
			fmt.Println("test2")
			fmt.Println("yes")
		}else if v.c-v.a == v.b || v.a-v.c == v.b {
			fmt.Println("test3")
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

//ab cd
//ac bd
//ad cd
//bc ad

func answer(a int) {
	if a & 1 == 0 {
		fmt.Println("yes")
	} else {
		fmt.Println("no")
	}
}

package main

import (
	"fmt"
)

type palki struct {
	a, b, c int
}

func main() {
	var n int
	fmt.Scanln(&n)
	var arr []palki
	for i := 0; i < n; i++ {
		var new palki
		fmt.Scanln(&new.a, &new.b, &new.c)
		arr = append(arr, new)
	}

	//3 1 4
	for _,v := range arr {
		if v.a & v.b == v.a {
			answer(v.c)
		} else if v.b & v.c == v.b {
			answer(v.a)
		}  else if v.a & v.c == v.a {
			answer(v.b)
		} else if v.a & (v.c-v.b) == v.a || v.a & (v.b-v.c) == v.a {
			fmt.Println("yes")
		} else if v.c & (v.b-v.a) == v.c || v.c & (v.a-v.b) == v.c {
			fmt.Println("yes")
		}else if v.b & (v.c-v.a) == v.b || v.b & (v.a-v.c) == v.b {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

//ab cd
//ac bd
//ad cd
//bc ad

func answer(a int) {
	if a & 1 == 0 {
		fmt.Println("yes")
	} else {
		fmt.Println("no")
	}
}

package main

import (
	"fmt"
)

type palki struct {
	a, b, c int
}

func main() {
	var n int
	fmt.Scanln(&n)
	var arr []palki
	for i := 0; i < n; i++ {
		var new palki
		fmt.Scanln(&new.a, &new.b, &new.c)
		arr = append(arr, new)
	}

	for _,v := range arr {
		if v.a & v.b == v.a {
			answer(v.c)
		} else if v.b & v.c == v.b {
			answer(v.a)
		} else if v.a & v.c == v.a {
			answer(v.b)
		} else {
			fmt.Println("no")
		}
	}
}

//ab cd
//ac bd
//ad cd
//bc ad

func answer(a int) {
	if a & 1 == 0 {
		fmt.Println("yes")
	} else {
		fmt.Println("no")
	}
}

package main

import (
	"fmt"
)

type palki struct {
	a, b, c int
}

func main() {
	var n int
	fmt.Scanln(&n)
	var arr []palki
	for i := 0; i < n; i++ {
		var new palki
		fmt.Scanln(&new.a, &new.b, &new.c)
		arr = append(arr, new)
	}

	for _, v := range arr {
		var yes bool
		for i := 1; i < v.a; i++ {
			if isRectangle(v.a-i, i, v.b, v.c) {
				yes = true
				fmt.Println("yes")
				break
			}
		}
		if !yes {
			fmt.Println("no")
			continue
		}
		for i := 1; i < v.b; i++ {
			if isRectangle(v.b-i, i, v.a, v.c) {
				yes = true
				fmt.Println("yes")
				break
			}
		}
		if !yes {
			fmt.Println("no")
			continue
		}
		for i := 1; i < v.c; i++ {
			if isRectangle(v.c-i, i, v.b, v.a) {
				yes = true
				fmt.Println("yes")
				break
			}
		}
		if !yes {
			fmt.Println("no")
			continue
		}

	}
}

//ab cd
//ac bd
//ad cd
//bc ad

func isRectangle(a, b, c, d int) bool {
	if (a == b && d == c) || (a == c && b == d) || (a == d && b == c) || (b == c && a == d) {
		return true
	}
	return false
}

package main
import(
    "fmt"
    "sort"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var list []int = make([]int,3)
		for j:=0;j<3;j++{
			fmt.Scan(&list[j])
		}
		sort.Ints(list)
		if abs(abs(list[0]-list[1])-list[2]) % 2 != 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var a,b,c,tally int
		fmt.Scan(&a,&b,&c)
		if a%2 != 0 {
			tally++
		}
		if b%2 != 0 {
			tally++
		}
		if c%2 != 0 {
			tally++
		}
		if tally == 1 || tally == 3 {
			fmt.Println("NO")
		} else {
			if largest(a,b,c) % 2 != 0 && (largest(a,b,c) != middle(a,b,c)) {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}
		}
	}
}
func largest(x,y,z int) int {
	if x >= y {
		if x >= z {
			return x
		}
	} else {
		if y >= z {
			return y
		}
	}
	return z
}
func middle(x,y,z int) int {
	if x >= y {
		if x >= z {
			if y >= z {
				return y
			} else {
				return z
			}
		}
	} else {
		if y >= z {
			if z >= x {
				return z
			} else {
				return x
			}
		}
	}
	if x >= y {
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var a,b,c,tally int
		fmt.Scan(&a,&b,&c)
		if a%2 != 0 {
			tally++
		}
		if b%2 != 0 {
			tally++
		}
		if c%2 != 0 {
			tally++
		}
		if tally == 1 || tally == 3 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

import "fmt"

func main() {

	// t := 0
	// fmt.Scan(&t)

	// for t > 0 {

	// 	l1, l2, l3 := 0, 0, 0

	// 	fmt.Scan(&l1, &l2, &l3)
	// 	fmt.Println(solve(l1, l2, l3))

	// 	t--
	// }

	fmt.Println(solve(4, 1, 1))
}

func solve(l1, l2, l3 int) string {

	array := []int{l1, l2, l3}
	big := max(l1, l2, l3)
	count := 0

	for i := range array {
		if array[i] == big {
			count++
		}
	}

	if count == 3 {
		if big%2 == 0 {
			return "YES"
		} else {
			return "NO"
		}
	}

	if count == 2 {
		for i := range array {
			if array[i] != big {
				if array[i]%2 == 0 {
					return "YES"
				} else {
					return "NO"
				}
			}
		}
	}

	temp := []int{}
	for i := range array {
		if array[i] != big {
			temp = append(temp, array[i])
		}
	}

	if temp[0] == temp[1] && big%2 == 0 {
		return "YES"
	}

	if big-temp[0] == temp[1] {
		return "YES"
	} else {
		return "NO"
	}

}

func max(a, b, c int) int {
	max := a

	if b > max {
		max = b
	}

	if c > max {
		max = c
	}

	return max
}

package main

import "fmt"

func main() {

	t := 0
	fmt.Scan(&t)

	for t > 0 {

		l1, l2, l3 := 0, 0, 0

		fmt.Scan(&l1, &l2, &l3)
		fmt.Println(solve(l1, l2, l3))

		t--
	}

	//fmt.Println(solve(5, 5, 4))
}

func solve(l1, l2, l3 int) string {

	array := []int{l1, l2, l3}
	big := max(l1, l2, l3)
	count := 0

	for i := range array {
		if array[i] == big {
			count++
		}
	}

	if count == 3 {
		if big%2 == 0 {
			return "YES"
		} else {
			return "NO"
		}
	}

	if count == 2 {
		for i := range array {
			if array[i] != big {
				if array[i]%2 == 0 {
					return "YES"
				} else {
					return "NO"
				}
			}
		}
	}

	temp := []int{}
	for i := range array {
		if array[i] != big {
			temp = append(temp, array[i])
		}
	}

	if big-temp[0] == temp[1] {
		return "YES"
	} else {
		return "NO"
	}

}

func max(a, b, c int) int {
	max := a

	if b > max {
		max = b
	}

	if c > max {
		max = c
	}

	return max
}

package main

import "fmt"

func main() {

	t := 0
	fmt.Scan(&t)

	for t > 0 {

		l1, l2, l3 := 0, 0, 0

		fmt.Scan(&l1, &l2, &l3)
		fmt.Println(solve(l1, l2, l3))

		t--
	}

	fmt.Println(solve(5, 5, 4))
}

func solve(l1, l2, l3 int) string {

	array := []int{l1, l2, l3}
	big := max(l1, l2, l3)
	count := 0

	for i := range array {
		if array[i] == big {
			count++
		}
	}

	if count == 3 {
		if big%2 == 0 {
			return "YES"
		} else {
			return "NO"
		}
	}

	if count == 2 {
		for i := range array {
			if array[i] != big {
				if array[i]%2 == 0 {
					return "YES"
				} else {
					return "NO"
				}
			}
		}
	}

	temp := []int{}
	for i := range array {
		if array[i] != big {
			temp = append(temp, array[i])
		}
	}

	if big-temp[0] == temp[1] {
		return "YES"
	} else {
		return "NO"
	}

}

func max(a, b, c int) int {
	max := a

	if b > max {
		max = b
	}

	if c > max {
		max = c
	}

	return max
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	str, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(str)
	for i := 0; i < n; i++ {
		line, _ := reader.ReadString('\n')
		arr := strings.Split(line, " ")
		s1, s2, s3 := arr[0], arr[1], arr[2]
		if match(s1, s2, s3) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func match(s1, s2, s3 string) bool {
	n1, _ := strconv.Atoi(s1)
	n2, _ := strconv.Atoi(s2)
	n3, _ := strconv.Atoi(s3)
	if n1 == n2 && n3%2 == 0 {
		return true
	}
	if n1 == n3 && n2%2 == 0 {
		return true
	}
	if n2 == n3 && n1%2 == 0 {
		return true
	}
	if n1 == n2+n3 || n2 == n1+n3 || n3 == n1+n2 {
		return true
	}
	return false

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("Enter text: ")
	str, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(str)
	for i := 0; i < n; i++ {
		line, _ := reader.ReadString('\n')
		arr := strings.Split(line, " ")
		s1, s2, s3 := arr[0], arr[1], arr[2]
		if match(s1, s2, s3) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func match(s1, s2, s3 string) bool {
	n1, _ := strconv.Atoi(s1)
	n2, _ := strconv.Atoi(s2)
	n3, _ := strconv.Atoi(s3)
	if n1 == n2 && n3%2 == 0 {
		return true
	}
	if n1 == n3 && n2%2 == 0 {
		return true
	}
	if n2 == n3 && n1%2 == 0 {
		return true
	}
	if n1 == n2+n3 || n2 == n1+n3 || n3 == n1+n2 {
		return true
	}
	return false

}


package main

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

type tree struct {
	root, height, dia int
}

var n, m, x, y int
var adj map[int][]int
var seen []bool
var rank, parent, comp, maxRank []int

// Ranking ... rank the tree
func Ranking(u, r, c int) int {
	if seen[u] {
		return 0
	}
	var res = u
	seen[u] = true
	rank[u] = r
	comp[u] = c
	for _, v := range adj[u] {
		if !seen[v] {
			parent[v] = u
			var mostRank = Ranking(v, r+1, c)
			if rank[mostRank] > rank[res] {
				res = mostRank
			}
		}
	}
	return res
}

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	fmt.Fscan(stdin, &n, &m)
	adj = map[int][]int{}
	seen = make([]bool, n)
	rank = make([]int, n)
	parent = make([]int, n)
	comp = make([]int, n)
	maxRank = []int{}

	for i := 0; i < m; i++ {
		fmt.Fscan(stdin, &x, &y)
		x--
		y--
		adj[x] = append(adj[x], y)
		adj[y] = append(adj[y], x)
	}

	for i, c := 0, 0; i < n; i++ {
		if !seen[i] {
			c++
			maxRank = append(maxRank, 0)
			maxRank[c-1] = Ranking(i, 1, c)
		}
	}

	seen = make([]bool, n)
	parent = make([]int, n)
	rank = make([]int, n)
	var forest = make([]tree, len(maxRank))
	for i, c := 0, 0; i < n; i++ {
		if !seen[i] {
			c++
			parent[maxRank[c-1]] = -1
			var longest = Ranking(maxRank[c-1], 0, c)
			forest[c-1].dia = rank[longest]
			forest[c-1].height = rank[longest]/2 + (rank[longest] % 2)
			// Trace
			for h := 0; longest != -1; h++ {
				if rank[longest] == forest[c-1].height {
					forest[c-1].root = longest
				}
				longest = parent[longest]
			}
		}
	}

	sort.Slice(forest[:], func(i, j int) bool {
		return forest[i].height > forest[j].height
	})

	var lastTree = forest[0]
	var dy = []int{}
	for i := 1; i < len(forest); i++ {
		if lastTree.height+forest[i].height+1 > lastTree.dia {
			lastTree.dia = lastTree.height + forest[i].height + 1
		}
		if lastTree.height == forest[i].height {
			lastTree.height++
		}
		dy = append(dy, forest[i].root)
	}

	// fmt.Println("Seen", seen)
	// fmt.Println("Rank", rank)
	// fmt.Println("Parent", parent)
	// fmt.Println("Component", comp)
	// fmt.Println("Max Rank", maxRank)
	// fmt.Println("Forest", forest)
	// fmt.Println(lastTree, dy)
	fmt.Println(lastTree.dia)
	for _, v := range dy {
		fmt.Println(lastTree.root+1, v+1)
	}
}

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p

	} else if mp.two == nil {
		mp.two = p

	} else if mp.three == nil {
		mp.three = p

	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three != nil && mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.two != nil && mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.one)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	pre := make([]int, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				pre[next] = s[deep-1][j]
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	mid := s[deep-1][0]
	for i := 0;i < deep/2;i++{
		mid = pre[mid]
	}
	res := &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   mid,
	}
	return res
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			//mp.AddPoint(p)
			//if n == 100 && m == 90 {
			//	fmt.Printf("p=%v\n", p)
			//}
		}
	}
	//if n == 100 && m == 90 {
	//	fmt.Printf("mp=%v %v %v\n", mp.one,mp.two,mp.three)
	//}
	sort.Sort(points)
	mp.one = points[0]
	plen := len(points)
	if plen > 1{
		mp.two = points[1]
	}
	if plen > 2{
		mp.three = points[2]
	}
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < plen; i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

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

	var n, m, v, w, u, o, mx, maxO int
	Fscan(in, &n, &m)
	g := make([][]int, n+1)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	vis := make([]bool, n+1)
	var f func(v, fa, d int)
	f = func(v, fa, d int) {
		vis[v] = true
		if d > mx {
			mx, u = d, v
		}
		for _, w := range g[v] {
			if w != fa {
				f(w, v, d+1)
			}
		}
	}
	var f2 func(v, fa, d int) bool
	f2 = func(v, fa, d int) bool {
		if v == u {
			if d == mx/2 {
				o = v
			}
			return true
		}
		for _, w := range g[v] {
			if w != fa && f2(w, v, d+1) {
				if d == mx/2 {
					o = v
				}
				return true
			}
		}
		return false
	}
	os := []int{}
	maxD := -1
	for i := 1; i <= n; i++ {
		if !vis[i] {
			mx = -1
			f(i, 0, 0)
			mx = -1
			x := u
			f(x, 0, 0)
			o = 0
			f2(x, 0, 0)
			os = append(os, o)
			if mx > maxD {
				maxD = mx
				maxO = o
			}
		}
	}
	for _, o := range os {
		if o != maxO {
			g[maxO] = append(g[maxO], o)
			g[o] = append(g[o], maxO)
		}
	}
	mx = -1
	f(1, 0, 0)
	mx = -1
	f(u, 0, 0)
	Fprintln(out, mx)
	for _, o := range os {
		if o != maxO {
			Fprintln(out, maxO, o)
		}
	}
}

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

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p

	} else if mp.two == nil {
		mp.two = p

	} else if mp.three == nil {
		mp.three = p

	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three != nil && mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.two != nil && mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.one)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			mp.AddPoint(p)
			//if n == 100 && m == 90 {
			//	fmt.Printf("p=%v\n", p)
			//}
		}
	}
	if n == 100 && m == 90 {
		fmt.Printf("mp=%v %v %v\n", mp.one,mp.two,mp.three)
	}
	sort.Sort(points)
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < len(points); i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p

	} else if mp.two == nil {
		mp.two = p

	} else if mp.three == nil {
		mp.three = p

	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three != nil && mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.two != nil && mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.one)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			//mp.AddPoint(p)
			//if n == 100 && m == 90 {
			//	fmt.Printf("p=%v\n", p)
			//}
		}
	}
	//if n == 100 && m == 90 {
	//	fmt.Printf("mp=%v %v %v\n", mp.one,mp.two,mp.three)
	//}
	sort.Sort(points)
	mp.one = points[0]
	plen := len(points)
	if plen > 1{
		mp.two = points[1]
	}
	if plen > 2{
		mp.three = points[2]
	}
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < plen; i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p

	} else if mp.two == nil {
		mp.two = p

	} else if mp.three == nil {
		mp.three = p

	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three != nil && mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.two != nil && mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.three)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			mp.AddPoint(p)
			//if n == 100 && m == 90 {
			//	fmt.Printf("p=%v\n", p)
			//}
		}
	}
	if n == 100 && m == 90 {
		fmt.Printf("mp=%v\n", mp)
	}
	sort.Sort(points)
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < len(points); i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p
		return
	} else if mp.two == nil {
		mp.two = p
		return
	} else if mp.three == nil {
		mp.three = p
		return
	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.three)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool,n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true{
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[(deep-1)/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			mp.AddPoint(p)
		//	fmt.Printf("p=%v\n",p)
		}
	}
	sort.Sort(points)
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < len(points); i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}
/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p
		return
	} else if mp.two == nil {
		mp.two = p
		return
	} else if mp.three == nil {
		mp.three = p
		return
	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.three)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			mp.AddPoint(p)
			if n == 100 && m == 90 {
				fmt.Printf("p=%v\n", p)
			}
		}
	}
	sort.Sort(points)
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < len(points); i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p
		return
	} else if mp.two == nil {
		mp.two = p
		return
	} else if mp.three == nil {
		mp.three = p
		return
	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.three)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool,n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true{
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			mp.AddPoint(p)
		}
	}
	sort.Sort(points)
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < len(points); i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p

	} else if mp.two == nil {
		mp.two = p

	} else if mp.three == nil {
		mp.three = p

	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three != nil && mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.two != nil && mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.three)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			mp.AddPoint(p)
			//if n == 100 && m == 90 {
			//	fmt.Printf("p=%v\n", p)
			//}
		}
	}
	if n == 100 && m == 90 {
		fmt.Printf("mp=%v %v %v\n", mp.one,mp.two,mp.three)
	}
	sort.Sort(points)
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < len(points); i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p

	} else if mp.two == nil {
		mp.two = p

	} else if mp.three == nil {
		mp.three = p

	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three != nil && mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.two != nil && mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.one)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			//mp.AddPoint(p)
			//if n == 100 && m == 90 {
			//	fmt.Printf("p=%v\n", p)
			//}
		}
	}
	if n == 100 && m == 90 {
		fmt.Printf("mp=%v %v %v\n", mp.one,mp.two,mp.three)
	}
	sort.Sort(points)
	mp.one = points[0]
	plen := len(points)
	if plen > 1{
		mp.two = points[1]
	}
	if plen > 2{
		mp.three = points[2]
	}
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < plen; i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p

	} else if mp.two == nil {
		mp.two = p

	} else if mp.three == nil {
		mp.three = p

	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three != nil && mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.two != nil && mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.one)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			mp.AddPoint(p)
			//if n == 100 && m == 90 {
			//	fmt.Printf("p=%v\n", p)
			//}
		}
	}
	//if n == 100 && m == 90 {
	//	fmt.Printf("mp=%v %v %v\n", mp.one,mp.two,mp.three)
	//}
	sort.Sort(points)
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < len(points); i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type Graph struct {
	header [][]int
}
type point struct {
	index   int
	d       int
	longest int
}
type PointSlice []*point
type maxTp struct {
	one   *point
	two   *point
	three *point
}

func (p *point) getR() int {
	return (p.d + 1) / 2
}
func (p PointSlice) Len() int {
	return len(p)
}
func (p PointSlice) Less(i, j int) bool {
	return p[i].d > p[j].d
}
func (p PointSlice) Swap(i, j int) {
	tmp := p[i]
	p[i] = p[j]
	p[j] = tmp
}
func (mp *maxTp) AddPoint(p *point) {
	if mp.one == nil {
		mp.one = p

	} else if mp.two == nil {
		mp.two = p

	} else if mp.three == nil {
		mp.three = p

	} else if mp.three.d < p.d {
		mp.three = p
	}
	mp.order()
}
func (mp *maxTp) order() {
	if mp.three != nil && mp.three.d > mp.two.d {
		mp.swap(mp.two, mp.three)
	}
	if mp.two != nil && mp.one.d < mp.two.d {
		mp.swap(mp.two, mp.three)
	}
}
func (mp *maxTp) swap(a, b *point) {
	var tmp *point = a
	a = b
	b = tmp
}

func newGraph(size int) *Graph {
	return &Graph{
		header: make([][]int, size),
	}
}
func (g *Graph) addEdge(from, to int) {
	if 0 == len(g.header[from]) {
		g.header[from] = make([]int, 0)
	}
	g.header[from] = append(g.header[from], to)
}

func diameter(g *Graph, root, n int, visited []bool) *point {
	//	fmt.Printf("root=%d \n", root)
	s := make([][]int, n+1)
	s[0] = make([]int, 1)
	s[0][0] = root
	visited[root] = true
	flag := make([]bool, n+1)
	deep := 1
	flag[root] = true
	for {
		nextP := make([]int, 0)
		for j := 0; j < len(s[deep-1]); j++ {
			for _, next := range g.header[s[deep-1][j]] {
				visited[next] = true
				if flag[next] == true {
					continue
				}
				flag[next] = true
				nextP = append(nextP, next)
			}
		}
		if len(nextP) == 0 {
			break
		}
		s[deep] = nextP
		deep++
	}
	//	fmt.Printf("s=%v\n",s)
	return &point{
		d:       deep - 1,
		longest: s[deep-1][0],
		index:   s[deep/2][0],
	}
}
func solveMaxd(mp *maxTp) int {
	var ans int = mp.one.d
	if mp.three == nil && mp.two == nil {
		return ans
	}
	if mp.three == nil {
		if mp.one.d < mp.one.getR()+mp.two.getR()+1 {
			return mp.one.getR() + mp.two.getR() + 1
		} else {
			return mp.one.d
		}
	}
	if mp.two.getR()+mp.three.getR()+2 > ans {
		ans = mp.two.getR() + mp.three.getR() + 2
	}
	if mp.one.getR()+mp.two.getR()+1 > ans {
		ans = mp.one.getR() + mp.two.getR() + 1
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	g := newGraph(n + 1)
	for i := 0; i < m; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		g.addEdge(from, to)
		g.addEdge(to, from)
	}
	visited := make([]bool, n+1)
	points := PointSlice(make([]*point, 0))
	mp := &maxTp{
	}
	for i := 1; i <= n; i++ {
		if visited[i] == false {
			end := diameter(g, i, n, visited)
			p := diameter(g, end.longest, n, visited)
			points = append(points, p)
			mp.AddPoint(p)
			//if n == 100 && m == 90 {
			//	fmt.Printf("p=%v\n", p)
			//}
		}
	}

	sort.Sort(points)
	fmt.Printf("%d\n", solveMaxd(mp))
	for i := 1; i < len(points); i++ {
		fmt.Printf("%d %d\n", points[0].index, points[i].index)
	}
}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

type tree struct {
	root, height, dia int
}

var n, m, x, y int
var adj map[int][]int
var seen []bool
var rank, parent, comp, maxRank []int

// Ranking ... rank the tree
func Ranking(u, r, c int) int {
	if seen[u] {
		return 0
	}
	var res = u
	seen[u] = true
	rank[u] = r
	comp[u] = c
	for _, v := range adj[u] {
		if !seen[v] {
			parent[v] = u
			var mostRank = Ranking(v, r+1, c)
			if rank[mostRank] > rank[res] {
				res = mostRank
			}
		}
	}
	return res
}

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	fmt.Fscan(stdin, &n, &m)
	adj = map[int][]int{}
	seen = make([]bool, n)
	rank = make([]int, n)
	parent = make([]int, n)
	comp = make([]int, n)
	maxRank = []int{}

	for i := 0; i < m; i++ {
		fmt.Fscan(stdin, &x, &y)
		x--
		y--
		adj[x] = append(adj[x], y)
		adj[y] = append(adj[y], x)
	}

	for i, c := 0, 0; i < n; i++ {
		if !seen[i] {
			c++
			maxRank = append(maxRank, 0)
			maxRank[c-1] = Ranking(i, 1, c)
		}
	}

	seen = make([]bool, n)
	parent = make([]int, n)
	rank = make([]int, n)
	var forest = make([]tree, len(maxRank))
	for i, c := 0, 0; i < n; i++ {
		if !seen[i] {
			c++
			parent[maxRank[c-1]] = -1
			var longest = Ranking(maxRank[c-1], 1, c)
			forest[c-1].dia = rank[longest] - 1
			var rootRank = rank[longest]/2 + 1
			// Trace
			for h := 0; longest != -1; h++ {
				if rank[longest] == rootRank {
					forest[c-1].root = longest
				}
				if parent[longest] == -1 {
					forest[c-1].height = h
				}
				longest = parent[longest]
			}
		}
	}

	sort.Slice(forest[:], func(i, j int) bool {
		return forest[i].height > forest[j].height
	})

	var lastTree = forest[0]
	var dx, dy = []int{}, []int{}
	for i := 1; i < len(forest); i++ {
		if lastTree.height == forest[i].height {
			lastTree.height++
		}
		lastTree.dia = lastTree.height + forest[i].height
		dx = append(dx, lastTree.root)
		dy = append(dy, forest[i].root)
	}

	// fmt.Println("Seen", seen)
	// fmt.Println("Rank", rank)
	// fmt.Println("Parent", parent)
	// fmt.Println("Component", comp)
	// fmt.Println("Max Rank", maxRank)
	// fmt.Println("Forest", forest)
	// fmt.Println(lastTree, dy)
	fmt.Println(lastTree.dia)
	for _, v := range dy {
		fmt.Println(lastTree.root+1, v+1)
	}
}

package main

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

type tree struct {
	root, height, dia int
}

var n, m, x, y int
var adj map[int][]int
var seen []bool
var rank, parent, comp, maxRank []int

// Ranking ... rank the tree
func Ranking(u, r, c int) int {
	if seen[u] {
		return 0
	}
	var res = u
	seen[u] = true
	rank[u] = r
	comp[u] = c
	for _, v := range adj[u] {
		if !seen[v] {
			parent[v] = u
			var mostRank = Ranking(v, r+1, c)
			if rank[mostRank] > rank[res] {
				res = mostRank
			}
		}
	}
	return res
}

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	fmt.Fscan(stdin, &n, &m)
	adj = map[int][]int{}
	seen = make([]bool, n)
	rank = make([]int, n)
	parent = make([]int, n)
	comp = make([]int, n)
	maxRank = []int{}

	for i := 0; i < m; i++ {
		fmt.Fscan(stdin, &x, &y)
		x--
		y--
		adj[x] = append(adj[x], y)
		adj[y] = append(adj[y], x)
	}

	for i, c := 0, 0; i < n; i++ {
		if !seen[i] {
			c++
			maxRank = append(maxRank, 0)
			maxRank[c-1] = Ranking(i, 1, c)
		}
	}

	seen = make([]bool, n)
	parent = make([]int, n)
	rank = make([]int, n)
	var forest = make([]tree, len(maxRank))
	for i, c := 0, 0; i < n; i++ {
		if !seen[i] {
			c++
			parent[maxRank[c-1]] = -1
			var longest = Ranking(maxRank[c-1], 0, c)
			forest[c-1].dia = rank[longest]
			forest[c-1].height = rank[longest]/2 + (rank[longest] % 2)
			// Trace
			for h := 0; longest != -1; h++ {
				if rank[longest] == forest[c-1].height {
					forest[c-1].root = longest
				}
				longest = parent[longest]
			}
		}
	}

	sort.Slice(forest[:], func(i, j int) bool {
		return forest[i].height > forest[j].height
	})

	var lastTree = forest[0]
	var dy = []int{}
	for i := 1; i < len(forest); i++ {
		lastTree.dia = lastTree.height + forest[i].height + 1
		if lastTree.height == forest[i].height {
			lastTree.height++
		}
		dy = append(dy, forest[i].root)
	}

	// fmt.Println("Seen", seen)
	// fmt.Println("Rank", rank)
	// fmt.Println("Parent", parent)
	// fmt.Println("Component", comp)
	// fmt.Println("Max Rank", maxRank)
	// fmt.Println("Forest", forest)
	// fmt.Println(lastTree, dy)
	fmt.Println(lastTree.dia)
	for _, v := range dy {
		fmt.Println(lastTree.root+1, v+1)
	}
}

package main

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

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

	var n, m, v, w, u, mx, maxO int
	Fscan(in, &n, &m)
	g := make([][]int, n+1)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	vis := make([]bool, n+1)
	var vs []int
	dep := make([]int, n+1)
	var f func(v, fa, d int)
	f = func(v, fa, d int) {
		vis[v] = true
		vs = append(vs, v)
		dep[v] = d
		if d > mx {
			mx, u = d, v
		}
		for _, w := range g[v] {
			if w != fa {
				f(w, v, d+1)
			}
		}
	}
	os := []int{}
	maxD := -1
	for i := 1; i <= n; i++ {
		if !vis[i] {
			mx = -1
			f(i, 0, 0)
			vs = []int{}
			mx = -1
			f(u, 0, 0)
			for _, v := range vs {
				if dep[v] == mx/2 {
					os = append(os, v)
					if mx > maxD {
						maxD = mx
						maxO = v
					}
					break
				}
			}
		}
	}
	for _, o := range os {
		if o != maxO {
			g[maxO] = append(g[maxO], o)
			g[o] = append(g[o], maxO)
		}
	}
	mx = -1
	f(1, 0, 0)
	mx = -1
	f(u, 0, 0)
	Fprintln(out, mx)
	for _, o := range os {
		if o != maxO {
			Fprintln(out, maxO, o)
		}
	}
}

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