package main

import "fmt"

func main() {
	var t, n, k int
	fmt.Scan(&t)
	for t > 0 {
		t--
		fmt.Scan(&n, &k)
		if k%4 == 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			for i := 1; i <= n; i += 2 {
				if (i+1)%4 == 0 {
					fmt.Println(i, i+1)
				} else if k%4 == 1 || k%4 == 3 {
					fmt.Println(i, i+1)
				} else if k%4 == 2 {
					fmt.Println(i+1, i)
				}
			}
		}
	}
}

package main

import "fmt"

type ans struct {
	a, b int
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, k int
		fmt.Scanf("%d %d\n", &n, &k)
		counts := make([]map[int]bool, 4)
		for i := range counts {
			counts[i] = make(map[int]bool)
		}
		used := make(map[int]bool)
		for i := 1; i <= n; i++ {
			counts[i%4][i] = true
		}

		if n%2 == 1 {
			fmt.Println("NO")
			continue
		}
		can := true
		var res []ans
		order := make([]int, 0, n)
		used2 := make(map[int]bool)
		for i := 1; i <= n; i++ {
			cur := i + k
			ost := cur % 4
			if (ost == 1 || ost == 3) && (i%4 != 0 && i%4 != 2) {
				used2[i] = true
				order = append(order, i)
			}
		}
		for i := 1; i <= n; i++ {
			cur := i + k
			ost := cur % 4
			if ost == 2 && (i%4 != 0 && i%4 != 2) {
				used2[i] = true
				order = append(order, i)
			}
		}
		for i := 1; i <= n; i++ {
			if !used2[i] {
				order = append(order, i)
			}
		}

		for _, i := range order {
			if !used[i] {
				cur := i + k
				ost := cur % 4
				if ost == 1 || ost == 3 {
					tar := 0
					if len(counts[tar]) > 0 {
						for key, v := range counts[tar] {
							if key != i && v == true {
								delete(counts[tar], key)
								delete(counts[i%4], i)
								used[i] = true
								used[key] = true
								res = append(res, ans{a: i, b: key})
								break
							}
						}
					}
				}
				if ost == 2 {
					tar := 2

					found := false
					if len(counts[tar]) > 0 {
						for key, v := range counts[tar] {
							if key != i && v == true {
								delete(counts[tar], key)
								delete(counts[i%4], i)
								used[i] = true
								used[key] = true
								res = append(res, ans{a: i, b: key})
								found = true
								break
							}
						}
					}
					if !found {
						tar = 0
						if len(counts[tar]) > 0 {
							for key, v := range counts[tar] {
								if key != i && v == true {
									delete(counts[tar], key)
									delete(counts[i%4], i)
									used[i] = true
									used[key] = true
									res = append(res, ans{a: i, b: key})
									break
								}
							}
						}
					}
				}
				if ost == 0 {

					found := false
					tar := 1
					if len(counts[tar]) > 0 {
						for key, v := range counts[tar] {
							if key != i && v == true {
								delete(counts[tar], key)
								delete(counts[i%4], i)
								used[i] = true
								used[key] = true
								found = true
								res = append(res, ans{a: i, b: key})
								break
							}
						}
					}
					if !found {
						tar = 3
						if len(counts[tar]) > 0 {
							for key, v := range counts[tar] {
								if key != i && v == true {
									delete(counts[tar], key)
									delete(counts[i%4], i)
									used[i] = true
									used[key] = true
									found = true
									res = append(res, ans{a: i, b: key})
									break
								}
							}
						}
						if !found {
							tar = 2
							if len(counts[tar]) > 0 {
								for key, v := range counts[tar] {
									if key != i && v == true {
										delete(counts[tar], key)
										delete(counts[i%4], i)
										used[i] = true
										used[key] = true
										found = true
										res = append(res, ans{a: i, b: key})
										break
									}
								}
							}
							if !found {
								tar = 0
								if len(counts[tar]) > 0 {
									for key, v := range counts[tar] {
										if key != i && v == true {
											delete(counts[tar], key)
											delete(counts[i%4], i)
											used[i] = true
											used[key] = true
											found = true
											res = append(res, ans{a: i, b: key})
											break
										}
									}
								}
							}
						}
					}
				}
			}
		}
		if len(res) < n/2 {
			can = false
		}
		if can {
			fmt.Println("YES")
			for _, v := range res {
				fmt.Println(v.a, v.b)
			}
		} else {
			fmt.Println("NO")
		}
	}
}

// 00
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k int
		fmt.Fscan(reader, &n, &k)
		if k%4 == 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			if k%2 == 1 {
				for i := 1; i <= n; i += 2 {
					fmt.Println(i, i+1)
				}
			} else {
				for i := 1; i <= n; i += 2 {
					if (i+1)%4 == 2 {
						fmt.Println(i+1, i)
					} else {
						fmt.Println(i, i+1)
					}
				}
			}
		}

	}
}

package main

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

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

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

	var T int
	var n int
	var k int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &k)

		if k%4 == 0 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			if k%4 == 2 {
				for i := 0; i*4 < n; i++ {
					a := i*4 + 1
					b, c, d := a+1, a+2, a+3
					Fprintln(out, b, a)
					if c < n {
						Fprintln(out, c, d)
					}
				}
			} else {
				for i := 0; i*4 < n; i++ {
					a := i*4 + 1
					b, c, d := a+1, a+2, a+3
					Fprintln(out, a, b)
					if c < n {
						Fprintln(out, c, d)
					}
				}
			}
		}
	}
}

package main

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

const N int = 1e5 + 7
const INF int = math.MaxInt

var a []int = make([]int, N)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, n, k int64

	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		fmt.Fscan(in, &n, &k)
		if k%2 == 1 {
			fmt.Fprintln(out, "YES")
			for i := int64(1); i < n; i += 2 {
				fmt.Fprintln(out, i, i+1)
			}
		} else if k%4 == 2 {
			fmt.Fprintln(out, "YES")
			for i := int64(1); i < n; i += 4 {
				fmt.Fprintln(out, i+1, i)
				if i+2 < n {
					fmt.Fprintln(out, i+2, i+3)
				}
			}
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		arr := readArrInt(input)
		n := arr[0]
		k := arr[1]
		solve(n, k)
	}
}

func solve(n, k int) {
	if k%4 == 1 || k%4 == 3 {
		fmt.Println("YES")
		for i := 1; i < n; i += 2 {
			fmt.Println(i, i+1)
		}
	} else if k%4 == 0 {
		fmt.Println("NO")
	} else if k%4 == 2 {
		fmt.Println("YES")
		for i := 3; i < n; i += 4 {
			fmt.Println(i, i+1)
		}
		for i := 2; i <= n; i += 4 {
			fmt.Println(i, i-1)
		}
	}
	//fmt.Println(n, k)
}

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

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

const MOD int64 = 1000000007

var n, k int

var h[]int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &k)

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {
	if k % 2 == 1 {
		fmt.Println("YES")

		//1234
		for i := 1; i <= n - 1; i+=2 {
			fmt.Println(i, " ", i + 1, " ")
		}
		return
	}

	//1 2  k = 2

	//1 2 3 4 5 6   k == 4
	// (a + k) * b

	if k % 4 == 0 {
		fmt.Println("NO")

	} else {
		fmt.Println("YES")

		odd := 0
		for i := 1; i <= n - 1; i+=2 {
			if odd % 2 == 0 {
				fmt.Println(i + 1, " ", i, " ")
			} else {
				fmt.Println(i, " ", i + 1, " ")
			}
			odd = odd ^ 1
		}
	}

	//(a + k) * b

}

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

var (
	reader bufio.Reader
	writer bufio.Writer
)

func main() {
	inp, err := os.Open("in.txt")
	if err == nil {
		os.Stdin = inp
		outp, _ := os.Create("out.txt")
		os.Stdout = outp
		defer outp.Close()
		defer inp.Close()
	}
	reader = *bufio.NewReader(os.Stdin)
	writer = *bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	scan(&T)

	for ; T > 0; T-- {
		var n, k int
		scan(&n, &k)

		if k % 2 == 1 {
			printf("YES\n")
			for i := 0; i < n; i += 2 {
				printf("%v %v\n", i + 1, i + 2)
			}
		} else if k % 4 == 0 {
			printf("NO\n")
		} else {
			printf("YES\n")
			var odd int = 1
			for i := 4; i <= n; i += 4 {
				printf("%v %v\n", odd, i)
				odd += 2
			}
			for i := 2; i <= n; i += 4 {
				printf("%v %v\n", i, odd)
				odd += 2
			}
		}
	}
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(&reader, a...)
}

func printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(&writer, format, a...)
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1719B
Date: 9/14/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1719/B
Problem: CF1719B
**/
func (in *CF1719B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, k := in.NextInt64(), in.NextInt64()
		if k%2 == 0 {
			c := 0
			var ans strings.Builder
			ans.WriteString("YES\n")
			ws := true
			for i := int64(0); i < n; i += 2 {
				if c%2 == 0 {
					if !f(i+2, i+1, k) {
						ws = false
						break
					}
					ans.WriteString(fmt.Sprintf("%v %v\n", i+2, i+1))

				} else {
					if !f(i+1, i+2, k) {
						ws = false
						break
					}
					ans.WriteString(fmt.Sprintf("%v %v\n", i+1, i+2))
				}
				c++
			}
			if ws {
				fmt.Print(ans.String())
			} else {
				fmt.Println("NO")
			}
		} else if k%2 != 0 {
			var ans strings.Builder
			ans.WriteString("YES\n")
			ws := true
			for i := int64(0); i < n; i += 2 {
				if !f(i+1, i+2, k) {
					ws = false
					break
				}
				ans.WriteString(fmt.Sprintf("%v %v\n", i+1, i+2))
			}
			if ws {
				fmt.Print(ans.String())
			} else {
				fmt.Println("NO")
			}
		}

	}
}

func f(a, b, k int64) bool {
	return ((a+k)*b)%4 == 0
}

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

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

package main

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

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

func solve(n, k int) string {
	if k%4 == 0 {
		return "NO"
	}
	var r []string
	r = append(r, "YES")
	for i := 1; i < n+1; i += 2 {
		if k%2 == 1 {
			r = append(r, fmt.Sprintf("%d %d", i, i+1))
		} else {
			if i%4 == 1 {
				r = append(r, fmt.Sprintf("%d %d", i+1, i))
			} else {
				r = append(r, fmt.Sprintf("%d %d", i, i+1))
			}
		}
	}
	return strings.Join(r, "\n")
}

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

package main

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

var (
	in   *bufio.Scanner
	out  *bufio.Writer
	once = false
)

func solve() {
	in.Scan()
	n, _ := strconv.Atoi(in.Text())
	in.Scan()
	k, _ := strconv.Atoi(in.Text())
	if k%2 != 0 {
		out.WriteString("YES\n")
		for i := 1; i < n; i = i + 2 {
			out.WriteString(strconv.Itoa(i) + " " + strconv.Itoa(i+1) + "\n")
		}
		return
	}
	if k == 0 || k%4 != 2 {
		out.WriteString("NO\n")
		return
	}
	out.WriteString("YES\n")
	for i := 3; i < n; i = i + 4 {
		out.WriteString(strconv.Itoa(i) + " " + strconv.Itoa(i+1) + "\n")
	}
	for i := 1; i < n; i = i + 4 {
		out.WriteString(strconv.Itoa(i+1) + " " + strconv.Itoa(i) + "\n")
	}
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	for t := 0; t < x; t++ {
		solve()
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n, k int
	scan(&n, &k)
	if k%2 == 1 {
		printf("YES\n")
		for i := 1; i <= n; i += 2 {
			printf("%d %d\n", i, i+1)
		}
	} else if k%4 == 0 {
		printf("NO\n")
	} else {
		printf("YES\n")
		for i := 2; i <= n; i += 2 {
			if i%4 == 2 {
				printf("%d %d\n", i, i-1)
			} else {
				printf("%d %d\n", i-1, i)
			}
		}
	}

}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
    "fmt"
    "sort"
)

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

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

func main() {
    var tc int;
    fmt.Scanf("%d\n", &tc)
    n, k := 0, 0
    // ia, ib := make([]byte, 1024), make([]byte, 1024)
    for ti:=0; ti<tc; ti++ {
        fmt.Scanf("%d %d\n", &n, &k)
        if (k%4)==0 {
            fmt.Println("NO")
            continue
        } else if (k%4)==2 {
            fmt.Println("YES")
            for i:=1; i<=n; i+=2 {
                if ((i+1)%4)==0 {
                    fmt.Println(i, i+1)
                } else {
                    fmt.Println(i+1, i)
                }
            }
        } else {
            fmt.Println("YES")
            for i:=0; i<n; i+=2 {
                fmt.Println(i+1, i+2)
            }
        }
    }
}

package main

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

const MOD int64 = 1000000007

var n, k int

var h[]int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &k)

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {
	if k % 2 == 1 {
		fmt.Println("YES")

		//1234
		for i := 1; i <= n - 1; i+=2 {
			fmt.Println(i, " ", i + 1, " ")
		}
		return
	}

	//1 2  k = 2

	//1 2 3 4 5 6, k == 4
	// (a + k) * b

	if k % 4 == 0 {
		fmt.Println("NO")

	} else {
		fmt.Println("YES")

		for i := 1; i <= n - 3; i+=4 {
			fmt.Println(i + 1, " ", i, " ")
			fmt.Println(i + 2, " ", i + 3, " ")
		}
	}

	//(a + k) * b

}

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

const MOD int64 = 1000000007

var n, k int

var h[]int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &k)

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {
	if k % 2 == 1 {
		fmt.Println("YES")

		//1234
		for i := 1; i <= n - 1; i+=2 {
			fmt.Println(i, " ", i + 1, " ")
		}
		return
	}

	if n < 4 {
		fmt.Println("NO")
		return
	}

	//1 2 3 4 5 6, k == 4
	// (a + k) * b

	if k % 4 == 0 {
		fmt.Println("NO")

	} else {
		fmt.Println("YES")

		for i := 1; i <= n - 3; i+=4 {
			fmt.Println(i + 1, " ", i, " ")
			fmt.Println(i + 2, " ", i + 3, " ")
		}
	}

	//(a + k) * b

}

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

var (
	reader bufio.Reader
	writer bufio.Writer
)

func main() {
	inp, err := os.Open("in.txt")
	if err == nil {
		os.Stdin = inp
		outp, _ := os.Create("out.txt")
		os.Stdout = outp
		defer outp.Close()
		defer inp.Close()
	}
	reader = *bufio.NewReader(os.Stdin)
	writer = *bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	scan(&T)

	for ; T > 0; T-- {
		var n, k int
		scan(&n, &k)

		if k % 2 == 1 {
			printf("YES\n")
			for i := 0; i < n; i += 2 {
				printf("%v %v\n", i + 1, i + 2)
			}
		} else if k % 4 == 0 {
			printf("NO\n")
		} else if n % 4 == 0 {
			printf("YES\n")
			var odd int = 1
			for i := 4; i <= n; i += 4 {
				printf("%v %v\n", odd, i)
				odd += 2
			}
			for i := 2; i <= n; i += 4 {
				printf("%v %v\n", i, odd)
				odd += 2
			}
		} else {
			printf("NO\n")
		}
	}
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(&reader, a...)
}

func printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(&writer, format, a...)
}

package main

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

var (
	reader bufio.Reader
	writer bufio.Writer
)

func main() {
	inp, err := os.Open("in.txt")
	if err == nil {
		os.Stdin = inp
		outp, _ := os.Create("out.txt")
		os.Stdout = outp
		defer outp.Close()
		defer inp.Close()
	}
	reader = *bufio.NewReader(os.Stdin)
	writer = *bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	scan(&T)

	for ; T > 0; T-- {
		var n, k int
		scan(&n, &k)

		if k % 2 == 1 {
			printf("YES\n")
			for i := 0; i < n; i += 2 {
				printf("%v %v\n", i + 1, i + 2)
			}
		} else if k % 4 == 0 {
			printf("NO\n")
		} else if n % 4 == 0 {
			printf("YES\n")
			var odd int = 1
			for i := 4; i <= n; i += 4 {
				printf("%v %v\n", i, odd)
				odd += 2
			}
			for i := 2; i <= n; i += 4 {
				printf("%v %v\n", i, odd)
				odd += 2
			}
		} else {
			printf("NO\n")
		}
	}
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(&reader, a...)
}

func printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(&writer, format, a...)
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1719B
Date: 9/14/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1719/B
Problem: CF1719B
**/
func (in *CF1719B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, k := in.NextInt64(), in.NextInt64()
		if k%2 == 0 && k > 0 {
			c := 0
			fmt.Println("YES")
			for i := int64(0); i < n; i += 2 {
				if c%2 == 0 {
					fmt.Println(i+2, i+1)
				} else {
					fmt.Println(i+1, i+2)
				}
				c++
			}
		} else if k%2 != 0 {
			fmt.Println("YES")
			for i := int64(0); i < n; i += 2 {
				fmt.Println(i+1, i+2)
			}
		} else {
			fmt.Println("NO")
		}

	}
}

