package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		A := make([]int, n)
		for i := 0; i < (n / 2); i++ {
			A[2*i] = 2 * (i + 1)
			A[2*i+1] = 2*i + 1
		}
		if n%2 == 1 {
			A[n-2] = n
			A[n-1] = n - 2
		}
		writer.WriteString(fmt.Sprint(A)[1:len(fmt.Sprint(A))-1] + "\n")
	}
	writer.Flush()
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

package main

import ."fmt"
//import "sort"
import "bufio"
import "os"
//import "string"
//import "time"
//import ."math"

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

func main() {
    defer writer.Flush()

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

}
func solve() {
    n := sint64()
	arr := make([]int64, n)
	for i := int64(0); i < n; i++ {
		arr[i] = i + 1
	}

	for i := int64(1); i < n; i += 2 {
		arr[i], arr[i - 1] = arr[i - 1], arr[i]
	}

	if n % 2 == 1 {
		arr[n - 1], arr[n - 2] = arr[n - 2], arr[n - 1]
	}

	for i := int64(0); i < n; i++ {
		printf("%d ", arr[i])
	}
	printf("\n")

}
func printf(f string, a ...interface{}) {
	Fprintf(writer, f, a...)
}
func sstring() string {
	scanner.Scan()
	return scanner.Text()
}
func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sum(a []int64) int64{
    ans := int64(0)
    for _, i := range a {
        ans += i
    }
    return ans
}
func abs(x int64) int64 {
    if x < 0 {
        return 0 - x
    }
    return x
}
func min(x, y int64) int64 {
    if x < y {
        return x
    }
    return y
}

package main

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

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

func solve(n int) string {
	var x string
	if n%2 == 0 {
		for i := 1; i <= n; i += 2 {
			x += fmt.Sprintf("%d %d ", i+1, i)
		}
	} else {
		x = "2 3 1 "
		for i := 4; i <= n; i += 2 {
			x += fmt.Sprintf("%d %d ", i+1, i)
		}
	}
	return x
}

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

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		if n%2 == 0 {
			k := int(n / 2)
			for i := 1; i < k+1; i++ {
				fmt.Println(2 * i)
				fmt.Println(2*i - 1)
			}
		} else {
			fmt.Println(3)
			fmt.Println(1)
			fmt.Println(2)
			k := int(n / 2)
			for i := 2; i < k+1; i++ {
				fmt.Println(2*i + 1)
				fmt.Println(2 * i)
			}

		}
	}

}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(num int) []int {
	a := make([]int, num)
	for i := 1; i < num+1; i++ {
		a[i-1] = i
	}

	for i := 0; i < num-1; i += 2 {
		a[i], a[i+1] = a[i+1], a[i]
	}
	if num%2 != 0 {
		a[num-3] = num
		a[num-1] = num - 1
		a[num-2] = num - 2
	}
	return a
}

func main() {
	log.Println("start")

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

	// num := 0
	// fmt.Fscan(in, &num)
	// for i := 0; i < num; i++ {
	var size int
	fmt.Fscan(in, &size)
	// a := make([]int, size)
	for i := 0; i < size; i++ {
		var num int
		fmt.Fscan(in, &num)
		a := solve(num)
		log.Printf("a = %#v\n", a)

		for _, v := range a {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

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

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

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

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

		solve(n)
		fmt.Println()
	}
}

func solve(n int) {

	if n == 3 {
		fmt.Print(2)
		fmt.Print(" ")
		fmt.Print(3)
		fmt.Print(" ")
		fmt.Print(1)
		fmt.Print(" ")
		return
	}

	if n % 2 == 0 {

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

	} else {
		fmt.Print(2)
		fmt.Print(" ")
		fmt.Print(3)
		fmt.Print(" ")
		fmt.Print(1)
		fmt.Print(" ")

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

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		vec := make([]int, N)
		for i := 1; i <= N; i++ {
			vec[i-1] = i
		}
		for i := 0; i < N-1; i += 2 {
			vec[i], vec[i+1] = vec[i+1], vec[i]
		}
		if N&1 != 0 {
			vec[N-3], vec[N-1] = vec[N-1], vec[N-3]
		}
		for i := 0; i < N; i++ {
			fmt.Fprint(out, vec[i], " ")
		}
		fmt.Fprintln(out)
	}
}

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

package main

import (
	"fmt"
)

func solve() {
	n := readInt()

	if n%2 == 0 {
		for i := 0; i < n/2; i++ {
			fmt.Printf("%d %d ", 2*i+2, 2*i+1)
		}
	} else {
		for i := 0; i < (n-3)/2; i++ {
			fmt.Printf("%d %d ", 2*i+2, 2*i+1)
		}
		fmt.Printf("%d %d %d", n, n-2, n-1)
	}
	fmt.Print("\n")
}

func main() {
	n := readInt()
	for i := 0; i < n; i++ {
		solve()
	}
}

func readInt() int {
	var n int
	fmt.Scan(&n)
	return n
}
func readIntN(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

func readIntNN(n, m int) [][]int {
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = readIntN(m)
	}
	return arr
}

func min(a ...int) int {
	min := a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
	}
	return min
}
func max(a ...int) int {
	max := a[0]
	for _, v := range a {
		if v > max {
			max = v
		}
	}
	return max
}

func minMax(a ...int) (min int, max int) {
	min, max = a[0], a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
		if v > max {
			max = v
		}
	}
	return
}

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

package main

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

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

func (in *CF1541A) 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 *CF1541A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1541A
Date: 11/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1541/A
Problem: CF1541A
**/
func (in *CF1541A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		sol := make([]int, n)

		for i := 1; i < n; i += 2 {
			sol[i] = i
			sol[i-1] = i + 1
		}

		if n % 2 != 0 {
			sol[n-2], sol[n-1] = n, sol[n-2]
		}

		for i := 0; i < n; i++ {
			fmt.Print(sol[i], " ")
		}
		fmt.Println()
	}
}

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

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

package main

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

type Scanner struct {
	scanner *bufio.Scanner
}

func StdinScanner() *Scanner {
	scanner := new(Scanner)
	scanner.scanner = bufio.NewScanner(os.Stdin)
	scanner.scanner.Split(bufio.ScanWords)

	return scanner
}

func (s Scanner) Int() int {
	s.scanner.Scan()
	n, _ := strconv.Atoi(s.scanner.Text())

	return n
}

func (s Scanner) Int64() int64 {
	s.scanner.Scan()
	n, _ := strconv.ParseInt(s.scanner.Text(), 10, 64)

	return n
}

func (s Scanner) Token() string {
	s.scanner.Scan()

	return s.scanner.Text()
}

func solve(n int) []int {
	if n == 2 {
		return []int{2, 1}
	}

	res := make([]int, n)

	if n%2 == 0 {
		for i := 0; i < n; i += 2 {
			res[i] = i + 2
			res[i+1] = i + 1
		}
	} else {
		for i := 0; i+3 < n; i += 2 {
			res[i] = i + 2
			res[i+1] = i + 1
		}
		res[n-3] = n
		res[n-2] = n - 2
		res[n-1] = n - 1
	}

	return res
}

func main() {
	scanner := StdinScanner()

	tests := scanner.Int()
	for i := 0; i < tests; i += 1 {
		x := scanner.Int()
		res := solve(x)
		for _, num := range res {
			fmt.Printf("%d ", num)
		}
		fmt.Println()
	}
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

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

		for i := 1; i < n; i += 2 {
			arr[i], arr[i-1] = arr[i-1], arr[i]
		}

		if n%2 == 1 {
			arr[n-1], arr[n-2] = arr[n-2], arr[n-1]
		}

		for i := 0; i < n; i++ {
			fmt.Printf("%d ", arr[i])
		}
		fmt.Println()
	}
}