func f(a, b, k int64) bool {
	return ((a+k)*b)%4 == 0
}

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

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

package main

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

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

func solve(n, k int) string {
	if k == 0 {
		return "NO"
	}
	var r []string
	r = append(r, "YES")
	for i := 1; i < n+1; i += 2 {
		r = append(r, fmt.Sprintf("%d %d", i+1-k%2, i+k%2))
	}
	return strings.Join(r, "\n")
}

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

package main

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

var (
	in   *bufio.Scanner
	out  *bufio.Writer
	once = false
)

func solve() {
	in.Scan()
	n, _ := strconv.Atoi(in.Text())
	in.Scan()
	k, _ := strconv.Atoi(in.Text())
	if k%2 != 0 {
		out.WriteString("YES\n")
		for i := 1; i < n; i = i + 2 {
			out.WriteString(strconv.Itoa(i) + " " + strconv.Itoa(i+1) + "\n")
		}
		return
	}
	if k == 0 || n%4 != 0 || k%4 != 2 {
		out.WriteString("NO\n")
		return
	}
	out.WriteString("YES\n")
	for i := 3; i < n; i = i + 4 {
		out.WriteString(strconv.Itoa(i) + " " + strconv.Itoa(i+1) + "\n")
	}
	for i := 1; i < n; i = i + 4 {
		out.WriteString(strconv.Itoa(i+1) + " " + strconv.Itoa(i) + "\n")
	}
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	for t := 0; t < x; t++ {
		solve()
	}
}


package main

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

const MAXN int = 200005