package main

import (
    "fmt"
    "strings"
)

func main() {
    var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var k, rn int
		fmt.Scan(&k)
		rn = (k % 2)
		fmt.Print("2 ", strings.Repeat("3 ", rn), "1 ")
		for flag, j := 1, 3+rn; j <= k; j, flag = j+1, flag*-1 {
			fmt.Print(j+flag, " ")
		}
		fmt.Println()
	}
}

package main

import (
    "fmt"
    "strings"
)

func main() {
    var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var k int
		fmt.Scan(&k)
		rn := (k % 2)
		fmt.Print("2 ", strings.Repeat("3 ", rn), "1 ")
		flag := 1
		for j := 3 + rn; j <= k; j++ {
			fmt.Print(j+flag, " ")
			flag *= -1
		}
		fmt.Println()
	}
}

package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    for i:=0; i<n; i++ {
        var k int
        fmt.Scan(&k)
        flag:=1
        for j:=1; j<=k-2; j++ {
            fmt.Print(j + flag," ")
            flag*=-1
        }
        if k%2 == 0 {
            fmt.Print(k,k-1)
        } else {
            fmt.Print(k,k-2)
        }
        fmt.Println()
    }

}

package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    for i:=0; i<n; i++ {
        var k int
        fmt.Scan(&k)
        flag:=1
        if k%2 == 0 {
            for j:=1; j<=k; j++ {
                fmt.Print(j + flag," ")
                flag*=-1
            }
        } else {
            for j:=1; j<=k-2; j++ {
                fmt.Print(j + flag," ")
                flag*=-1
            }
            fmt.Print(k,k-2)
        }
        fmt.Println()
    }

}

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

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    input, _ := reader.ReadString('\n')

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var n int
		n, _ = GetInt(input)

		m := n>>1 - 1
		for i:=1; i<=m; i++ {
			fmt.Printf("%d %d ", 2*i, 2*i-1)
		}
		if n & 0x1 == 1 {
			fmt.Printf("%d %d %d\n", n, n-2, n-1)

		} else {
			fmt.Printf("%d %d\n", n, n-1)
		}
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		fmt.Printf("%d ",n)
		for j:=1;j<=n-1;j++{
			fmt.Printf("%d ",j)
		}
		fmt.Println()
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		fmt.Printf("%d ",n)
		for j:=1;j<=n-1;j++{
			fmt.Printf("%d ",j)
		}
	}
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    input, _ := reader.ReadString('\n')

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var n int
		n, _ = GetInt(input)

		m := n>>1 - 1
		for i:=0; i<m; i++ {
			fmt.Printf("%d %d ", 1<<i+1, 1<<i)
		}
		if n & 0x1 == 1 {
			fmt.Printf("%d %d %d\n", n, n-2, n-1)

		} else {
			fmt.Printf("%d %d\n", n, n-1)
		}
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    input, _ := reader.ReadString('\n')

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var n int
		n, _ = GetInt(input)

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

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

import ."fmt"
//import "sort"
import "bufio"
import "os"
//import "string"
//import "time"
//import ."math"

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

func main() {
    defer writer.Flush()

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

}
func solve() {
    n := sint64()
    printf("%d ", n)
    for i := int64(1); i < n; i++ {
        printf("%d ", i)
    }
    printf("\n")

}
func printf(f string, a ...interface{}) {
	Fprintf(writer, f, a...)
}
func sstring() string {
	scanner.Scan()
	return scanner.Text()
}
func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sum(a []int64) int64{
    ans := int64(0)
    for _, i := range a {
        ans += i
    }
    return ans
}
func abs(x int64) int64 {
    if x < 0 {
        return 0 - x
    }
    return x
}
func min(x, y int64) int64 {
    if x < y {
        return x
    }
    return y
}

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		A := make([]int, n)
		for i := 0; i < (n / 2); i++ {
			A[2*i] = 2 * (i + 1)
			A[2*i+1] = 2*i + 1
		}
		if n%2 == 1 {
			A[n-2] = n
			A[n-1] = n - 2
		}
		writer.WriteString(fmt.Sprint(A)[1:2*n] + "\n")
	}
	writer.Flush()
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

package main

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

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

func solve(n int) string {
	var x string
	if n%2 == 0 {
		for i := 1; i <= n; i += 2 {
			x += fmt.Sprintf("%d %d ", i+1, i)
		}
	} else {
		x = "2 3 1 "
		for i := 4; i <= n; i += 2 {
			x += fmt.Sprintf("%d %d ", i, i+1)
		}
	}
	return x
}

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

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		fmt.Println(n)
		for i := 1; i < n; i++ {
			fmt.Println(i)
		}

	}

}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

// func solve(a []int) {
//
// }

func main() {
	log.Println("start")

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

	// num := 0
	// fmt.Fscan(in, &num)
	// for i := 0; i < num; i++ {
	var size int
	fmt.Fscan(in, &size)
	// a := make([]int, size)
	for i := 0; i < size; i++ {
		var num int
		fmt.Fscan(in, &num)
		// log.Printf("num = %#v\n", num)
		fmt.Printf("%d ", num)
		for i := 1; i < num; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
	}
	// solve(a)
	// }
	log.Println("__end__")
}

package main

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

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

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

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

		solve(n)
		fmt.Println()
	}
}

func solve(n int) {

	if n == 3 {
		fmt.Print(2)
		fmt.Print(" ")
		fmt.Print(3)
		fmt.Print(" ")
		fmt.Print(1)
		fmt.Print(" ")
		return
	}

	if n % 2 == 0 {

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

	} else {
		fmt.Print(2)
		fmt.Print(" ")
		fmt.Print(3)
		fmt.Print(" ")
		fmt.Print(1)
		fmt.Print(" ")

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

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


package main

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

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

  var numRows, numCols, r0, c0 int
  line, _ := reader.ReadString('\n')
  line = strings.TrimSpace(line)
  fmt.Sscanf(line, "%d%d%d%d", &numRows, &numCols, &r0, &c0)
  dr := []int{ -1, 0, 1, 0 }
  dc := []int{ 0, 1, 0, -1 }
  dirs := map[byte]int{ 'U': 0, 'R': 1, 'D': 2, 'L': 3 }

  s, _ := reader.ReadString('\n')
  s = strings.TrimSpace(s)
  numMoves := len(s)
  explodeTime := make([]int, numMoves + 1)
  cellExploded := make([][]bool, numRows + 1)
  for r := 0; r <= numRows; r++ {
    cellExploded[r] = make([]bool, numCols + 1)
  }
  cellExploded[r0][c0] = true
  explodeTime[0] = 1
  testsLeft := numRows * numCols - 1

  r, c := r0, c0
  for i := 0; i < numMoves; i++ {
    dir := dirs[s[i]]
    R, C := r + dr[dir], c + dc[dir]
    if R < 1 || R > numRows || C < 1 || C > numCols {
      continue
    }
    r, c = R, C
    if !cellExploded[r][c] {
      cellExploded[r][c] = true
      explodeTime[i + 1] = 1
      testsLeft--
    }
  }
  explodeTime[numMoves] += testsLeft

  writer.WriteString(fmt.Sprintf("%d", explodeTime[0]))
  for i := 1; i <= numMoves; i++ {
    writer.WriteString(fmt.Sprintf(" %d", explodeTime[i]))
  }
  writer.WriteString("\n")
}

package main

import "fmt"

func main(){
	var x int
	var y int
	var x0 int
	var y0 int
	var com []byte
	var visited int
	fmt.Scanf("%d %d %d %d ",&x,&y,&x0,&y0)
	map_ := make([][]bool,x + 1)
	for i_,_ := range map_{
		map_[i_] = make([]bool,y + 1)
	}
	fmt.Scanf("%s",&com)
	fmt.Print("1 ")
	visited = 1
	map_[x0][y0] = true
	for i := 0;i < len(com);i++{
		if i == len(com) - 1{
			fmt.Print(x * y - visited)
			break
		}
		switch com[i]{
			case 'U':
			if(x0 > 1){
				x0--
				if map_[x0][y0] == false{
					visited++
					map_[x0][y0] = true
					fmt.Print("1 ")
				}else {
					fmt.Print("0 ")
				}
			}else {
				fmt.Print("0 ")
			}
			case 'D':
			if(x0 < x){
				x0++
				if map_[x0][y0] == false{
					visited++
					map_[x0][y0] = true
					fmt.Print("1 ")
				}else {
					fmt.Print("0 ")
				}
			}else {
				fmt.Print("0 ")
			}
			case 'L':
			if(y0 > 1){
				y0--
				if map_[x0][y0] == false{
					visited++
					map_[x0][y0] = true
					fmt.Print("1 ")
				}else {
					fmt.Print("0 ")
				}
			}else {
				fmt.Print("0 ")
			}
			case 'R':
			if(y0 < y){
				y0++
				if map_[x0][y0] == false{
					visited++
					map_[x0][y0] = true
					fmt.Print("1 ")
				}else {
					fmt.Print("0 ")
				}
			}else {
				fmt.Print("0 ")
			}
		}
	}
}

package main

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

type Dxy struct {
	x, y int
}

var dir map[uint8]Dxy

func initDirMap() {
	dir = make(map[uint8]Dxy)
	dir['L'] = Dxy {
		0, -1,
	}
	dir['R'] = Dxy {
		0, 1,
	}
	dir['U'] = Dxy {
		-1, 0,
	}
	dir['D'] = Dxy {
		1, 0,
	}
}
var mat [500][500] int

func main() {
	initDirMap()

	stdin := bufio.NewReader(os.Stdin)

	var n, m, x0, y0 int
	fmt.Fscanf(stdin, "%d%d%d%d\n", &n, &m, &x0, &y0)

	x0 = x0 - 1
	y0 = y0 - 1

	var cmd string
	fmt.Fscanf(stdin, "%s\n", &cmd)

	cnt := 0
	for i := 0; i < len(cmd); i++ {
		// fmt.Println("")
		// fmt.Println(x0, y0)
		if mat[x0][y0] == 0 {
			fmt.Printf("1 ")
			cnt = cnt + 1
			mat[x0][y0] = 1
		} else {
			fmt.Printf("0 ")
		}

		dxy := dir[cmd[i]]

		x1 := x0 + dxy.x
		y1 := y0 + dxy.y

		// if is valid
		if x1 >=0 && x1 < n && y1 >= 0 && y1 < m {
			x0 = x1
			y0 = y1
		}

	}
	fmt.Println(n * m - cnt)

}

package main

import "fmt"

func main(){
	var x int
	var y int
	var x0 int
	var y0 int
	var com []byte
	var visited int
	fmt.Scanf("%d %d %d %d ",&x,&y,&x0,&y0)
	fmt.Scanf("%s",&com)
	fmt.Print("1 ")
	visited = 1
	for i := 0;i < len(com);i++{
		if i == len(com) - 1{
			fmt.Print(x * y - visited)
			break
		}
		switch com[i]{
			case 'U':
			if(x0 > 1){
				visited++
				x0--
				fmt.Print("1 ")
			}else {
				fmt.Print("0 ")
			}
			case 'D':
			if(x0 < x){
				visited++
				x0++
				fmt.Print("1 ")
			}else {
				fmt.Print("0 ")
			}
			case 'L':
			if(y0 > 1){
				visited++
				y0--
				fmt.Print("1 ")
			}else {
				fmt.Print("0 ")
			}
			case 'R':
			if(y0 < y){
				visited++
				y0++
				fmt.Print("1 ")
			}else {
				fmt.Print("0 ")
			}
		}
	}
}


package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    a, ans, cnt := make([]int,n), 0, 0
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
        if (i >= 2) {
            if a[i] == (a[i-1]+a[i-2]) {
                cnt++
            } else {
                if ans < cnt { ans = cnt }
                cnt = 0
            }
        }
    }
    if ans < cnt { ans = cnt }
    if ans == 0 {
        if n == 1 { fmt.Println(1) } else { fmt.Println(2) }
    } else {
        fmt.Println(ans+2)
    }
}

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

func main() {
	var n,i int
	as,l:=2,2
	fmt.Scan(&n)
	a:=make([]int,200005)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	if n==1 {
		as=1
	}
	for i=1;i<=n;i++ {
		input.Scan()
		aa,_:= strconv.Atoi(input.Text())
		a[i]=aa
		//fmt.Scan(&a[i])
	}
	for i=3;i<=n;i++ {
		if a[i]==(a[i-1]+a[i-2]) {
			l++
		}
		if a[i]!=(a[i-1]+a[i-2]) {
			l=2
		}
		if l>as {
				as=l
		}
	}
	fmt.Println(as)
}

package main
import (
    "fmt"
    "bufio"
    "os"
)
func get_max(a, b int) int {
    if a > b { return a }
    return b
}