func maxVal(u int64, v int64) int64 {
	if u > v {
		return u
	}
	return v
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	vArr := make([]int64, MAXN)
	var n, q, i int
	var t, ans, m int64
	m = 0
	fmt.Fscan(in, &n)
	for i = 1; i <= n; i++ {
		fmt.Fscan(in, &vArr[i])
		vArr[i] += vArr[i-1]
		m = maxVal(m, int64(math.Ceil(float64(vArr[i])/float64(i))))
	}
	// fmt.Fprintln(out, "max value is ", m)
	fmt.Fscan(in, &q)
	for i = 1; i <= q; i++ {
		fmt.Fscan(in, &t)
		if t < m {
			ans = -1
		} else {
			ans = (vArr[n] + t - 1) / t
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

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

	n := 0
	fmt.Fscan(in, &n)
	a := make([]int, n)
	s := int64(0)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		s += int64(a[i])
	}
	b := make([]int64, n)
	ma := int64(0)

	s2 := int64(0)

	for i := 0; i < n; i++ {
		cnt := int64(i + 1)
		s2 += int64(a[i])
		az := (s + cnt - 1) / cnt

		b[i] = max(az, ma)
		z := (s2 + cnt - 1) / cnt
		ma = max(ma, z)
	}

	m := 0
	fmt.Fscan(in, &m)
	for im := 0; im < m; im++ {
		t := int64(0)
		fmt.Fscan(in, &t)
		ans := sort.Search(n, func(i int) bool {
			return b[i] <= t
		})
		if ans == n {
			ans = -1
		} else {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

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

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

	var sum int64
	min := int64(-1)
	for i := 0; i < n; i++ {
		sum += aa[i]
		if min < int64(math.Ceil(float64(sum)/float64(i+1))) {
			min = int64(math.Ceil(float64(sum) / float64(i+1)))
		}
	}

	var q int
	fmt.Fscan(in, &q)
	for i := 0; i < q; i++ {
		var v int64
		fmt.Fscan(in, &v)
		if v < min {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, int64(math.Ceil(float64(sum)/float64(v))))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func gi64() int64     { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis64(n int) []int64  { res := make([]int64,n); for i:=0;i<n;i++ { res[i] = gi64() }; return res }

func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}

func ia64(m int) []int64 { return make([]int64,m) }
func iai64(m int,v int64) []int64 { a := make([]int64,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi64(n int,m int,v int64) [][]int64 {
	r := make([][]int64,n); for i:=0;i<n;i++ { x := make([]int64,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill264(m int) ([]int64,[]int64) { a,b := ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i] = gi64(),gi64()}; return a,b }
func fill364(m int) ([]int64,[]int64,[]int64) { a,b,c := ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi64(),gi64(),gi64()}; return a,b,c }
func fill464(m int) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia64(m),ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi64(),gi64(),gi64(),gi64()}; return a,b,c,d }
func abs64(a int64) int64 { if a < 0 { return -a }; return a }
func rev64(a []int64) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max64(a,b int64) int64 { if a > b { return a }; return b }
func min64(a,b int64) int64 { if a > b { return b }; return a }
func maxarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr64(a []int64) int64 { ans := int64(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr64(a []int64) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint64(a,e int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd64(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended64(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended64(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv64(a,m int64) (int64,bool) { g,x,_ := gcdExtended64(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecint64string(a []int64) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.FormatInt(a,10) }; return strings.Join(astr," ") }
func makefact64(n int,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * int64(i) % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * int64(i+1) % mod }
	return fact,factinv
}
const INF int64 = int64(1) << 62;
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N := gi(); V := gis64(N); Q := gi(); T := gis64(Q)
	// Calculate the minimum time to fill up the first n locks with n pipes
	arr := iai64(N+1,0); s := int64(0)
	for i:=1;i<=N;i++ { s += V[i-1]; t := (s+int64(i)-1)/int64(i); arr[i] = max64(arr[i-1],t) }
	// Calculate the minimum time to fill up all n locks with n pipes assuming they were all at the beginning
	for i:=1;i<=N;i++ { arr[i] = max64(arr[i],(s+int64(i)-1)/int64(i) ) }
	// Iterate through the queries and use binary search to find the answer
	for _,t := range T {
		ans := -1
		if arr[N] <= t {
			l,u := 0,N;
			for u-l > 1 { m := (u+l)>>1; if arr[m] <= t { u = m } else { l = m } }
			ans = u
		}
		fmt.Fprintln(wrtr,ans)
	}
}


package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func solveCase() {
	n := rw.NextInt()
	g := make([][]int, n)
	for i := 0; i < n-1; i++ {
		x, y := rw.NextInt()-1, rw.NextInt()-1
		g[x] = append(g[x], y)
		g[y] = append(g[y], x)
	}
	sz := make([]int, n)
	var dfs func(int, int)
	var b, max []int
	max = make([]int, n)
	dfs = func(u, p int) {
		b = append(b, u)
		sz[u] = 1
		max[u] = -1
		for _, v := range g[u] {
			if v != p {
				dfs(v, u)
				sz[u] += sz[v]
				if sz[v] > max[u] {
					max[u] = sz[v]
				}
			}
		}
		if n-sz[u] > max[u] {
			max[u] = n - sz[u]
		}
	}
	dfs(0, -1)
	sort.Slice(b[:], func(i, j int) bool { return max[b[i]] < max[b[j]] })
	if max[b[0]] != max[b[1]] {
		rw.PrintlnInts(1, g[0][0]+1)
		rw.PrintlnInts(1, g[0][0]+1)
	} else {
		u := b[0]
		p := b[1]
		for len(g[u]) > 1 {
			for _, v := range g[u] {
				if v != p {
					u, p = v, u
					break
				}
			}
		}
		rw.PrintlnInts(u+1, p+1)
		rw.PrintlnInts(u+1, b[1]+1)
	}
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

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

package main

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

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

var (
	t int

	n int
	G [][]int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		G = make([][]int, n)
		for i := 0; i < n-1; i++ {
			a, b := readi2()
			a--
			b--

			G[a] = append(G[a], b)
			G[b] = append(G[b], a)
		}

		solve()
	}
}

func solve() {
	Init()
	FindCentroid(0, n)
	// debugf("centroids: %v\n", centroids)

	if len(centroids) == 1 {
		to := G[0][0]
		fmt.Println(1, to+1)
		fmt.Println(1, to+1)
		return
	}

	c1, c2 := centroids[0], centroids[1]
	// c2の葉ノードとその親ノードを見つける
	// ただし、c1への遷移は避ける
	pid, lid := dfs(-1, c2, c1)
	fmt.Println(pid+1, lid+1)
	fmt.Println(c1+1, lid+1)
}

func dfs(pid, cid, ngID int) (int, int) {
	for _, nid := range G[cid] {
		if nid == pid || nid == ngID {
			continue
		}
		return dfs(cid, nid, ngID)
	}

	return pid, cid
}

var (
	sizeSubtree []int
	isRemoved   []bool
	whoIsParent []int

	centroids []int
)

func FindCentroidRecursive(v, size, p int) {
	sizeSubtree[v] = 1
	whoIsParent[v] = p
	isCentroid := true
	for _, ch := range G[v] {
		if ch == p {
			continue
		}
		if isRemoved[ch] {
			continue
		}

		FindCentroidRecursive(ch, size, v)

		if sizeSubtree[ch] > size/2 {
			isCentroid = false
		}
		sizeSubtree[v] += sizeSubtree[ch]
	}

	if size-sizeSubtree[v] > size/2 {
		isCentroid = false
	}

	if isCentroid {
		centroids = append(centroids, v)
	}
}

func Init() {
	sizeSubtree = make([]int, n)
	isRemoved = make([]bool, n)
	whoIsParent = make([]int, n)
	centroids = []int{}
}

func FindCentroid(root, size int) (int, [][2]int) {
	subtrees := [][2]int{}
	// centroids.clear()
	FindCentroidRecursive(root, size, -1)
	center := centroids[0]
	for _, ch := range G[center] {
		if isRemoved[ch] {
			continue
		}
		if ch == whoIsParent[center] {
			subtrees = append(subtrees, [2]int{ch, size - sizeSubtree[center]})
		} else {
			subtrees = append(subtrees, [2]int{ch, sizeSubtree[ch]})
		}
	}
	return center, subtrees
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1406C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var T, n, v, w int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		g := make([][]int, n+1)
		for i := 1; i < n; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		ct := []int{}
		min := int(1e9)
		var f func(v, fa int) int
		f = func(v, fa int) int {
			sz, maxSz := 1, 0
			for _, w := range g[v] {
				if w != fa {
					s := f(w, v)
					sz += s
					maxSz = max(maxSz, s)
				}
			}
			maxSz = max(maxSz, n-sz)
			if maxSz < min {
				min = maxSz
				ct = []int{v}
			} else if maxSz == min {
				ct = append(ct, v)
			}
			return sz
		}
		f(1, 0)
		if len(ct) == 1 {
			Fprintln(out, v, w)
			Fprintln(out, v, w)
		} else {
			v, w = ct[0], ct[1]
			u := g[v][0]
			if u == w {
				u = g[v][1]
			}
			Fprintln(out, v, u)
			Fprintln(out, w, u)
		}
	}
}

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

package main

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

type Edge struct {
	u, v int
}

type Vertex struct {
	id             int
	neighbours     []*Vertex
	neighbourCount int
	subtreeCount   int
}

func (v *Vertex) addNeighbour(neighbour *Vertex) {
	v.neighbours = append(v.neighbours, neighbour)
	v.neighbourCount += 1
}

func findLeafEdge(v Vertex, parent Vertex) Edge {
	for _, neighbour := range v.neighbours {
		if neighbour.id == parent.id {
			continue
		}
		return findLeafEdge(*neighbour, v)
	}
	return Edge{u: parent.id, v: v.id}
}

func populateSubtreeCount(root *Vertex) {
	root.subtreeCount = 1
	for _, neighbour := range root.neighbours {
		if neighbour.subtreeCount == 0 {
			populateSubtreeCount(neighbour)
			root.subtreeCount += neighbour.subtreeCount
		}
	}
}

func findCentroid(root *Vertex, n int, visited []bool) (*Vertex, *Vertex) {
	for _, neighbour := range root.neighbours {
		if visited[neighbour.id-1] {
			continue
		}
		visited[neighbour.id-1] = true
		if neighbour.subtreeCount > n/2 {
			return findCentroid(neighbour, n, visited)
		}
		if neighbour.subtreeCount == n/2 {
			return root, neighbour
		}
	}
	return root, nil
}

func findCentroidMain(vertices []*Vertex, n int) (*Vertex, *Vertex) {
	for _, v := range vertices {
		if v.subtreeCount > 0 {
			continue
		}
		populateSubtreeCount(v)
	}
	visited := make([]bool, n)
	for i, v := range vertices {
		if visited[i] {
			continue
		}
		visited[i] = true
		if c1, c2 := findCentroid(v, n, visited); c1 != nil {
			return c1, c2
		}
	}
	return nil, nil
}

func solveDupCentroid(edges []Edge, n int) (Edge, Edge) {
	vertices := make([]*Vertex, n)
	for _, e := range edges {
		if vertices[e.u-1] == nil {
			vertices[e.u-1] = &Vertex{id: e.u}
		}
		if vertices[e.v-1] == nil {
			vertices[e.v-1] = &Vertex{id: e.v}
		}
		vertices[e.u-1].addNeighbour(vertices[e.v-1])
		vertices[e.v-1].addNeighbour(vertices[e.u-1])
	}
	centroid, childCentroid := findCentroidMain(vertices, n)
	if childCentroid == nil {
		return edges[0], edges[0]
	}
	leafEdge := findLeafEdge(*childCentroid, *centroid)
	return Edge{u: centroid.id, v: leafEdge.v}, leafEdge
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t, n int
	var addEdge, removeEdge Edge
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscanln(reader, &n)
		edges := make([]Edge, n-1)
		for i := 0; i < n-1; i++ {
			e := Edge{}
			fmt.Fscanln(reader, &e.u, &e.v)
			edges[i] = e
		}
		addEdge, removeEdge = solveDupCentroid(edges, n)
		fmt.Fprintln(writer, removeEdge.u, removeEdge.v)
		fmt.Fprintln(writer, addEdge.u, addEdge.v)
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

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

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

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

type node struct {
	id  int64
	out map[int64]int64
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		nodes := map[int64]*node{}
		for i := int64(0); i < n-1; i++ {
			l, r := sint64(), sint64()
			if nodes[l] == nil {
				nodes[l] = &node{
					id:  l,
					out: map[int64]int64{},
				}
			}
			if nodes[r] == nil {
				nodes[r] = &node{
					id:  r,
					out: map[int64]int64{},
				}
			}
			nodes[l].out[r] = -1
			nodes[r].out[l] = -1
		}
		sol(nodes)
	}
}

func sol(nodes map[int64]*node) {
	if len(nodes)&1 == 1 {
		for i := range nodes {
			for j := range nodes[i].out {
				printf("%d %d\n", i, j)
				printf("%d %d\n", i, j)
				return
			}
		}
	}

	explored := map[int64]bool{}

	var count func(nodeId int64) (bool, int64)
	count = func(nodeId int64) (bool, int64) {
		explored[nodeId] = true
		ret := int64(1)
		haveResRet := false
		for i := range nodes[nodeId].out {
			if !explored[i] {
				haveRes, next := count(i)
				if haveRes {
					haveResRet = true
				}
				if next == int64(len(nodes))/2 {
					for j := range nodes[nodeId].out {
						if j != i {
							printf("%d %d\n", nodeId, j)
							printf("%d %d\n", i, j)
							return true, 0
						}
					}
				}
				nodes[nodeId].out[i] = next
				ret += next
			}
		}
		return haveResRet, ret
	}
	for i := range nodes {
		haveRes, _ := count(i)
		if haveRes {
			return
		}
		break
	}

	for i := range nodes {
		for j := range nodes[i].out {
			printf("%d %d\n", i, j)
			printf("%d %d\n", i, j)
			return
		}
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

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

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

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		nodes := make([][]int64, n)
		for i := int64(0); i < n-1; i++ {
			l, r := sint64()-1, sint64()-1
			nodes[l] = append(nodes[l], r)
			nodes[r] = append(nodes[r], l)
		}
		sol(nodes)
	}
}

func sol(nodes [][]int64) {
	defer func() {
		if err := recover(); err != nil {
			return
		}
	}()

	var dfs func(from, to int64) int64
	dfs = func(from, to int64) int64 {
		curr := int64(1)
		for _, nxt := range nodes[to] {
			if nxt == from {
				continue
			}
			out := dfs(to, nxt)
			// found centroid
			if out == int64(len(nodes)) / 2 {
				for _, node := range nodes[to] {
					if node != nxt {
						printf("%d %d\n", node+1, to+1)
						printf("%d %d\n", node+1, nxt+1)
						panic("")
					}
				}
			}
			curr += out
		}
		return curr
	}
	dfs(-1, 0)

	printf("%d %d\n", 1, nodes[0][0]+1)
	printf("%d %d\n", 1, nodes[0][0]+1)
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.NextInt(); t > 0; t-- {
		n := io.NextInt()
		g := make([][]int, n+1)
		for i := 0; i < n-1; i++ {
			u, v := io.NextInt(), io.NextInt()
			g[u] = append(g[u], v)
			g[v] = append(g[v], u)
		}

		sz := make([]int, len(g))
		var calcSz func(int)
		calcSz = func(u int) {
			sz[u] = 1
			for _, v := range g[u] {
				remove(&g[v], u)
				calcSz(v)
				sz[u] += sz[v]
			}
		}
		calcSz(1)

		var getCentroid func(int) int
		getCentroid = func(u int) int {
			for _, v := range g[u] {
				if sz[v]*2 > sz[u] {
					remove(&g[u], v)
					g[v], sz[u], sz[v] = append(g[v], u), sz[u]-sz[v], sz[u]
					return getCentroid(v)
				}
			}
			return u
		}
		cen := getCentroid(1)

		ans := [4]int{cen, g[cen][0], cen, g[cen][0]}
		for _, v := range g[cen] {
			if sz[cen] == 2*sz[v] {
				ans = [4]int{v, g[v][0], cen, g[v][0]}
			}
		}
		io.Println(ans[0], ans[1])
		io.Println(ans[2], ans[3])
	}
}

func remove(a *[]int, v int) {
	b := *a
	j := len(b) - 1
	for i, x := range b {
		if x == v {
			b[i], *a = b[j], b[:j]
			return
		}
	}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

type node struct {
	edgesTo              []int
	edgeChildren         []int
	numberOfChildren     int
	maxRelationComponent int
}

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

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

func detectEdgeChildren(currentId int, nodes []node, used []bool) int {
	used[currentId] = true
	n := &nodes[currentId]

	for id, el := range n.edgesTo {
		if used[el] == false {
			n.edgeChildren[id] = detectEdgeChildren(el, nodes, used) + 1
			n.numberOfChildren += n.edgeChildren[id]
		}
	}

	n.maxRelationComponent = 0
	for _, el := range n.edgeChildren {
		if el == 0 {
			if len(nodes)-n.numberOfChildren - 1 > n.maxRelationComponent {
				n.maxRelationComponent = len(nodes) - n.numberOfChildren - 1
			}
		} else if n.maxRelationComponent < el {
			n.maxRelationComponent = el
		}
	}

	return n.numberOfChildren
}

func main() {
	defer writer.Flush()
	var t, n, x, y int
	scan(&t)

	for i := 0; i < t; i++ {
		scan(&n)
		nodes := make([]node, n)
		used := make([]bool, n)
		for j := 0; j < n - 1; j++ {
			scan(&x, &y)
			nodes[x-1].edgesTo = append(nodes[x-1].edgesTo, y-1)
			nodes[y-1].edgesTo = append(nodes[y-1].edgesTo, x-1)
		}

		for j := 0; j < n; j ++ {
			nodes[j].edgeChildren = make([]int, len(nodes[j].edgesTo))
		}

		detectEdgeChildren(0, nodes, used)

		min := nodes[0].maxRelationComponent
		minIdx := 0
		for id, el := range nodes {
			if el.maxRelationComponent < min {
				min = el.maxRelationComponent
				minIdx = id
			}
		}

		min2Idx := -1
		for _, el := range nodes[minIdx].edgesTo {
			if nodes[el].maxRelationComponent == min {
				min2Idx = el
				break
			}
		}

		if min2Idx == -1 {
			connectedId := nodes[minIdx].edgesTo[0]
			printf("%d %d\n%d %d\n", minIdx + 1, connectedId + 1, minIdx+1, connectedId +1)
		} else {
			connectedId := nodes[min2Idx].edgesTo[0]
			if connectedId == minIdx {
				connectedId = nodes[min2Idx].edgesTo[1]
			}
			printf("%d %d\n%d %d\n", min2Idx + 1, connectedId + 1, minIdx+1, connectedId +1)
		}

	}
}

package main

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

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

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

var centroidEdge *Edge

func main() {
	defer writer.Flush()

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

	for i := 0; i < tcases; i++ {
		centroidEdge = nil
		var x1, x2, y1, y2 int

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

		nodes := make([]*Node, n+1, n+1)

		for j := 1; j <= n; j++ {
			nodes[j] = NewNode(j)
		}

		// printf("%d nodes created\n", n)

		for j := 0; j < n-1; j++ {
			var to, fr int
			scanf("%d %d\n", &to, &fr)

			_ = NewEdge(nodes[to], nodes[fr])
		}

		// printf("edges added\n")

		dfs(nodes[1], n, 1)

		// printf("dfs done\n")

		if centroidEdge != nil {
			x1 = centroidEdge.to.id
			for _, e := range centroidEdge.to.edges {
				if e.LinkedNode(centroidEdge.to) != centroidEdge.fr {
					x2 = e.LinkedNode(centroidEdge.to).id
				}
			}

			y1 = centroidEdge.fr.id
			y2 = x2
		} else {
			x1, y1 = 1, 1
			p := nodes[1].edges[0].LinkedNode(nodes[1]).id
			x2, y2 = p, p
		}

		printf("%d %d\n%d %d\n", x1, x2, y1, y2)
	}
}

type Node struct {
	id    int
	edges []*Edge

	flag int
}

func NewNode(id int) *Node {
	n := Node{id: id}
	return &n
}

func (n *Node) AddEdge(e *Edge) {
	n.edges = append(n.edges, e)
}

type Edge struct {
	fr *Node
	to *Node

	frWeight int // Number of nodes on either side of this edge.
	toWeight int
}

func NewEdge(fr *Node, to *Node) *Edge {
	e := Edge{
		fr: fr,
		to: to,
	}

	fr.AddEdge(&e)
	to.AddEdge(&e)

	return &e
}

func (e *Edge) LinkedNode(n *Node) *Node {
	if n == e.fr {
		return e.to
	} else if n == e.to {
		return e.fr
	} else {
		panic("this is not the edge you're looking for")
	}
}

func dfs(n *Node, total int, flag int) int {
	if n.flag == flag {
		return 0
	} else {
		n.flag = flag
	}

	totalWt := 1
	for _, e := range n.edges {
		wt := dfs(e.LinkedNode(n), total, flag)

		if wt == total-wt {
			centroidEdge = e
		}

		totalWt += wt
	}

	return totalWt
}

package main

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

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

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

var centroidEdge *Edge

func main() {
	defer writer.Flush()

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

	for i := 0; i < tcases; i++ {
		centroidEdge = nil
		x1, x2 := 1, 2
		y1, y2 := 1, 2

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

		nodes := make([]*Node, n+1, n+1)

		for j := 1; j <= n; j++ {
			nodes[j] = NewNode(j)
		}

		// printf("%d nodes created\n", n)

		for j := 0; j < n-1; j++ {
			var to, fr int
			scanf("%d %d\n", &to, &fr)

			_ = NewEdge(nodes[to], nodes[fr])
		}

		// printf("edges added\n")

		dfs(nodes[1], n, 1)

		// printf("dfs done\n")

		if centroidEdge != nil {
			x1 = centroidEdge.to.id
			for _, e := range centroidEdge.to.edges {
				if e.LinkedNode(centroidEdge.to) != centroidEdge.fr {
					x2 = e.LinkedNode(centroidEdge.to).id
				}
			}

			y1 = centroidEdge.fr.id
			y2 = x2
		}

		printf("%d %d\n%d %d\n", x1, x2, y1, y2)
	}
}

type Node struct {
	id    int
	edges []*Edge

	flag int
}

func NewNode(id int) *Node {
	n := Node{id: id}
	return &n
}

func (n *Node) AddEdge(e *Edge) {
	n.edges = append(n.edges, e)
}

type Edge struct {
	fr *Node
	to *Node

	frWeight int // Number of nodes on either side of this edge.
	toWeight int
}

func NewEdge(fr *Node, to *Node) *Edge {
	e := Edge{
		fr: fr,
		to: to,
	}

	fr.AddEdge(&e)
	to.AddEdge(&e)

	return &e
}

func (e *Edge) LinkedNode(n *Node) *Node {
	if n == e.fr {
		return e.to
	} else if n == e.to {
		return e.fr
	} else {
		panic("this is not the edge you're looking for")
	}
}

func dfs(n *Node, total int, flag int) int {
	if n.flag == flag {
		return 0
	} else {
		n.flag = flag
	}

	totalWt := 1
	for _, e := range n.edges {
		wt := dfs(e.LinkedNode(n), total, flag)

		if wt == total-wt {
			centroidEdge = e
		}

		totalWt += wt
	}

	return totalWt
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1406C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

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

		ct := []int{}
		min := int(1e9)
		var f func(v, fa int) int
		f = func(v, fa int) int {
			sz, maxSz := 1, 0
			for _, w := range g[v] {
				if w != fa {
					s := f(w, v)
					sz += s
					maxSz = max(maxSz, s)
				}
			}
			maxSz = max(maxSz, n-sz)
			if maxSz < min {
				min = maxSz
				ct = []int{v}
			} else if maxSz == min {
				ct = append(ct, v)
			}
			return sz
		}
		f(1, 0)
		if len(ct) == 1 {
			Fprintln(out, v, w)
			Fprintln(out, v, w)
		} else {
			v, w, u = ct[0], ct[1], g[v][0]
			if g[v][0] == w {
				u = g[v][1]
			}
			Fprintln(out, v, u)
			Fprintln(out, w, u)
		}
	}
}

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

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func solveCase() {
	n := rw.NextInt()
	g := make([][]int, n)
	for i := 0; i < n-1; i++ {
		x, y := rw.NextInt()-1, rw.NextInt()-1
		g[x] = append(g[x], y)
		g[y] = append(g[y], x)
	}
	sz := make([]int, n)
	var dfs func(int, int)
	var b, max []int
	max = make([]int, n)
	dfs = func(u, p int) {
		b = append(b, u)
		sz[u] = 1
		max[u] = -1
		for _, v := range g[u] {
			if v != p {
				dfs(v, u)
				sz[u] += sz[v]
				if sz[v] > max[u] {
					max[u] = sz[v]
				}
			}
		}
		if n-sz[u] > max[u] {
			max[u] = n - sz[u]
		}
	}
	dfs(0, -1)
	sort.Slice(b[:], func(i, j int) bool { return max[i] < max[j] })
	if max[b[0]] != max[b[1]] {
		rw.PrintlnInts(1, g[0][0]+1)
		rw.PrintlnInts(1, g[0][0]+1)
	} else {
		u := b[0]
		p := b[1]
		for len(g[u]) > 1 {
			for _, v := range g[u] {
				if v != p {
					u, p = v, u
					break
				}
			}
		}
		rw.PrintlnInts(u+1, p+1)
		rw.PrintlnInts(u+1, b[1]+1)
	}
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

type Edge struct {
	u, v int
}

type Vertex struct {
	id             int
	neighbours     []*Vertex
	neighbourCount int
	subtreeCount   int
}

func (v *Vertex) addNeighbour(neighbour *Vertex) {
	v.neighbours = append(v.neighbours, neighbour)
	v.neighbourCount += 1
}

func findLeafEdge(v Vertex, parent Vertex) Edge {
	if v.neighbourCount == 0 {
		return Edge{u: parent.id, v: v.id}
	}
	return findLeafEdge(*v.neighbours[0], v)
}

func populateSubtreeCount(root *Vertex) {
	root.subtreeCount = 1
	for _, neighbour := range root.neighbours {
		if neighbour.subtreeCount == 0 {
			populateSubtreeCount(neighbour)
		}
		root.subtreeCount += neighbour.subtreeCount
	}
}

func findCentroid(root *Vertex, n int) (*Vertex, *Vertex) {
	if root.subtreeCount-1 <= n/2 {
		return nil, nil
	}
	for _, neighbour := range root.neighbours {
		if neighbour.subtreeCount == n/2 {
			return root, neighbour
		}
		if neighbour.subtreeCount-1 > n/2 {
			return findCentroid(neighbour, n)
		}
	}
	return root, nil
}

func findCentroidMain(vertices []*Vertex, n int) (*Vertex, *Vertex) {
	for _, v := range vertices {
		if v.subtreeCount > 0 {
			continue
		}
		populateSubtreeCount(v)
	}
	for _, v := range vertices {
		if c1, c2 := findCentroid(v, n); c1 != nil {
			return c1, c2
		}
	}
	return nil, nil
}

func solveDupCentroid(edges []Edge, n int) (Edge, Edge) {
	vertices := make([]*Vertex, n)
	for _, e := range edges {
		if vertices[e.u-1] == nil {
			vertices[e.u-1] = &Vertex{id: e.u}
		}
		if vertices[e.v-1] == nil {
			vertices[e.v-1] = &Vertex{id: e.v}
		}
		vertices[e.u-1].addNeighbour(vertices[e.v-1])
	}
	centroid, childCentroid := findCentroidMain(vertices, n)
	if childCentroid == nil {
		return edges[0], edges[0]
	}
	leafEdge := findLeafEdge(*childCentroid, *centroid)
	return Edge{u: centroid.id, v: leafEdge.v}, leafEdge
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t, n int
	var addEdge, removeEdge Edge
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscanln(reader, &n)
		edges := make([]Edge, n-1)
		for i := 0; i < n-1; i++ {
			e := Edge{}
			fmt.Fscanln(reader, &e.u, &e.v)
			edges[i] = e
		}
		addEdge, removeEdge = solveDupCentroid(edges, n)
		fmt.Fprintln(writer, removeEdge.u, removeEdge.v)
		fmt.Fprintln(writer, addEdge.u, addEdge.v)
	}
}

package main

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

type Edge struct {
	u, v int
}

type Vertex struct {
	id             int
	neighbours     []*Vertex
	neighbourCount int
	subtreeCount   int
}

func (v *Vertex) addNeighbour(neighbour *Vertex) {
	v.neighbours = append(v.neighbours, neighbour)
	v.neighbourCount += 1
}

func findLeafEdge(v Vertex, parent Vertex) Edge {
	if v.neighbourCount == 0 {
		return Edge{u: parent.id, v: v.id}
	}
	return findLeafEdge(*v.neighbours[0], v)
}

func populateSubtreeCount(root *Vertex) {
	root.subtreeCount = 1
	for _, neighbour := range root.neighbours {
		if neighbour.subtreeCount == 0 {
			populateSubtreeCount(neighbour)
		}
		root.subtreeCount += neighbour.subtreeCount
	}
}

func findCentroid(root *Vertex, n int) (*Vertex, *Vertex) {
	for _, neighbour := range root.neighbours {
		if neighbour.subtreeCount > n/2 {
			return findCentroid(neighbour, n)
		}
		if neighbour.subtreeCount == n/2 {
			return root, neighbour
		}
	}
	return root, nil
}

func findCentroidMain(vertices []*Vertex, n int) (*Vertex, *Vertex) {
	for _, v := range vertices {
		if v.subtreeCount > 0 {
			continue
		}
		populateSubtreeCount(v)
	}
	for _, v := range vertices {
		if c1, c2 := findCentroid(v, n); c1 != nil {
			return c1, c2
		}
	}
	return nil, nil
}

func solveDupCentroid(edges []Edge, n int) (Edge, Edge) {
	vertices := make([]*Vertex, n)
	for _, e := range edges {
		if vertices[e.u-1] == nil {
			vertices[e.u-1] = &Vertex{id: e.u}
		}
		if vertices[e.v-1] == nil {
			vertices[e.v-1] = &Vertex{id: e.v}
		}
		vertices[e.u-1].addNeighbour(vertices[e.v-1])
	}
	centroid, childCentroid := findCentroidMain(vertices, n)
	if childCentroid == nil {
		return edges[0], edges[0]
	}
	leafEdge := findLeafEdge(*childCentroid, *centroid)
	return Edge{u: centroid.id, v: leafEdge.v}, leafEdge
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t, n int
	var addEdge, removeEdge Edge
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscanln(reader, &n)
		edges := make([]Edge, n-1)
		for i := 0; i < n-1; i++ {
			e := Edge{}
			fmt.Fscanln(reader, &e.u, &e.v)
			edges[i] = e
		}
		addEdge, removeEdge = solveDupCentroid(edges, n)
		fmt.Fprintln(writer, removeEdge.u, removeEdge.v)
		fmt.Fprintln(writer, addEdge.u, addEdge.v)
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

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

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

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

type node struct {
	id int64
	out map[int64]int64
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		nodes := map[int64]*node{}
		for i := int64(0); i < n-1; i++ {
			l, r := sint64(), sint64()
			if nodes[l] == nil {
				nodes[l] = &node{
					id: l,
					out: map[int64]int64{},
				}
			}
			if nodes[r] == nil {
				nodes[r] = &node{
					id: r,
					out: map[int64]int64{},
				}
			}
			nodes[l].out[r] = -1
			nodes[r].out[l] = -1
		}
		sol(nodes)
	}
}

func sol(nodes map[int64]*node) {
	if len(nodes) & 1 == 1 {
		first := int64(-1)
		for i := range nodes {
			if first == -1 {
				first = i
			} else {
				printf("%d %d\n", first, i)
				printf("%d %d\n", first, i)
				return
			}
		}
	}

	explored := map[int64]bool{}

	var count func(nodeId int64) int64
	count = func(nodeId int64) int64 {
		explored[nodeId] = true
		ret := int64(1)
		for i := range nodes[nodeId].out {
			if !explored[i] {
				next := count(i)
				nodes[nodeId].out[i] = next
				ret += next
			}
		}
		return ret
	}

	// count for first node
	var startNode int64
	for i := range nodes {
		startNode = i
		count(i)
		break
	}

	explored = map[int64]bool{}
	for {
		shouldContinue := false
		explored[startNode] = true
		for i := range nodes[startNode].out {
			if !explored[i] {
				// found centroid
				if nodes[startNode].out[i] == int64(len(nodes)) / 2 {
					// find random edge that is not i
					for j := range nodes[startNode].out {
						if j != i {
							printf("%d %d\n", startNode, j)
							printf("%d %d\n", i, j)
							return
						}
					}
				}
				// go towards centroid
				if nodes[startNode].out[i] > int64(len(nodes)) / 2 {
					sumOut := int64(0)
					for j := range nodes[startNode].out {
						sumOut += nodes[startNode].out[j]
					}
					nodes[i].out[startNode] = sumOut + 1 - nodes[startNode].out[i]
					startNode = i
					shouldContinue = true
					break
				}
			}
		}
		if shouldContinue {
			continue
		}
		first := int64(-1)
		for i := range nodes {
			if first == -1 {
				first = i
			} else {
				printf("%d %d\n", first, i)
				printf("%d %d\n", first, i)
				return
			}
		}
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

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

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

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

type node struct {
	id int64
	out map[int64]int64
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		nodes := map[int64]*node{}
		for i := int64(0); i < n-1; i++ {
			l, r := sint64(), sint64()
			if nodes[l] == nil {
				nodes[l] = &node{
					id: l,
					out: map[int64]int64{},
				}
			}
			if nodes[r] == nil {
				nodes[r] = &node{
					id: r,
					out: map[int64]int64{},
				}
			}
			nodes[l].out[r] = -1
			nodes[r].out[l] = -1
		}
		sol(nodes)
	}
}

func sol(nodes map[int64]*node) {
	if len(nodes) & 1 == 1 {
		first := int64(-1)
		for i := range nodes {
			if first == -1 {
				first = i
			} else {
				if first < i {
					printf("%d %d\n", first, i)
					printf("%d %d\n", first, i)
				} else {
					printf("%d %d\n", i, first)
					printf("%d %d\n", i, first)
				}
				return
			}
		}
	}

	explored := map[int64]bool{}

	var count func(nodeId int64) (bool, int64)
	count = func(nodeId int64) (bool, int64) {
		explored[nodeId] = true
		ret := int64(1)
		haveResRet := false
		for i := range nodes[nodeId].out {
			if !explored[i] {
				haveRes, next := count(i)
				if haveRes {
					haveResRet = true
				}
				if next == int64(len(nodes)) / 2 {
					for j := range nodes[nodeId].out {
						if j != i {
							if nodeId < j {
								printf("%d %d\n", nodeId, j)
							} else {
								printf("%d %d\n", j, nodeId)
							}
							if i < j {
								printf("%d %d\n", i, j)
							} else {
								printf("%d %d\n", j, i)
							}
							return true, 0
						}
					}
				}
				nodes[nodeId].out[i] = next
				ret += next
			}
		}
		return haveResRet, ret
	}
	for i := range nodes {
		haveRes, _ := count(i)
		if haveRes {
			return
		}
		break
	}

	first := int64(-1)
	for i := range nodes {
		if first == -1 {
			first = i
		} else {
			if first < i {
				printf("%d %d\n", first, i)
				printf("%d %d\n", first, i)
			} else {
				printf("%d %d\n", i, first)
				printf("%d %d\n", i, first)
			}
			return
		}
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

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

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

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

type node struct {
	id int64
	out map[int64]int64
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		nodes := map[int64]*node{}
		for i := int64(0); i < n-1; i++ {
			l, r := sint64(), sint64()
			if nodes[l] == nil {
				nodes[l] = &node{
					id: l,
					out: map[int64]int64{},
				}
			}
			if nodes[r] == nil {
				nodes[r] = &node{
					id: r,
					out: map[int64]int64{},
				}
			}
			nodes[l].out[r] = -1
			nodes[r].out[l] = -1
		}
		sol(nodes)
	}
}

func sol(nodes map[int64]*node) {
	if len(nodes) & 1 == 1 {
		first := int64(-1)
		for i := range nodes {
			if first == -1 {
				first = i
			} else {
				printf("%d %d\n", first, i)
				printf("%d %d\n", first, i)
				return
			}
		}
	}

	explored := map[int64]bool{}

	var count func(nodeId int64) (bool, int64)
	count = func(nodeId int64) (bool, int64) {
		explored[nodeId] = true
		ret := int64(1)
		haveResRet := false
		for i := range nodes[nodeId].out {
			if !explored[i] {
				haveRes, next := count(i)
				if haveRes {
					haveResRet = true
				}
				if next == int64(len(nodes)) / 2 {
					for j := range nodes[nodeId].out {
						if j != i {
							printf("%d %d\n", nodeId, j)
							printf("%d %d\n", i, j)
							return true, 0
						}
					}
				}
				nodes[nodeId].out[i] = next
				ret += next
			}
		}
		return haveResRet, ret
	}
	for i := range nodes {
		haveRes, _ := count(i)
		if haveRes {
			return
		}
		break
	}

	first := int64(-1)
	for i := range nodes {
		if first == -1 {
			first = i
		} else {
			printf("%d %d\n", first, i)
			printf("%d %d\n", first, i)
			return
		}
	}
}


package main

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

func main() {
	defer writer.Flush()

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

	var b strings.Builder

	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

		for j := 0; j < n; j++ {
			scanf("%d", &a[j])
		}
		scanf("\n")

		cream := 0
		for j := n - 1; j >= 0; j-- {
			cream = max(cream, a[j])
			if cream > 0 {
				a[j] = 1
				cream--
			}
		}

		for j := 0; j < n; j++ {
			fmt.Fprintf(&b, "%d ", a[j])
		}
		fmt.Fprintf(&b, "\n")
	}

	printf(b.String())
}

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

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

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

package main

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

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

//https://codeforces.com/problemset/problem/1501/B

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	for t := nextNum(); t > 0; t-- {
		solve1()
	}
}

func solve() {
	n := nextNum()
	a := make([]int, n)
	lo := 0
	for i := 0; i < n; i++ {
		cur := i
		for j := nextNum(); j > 0 && cur >= 0; j-- {
			a[cur] = 1
			if cur <= lo {
				lo = i + 1
				break
			}
			cur--
		}
	}
	for i, v := range a {
		if i == n-1 {
			printf("%d\n", v)
		} else {
			printf("%d ", v)
		}
	}
}

func solve1() {
	n := nextNum()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextNum()
	}
	cur := n
	for i := n - 1; i >= 0; i-- {
		if a[i] > 0 {
			cur = min(cur, max(i-a[i]+1, 0))
			if cur == 0 {
				for j := i; j >= 0; j-- {
					a[j] = 1
				}
				break
			}
		}
		if i < cur {
			a[i] = 0
		} else {
			a[i] = 1
		}
	}

	for i, v := range a {
		if i == n-1 {
			printf("%d\n", v)
		} else {
			printf("%d ", v)
		}
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

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

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

package main

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

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

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

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

func main() {
	defer writer.Flush()
	var t, n int
	scan(&t)
	out := make([][]int, t)

	for i := 0; i < t; i++ {
		scan(&n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			scan(&a[j])
		}
		ans := make([]int, n)
		med := 0
		for j := n - 1; j >= 0; j-- {
			med = max(med, a[j])
			if med > 0 {
				ans[j] = 1
			} else {
				ans[j] = 0
			}
			med--
		}
		out[i] = ans
	}
	for i := 0; i < t; i++ {
		for j := 0; j < len(out[i]); j++ {
			fmt.Printf("%d ", out[i][j])
		}
		fmt.Println()
	}
}

package main

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

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

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

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

func main() {
	//reader := bufio.NewReader(os.Stdin)
	//t, _ := reader.ReadString('\n')
	var t, n int
	scan(&t)
	out := make([][]int, t)

	for i := 0; i < t; i++ {
		scan(&n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			scan(&a[j])
		}
		ans := make([]int, n)
		med := 0
		for j := n - 1; j >= 0; j-- {
			med = max(med, a[j])
			if med > 0 {
				ans[j] = 1
			} else {
				ans[j] = 0
			}
			med--
		}
		out[i] = ans
	}
	for i := 0; i < t; i++ {
		for j := 0; j < len(out[i]); j++ {
			fmt.Printf("%d ", out[i][j])
		}
		fmt.Println("")
	}
}

package main

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

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	for t := nextNum(); t > 0; t-- {
		solve()
	}
}

func solve() {
	n := nextNum()
	arr := make([]int, n + 2)
	for i := 1; i <= n; i++ {
		num := nextNum()
		if num == 0 {
			continue
		}
		arr[i]++
		if i - num > 0 {
			arr[i - num]--
		}
	}
	for i := n; i > 0; i-- {
		arr[i] = arr[i + 1] + arr[i]
	}
	for i := 1; i <= n; i++ {
		var res = 0
		if arr[i] > 0 {
			res = 1
		}
		arr[i] = 0
		if i == n {
			printf("%d\n", res)
		} else {
			printf("%d ", res)
		}
	}

}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

// 00
package main

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

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}
func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		ans := make([]int, n)
		curr := n
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		for i := n - 1; i >= 0; i-- {
			curr = min(curr, i-a[i]+1)
			if curr <= i {
				ans[i] = 1
			} else {
				ans[i] = 0
			}
		}
		for i := 0; i < n; i++ {
			write_int(f, ans[i])
			if i == n-1 {
				write_string(f, "\n")
			} else {
				write_string(f, " ")
			}
		}
	}
}

package main

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

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

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

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

func sint() int { // ~[-2e9, 2e9]
	s := sstring()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

func sint64() int64 { // ~[-9e18, 9e18]
	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 sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

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

type Layer struct {
	drenched bool
	prev     int64
}

func (n Layer) String() string {
	if n.drenched {
		return "1"
	}
	return "0"
}

func sol(n int64, a []int64) []Layer {
	ret := make([]Layer, n)
	for i := range ret {
		ret[i].prev = int64(i - 1)
	}
	var f func(int64, int64) int64
	f = func(curr, target int64) int64 {
		if curr < 0 {
			return -1
		}
		if curr < target {
			panic("something went wrong")
		}
		ret[curr].drenched = true
		if target == curr {
			return ret[curr].prev
		}
		if ret[curr].prev < target {
			return ret[curr].prev
		}
		prev := f(ret[curr].prev, target)
		ret[curr].prev = prev
		return prev
	}
	for i := range a {
		if a[i] == 0 {
			continue
		}
		curr := int64(i)
		target := curr - a[i] + 1
		f(curr, target)
	}
	return ret
}

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, p := make([]int, n), make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
		}
		c := 0
		for j := n - 1; j >= 0; j-- {
			if c == 0 && o[j] == 0 {
				p[j] = 0
			} else {
				p[j] = 1
				if o[j] > c {
					c = o[j]
				}
				c--
			}
		}
		for j := 0; j < n; j++ {
			fmt.Fprint(w, p[j], " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var fields []string

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

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

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

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

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

		for i, carry := n-1, 0; i >= 0; i-- {
			if a[i] > carry {
				carry = a[i]
			}

			if carry > 0 {
				carry--
				a[i] = 1
			} else {
				a[i] = 0
			}
		}

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

package main

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

func R(s string) (a string) {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	a = string(r)
	return
}

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

func yes() {
	p("YES")
}

func no() {
	p("NO")
}

func remove(slice []int, s int) []int {
	return append(slice[:s], slice[s+1:]...)
}

func dch(s []rune, index int) []rune {
	return append(s[0:index], s[index+1:]...)
}

func p(a ...interface{})            { fmt.Fprint(writer, a...) }
func pln(a ...interface{})          { fmt.Fprintln(writer, a...) }
func s(a ...interface{})            { fmt.Fscan(reader, a...) }
func pf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func sf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	////////////////
	c := 0
	s(&c)
	for c != 0 {
		solve()
		c--
	}
	////////////////
}

func solve() {
	n := 0
	s(&n)
	m := make([]int, n)
	m1 := make([]int, n)
	for i := n-1; i >= 0; i--{
		s(&m[i])
	}
	t := 0
	for i := 0; i < n; i++ {
		if t == 0 && m[i] == 0 {
			continue
		}
		if m[i] > t {
			t = m[i]
		}
		if t != 0 {
			m1[i] = 1
			t--
		}
	}
	for i :=  n-1; i >= 0; i-- {
		p(m1[i], " ")
	}
	pln()
}

package main

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

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

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

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

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

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

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

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

	ans := make([]int, n)

	st := []int{}
	for i := 0; i < n; i++ {
		st = append(st, i)
	}

	for i := n - 1; i >= 0; i-- {
		for len(st) > 0 {
			top := st[len(st)-1]
			if top > i {
				st = st[:len(st)-1]
			} else {
				break
			}
		}

		for len(st) > 0 {
			top := st[len(st)-1]
			if top > i-a[i] {
				ans[top] = 1
				st = st[:len(st)-1]
			} else {
				break
			}
		}
	}

	for i := range ans {
		printf("%d ", ans[i])
	}
	printf("\n")
}

func solveA() {
	var n int
	scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range b {
		scan(&a[i])
		scan(&b[i])
	}
	tm := make([]int, n)
	for i := range tm {
		scan(&tm[i])
	}

	ans := 0
	prev := 0

	for i := range a {
		ans += a[i] - prev + tm[i]
		if i == n-1 {
			break
		}

		need := (b[i] - a[i] + 1) / 2
		stay := 0
		if ans < b[i] {
			stay = b[i] - ans
			ans = b[i]
		}
		if stay < need {
			ans += need - stay
		}

		prev = b[i]
	}

	printf("%d\n", ans)
}

package main

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

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

//https://codeforces.com/problemset/problem/1501/B

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	for t := nextNum(); t > 0; t-- {
		solve1()
	}
}

func solve() {
	n := nextNum()
	a := make([]int, n)
	lo := 0
	for i := 0; i < n; i++ {
		cur := i
		for j := nextNum(); j > 0 && cur >= 0; j-- {
			a[cur] = 1
			if cur <= lo {
				lo = i + 1
				break
			}
			cur--
		}
	}
	for i, v := range a {
		if i == n-1 {
			printf("%d\n", v)
		} else {
			printf("%d ", v)
		}
	}
}

func solve1() {
	n := nextNum()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextNum()
	}
	cur := n
	for i := n - 1; i > 0; i-- {
		if a[i] > 0 {
			cur = min(cur, max(i-a[i]+1, 0))
			if cur == 0 {
				for j := i; j >= 0; j-- {
					a[j] = 1
				}
				break
			}
		}
		if i < cur {
			a[i] = 0
		} else {
			a[i] = 1
		}
	}

	for i, v := range a {
		if i == n-1 {
			printf("%d\n", v)
		} else {
			printf("%d ", v)
		}
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

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

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

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d", &t)
	var arr [200007]int = [200007]int{}
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d", &n)
		for i := 1; i <= n; i++ {
			var num int
			fmt.Scanf("%d", &num)
			if num == 0 {
				continue
			}
			arr[i]++
			if i - num > 0 {
				arr[i - num]--
			}
		}
		for i := n; i > 0; i-- {
			arr[i] = arr[i + 1] + arr[i]
		}
		for i := 1; i <= n; i++ {
			var res = 0
			if arr[i] > 0 {
				res = 1
			}
			arr[i] = 0
			if i == n {
				fmt.Printf("%d\n", res)
			} else {
				fmt.Printf("%d ", res)
			}
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d", &t)
	var arr [200007]int = [200007]int{}
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d", &n)
		for i := 1; i <= n; i++ {
			var num int
			fmt.Scanf("%d", &num)
			if num == 0 {
				continue
			}
			arr[i]++
			if i - num > 0 {
				arr[i - num]--
			}
		}
		for i := n; i > 0; i-- {
			arr[i] = arr[i + 1] + arr[i]
		}
		for i := 1; i <= n; i++ {
			var res = 0
			if arr[i] > 0 {
				res = 1
			}
			arr[i] = 0
			if i == n {
				fmt.Println(res)
			} else {
				fmt.Printf("%d ", res)
			}
		}
	}
}

package main

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

func main() {
	defer writer.Flush()

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

	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

		for j := 0; j < n; j++ {
			scanf("%d", &a[j])
		}

		cream := 0
		for j := n - 1; j >= 0; j-- {
			cream = max(cream, a[j])
			if cream > 0 {
				a[j] = 1
				cream--
			}
		}

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

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

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

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