func main() {
    var n, ans int
    var _a [110000]int
    bin := bufio.NewReader(os.Stdin)
    fmt.Fscan(bin, &n)
    for i := 0; i < n;i++ {
        fmt.Fscan(bin, &_a[i])
    }
    a := _a[:n]
    var p int

    for i := 0; i < n; i++ {
        if i < 2 {
            p = i + 1
        } else if a[i] == a[i - 1] + a[i - 2] {
            p = p + 1
        } else {
            p = 2
        }
        ans = get_max(ans, p)
    }
    fmt.Printf("%d\n", ans)
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

func (s *Scanner) Text() string {
	return string(s.token)
}

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

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

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

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

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

func main() {
	defer w.Flush()
	n := ni32()
	a1, a2, a3 := 0, 0, 0
	cur, ans := 0, min(2, n)
	for i := 0; i < n; i++ {
		a1, a2, a3 = a2, a3, ni32()
		if i >= 2 {
			if a3 == a1+a2 {
				if cur == 0 {
					cur = 3
				} else {
					cur++
				}
				ans = max(ans, cur)
			} else {
				cur = 0
			}
		}
	}
	pri32(ans)
}

// 365B-mic
package main

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

func main() {
    w := bufio.NewScanner(os.Stdin)
    w.Split(bufio.ScanWords)
    var n, a, b, cou int
    var x float64
    fmt.Scan(&n)
    if n <= 2 {
        fmt.Println(n)
        return
    }
    cou = 2
    fmt.Scan(&a, &b)
    d := make([]int, n)
    for i := 2; i < n; i++ {
        w.Scan()
        s, _ := strconv.Atoi(w.Text())
        d[i] = s
    }
    for i := 2; i < n; i++ {
        if d[i] == a+b {
            cou++
        } else {
            x = math.Max(float64(x), float64(cou))
            cou = 2
        }
        a = b
        b = d[i]
    }
    x = math.Max(float64(x), float64(cou))
    fmt.Println(x)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	if n == 1 || n == 2 {
		fmt.Println(n)
		return
	}
	A := make([]int, n)

	var j int
	for i := 0; i < n-1; i++ {
		fmt.Scan(&j)
		A[i] = j
	}
	fmt.Scan(&j)
	A[n-1] = j

	l, r, max := 0, 1, 2
	for r < n-1 {
		if A[r-1] + A[r] == A[r+1] {
			r++
			if r-l+1 > max {
				max = r-l+1
			}
		} else {
			l, r = r, r+1
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
    var n int
    var (
        cur uint64
        fst, snd uint64
        cnt, maxcnt int = 2, 2
    )

    fmt.Scan(&n)
    if n < 2 {
        fmt.Println(1)
    } else {
        fmt.Scan(&fst, &snd)

        for i := 2; i<n; i++ {
            fmt.Scan(&cur)
            if cur == fst + snd {
                cnt++
            } else {
                if cnt > maxcnt {
                    maxcnt = cnt
                }
                cnt = 2
            }
            fst = snd
            snd = cur
        }

        if cnt > maxcnt {
            maxcnt = cnt
        }

        fmt.Println(maxcnt)
    }
}

package main

import (
	"fmt"
)

func main() {
	var n,k int
	var s string
	var c [10]int

	fmt.Scan(&n,&k)
	t:=0
	for i:=0;i<n;i++ {
		fmt.Scan(&s)
		b:=1
		for j:=0;j<10;j++ {
			c[j]=0
		}
		for k:=0;k<len(s);k++ {
			c[s[k]-'0']=1
		}
		for j:=0;j<=k;j++ {
			if c[j]==0 {
				b=0
				break
			}
		}
		t+=b
	}
	fmt.Println(t)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    a, ans, cnt := make([]int,n), 0, 0
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
        if (i >= 2) {
            if a[i] == (a[i-1]+a[i-2]) {
                cnt++
            } else {
                if ans < cnt { ans = cnt }
                cnt = 0
            }
        }
    }
    if ans < cnt { ans = cnt }
    fmt.Println(ans+2)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    a, ans, cnt := make([]int,n), 0, 0
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
        if (i >= 2) {
            if a[i] == (a[i-1]+a[i-2]) {
                cnt++
            } else {
                if ans < cnt { ans = cnt }
                cnt = 0
            }
        }
    }
    if ans < cnt { ans = cnt }
    if ans == 0 {
        fmt.Println(1)
    } else {
        fmt.Println(ans+2)
    }
}

package main
import (
    "fmt"
    "bufio"
    "os"
)
func get_max(a, b int) int {
    if a > b { return a }
    return b
}

func main() {
    var n, ans int
    var _a [110000]int
    bin := bufio.NewReader(os.Stdin)
    fmt.Fscan(bin, &n)
    for i := 0; i < n;i++ {
        fmt.Fscan(bin, &_a[i])
    }
    a := _a[:n]
    var p int

    for i := 0; i < n; i++ {
        if i < 2 {
            p = i + 1
        } else if a[i] == a[i - 1] + a[i - 2] {
            p = p + 1
        } else {
            p = 0
        }
        ans = get_max(ans, p)
    }
    fmt.Printf("%d\n", ans)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	if n == 1 || n == 2 {
		fmt.Println(n)
	}
	A := make([]int, n)

	var j int
	for i := 0; i < n-1; i++ {
		fmt.Scan(&j)
		A[i] = j
	}
	fmt.Scan(&j)
	A[n-1] = j

	l, r, max := 0, 1, 2
	for r < n-1 {
		if A[r-1] + A[r] == A[r+1] {
			r++
			if r-l+1 > max {
				max = r-l+1
			}
		} else {
			l, r = r, r+1
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
    var n int
    var (
        cur int
        fst, snd int
        cnt int = 2
    )

    fmt.Scan(&n)
    fmt.Scan(&fst, &snd)

    for i := 2; i<n; i++ {
        fmt.Scan(&cur)
        if cur == fst + snd {
            cnt++
        } else {
            cnt = 2
        }
        fst = snd
        snd = cur
    }

    fmt.Println(cnt)
}

package main

import "fmt"

func main() {
    var n int
    var (
        cur uint64
        fst, snd uint64
        cnt int = 2
    )

    fmt.Scan(&n)
    if n < 2 {
        fmt.Println(1)
    } else {
        fmt.Scan(&fst, &snd)

        for i := 2; i<n; i++ {
            fmt.Scan(&cur)
            if cur == fst + snd {
                cnt++
            } else {
                cnt = 2
            }
            fst = snd
            snd = cur
        }

        fmt.Println(cnt)
    }
}

package main

import "fmt"

func main() {
    var n int
    var (
        cur uint64
        fst, snd uint64
        cnt, maxcnt int = 2, 2
    )

    fmt.Scan(&n)
    if n < 2 {
        fmt.Println(1)
    } else {
        fmt.Scan(&fst, &snd)

        for i := 2; i<n; i++ {
            fmt.Scan(&cur)
            if cur == fst + snd {
                cnt++
            } else {
                if cnt > maxcnt {
                    maxcnt = cnt
                }
                cnt = 2
            }
            fst = snd
            snd = cur
        }

        fmt.Println(maxcnt)
    }
}

package main

import "fmt"

func main() {
    var n int
    var (
        cur int
        fst, snd int
        cnt int = 2
    )

    fmt.Scan(&n)
    if n < 2 {
        fmt.Println(1)
    } else {
        fmt.Scan(&fst, &snd)

        for i := 2; i<n; i++ {
            fmt.Scan(&cur)
            if cur == fst + snd {
                cnt++
            } else {
                cnt = 2
            }
            fst = snd
            snd = cur
        }

        fmt.Println(cnt)
    }
}

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

func main() {
	var n,i int
	as,l:=2,2
	fmt.Scan(&n)
	a:=make([]int,200005)
	if n==1 {
		as=1
	}
	for i=1;i<=n;i++ {
		fmt.Scan(&a[i])
	}
	for i=3;i<=n;i++ {
		if a[i]==(a[i-1]+a[i-2]) {
			l++
		}
		if a[i]!=(a[i-1]+a[i-2]) {
			l=2
		}
	}
	if l>as {
		as=l
	}
	fmt.Println(as)
}


package main
import ."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var T, n, v int
	for Scan(&T); T > 0; T-- {
		a := [2][]interface{}{}
		for Scan(&n); n > 0; n-- {
			Scan(&v)
			a[v&1] = append(a[v&1], v)
		}
		Println(a[0]...)
		Println(a[1]...)
	}
}

package main

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

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

	var T, N, A int
	for fmt.Fscan(in, &T); T > 0; T-- {
		nums := make([]int, 0)
		for fmt.Fscan(in, &N); N > 0; N-- {
			fmt.Fscan(in, &A)
			nums = append(nums, A)
		}
		for _, v := range nums {
			if v%2 == 1 {
				fmt.Fprint(out, v, " ")
			}
		}
		for _, v := range nums {
			if v%2 == 0 {
				fmt.Fprint(out, v, " ")
			}
		}
		fmt.Fprintln(out)
	}
}

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

package main

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

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

	var T, N, A int
	for fmt.Fscan(in, &T); T > 0; T-- {
		nums := []int{}
		for fmt.Fscan(in, &N); N > 0; N-- {
			fmt.Fscan(in, &A)
			nums = append(nums, A)
		}
		for _, v := range nums {
			if v%2 == 1 {
				fmt.Fprint(out, v, " ")
			}
		}
		for _, v := range nums {
			if v%2 == 0 {
				fmt.Fprint(out, v, " ")
			}
		}
		fmt.Fprintln(out)
	}
}

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

package main

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

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

	var T, N, A int
	for fmt.Fscan(in, &T); T > 0; T-- {
		odds, evens := []int{}, []int{}
		for fmt.Fscan(in, &N); N > 0; N-- {
			fmt.Fscan(in, &A)
			if A&1 == 0 {
				evens = append(evens, A)
			} else {
				odds = append(odds, A)
			}
		}
		for i := 0; i < len(odds); i++ {
			fmt.Fprint(out, odds[i], " ")
		}
		for i := 0; i < len(evens); i++ {
			fmt.Fprint(out, evens[i], " ")
		}
		fmt.Fprintln(out)
	}
}

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		var odds []int
		var evens []int
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if x%2 != 0 {
				odds = append(odds,x)
			} else {
				evens = append(evens,x)
			}
		}
		odds = append(odds,evens...)
		for j:=0;j<len(odds);j++{
			fmt.Fprintf(out,"%v ",odds[j])
		}
		fmt.Fprintln(out,)
	}
}

package main

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

const REPEAT bool = true
const CASE   bool = false

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

  if REPEAT {
    var t int
    Fscan(in, &t);
    for i := 1; i <= t; i++ {
      if CASE {
        Fprintf(out, "Case #%d: ", i)
      }
      solve(in, out)
    }
  } else {
    solve(in, out)
  }
}

func solve(in io.Reader, out io.Writer) {
  var n int
  Fscan(in, &n)
  arr := make([]int, n)
  for i := range arr {
    Fscan(in, &arr[i])
  }
  for i := range arr {
    if arr[i] % 2 == 0 {
      Fprint(out, arr[i], " ")
    }
  }
  for i := range arr {
    if arr[i] % 2 != 0 {
      Fprint(out, arr[i], " ")
    }
  }
  Fprintln(out)
}

package main

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

const maxN = 10023

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n, xs, ys, a int
    var x[maxN] int
    var y[maxN] int
    fmt.Fscan(in, &n)
    xs = 0
    ys = 0
    for i := 0; i < n; i++ {
      fmt.Fscan(in, &a)
      if a % 2 == 0 {
        y[ys] = a
        ys++
      }else {
        x[xs] = a
        xs++
      }
    }
    for i := 0; i < xs; i++ {
      fmt.Fprintf(out, "%d ", x[i])
    }
    for i := 0; i < ys; i++ {
      fmt.Fprintf(out, "%d ", y[i])
    }
    fmt.Fprint(out, "\n")
  }
}

package main

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

const maxN = 10023

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n, xs, ys, a int
    var x[maxN] int
    var y[maxN] int
    fmt.Fscan(in, &n)
    xs = 0
    ys = 0
    for i := 0; i < n; i++ {
      fmt.Fscan(in, &a)
      if a % 2 == 0 {
        y[ys] = a
        ys++
      }else {
        x[xs] = a
        xs++
      }
    }
    for i := 0; i < xs; i++ {
      fmt.Fprintf(out, "%d ", x[i])
    }
    for i := 0; i < ys; i++ {
      fmt.Fprintf(out, "%d ", y[i])
    }
    fmt.Fprintln(out)
  }
}

package main

import ."fmt"
func main(){
    var t,n,x int
    for Scan(&t) ; t>0 ; t-- {
        a := [2][]interface{}{}
        for Scan(&n) ; n>0 ; n-- {
            Scan(&x)
            a[x&1]=append(a[x&1],x)
        }
        Println(a[0]...)
        Println(a[1]...)
    }
}

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		a := [2][]interface{}{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			a[v&1] = append(a[v&1], v)
		}
		Fprintln(out, a[0]...)
		Fprintln(out, a[1]...)
	}
}

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

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
		}
		p := []int{}
		for j := 0; j < n; j++ {
			if o[j]&1 == 0 {
				p = append(p, o[j])
			} else {
				fmt.Fprint(w, o[j], " ")
			}
		}
		for _, v := range p {
			fmt.Fprint(w, v, " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func solve(n int, a []int) string {
	var x string
	for _, v := range a {
		if v%2 == 0 {
			x += fmt.Sprintf("%d ", v)
		}
	}
	for _, v := range a {
		if v%2 == 1 {
			x += fmt.Sprintf("%d ", v)
		}
	}
	return x
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N, a int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		es := make([]int, 0)
		os := make([]int, 0)
		for n := 0; n < N; n++ {
			Fscan(in, &a)
			if a%2 == 0 {
				es = append(es, a)
			} else {
				os = append(os, a)
			}
		}
		for _, e := range es {
			Fprint(out, e, " ")
		}
		for _, o := range os {
			Fprint(out, o, " ")
		}
		Fprintln(out)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		a := make([]int, n)

		for i := range a {
			a[i] = ScanInt()
		}

		for i, j := 0, n-1; i < j; {
			for i < n && a[i]%2 == 0 {
				i++
			}

			for j >= 0 && a[j]%2 == 1 {
				j--
			}

			if i < j {
				a[i], a[j] = a[j], a[i]
			}
		}

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

package main

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

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

func (in *CF1509) 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 *CF1509) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1509
 Date: 17/04/21
 User: pepradere
 URL: https://codeforces.com/contest/1509/problem/A
 Problem: CF1509
**/
func (in *CF1509) Run() {
	T := in.NextInt()
	for ; T > 0; T-- {
		N := in.NextInt()
		var even []int
		var odd []int
		for ; N > 0; N-- {
			num := in.NextInt()
			if num %2 == 0{
				even = append(even, num )
			} else {
				odd = append(odd, num)
			}
		}
		var sol []int
		if len(even) > len(odd) {
			sol = append(sol, even...)
			sol = append(sol, odd...)
		} else {
			sol = append(sol, odd...)
			sol = append(sol, even...)
		}

		for i := 0; i < len(sol); i++ {
			if i > 0 {
				fmt.Print(" ")
			}
			fmt.Print(sol[i])
		}
		fmt.Println()
	}

}

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

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

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		EVEN := make([]int, 0)
		ODD := make([]int, 0)
		for i := 0; i < n; i++ {
			var q int
			fmt.Fscan(input, &q)
			if q%2 == 0 {
				EVEN = append(EVEN, q)
			} else {
				ODD = append(ODD, q)
			}

		}
		t := len(EVEN)
		tt := len(ODD)
		for i := 0; i < t; i++ {
			fmt.Println(EVEN[i])
		}
		for i := 0; i < tt; i++ {
			fmt.Println(ODD[i])
		}

	}
}

package main

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

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

func Scan(a ...interface{})    { fmt.Fscan(reader, a...) }
func Scanln(a ...interface{})  { fmt.Fscanln(reader, a...) }
func Print(a ...interface{})   { fmt.Fprint(writer, a...) }
func Println(a ...interface{}) { fmt.Fprintln(writer, a...) }

func main() {
	defer writer.Flush()
	var t int
	Scanln(&t)
	for ; t > 0; t-- {
		var n int
		Scanln(&n)
		odd := make([]int, 0)
		even := make([]int, 0)
		for i := 0; i < n; i++ {
			var a int
			Scan(&a)
			if a%2 == 1 {
				odd = append(odd, a)
			} else {
				even = append(even, a)
			}
		}
		Scanln()
		for _, v := range odd {
			Print(v, " ")
		}
		for _, v := range even {
			Print(v, " ")
		}
		Println()
	}

}

package main

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

func main() {

	r :=bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int

		fmt.Fscan(r, &n)

		h := make([]int, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &h[j])
		}

		ans := solve(h)

		for j := 0; j < len(ans); j++ {
			fmt.Print(ans[j])
			fmt.Print(" ")
		}
		fmt.Println()
	}
}

func solve(h []int) []int {
	var even []int
	var odd []int

	var ans []int

	for i := 0; i < len(h); i++ {
		if h[i]  % 2 == 0 {
			even = append(even, h[i])
		} else {
			odd = append(odd, h[i])
		}
	}
	for j := 0; j < len(even); j++ {
		ans = append(ans, even[j])
	}

	for j := 0; j < len(odd); j++ {
		ans = append(ans, odd[j])
	}

	return ans
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		var odds []int
		var evens []int
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if x%2 != 0 {
				odds = append(odds,x)
			} else {
				evens = append(evens,x)
			}
		}
		odds = append(odds,evens...)
		fmt.Fprintln(out,odds)
	}
}

package main

import ."fmt"
func main(){
    var t,n,x int
    for Scanf("%d",&t) ; t>0 ; t-- {
        a := [2][]interface{}{}
        for Scanf("%d",&n) ; n>0 ; n-- {
            Scanf("%d",&x)
            a[x&1]=append(a[x&1],x)
        }
        Println(a[0]...)
        Println(a[1]...)
    }
}


package main

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

// github.com/EndlessCheng/codeforces-go
func prim(dist [][]int) (mst int64) {
	n := len(dist)
	minW := make([]int, n)
	for i := range minW {
		minW[i] = 2e9
	}
	minW[0] = 0
	used := make([]bool, n)
	for {
		v := -1
		for i, u := range used {
			if !u && (v < 0 || minW[i] < minW[v]) {
				v = i
			}
		}
		if v < 0 {
			break
		}
		used[v] = true
		mst += int64(minW[v])
		for w, wt := range dist[v] {
			minW[w] = min(minW[w], wt)
		}
	}
	return
}

func CF1508C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, v, w, wt, xor int
	Fscan(in, &n, &m)
	type edge struct{ v, w, wt int }
	es := make([]edge, m)
	for i := range es {
		Fscan(in, &v, &w, &wt)
		xor ^= wt
		es[i] = edge{v - 1, w - 1, wt}
	}

	fa := make([]int, n)
	var f func(int) int
	f = func(x int) int {
		if fa[x] != x {
			fa[x] = f(fa[x])
		}
		return fa[x]
	}

	if n < 1e3 && m >= (n-2)*(n-1)/2 {
		g := make([]map[int]bool, n)
		for i := range g {
			g[i] = map[int]bool{}
		}
		for _, e := range es {
			g[e.v][e.w] = true
			g[e.w][e.v] = true
		}
		for i := range fa {
			fa[i] = i
		}
		for v, mp := range g {
			for w := 0; w < n; w++ {
				if mp[w] {
					continue
				}
				if v, w := f(v), f(w); v != w {
					fa[v] = w
					continue
				}
				dist := make([][]int, n)
				for i := range dist {
					dist[i] = make([]int, n)
				}
				for _, e := range es {
					dist[e.v][e.w] = e.wt
					dist[e.w][e.v] = e.wt
				}
				ans := int64(1e18)
				for i, r := range dist {
					for j, d := range r[:i] {
						if d == 0 {
							dist[i][j] = xor
							dist[j][i] = xor
							if res := prim(dist); res < ans {
								ans = res
							}
							dist[i][j] = 0
							dist[j][i] = 0
						}
					}
				}
				Fprint(out, ans)
				return
			}
		}
	}

	g := make([][]int, n)
	for _, e := range es {
		g[e.v] = append(g[e.v], e.w)
		g[e.w] = append(g[e.w], e.v)
	}
	maxDegInv, maxDegInvV := 0, 0
	for v, edges := range g {
		if degInv := n - 1 - len(edges); degInv > maxDegInv {
			maxDegInv, maxDegInvV = degInv, v
		}
	}

	for i := range fa {
		fa[i] = i
	}
	mergeInv := func(v int, edges []int) {
		has := map[int]bool{v: true}
		for _, w := range edges {
			has[w] = true
		}
		for i := 0; i < n; i++ {
			if !has[i] {
				fa[f(i)] = f(v)
			}
		}
	}
	mergeInv(maxDegInvV, g[maxDegInvV])
	for v, edges := range g {
		if f(v) != f(maxDegInvV) {
			mergeInv(v, edges)
		}
	}

	sort.Slice(es, func(i, j int) bool { return es[i].wt < es[j].wt })
	ans := int64(0)
	for _, e := range es {
		if v, w := f(e.v), f(e.w); v != w {
			fa[v] = w
			ans += int64(e.wt)
		}
	}
	Fprint(out, ans)
}

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

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

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+2 < n {
			cs[last+2] += 1
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				if i < v {
					useful = append(useful, edge{
						u: i,
						v: v,
						w: 0,
					})
				}
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			if i < v {
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(0)
		d.reset()
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+2 < n {
			d.merge(i, n-1)
			if last + 2 < n {
				cs[last+2] += 1
			}
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				if i < v {
					useful = append(useful, edge{
						u: i,
						v: v,
						w: 0,
					})
				}
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			if i < v {
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(0)
		d.reset()
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+1 < n {
			d.merge(i, n-1)
			if last + 2 < n {
				cs[last+2] += 1
			}
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				if i < v {
					useful = append(useful, edge{
						u: i,
						v: v,
						w: 0,
					})
				}
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			if i < v {
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(0)
		d.reset()
		comp := n
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			comp--
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if comp == 1 && mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func prim(g [][]int) (mst int64) {
	n := len(g)
	minW := make([]int, n)
	for i := range minW {
		minW[i] = 2e9
	}
	minW[0] = 0
	used := make([]bool, n)
	for {
		v := -1
		for i, u := range used {
			if !u && (v < 0 || minW[i] < minW[v]) {
				v = i
			}
		}
		if v < 0 {
			break
		}
		used[v] = true
		mst += int64(minW[v])
		for w, wt := range g[v] {
			if wt < minW[w] {
				minW[w] = wt
			}
		}
	}
	return
}

func CF1508C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, v, w, wt, xor, maxV int
	Fscan(in, &n, &m)
	type edge struct{ v, w, wt int }
	es := make([]edge, m)
	for i := range es {
		Fscan(in, &v, &w, &wt)
		xor ^= wt
		es[i] = edge{v - 1, w - 1, wt}
	}

	if n < 1e3 && m >= (n-2)*(n-1)/2 {
		g := make([][]int, n)
		for i := range g {
			g[i] = make([]int, n)
		}
		for _, e := range es {
			g[e.v][e.w] = e.wt
			g[e.w][e.v] = e.wt
		}
		ans := int64(1e18)
		for i, r := range g {
			for j, wt := range r[:i] {
				if wt == 0 {
					g[i][j] = xor
					g[j][i] = xor
					if res := prim(g); res < ans {
						ans = res
					}
					g[i][j] = 0
					g[j][i] = 0
				}
			}
		}
		Fprint(out, ans)
		return
	}

	fa := make([]int, n)
	for i := range fa {
		fa[i] = i
	}
	var f func(int) int
	f = func(x int) int {
		if fa[x] != x {
			fa[x] = f(fa[x])
		}
		return fa[x]
	}
	g := make([][]int, n)
	for _, e := range es {
		g[e.v] = append(g[e.v], e.w)
		g[e.w] = append(g[e.w], e.v)
	}
	for v, ws := range g {
		if len(ws) < len(g[maxV]) {
			maxV = v
		}
	}
	mergeInv := func(v int) {
		has := map[int]bool{v: true}
		for _, w := range g[v] {
			has[w] = true
		}
		for i := range g {
			if !has[i] {
				fa[f(i)] = f(v)
			}
		}
	}
	mergeInv(maxV)
	for v := range g {
		if f(v) != f(maxV) {
			mergeInv(v)
		}
	}
	sort.Slice(es, func(i, j int) bool { return es[i].wt < es[j].wt })
	ans := int64(0)
	for _, e := range es {
		if v, w := f(e.v), f(e.w); v != w {
			fa[v] = w
			ans += int64(e.wt)
		}
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func prim8(dist [][]int) (mst int64) {
	n := len(dist)
	minW := make([]int, n)
	for i := range minW {
		minW[i] = 2e9
	}
	minW[0] = 0
	used := make([]bool, n)
	for {
		v := -1
		for i, u := range used {
			if !u && (v < 0 || minW[i] < minW[v]) {
				v = i
			}
		}
		if v < 0 {
			break
		}
		used[v] = true
		mst += int64(minW[v])
		for w, wt := range dist[v] {
			minW[w] = min(minW[w], wt)
		}
	}
	return
}

func CF1508C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, v, w, wt, xor, maxV int
	Fscan(in, &n, &m)
	fa := make([]int, n)
	var f func(int) int
	f = func(x int) int {
		if fa[x] != x {
			fa[x] = f(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, wt int }
	es := make([]edge, m)
	for i := range es {
		Fscan(in, &v, &w, &wt)
		xor ^= wt
		es[i] = edge{v - 1, w - 1, wt}
	}

	if n < 1e3 && m >= (n-2)*(n-1)/2 {
		g := make([][]bool, n)
		for i := range g {
			g[i] = make([]bool, n)
		}
		for _, e := range es {
			g[e.v][e.w] = true
			g[e.w][e.v] = true
		}
		for i := range fa {
			fa[i] = i
		}
		for v, ws := range g {
			for w, has := range ws {
				if has {
					continue
				}
				if v, w := f(v), f(w); v != w {
					fa[v] = w
					continue
				}
				dist := make([][]int, n)
				for i := range dist {
					dist[i] = make([]int, n)
				}
				for _, e := range es {
					dist[e.v][e.w] = e.wt
					dist[e.w][e.v] = e.wt
				}
				ans := int64(1e18)
				for i, r := range dist {
					for j, d := range r[:i] {
						if d == 0 {
							dist[i][j] = xor
							dist[j][i] = xor
							if res := prim8(dist); res < ans {
								ans = res
							}
							dist[i][j] = 0
							dist[j][i] = 0
						}
					}
				}
				Fprint(out, ans)
				return
			}
		}
	}

	for i := range fa {
		fa[i] = i
	}
	g := make([][]int, n)
	for _, e := range es {
		g[e.v] = append(g[e.v], e.w)
		g[e.w] = append(g[e.w], e.v)
	}
	for v, ws := range g {
		if len(ws) < len(g[maxV]) {
			maxV = v
		}
	}
	mergeInv := func(v int) {
		has := map[int]bool{}
		for _, w := range g[v] {
			has[w] = true
		}
		for i := range g {
			if i != v && !has[i] {
				fa[f(i)] = f(v)
			}
		}
	}
	mergeInv(maxV)
	for v := range g {
		if f(v) != f(maxV) {
			mergeInv(v)
		}
	}
	sort.Slice(es, func(i, j int) bool { return es[i].wt < es[j].wt })
	ans := int64(0)
	for _, e := range es {
		if v, w := f(e.v), f(e.w); v != w {
			fa[v] = w
			ans += int64(e.wt)
		}
	}
	Fprint(out, ans)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func prim8(dist [][]int) (mst int64) {
	n := len(dist)
	minW := make([]int, n)
	for i := range minW {
		minW[i] = 2e9
	}
	minW[0] = 0
	used := make([]bool, n)
	for {
		v := -1
		for i, u := range used {
			if !u && (v < 0 || minW[i] < minW[v]) {
				v = i
			}
		}
		if v < 0 {
			break
		}
		used[v] = true
		mst += int64(minW[v])
		for w, wt := range dist[v] {
			minW[w] = min(minW[w], wt)
		}
	}
	return
}

func CF1508C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, v, w, wt, xor, maxV int
	Fscan(in, &n, &m)
	fa := make([]int, n)
	var f func(int) int
	f = func(x int) int {
		if fa[x] != x {
			fa[x] = f(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, wt int }
	es := make([]edge, m)
	for i := range es {
		Fscan(in, &v, &w, &wt)
		xor ^= wt
		es[i] = edge{v - 1, w - 1, wt}
	}

	if n < 1e3 && m >= (n-2)*(n-1)/2 {
		g := make([][]bool, n)
		for i := range g {
			g[i] = make([]bool, n)
		}
		for _, e := range es {
			g[e.v][e.w] = true
			g[e.w][e.v] = true
		}
		for i := range fa {
			fa[i] = i
		}
		for v, ws := range g {
			for w, has := range ws {
				if has {
					continue
				}
				if v, w := f(v), f(w); v != w {
					fa[v] = w
					continue
				}
				dist := make([][]int, n)
				for i := range dist {
					dist[i] = make([]int, n)
				}
				for _, e := range es {
					dist[e.v][e.w] = e.wt
					dist[e.w][e.v] = e.wt
				}
				ans := int64(1e18)
				for i, r := range dist {
					for j, d := range r[:i] {
						if d == 0 {
							dist[i][j] = xor
							dist[j][i] = xor
							if res := prim8(dist); res < ans {
								ans = res
							}
							dist[i][j] = 0
							dist[j][i] = 0
						}
					}
				}
				Fprint(out, ans)
				return
			}
		}
	}

	for i := range fa {
		fa[i] = i
	}
	g := make([][]int, n)
	for _, e := range es {
		g[e.v] = append(g[e.v], e.w)
		g[e.w] = append(g[e.w], e.v)
	}
	for v, ws := range g {
		if len(ws) < len(g[maxV]) {
			maxV = v
		}
	}
	mergeInv := func(v int) {
		has := map[int]bool{v: true}
		for _, w := range g[v] {
			has[w] = true
		}
		for i := range g {
			if !has[i] {
				fa[f(i)] = f(v)
			}
		}
	}
	mergeInv(maxV)
	for v := range g {
		if f(v) != f(maxV) {
			mergeInv(v)
		}
	}
	sort.Slice(es, func(i, j int) bool { return es[i].wt < es[j].wt })
	ans := int64(0)
	for _, e := range es {
		if v, w := f(e.v), f(e.w); v != w {
			fa[v] = w
			ans += int64(e.wt)
		}
	}
	Fprint(out, ans)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func prim(dist [][]int) (mst int64) {
	n := len(dist)
	minW := make([]int, n)
	for i := range minW {
		minW[i] = 2e9
	}
	minW[0] = 0
	used := make([]bool, n)
	for {
		v := -1
		for i, u := range used {
			if !u && (v < 0 || minW[i] < minW[v]) {
				v = i
			}
		}
		if v < 0 {
			break
		}
		used[v] = true
		mst += int64(minW[v])
		for w, wt := range dist[v] {
			minW[w] = min(minW[w], wt)
		}
	}
	return
}

func CF1508C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, v, w, wt, xor, maxDegInvV int
	Fscan(in, &n, &m)
	fa := make([]int, n)
	var f func(int) int
	f = func(x int) int {
		if fa[x] != x {
			fa[x] = f(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, wt int }
	es := make([]edge, m)
	for i := range es {
		Fscan(in, &v, &w, &wt)
		xor ^= wt
		es[i] = edge{v - 1, w - 1, wt}
	}

	if n < 1e3 && m >= (n-2)*(n-1)/2 {
		g := make([]map[int]bool, n)
		for i := range g {
			g[i] = map[int]bool{}
		}
		for _, e := range es {
			g[e.v][e.w] = true
			g[e.w][e.v] = true
		}
		for i := range fa {
			fa[i] = i
		}
		for v, mp := range g {
			for w := range g {
				if mp[w] {
					continue
				}
				if v, w := f(v), f(w); v != w {
					fa[v] = w
					continue
				}
				dist := make([][]int, n)
				for i := range dist {
					dist[i] = make([]int, n)
				}
				for _, e := range es {
					dist[e.v][e.w] = e.wt
					dist[e.w][e.v] = e.wt
				}
				ans := int64(1e18)
				for i, r := range dist {
					for j, d := range r[:i] {
						if d == 0 {
							dist[i][j] = xor
							dist[j][i] = xor
							if res := prim(dist); res < ans {
								ans = res
							}
							dist[i][j] = 0
							dist[j][i] = 0
						}
					}
				}
				Fprint(out, ans)
				return
			}
		}
	}

	for i := range fa {
		fa[i] = i
	}
	g := make([][]int, n)
	for _, e := range es {
		g[e.v] = append(g[e.v], e.w)
		g[e.w] = append(g[e.w], e.v)
	}
	for v, ws := range g {
		if len(ws) < len(g[maxDegInvV]) {
			maxDegInvV = v
		}
	}
	mergeInv := func(v int) {
		has := map[int]bool{v: true}
		for _, w := range g[v] {
			has[w] = true
		}
		for i := range g {
			if !has[i] {
				fa[f(i)] = f(v)
			}
		}
	}
	mergeInv(maxDegInvV)
	for v := range g {
		if f(v) != f(maxDegInvV) {
			mergeInv(v)
		}
	}
	sort.Slice(es, func(i, j int) bool { return es[i].wt < es[j].wt })
	ans := int64(0)
	for _, e := range es {
		if v, w := f(e.v), f(e.w); v != w {
			fa[v] = w
			ans += int64(e.wt)
		}
	}
	Fprint(out, ans)
}

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

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

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+1 < n {
			d.merge(i, n-1)
			if last + 2 < n {
				cs[last+2] += 1
			}
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			useful = append(useful, edge{
				u: i,
				v: v,
				w: 0,
			})
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	if n > 600 {
		fmt.Println(xr, mst)
	}
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(0)
		d.reset()
		comp := n
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			comp--
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if comp == 1 && mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+1 < n {
			d.merge(i, n-1)
			if last + 2 < n {
				cs[last+2] += 1
			}
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			useful = append(useful, edge{
				u: i,
				v: v,
				w: 0,
			})
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(0)
		d.reset()
		comp := n
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			comp--
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if comp == 1 && mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+1 < n {
			d.merge(i, n-1)
			if last + 2 < n {
				cs[last+2] += 1
			}
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			useful = append(useful, edge{
				u: i,
				v: v,
				w: 0,
			})
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(0)
		d.reset()
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+1 < n {
			d.merge(i, n-1)
			if last + 2 < n {
				cs[last+2] += 1
			}
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		if n > 600 {
			fmt.Println("!")
		}
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			useful = append(useful, edge{
				u: i,
				v: v,
				w: 0,
			})
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(xr)
		d.reset()
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+1 < n {
			d.merge(i, n-1)
			if last + 2 < n {
				cs[last+2] += 1
			}
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			useful = append(useful, edge{
				u: i,
				v: v,
				w: 0,
			})
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(xr)
		d.reset()
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+2 < n {
			d.merge(i, n-1)
			cs[last+2] += 1
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			useful = append(useful, edge{
				u: i,
				v: v,
				w: 0,
			})
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst += int64(xr)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(xr)
		d.reset()
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+2 < n {
			cs[last+2] += 1
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			useful = append(useful, edge{
				u: i,
				v: v,
				w: 0,
			})
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst = int64(1e18)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(xr)
		d.reset()
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}

package main

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

type dsu struct{
	p []int
}

func newDSU(n int) *dsu{
	ret := &dsu{}
	ret.p = make([]int, n)
	for i:=0;i<n;i++{
		ret.p[i]=i
	}
	return ret
}

func (d *dsu) find(u int) int {
	if d.p[u] == u {
		return u
	}
	d.p[u] = d.find(d.p[u])
	return d.p[u]
}

func (d *dsu) merge(u, v int) {
	d.p[d.find(u)]=d.find(v)
}

func (d *dsu) reset() {
	for i := 0; i < len(d.p); i++ {
		d.p[i] = i
	}
}

type edge struct{
	u,v,w int
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n,e int
	fmt.Fscan(in, &n, &e)

	g := make([][]int, n)

	xr := 0
	ed := make([]edge, e)
	for i := 0;i < e; i++{
		fmt.Fscan(in, &ed[i].u,&ed[i].v,&ed[i].w)
		ed[i].u--
		ed[i].v--
		xr ^= ed[i].w
		g[ed[i].u]=append(g[ed[i].u], ed[i].v)
		g[ed[i].v]=append(g[ed[i].v], ed[i].u)
	}
	for _, adj := range g {
		sort.Ints(adj)
	}
	sort.Slice(ed, func(i,j int)bool{
		return ed[i].w < ed[j].w
	})
	cs := make([]int, n)
	d := newDSU(n)
	for i:=0;i<n;i++ {
		last := -1
		for j:=0;j<len(g[i]); j++ {
			if last + 1 < g[i][j] {
				d.merge(i, g[i][j]-1)
				cs[last+2]+=1
				cs[g[i][j]]-=1
			}
			last=g[i][j]
		}
		if last+2 < n {
			d.merge(i, n-1)
			cs[last+2] += 1
		}
	}
	for i:=1;i<n;i++{
		cs[i]+=cs[i-1]
		if cs[i] > 0 {
			d.merge(i-1, i)
		}
	}
	mst := int64(0)
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		mst += int64(e.w)
	}
	if int64(n)*int64(n-1)/2 > int64(e + n-1) || xr == 0 {
		fmt.Fprintln(out, mst)
		return
	}

	useful := []edge{}
	for i := 0; i < n; i++ {
		v := 0
		for j := 0; j<len(g[i]); j++ {
			for ; v <= g[i][j]; v++ {
				if v == g[i][j] || v == i {
					continue
				}
				useful = append(useful, edge{
					u: i,
					v: v,
					w: 0,
				})
			}
		}
		for ; v < n; v++ {
			if v == i {
				continue
			}
			useful = append(useful, edge{
				u: i,
				v: v,
				w: 0,
			})
		}
	}
	d.reset()
	for _, e := range ed {
		if d.find(e.u) == d.find(e.v) {
			continue
		}
		d.merge(e.u, e.v)
		useful = append(useful, e)
	}
	mst = int64(1e18)
	for i := 0; i < len(useful); i++ {
		if useful[i].w != 0 {
			continue
		}
		cur := int64(xr)
		d.reset()
		for j, e := range useful {
			if i == j {
				continue
			}
			if d.find(e.u) == d.find(e.v) {
				continue
			}
			d.merge(e.u, e.v)
			cur += int64(e.w)
		}
		if mst > cur {
			mst = cur
		}
	}
	fmt.Fprintln(out, mst)
}