package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strings"
)

type segment struct {
	l, r, len int
}

func newSegment(l, r int) *segment {
	len := r - l + 1
	if len > 0 {
		return &segment{l, r, len}
	}
	return nil
}

type PriorityQueue []*segment

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].len > pq[j].len || (pq[i].len == pq[j].len && pq[i].l < pq[j].l)
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	s := x.(*segment)
	*pq = append(*pq, s)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	s := old[n-1]
	old[n-1] = nil
	*pq = old[0 : n-1]
	return s
}

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

	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		var pq PriorityQueue
		heap.Init(&pq)
		heap.Push(&pq, newSegment(1, n))

		ans := make([]int, n)
		cnt := 1
		for pq.Len() > 0 {
			e := heap.Pop(&pq)
			seg := e.(*segment)
			var idx int
			if (seg.r-seg.l+1)%2 == 1 {
				idx = (seg.l + seg.r) / 2
			} else {
				idx = (seg.l + seg.r - 1) / 2
			}
			if l := newSegment(seg.l, idx-1); l != nil {
				heap.Push(&pq, l)
			}
			if r := newSegment(idx+1, seg.r); r != nil {
				heap.Push(&pq, r)
			}
			ans[idx-1] = cnt
			cnt++
		}
		fmt.Fprintln(writer, strings.Trim(fmt.Sprint(ans), "[]"))
	}
}

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

package main

import (
	"bufio"
	"container/heap"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

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

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

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

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

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

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

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

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

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

var (
	t int
	n int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()

		solve()
	}
}

func solve() {
	A := make([]int, n)

	pq := NewSegmentPQ()
	pq.push(&Segment{
		left: 0, right: n - 1, length: n,
	})

	i := 1
	for pq.Len() > 0 {
		pop := pq.pop()

		mid := (pop.left + pop.right) / 2
		A[mid] = i
		i++

		if (mid-1)-pop.left+1 > 0 {
			pq.push(&Segment{left: pop.left, right: mid - 1, length: (mid - 1) - pop.left + 1})
		}
		if pop.right-(mid+1)+1 > 0 {
			pq.push(&Segment{left: mid + 1, right: pop.right, length: pop.right - (mid + 1) + 1})
		}
	}

	fmt.Println(PrintIntsLine(A...))
}

type Segment struct {
	pri         int
	left, right int
	length      int
}
type SegmentPQ []*Segment

// Interfaces
func NewSegmentPQ() *SegmentPQ {
	temp := make(SegmentPQ, 0)
	pq := &temp
	heap.Init(pq)

	return pq
}
func (pq *SegmentPQ) push(target *Segment) {
	heap.Push(pq, target)
}
func (pq *SegmentPQ) pop() *Segment {
	return heap.Pop(pq).(*Segment)
}

func (pq SegmentPQ) Len() int { return len(pq) }
func (pq SegmentPQ) Less(i, j int) bool {
	if pq[i].length > pq[j].length {
		return true
	} else if pq[i].length < pq[j].length {
		return false
	} else {
		return pq[i].left < pq[j].left
	}
} // <: ASC, >: DESC
func (pq SegmentPQ) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *SegmentPQ) Push(x interface{}) {
	item := x.(*Segment)
	*pq = append(*pq, item)
}
func (pq *SegmentPQ) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"os"
)

type pair struct{ l, i int }
type hp []pair

func (h hp) Len() int            { return len(h) }
func (h hp) Less(i, j int) bool  { a, b := h[i], h[j]; return a.l > b.l || a.l == b.l && a.i < b.i }
func (h hp) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *hp) Push(v interface{}) { *h = append(*h, v.(pair)) }
func (h *hp) Pop() interface{}   { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v }
func (h *hp) push(v pair)        { heap.Push(h, v) }
func (h *hp) pop() pair          { return heap.Pop(h).(pair) }

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		ans := make([]interface{}, n)
		h := hp{{n - 1, 0}}
		for v := 1; v <= n; v++ {
			p := h.pop()
			l, i := p.l>>1, p.i
			ans[i+l] = v
			if l > 0 {
				h.push(pair{l - 1, i})
			}
			if p.l > l {
				h.push(pair{p.l - l - 1, i + l + 1})
			}
		}
		Fprintln(out, ans...)
	}
}

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		a := make([]int, n+1)
		val := 1
		hp := NewMaxHeap([]node{{1, n, n}})
		for len(hp.a) > 0 {
			poll := hp.Poll()
			mdl := 0

			if (poll.r-poll.l+1)%2 == 0 {
				mdl = (poll.l + poll.r - 1) / 2
			} else {
				mdl = (poll.l + poll.r) / 2
			}
			a[mdl] = val
			val++

			// put back in heap
			if poll.l < mdl && poll.l > 0 {
				leftNode := node{
					l: poll.l,
					r: mdl - 1,
				}
				leftNode.size = leftNode.r - leftNode.l + 1
				hp.Offer(leftNode)
			}
			if poll.r > mdl && poll.r <= n {
				rightNode := node{
					l: mdl + 1,
					r: poll.r,
				}
				rightNode.size = rightNode.r - rightNode.l + 1
				hp.Offer(rightNode)
			}
		}

		P(SArr(a[1:]))
	}

	close(O)
	oWg.Wait()
}

type node struct {
	l, r, size int
}

func NewMaxHeap(arg []node) heap {
	heap := heap{}
	heap.a = arg
	heap.cmp = func(i, j int, a []node) bool {
		if !(i >= 0 && i < len(a) && j >= 0 && j < len(a)) {
			return false
		}
		if heap.a[i].size > heap.a[j].size {
			return true
		} else if heap.a[i].size < heap.a[j].size {
			return false
		} else {
			return i <= j
		}
	}
	if len(arg) > 0 {
		heap.BuildHeap()
	}
	return heap
}

type heap struct {
	a   []node
	cmp func(i, j int, a []node) bool
}

func (h *heap) heapify(i int) {
	largest := i
	l := i<<1 + 1
	r := i<<1 + 2

	if l >= 0 && l < len(h.a) &&
		(h.a[l].size > h.a[largest].size ||
		(h.a[l].size == h.a[largest].size && h.a[l].l < h.a[largest].l)) { //h.a[parent].size > h.a[i].size || (h.a[parent].size >= h.a[i].size && h.a[parent].l <= h.a[i].l)
		largest = l
	}
	if r >= 0 && r < len(h.a) &&
		(h.a[r].size > h.a[largest].size ||
			(h.a[r].size == h.a[largest].size && h.a[r].l < h.a[largest].l)) { //h.a[parent].size > h.a[i].size || (h.a[parent].size >= h.a[i].size && h.a[parent].l <= h.a[i].l)
		largest = r
	}
	if largest != i {
		h.a[largest], h.a[i] = h.a[i], h.a[largest]
		h.heapify(largest)
	}
}

// build max heap
func (h *heap) BuildHeap() {
	for i := (len(h.a) / 2) - 1; i >= 0; i-- {
		h.heapify(i)
	}
}

func (h *heap) Poll() node {
	if len(h.a) == 0 {
		return node{}
	}
	ele := h.a[0]
	h.a[0] = h.a[len(h.a)-1]
	h.a = h.a[:len(h.a)-1]
	h.heapify(0)
	return ele
}

func (h *heap) Offer(key node) {
	h.a = append(h.a, key)

	for i := len(h.a) - 1; i >= 0; {
		parent := (i - 1) / 2
		if h.a[parent].size > h.a[i].size || (h.a[parent].size >= h.a[i].size && h.a[parent].l <= h.a[i].l) {
			return
		}
		h.a[parent], h.a[i] = h.a[i], h.a[parent]
		i = parent
	}
}

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

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

func init() {
	P = fmt.Println

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

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

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
	"container/heap"
	"os"
	"bufio"
	"strings"
)

type Interval struct {l, r, sz int }
type priority_queue []*Interval

func Segment(l, r int) *Interval {
	if r - l >= 0 {return &Interval{l, r, r - l + 1} }
	return nil
}

func (pq priority_queue) Len() int { return len(pq) }

func (pq priority_queue) Less(i, j int) bool {
	return pq[i].sz > pq[j].sz || (pq[i].sz == pq[j].sz && pq[i].l < pq[j].l)
}

func (pq priority_queue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priority_queue) Push(x interface{}){
	*pq = append(*pq, x.(*Interval))
}

func (pq *priority_queue) Pop() interface{}{
	old := *pq
	s := old[len(old) - 1]
	old[len(old) - 1] = nil
	*pq = old[: len(old)-1]
	return s
}

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

	var tc int
	fmt.Fscan(reader, &tc)
	for ;tc > 0; tc-- {
		var n int
		fmt.Fscan(reader, &n)
		var pq priority_queue
		heap.Init(&pq)
		heap.Push(&pq, Segment(1, n))
		ans := make([]int, n)
		cnt := 1
		for pq.Len() > 0 {
			tp := heap.Pop(&pq)
			seg := tp.(*Interval)
			len := (seg.r - seg.l + 1)
			var i int
			if len % 2 == 1 {
				i = (seg.l + seg.r) / 2
			} else {
				i = (seg.l + seg.r - 1) / 2
			}
			if l := Segment(seg.l, i - 1); l != nil { heap.Push(&pq, l) }
			if r := Segment(i + 1, seg.r); r != nil { heap.Push(&pq, r) }
			ans[i - 1] = cnt
			cnt++
		}
		fmt.Fprintln(writer, strings.Trim(fmt.Sprint(ans), "[]"))
	}
}

package main

import (
	"bufio"
	"os"
	"strconv"

	"fmt"
	"container/heap"
	"strings"
)

type Item struct {
	left, right int
	index int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	if (pq[i].right - pq[i].left) > (pq[j].right - pq[j].left) {
		return true
	} else if (pq[i].right - pq[i].left) == (pq[j].right - pq[j].left) {
		return pq[i].left < pq[j].left
	} else {
		return false
	}
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		al := scanner.Text()

		a, err := strconv.Atoi(al)

		if err != nil {
			panic(err)
		}

		ans := solve4(a)

		fmt.Print(strings.Trim(fmt.Sprintf("%v", ans), "[]"))

		fmt.Println()
	}
}

func solve4(a int) []int {
	counter := 1
	arr := make([]int, a + 1)

	var pq PriorityQueue

	pq = append(pq, &Item{left: 1, right: a})

	heap.Init(&pq)

	for ;len(pq) > 0; {

		item := heap.Pop(&pq)

		process(item.(*Item), &counter, &arr, &pq)
	}

	var result []int

	for i := 1; i < len(arr); i++ {
		result = append(result, arr[i])
	}

	return result
}

func process(item *Item, counter *int, arr *[]int, queue *PriorityQueue)  {
	a := item.left
	b := item.right

	if a == b {
		(*arr)[a] = *counter

		*counter ++

		return
	} else if a > b {
		return
	}

	var mid int

	if (b - a + 1) % 2 == 1 {
		mid = (b + a)/2
	} else {
		mid = (b + a - 1)/2
	}

	(*arr)[mid] = *counter

	*counter ++

	heap.Push(queue, &Item{left: mid + 1, right: b})
	heap.Push(queue, &Item{left: a, right: mid - 1})
}

package main

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

type Indexes []int

type ByLen []Indexes

func (a ByLen) Len() int           { return len(a) }
func (a ByLen) Less(i, j int) bool {

	if (a[i][1] - a[i][0] + 1) > (a[j][1] - a[j][0] + 1) {
		return true
	} else if (a[i][1] - a[i][0] + 1) == (a[j][1] - a[j][0] + 1) {
		return a[i][0] < a[j][0]
	}
	return false
}
func (a ByLen) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		al := scanner.Text()

		a, err := strconv.Atoi(al)

		if err != nil {
			panic(err)
		}

		ans := solve4(a)

		fmt.Print(strings.Trim(fmt.Sprintf("%v", ans), "[]"))

		fmt.Println()
	}
}

func solve4(a int) []int {
	counter := 1

	result := make([]int, a)

	var indexes []Indexes
	indexes = append(indexes, []int{0, a - 1})

	for ;len(indexes) > 0; {
		sort.Sort(ByLen(indexes))

		l := len(indexes)

		for i:=0; i < l; i++ {
			left := indexes[0][0]
			right := indexes[0][1]

			indexes = indexes[1 :]

			if left > right {
				continue
			}

			var mid int

			if (right - left + 1) % 2 == 1 {
				mid = (right + left)/2
			} else {
				mid = (right + left - 1)/2
			}

			result[mid] = counter

			counter ++

			if left == right {
				continue
			}

			indexes = append(indexes, []int {mid + 1, right})
			indexes = append(indexes, []int {left, mid - 1})
		}
	}

	return result
}

package main

import (
	"bufio"
	"os"
	"strconv"

	"fmt"
)

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		al := scanner.Text()

		a, err := strconv.Atoi(al)

		if err != nil {
			panic(err)
		}

		ans := solve4(a)

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

		fmt.Println()
	}
}

func solve4(a int) []int {
	counter := 1
	arr := make([]int, a + 1)

	var queue [][]int

	queue = append(queue, []int {1, a})

	for ;len(queue) > 0; {

		item := queue[0]

		queue = queue[1 : ]

		process(item, &counter, &arr, &queue)
	}

	var result []int

	for i := 1; i < len(arr); i++ {
		result = append(result, arr[i])
	}

	return result
}

func process(item []int, counter *int, arr *[]int, queue *[][]int)  {
	a := item[0]
	b := item[1]

	if a == b {
		(*arr)[a] = *counter

		*counter ++

		return
	} else if a > b {
		return
	}

	var mid int

	if (b - a + 1) % 2 == 1 {
		mid = (b + a)/2
	} else {
		mid = (b + a - 1)/2
	}

	(*arr)[mid] = *counter

	*counter ++

	if b - mid > mid - a {
		*queue = append(*queue, []int {mid + 1, b})
		*queue = append(*queue, []int {a, mid - 1})

	} else {
		*queue = append(*queue, []int {a, mid - 1})
		*queue = append(*queue, []int {mid + 1, b})
	}
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strings"
)

type segment struct {
	l, r, len int
}

func newSegment(l, r int) *segment {
	len := r - l + 1
	if len > 0 {
		return &segment{l, r, len}
	}
	return nil
}

type PriorityQueue []*segment

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].len > pq[j].len || (pq[i].len == pq[j].len && pq[i].l < pq[i].l)
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	s := x.(*segment)
	*pq = append(*pq, s)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	s := old[n-1]
	old[n-1] = nil
	*pq = old[0 : n-1]
	return s
}

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

	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		var pq PriorityQueue
		heap.Init(&pq)
		heap.Push(&pq, newSegment(1, n))

		ans := make([]int, n)
		cnt := 1
		for pq.Len() > 0 {
			e := heap.Pop(&pq)
			seg := e.(*segment)
			var idx int
			if (seg.r-seg.l+1)%2 == 1 {
				idx = (seg.l + seg.r) / 2
			} else {
				idx = (seg.l + seg.r - 1) / 2
			}
			if l := newSegment(seg.l, idx-1); l != nil {
				heap.Push(&pq, l)
			}
			if r := newSegment(idx+1, seg.r); r != nil {
				heap.Push(&pq, r)
			}
			ans[idx-1] = cnt
			cnt++
		}
		fmt.Fprintln(writer, strings.Trim(fmt.Sprint(ans), "[]"))
	}
}


package main

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

var (
	t, n int
	a, b []int
)

func check(k int) bool {
	step := 0
	copy(b, a)

	for i := 0; i < n; i++ {
		if b[i] <= k-step {
			for j := n - 1; j > i; j-- {
				b[j-step] += k - step
				break
			}
			step++
		}
	}

	if step < k {
		return false
	}
	return true
}

func main() {
	defer flush()
	scan(&t)
	for ; t != 0; t-- {
		scan(&n)
		a = make([]int, n)
		b = make([]int, n)
		for i := 0; i < n; i++ {
			scan(&a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		l, r := 0, n
		for l < r {
			mid := (l + r + 1) / 2
			if check(mid) {
				l = mid
			} else {
				r = mid - 1
			}
		}
		println(l)
	}
}

var (
	ioR *bufio.Reader
	ioW *bufio.Writer
)

func init() {
	ioR = bufio.NewReader(os.Stdin)
	ioW = bufio.NewWriter(os.Stdout)
}

func scan(a ...any) {
	fmt.Fscan(ioR, a...)
}

func println(a ...any) {
	fmt.Fprintln(ioW, a...)
}

func flush() {
	ioW.Flush()
}

package main

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

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

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

		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n+1)

		for i := 0; i < n; i++ {
			var temp int
			fmt.Fscan(r, &temp)
			a[temp]++
		}

		var k int
		for i := 1; i <= n; i++ {
			pos := true
			act := 0
			ref := 0

			for j := 1; j <= i; j++ {
				if j == 1 {
					ref += i + 1 - j
				} else {
					ref++
				}
				act += a[j]
				if act < ref { pos = false }
			}

			if !pos { break }
			k = i
		}

		fmt.Fprintln(w, k)
	}

}

package main

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

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

func debug(a ...interface{}) {
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func solve() {
	var n int
	scanf("%d\n", &n)
	a := make([]int, n)
	for i:=0; i<n; i++ {
		scanf("%d ", &a[i])
	}
	scanf("\n")

	// debug("n", n)
	// debug("a", a)

	var res int = 0
	beg, fin := 1, n
	for beg <= fin {
		k := (beg + fin) / 2
		// debug("k", k)
		cnt := make([]int, 2*n+10)
		for i:=0; i<n; i++ {
			cnt[a[i]]++
		}
		aliceWins := true
		origK := k
		for k > 0 {
			num := k
			for num >= 1 {
				if cnt[num] > 0 {
					break
				}
				num--
			}
			if num == 0 {
				aliceWins = false
				break
			}
			cnt[num]--

			for incNum:=1; incNum<=k; incNum++ {
				if cnt[incNum] > 0 {
					cnt[incNum]--
					cnt[incNum + k]++
					break
				}
			}

			k--
		}

		if aliceWins {
			res = origK
			beg = origK + 1
			continue
		}
		fin = origK - 1
	}
	printf("%d\n", res)
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		solve()
	}
}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1

	// ws := bufio.NewWriter(os.Stdout)
	t := fastScan()

	for i := 0; i < t; i++ {
		lst := []int{}
		n := fastScan()
		var x int
		for ele := 0; ele < n; ele++ {
			x = fastScan()
			lst = append(lst, x)
		}
		sort.Ints(lst)
		s := 0
		e := n
		ans := 0
		for s <= e {
			mid := (s + e) / 2
			if possible(mid, lst) {
				ans = mid
				s = mid + 1
			} else {
				e = mid - 1
			}
		}

		fmt.Println(ans)

	}

	// ws.Flush()

}

func possible(k int, lst []int) bool {
	f := 0
	l := len(lst) - 1
	for s := 1; s < k+1; s++ {
		temp := (k - s + 1)
		for l >= f {
			if lst[l] <= temp {
				break
			}
			l--
		}
		if l < f {
			return false
		}
		l--
		if l >= f {
			f += 1
		}
	}
	return true
}

package main

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

var (
	t, n int
	a, b []int
)

func check(k int) bool {
	step := 0
	copy(b, a)

	for i := 0; i < n; i++ {
		if b[i] <= k-step {
			for j := i + 1; j < n; j++ {
				if b[j] <= k-step-1 {
					b[j] += k - step
					break
				}
			}
			step++
		}
	}
	if step < k {
		return false
	}
	return true
}

func main() {
	defer flush()
	scan(&t)
	for ; t != 0; t-- {
		scan(&n)
		a = make([]int, n)
		b = make([]int, n)
		for i := 0; i < n; i++ {
			scan(&a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		l, r := 0, n
		for l < r {
			mid := (l + r + 1) / 2
			if check(mid) {
				l = mid
			} else {
				r = mid - 1
			}
		}
		println(l)
	}
}

var (
	ioR *bufio.Reader
	ioW *bufio.Writer
)

func init() {
	ioR = bufio.NewReader(os.Stdin)
	ioW = bufio.NewWriter(os.Stdout)
}

func scan(a ...any) {
	fmt.Fscan(ioR, a...)
}

func println(a ...any) {
	fmt.Fprintln(ioW, a...)
}

func flush() {
	ioW.Flush()
}

package main

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

var (
	t, n int
	a, b []int
)

func check(k int) bool {
	step := 1
	flag := true
	copy(b, a)

	for i := 0; i < n; i++ {
		if b[i] <= k-step+1 {
			flag = false
			for j := i + 1; j < n; j++ {
				if b[j] < k-step {
					b[j] += k - step + 1
					break
				}
			}
			step++
		}
	}
	if flag || step < k {
		return false
	}
	return true
}

func main() {
	defer flush()
	scan(&t)
	for ; t != 0; t-- {
		scan(&n)
		a = make([]int, n)
		b = make([]int, n)
		for i := 0; i < n; i++ {
			scan(&a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		l, r := 0, n
		for l < r {
			mid := (l + r + 1) / 2
			if check(mid) {
				l = mid
			} else {
				r = mid - 1
			}
		}
		println(l)
	}
}

var (
	ioR *bufio.Reader
	ioW *bufio.Writer
)

func init() {
	ioR = bufio.NewReader(os.Stdin)
	ioW = bufio.NewWriter(os.Stdout)
}

func scan(a ...any) {
	fmt.Fscan(ioR, a...)
}

func println(a ...any) {
	fmt.Fprintln(ioW, a...)
}

func flush() {
	ioW.Flush()
}

package main

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

var (
	t, n int
	a, b []int
)

func check(k int) bool {
	step := 1
	flag := true
	copy(b, a)
	for i := 0; i < n; i++ {
		if b[i] <= k-step+1 {
			flag = false
			for j := i + 1; j < n; j++ {
				if b[j] < k-step {
					b[j] += k - step + 1
				}
			}
			step++
		}
	}
	if flag || step < k {
		return false
	}
	return true
}

func main() {
	defer flush()
	scan(&t)
	for ; t != 0; t-- {
		scan(&n)
		a = make([]int, n)
		b = make([]int, n)
		for i := 0; i < n; i++ {
			scan(&a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		l, r := 0, n
		for l < r {
			mid := (l + r + 1) / 2
			if check(mid) {
				l = mid
			} else {
				r = mid - 1
			}
		}
		println(l)
	}
}

var (
	ioR *bufio.Reader
	ioW *bufio.Writer
)

func init() {
	ioR = bufio.NewReader(os.Stdin)
	ioW = bufio.NewWriter(os.Stdout)
}

func scan(a ...any) {
	fmt.Fscan(ioR, a...)
}

func println(a ...any) {
	fmt.Fprintln(ioW, a...)
}

func flush() {
	ioW.Flush()
}

package main

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

var (
	t, n int
	a    []int
)

func main() {
	defer flush()
	scan(&t)
	for ; t != 0; t-- {
		scan(&n)
		a = make([]int, n+1)
		for i := 1; i <= n; i++ {
			scan(&a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] <= a[j]
		})
		cnt := 0
		for i := 1; i <= n; i++ {
			if a[i] != a[i-1] && cnt+1 >= a[i] {
				cnt++
			}
		}
		println(cnt)
	}
}

//

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
}

func scan(a ...any) {
	fmt.Fscan(r, a...)
}

func println(a ...any) {
	fmt.Fprintln(w, a...)
}

func flush() {
	w.Flush()
}

package main

import "fmt"

func main() {
	fmt.Println("hello world")
}

package main

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

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

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

		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n+1)

		for i := 0; i < n; i++ {
			var temp int
			fmt.Fscan(r, &temp)
			a[temp]++
		}

		var k int
		for i := 1; i <= n; i++ {
			pos := true
			act := 0

			for j := 1; j <= i; j++ {
				ref := i + 1 -j
				act += a[j]
				if act < ref { pos = false }
			}

			if !pos { break }
			k = i
		}

		fmt.Fprintln(w, k)
	}

}


package main

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

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

	var t, n int
	_arr := make([]int, 2e3+10)
	ans := make([]int, 2e3+10)
	for Fscan(in, &t); t > 0; t-- {
		ans = ans[:0]
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fscan(in, &_arr[i])
		}
		arr := _arr[:n]
		for next := n; next > 1; next-- {
			var idx int
			for idx = 0; idx < next; idx++ {
				if arr[idx] == next {
					break
				}
			}
			ans = append(ans, (idx+1)%next)
			ri := next - idx - 1
			if ri == 0 {
				continue
			}
			temp := make([]int, next)
			for i := 0; i < next; i++ {
				temp[(i+ri)%next] = arr[i]
			}
			arr = temp
		}
		Fprint(out, 0, " ")
		for i := len(ans) - 1; i > 0; i-- {
			Fprint(out, ans[i], " ")
		}
		Fprint(out, ans[0], "\n")
	}
}

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

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

const (
	INIT = -1
)

var (
	a []int
)

// [l,r)
func reverse(l, r int) {
	r--
	for l < r {
		a[l] = a[l] ^ a[r]
		a[r] = a[l] ^ a[r]
		a[l] = a[l] ^ a[r]

		l++
		r--
	}
}

// [l,r)
func rotate(r, n int) {
	reverse(0, r)
	reverse(r, n)
	reverse(0, n)
}

func solve(n int) []int {
	ans := []int{}
	for i := n - 1; i >= 0; i-- {
		// fmt.Printf("i %d a %v\n", i, a)

		want := i + 1
		if a[i] == want {
			ans = append(ans, 0)
			continue
		}
		pos := INIT
		for j := 0; j < i; j++ {
			if a[j] == want {
				pos = j
				break
			}
		}
		check(pos != INIT)
		rotate(pos+1, i+1)
		ans = append(ans, pos+1)
	}
	return ans
}

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

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

	for ; tc > 0; tc-- {
		var n int
		fmt.Fscan(r, &n)
		a = make([]int, n)

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

		ans := solve(n)
		for i := n - 1; i >= 0; i-- {
			fmt.Fprintf(w, "%d ", ans[i])
		}
		fmt.Fprintln(w)

	}
}

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

const (
	INIT = -1
)

var (
	a []int
)

// [l,r)
func reverse(l, r int) {
	r--
	for l < r {
		a[l] = a[l] ^ a[r]
		a[r] = a[l] ^ a[r]
		a[l] = a[l] ^ a[r]

		l++
		r--
	}
}

// [l,r)
func rotate(r, n int) {
	reverse(0, r)
	reverse(r, n)
	reverse(0, n)
}

func solve(n int) {
	ans := []int{}
	for i := n - 1; i >= 0; i-- {
		// fmt.Printf("i %d a %v\n", i, a)

		want := i + 1
		if a[i] == want {
			ans = append(ans, 0)
			continue
		}
		pos := INIT
		for j := 0; j < i; j++ {
			if a[j] == want {
				pos = j
				break
			}
		}
		check(pos != INIT)
		rotate(pos+1, i+1)
		ans = append(ans, pos+1)
	}

	for i := n - 1; i >= 0; i-- {
		fmt.Printf("%d ", ans[i])
	}
	fmt.Println()
}

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

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

	for ; tc > 0; tc-- {
		var n int
		fmt.Fscan(r, &n)
		a = make([]int, n)

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

		solve(n)

	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n+1)
		mmid := make(map[int]int)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &arr[i])
			mmid[arr[i]] = i
		}
		ans := make([]int, n+1)
		for i := n; i >= 1; i-- {

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

package main

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

func CF1650DFindTarget(a []int, t int) int {
	for i := 0; i < len(a); i++ {
		if a[i] == t {
			return i
		}
	}
	return -1
}

func solveCF1650DCase(in io.Reader, out io.Writer) {
	var n int
	fmt.Fscan(in, &n)

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

	countCache := make([]int, n)
	for i := 0; i < n; i++ {
		target := n - i
		idx := CF1650DFindTarget(a, target)
		numRotated := (idx + 1) % target
		countCache[n-1-i] = numRotated
		a = append(a[numRotated:(n-i)], a[:numRotated]...)
	}

	for i := 0; i < len(countCache); i++ {
		fmt.Fprintf(out, "%d ", countCache[i])
	}
	fmt.Fprintln(out)
}

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

	var cases int
	fmt.Fscan(in, &cases)
	for cc := 0; cc < cases; cc++ {
		solveCF1650DCase(in, out)
	}
}

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

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n int
		_, _ = fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		ans := make([]int, n)
		for i := n; i > 0; i-- {
			for j, num := range a {
				if num == i {
					ans[i-1] = (j + 1) % i
					a = append(a[j+1:], a[:j]...)
					break
				}
			}
			//fmt.Println(a, ans)
		}
		//fmt.Fprintln(out, ans)
		for i := 0; i < n; i++ {
			fmt.Fprint(out, ans[i])
			if i < n-1 {
				fmt.Fprint(out, " ")
			} else {
				fmt.Fprintln(out)
			}
		}
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main
import ."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	T,n:=0,0
	for Scan(&T); T > 0; T-- {
		Scan(&n)
		a := make([]int, n)
		for i := range a {Scan(&a[i])}
		d := make([]interface{}, n)
		for i := n; i > 0; i-- {
			for j, v := range a {
				if v == i {
					d[i-1] = (j + 1) % i
					a = append(a[j+1:], a[:j]...)
					break
				}
			}
		}
		Println(d...)
	}
}

package main

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

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

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

	c := 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		n := 0
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		res := make([]int, n)
		for i := n - 1; i >= 0; i-- {
			for arr[i] != i+1 {
				t := arr[0]
				last := arr[i]
				for j := i - 1; j >= 0; j-- {
					tmp := arr[j]
					arr[j] = last
					last = tmp
				}
				arr[i] = t
				res[i]++
			}
		}
		for _, v := range res {
			fmt.Fprint(out, v, " ")
		}
		out.Flush()
		fmt.Println()
	}
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	shift := func(a []int, cnt int) {
		b := make([]int, len(a))

		for i, num := range a {
			j := i - cnt
			if j < 0 {
				j += len(a)
			}

			b[j] = num
		}

		for i, num := range b {
			a[i] = num
		}
	}

	ans := make([]int, 0)

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

		cnt := j + 1

		shift(a[:i+1], cnt)

		ans = append(ans, cnt%(i+1))
	}

	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintf(writer, "%d ", ans[i])
	}
	fmt.Fprintln(writer)
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	idx := 0
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx]
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n := cin.NextInt()
	a := cin.NextInts(n)
	ans := make([]int, n)
	for i := n - 1; i >= 0; i-- {
		var xidx int
		for j := 0; j < i+1; j++ {
			if a[j] == i+1 {
				xidx = j
				break
			}
		}
		ans[i] = (xidx + 1) % (i + 1)
		a = append(a[xidx+1:i+1], a[:xidx+1]...)
	}
	for i := range ans {
		cout.Print(ans[i])
		if i < n-1 {
			cout.Print(" ")
		}
	}
	cout.Println()
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker


package main

import (
    "fmt"
    )

func main() {
    var l, p, q int
    fmt.Scan(&l, &p, &q)

    fmt.Println(float32(l * p) / float32(p+q))
}

package main

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	l, p, q := nextFloat(), nextFloat(), nextFloat()

	println(l / (p + q) * p)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }


package main

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

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 debug(a ...interface{}) {
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func solve() {
	var n int
	scanf("%d\n", &n)
	var s string
	scanf("%s", &s)

	var res, newS, first, second strings.Builder
	i := 0
	for i < n {
		if s[i] == '1' {
			break
		}
		i++
	}

	for i < n {
		newS.WriteRune(rune(s[i]))
		i++
	}

	if newS.Len() == 0 {
		printf("0")
		return
	}

	i = 0
	for i < newS.Len() {
		if newS.String()[i] == '0' {
			break
		}
		first.WriteRune(rune(newS.String()[i]))
		i++
	}

	j := i
	for j < newS.Len() {
		second.WriteRune(rune(newS.String()[j]))
		j++
	}

	if second.Len() == 0 {
		printf("%s", first.String())
		return
	}

	rem := second.Len()
	res = second
	for j:=0; j<i; j++ {
		var newSecond strings.Builder
		for k:=0; k<rem; k++ {
			if second.String()[k] == '1' {
				newSecond.WriteRune(rune('1'))
				continue
			}
			newSecond.WriteRune(rune(newS.String()[j+k]))
		}
		if strings.Compare(newSecond.String(), res.String()) == 1 {
			res = newSecond
		}
	}

	first.WriteString(res.String())
	printf("%s", first.String())
}

func main() {
	defer writer.Flush()

	solve()
}

package main

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

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

func max(i, j string) string {
    for k := range i {
        if i[k] != j[k] {
            if i[k] == '1' {
                return i
            } else {
                return j
            }
        }
    }
    return i
}

func main() {
    var n int
    var s string
    Fscan(in, &n, &s)

    first_one := strings.Index(s, "1")

    if first_one == -1 {
        Fprintln(out, "0")
    } else {
        a := s[first_one : n]
        ans := a

        first_zero := strings.Index(a, "0")
        for i := 0; i < first_zero; i++ {
            res := []byte(a)
            for k, j := first_zero, i; k < len(a); k++ {
                if res[k] == '0' && a[j] == '1' {
                    res[k] = '1'
                }
                j++
            }

            ans = max(string(res), ans)
        }

        Fprintln(out, ans)
    }

    out.Flush()
}

package main

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

var r *bufio.Reader
var w *bufio.Writer
func init(){
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
}
func main(){
	defer w.Flush()
	var n int
	var s []byte
	fmt.Fscan(r, &n,&s)
	sn :=make([]byte, len(s))
	copy(sn, s)
	var bits big.Int
	cur:=0
	for i:=len(s)-1;i>=0;i--{
		if s[i]==49{
			bits.SetBit(&bits, cur, 1)
		}
		cur++;
	}
	var old,ans big.Int
	old.Set(&bits)
	ans.Set(&bits)
	iter:=0
	for old.Sign()!=0 && iter<1000{
		iter++
		var temp big.Int
		temp.Set(&bits)
		temp.Or(&bits, &old)
		if ans.Cmp(&temp)==-1{
			ans.Set(&temp)
		}
		old.Div(&old, big.NewInt(2))
	}
	fmt.Println(ans.Text(2))
}

package main

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

func maxl(a, b []byte) []byte {
	for i := range a {
		if a[i] < b[i] { return b }
		if b[i] < a[i] { break }
	}
	return a
}

func or(a, b []byte) []byte {
	c := make([]byte, len(a))
	i := 0

	for i < len(a) {
		ai := len(a) - 1 - i
		if i < len(b) {
			bi := len(b) - 1 - i
			c[ai] = a[ai] | b[bi]
		} else {
			c[ai] = a[ai]
		}
		i++
	}

	return c
}

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

	var n int
	var a []byte

	fmt.Fscan(r, &n, &a)
	for i := range a { a[i] -= '0' }

	var i, j int
	for i < n && a[i] == 0 { i++ }
	for j = i; j < n && a[j] == 1; j++ {}

	l := n - j

	if l > 0 {
		res := a[i:]
		for k := 0; k + l < n; k++ {
			nres := or(a[i:], a[k:k+l])
			res = maxl(res, nres)
		}

		for _, v := range res { fmt.Fprintf(w, "%d", v) }
		fmt.Fprintln(w, "")
	} else {
		fmt.Fprintln(w, "0")
	}
}

package main

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

func maxl(a, b []byte) []byte {
	for i := range a {
		if a[i] < b[i] {
			return b
		}
		if b[i] < a[i] {
			return a
		}
	}
	return a
}

func or(a, b []byte) []byte {
	c := make([]byte, len(a))
	i := 0

	for i < len(a) {
		if i < len(b) {
			c[len(a) - 1 - i] = a[len(a) - 1 - i] | b[len(b) - 1 - i]
		} else {
			c[len(a) -1 - i] = a[len(a) - 1 - i]
		}
		i++
	}

	return c
}

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

	var n int
	var a []byte

	fmt.Fscan(r, &n, &a)
	for i := range a { a[i] -= '0' }

	var i, j int
	for i < n && a[i] == 0 { i++ }
	for j = i; j < n && a[j] == 1; j++ {}

	l := n - j

	if l > 0 {
		res := a[i:]
		// fmt.Fprintf(w, "1 &&& i:%d j:%d l:%d\n", i, j, l)
		// fmt.Fprintln(w, "1 &&& res: ", res)
		for k := 0; k + l < n; k++ {
			nres := or(a[i:], a[k:k+l])
			res = maxl(res, nres)
			// fmt.Fprintln(w, "2 &&& cmp: ", a[k:k+l])
			// fmt.Fprintln(w, "2 &&& nres: ", nres)
			// fmt.Fprintln(w, "2 &&& res: ", res)
		}

		for _, v := range res { fmt.Fprintf(w, "%d", v) }
		fmt.Fprintln(w, "")
	} else {
		fmt.Fprintln(w, "0")
	}
}

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...) }

type BestAns struct {
	withLid    int64
	withoutLid int64
}

var MOD int64 = 1000*1000*1000 + 7

func reverse(a []bool) []bool {
	res := make([]bool, len(a), len(a))
	for i := 0; i < len(a); i++ {
		res[len(a)-i-1] = a[i]
	}
	return res
}

func or(a, b []bool) []bool {
	if len(a) < len(b) {
		a, b = b, a
	}

	a = reverse(a)
	b = reverse(b)

	ans := make([]bool, len(a), len(a))

	for i := 0; i < len(a); i++ {
		if i >= len(b) {
			ans[i] = a[i]
		} else {
			ans[i] = a[i] || b[i]
		}
	}
	return reverse(ans)
}

func sor(a, b string) string {

	na := make([]bool, len(a), len(a))
	nb := make([]bool, len(b), len(b))

	for i := 0; i < len(a); i++ {
		if a[i] == '1' {
			na[i] = true
		}
	}

	for i := 0; i < len(b); i++ {
		if b[i] == '1' {
			nb[i] = true
		}
	}

	orres := or(na, nb)

	ans := make([]rune, len(orres), len(orres))

	for i := 0; i < len(orres); i++ {
		if orres[i] {
			ans[i] = '1'
		} else {
			ans[i] = '0'
		}
	}

	return string(ans)
}

func main() {
	defer writer.Flush()

	var n int
	var s string

	scanf("%d\n", &n)
	scanf("%s\n", &s)

	firstOneIndex := n

	for i := 0; i < n; i++ {
		if s[i] == '1' {
			firstOneIndex = i
			break
		}
	}
	if firstOneIndex == n {
		printf("%s\n", "0")
		return
	}

	firstInterval := s[firstOneIndex:]

	cur := firstOneIndex
	for s[cur] == '1' {
		cur++
	}

	ans := firstInterval
	for i := firstOneIndex; i < cur; i++ {
		if s[i] == '0' {
			break
		}
		secondInterval := s[i : i+n-cur]
		candidate := sor(firstInterval, secondInterval)
		if candidate > ans {
			ans = candidate
		}
	}

	first := 0
	for ans[first] == '0' {
		first++
	}
	printf("%s\n", ans[first:])
}

package main

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

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

func max(i, j string) string {
    for k := range i {
        if i[k] != j[k] {
            if i[k] == '1' {
                return i
            } else {
                return j
            }
        }
    }
    return i
}

func main() {
    var n int
    var s string
    Fscan(in, &n, &s)

    first_one := strings.Index(s, "1")

    if first_one == -1 {
        Fprintln(out, "0")
    } else {
        a := s[first_one : n]
        ans := a

        first_zero := strings.Index(a, "0")
        for i := 0; i < first_zero; i++ {
            res := []byte(a)
            for k, j := first_zero, 0; k < len(a); k++ {
                if res[k] == '0' && a[j] == '1' {
                    res[k] = '1'
                }
                j++
            }

            ans = max(string(res), ans)
        }

        Fprintln(out, ans)
    }

    out.Flush()
}

package main

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

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

func max(i, j string) string {
    for k := range i {
        if i[k] != j[k] {
            if i[k] == '1' {
                return i
            } else {
                return j
            }
        }
    }
    return i
}

func main() {
    var n int
    var s string
    Fscan(in, &n, &s)

    first_one := strings.Index(s, "1")

    if first_one == -1 {
        Fprintln(out, "0")
    } else {
        a := s[first_one : n]
        ans := a

        first_zero := strings.Index(a, "0")
        for i := 0; i < first_zero; i++ {
            res := []byte(a)
            for k, j := i, 0; k < len(a); k++ {
                if res[k] == '0' && a[j] == '1' {
                    res[k] = '1'
                }
                j++
            }

            ans = max(string(res), ans)
        }

        Fprintln(out, ans)
    }

    out.Flush()
}

package main

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

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...) }

type BestAns struct {
	withLid    int64
	withoutLid int64
}

var MOD int64 = 1000*1000*1000 + 7

func reverse(a []bool) []bool {
	res := make([]bool, len(a), len(a))
	for i := 0; i < len(a); i++ {
		res[len(a)-i-1] = a[i]
	}
	return res
}

func or(a, b []bool) []bool {
	if len(a) < len(b) {
		a, b = b, a
	}

	a = reverse(a)
	b = reverse(b)

	ans := make([]bool, len(a), len(a))

	for i := 0; i < len(a); i++ {
		if i >= len(b) {
			ans[i] = a[i]
		} else {
			ans[i] = a[i] || b[i]
		}
	}
	return reverse(ans)
}

func sor(a, b string) string {

	na := make([]bool, len(a), len(a))
	nb := make([]bool, len(b), len(b))

	for i := 0; i < len(a); i++ {
		if a[i] == '1' {
			na[i] = true
		}
	}

	for i := 0; i < len(b); i++ {
		if b[i] == '1' {
			nb[i] = true
		}
	}

	orres := or(na, nb)

	ans := make([]rune, len(orres), len(orres))

	for i := 0; i < len(orres); i++ {
		if orres[i] {
			ans[i] = '1'
		} else {
			ans[i] = '0'
		}
	}

	return string(ans)
}

func main() {
	defer writer.Flush()

	var n int
	var s string

	scanf("%d\n", &n)
	scanf("%s\n", &s)

	firstOneIndex := n

	for i := 0; i < n; i++ {
		if s[i] == '1' {
			firstOneIndex = i
			break
		}
	}
	if firstOneIndex == n {
		printf("%s\n", strings.Repeat("0", n))
		return
	}

	firstInterval := s[firstOneIndex:]

	cur := firstOneIndex
	for s[cur] == '1' {
		cur++
	}

	ans := firstInterval
	for i := firstOneIndex; i < cur; i++ {
		if s[i] == '0' {
			break
		}
		secondInterval := s[i : i+n-cur]
		candidate := sor(firstInterval, secondInterval)
		if candidate > ans {
			ans = candidate
		}
	}
	printf("%s\n", ans)
}


package main

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

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

type Edge struct {
	v int
	e int
}

type Node struct {
	edges []Edge
	w     int
}

func (n *Node) Add(v, e int) {
	n.edges = append(n.edges, Edge{v, e})
}

var dfs func(int, int, int)

func main() {
	myio := NewIO(os.Stdin, os.Stdout)
	defer myio.Flush()
	t := myio.ReadInt()
	sol := func() {
		n := myio.ReadInt()
		N := 1 << n
		e1 := make([]int, 1<<n)
		e2 := make([]int, 1<<n)
		w := make([]int, 1<<n)

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

		for i := 0; i < N-1; i++ {
			e1[i] = myio.ReadInt()
			e2[i] = myio.ReadInt()
			nodes[e1[i]].Add(e2[i], i)
			nodes[e2[i]].Add(e1[i], i)
		}

		nodes[1].w = N
		idx := 1
		dfs = func(v, p, xor int) {
			for _, eg := range nodes[v].edges {
				if eg.v == p {
					continue
				}
				if xor&N > 0 {
					w[eg.e] = idx + N
					nodes[eg.v].w = idx
				} else {
					w[eg.e] = idx
					nodes[eg.v].w = idx + N
				}
				idx++
				dfs(eg.v, v, xor^N)
			}
		}
		dfs(1, 0, N)
		myio.Println("1")
		for i := 1; i <= N; i++ {
			myio.Print(nodes[i].w, " ")
		}
		myio.Println()
		for i := 0; i < N-1; i++ {
			myio.Print(w[i], " ")
		}
		myio.Println()
	}
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

type Edge struct {
	v int
	e int
}

type Node struct {
	edges []Edge
	w     int
}

func (n *Node) Add(v, e int) {
	n.edges = append(n.edges, Edge{v, e})
}

var dfs func(int, int, int)

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)

	nextInt := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return x
	}

	t := nextInt()
	sol := func() {
		n := nextInt()
		N := 1 << n
		e1 := make([]int, 1<<n)
		e2 := make([]int, 1<<n)
		w := make([]int, 1<<n)

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

		for i := 0; i < N-1; i++ {
			e1[i] = nextInt()
			e2[i] = nextInt()
			nodes[e1[i]].Add(e2[i], i)
			nodes[e2[i]].Add(e1[i], i)
		}

		nodes[1].w = N
		idx := 1
		dfs = func(v, p, xor int) {
			for _, eg := range nodes[v].edges {
				if eg.v == p {
					continue
				}
				if xor&N > 0 {
					w[eg.e] = idx + N
					nodes[eg.v].w = idx
				} else {
					w[eg.e] = idx
					nodes[eg.v].w = idx + N
				}
				idx++
				dfs(eg.v, v, xor^N)
			}
		}
		dfs(1, 0, N)
		fmt.Println("1")
		for i := 1; i <= N; i++ {
			fmt.Print(nodes[i].w, " ")
		}
		fmt.Println()
		for i := 0; i < N-1; i++ {
			fmt.Print(w[i], " ")
		}
		fmt.Println()
	}
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

type Edge struct {
	v int
	e int
}

type Node struct {
	edges []Edge
	w     int
}

func (n *Node) Add(v, e int) {
	n.edges = append(n.edges, Edge{v, e})
}

var dfs func(int, int, int)

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)

	nextInt := func() int {
		in.Scan()
		vv, _ := strconv.Atoi(in.Text())
		return vv
	}

	t := nextInt()
	sol := func() {
		n := nextInt()
		N := 1 << n
		e1 := make([]int, 1<<n)
		e2 := make([]int, 1<<n)
		w := make([]int, 1<<n)

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

		for i := 0; i < N-1; i++ {
			e1[i] = nextInt()
			e2[i] = nextInt()
			nodes[e1[i]].Add(e2[i], i)
			nodes[e2[i]].Add(e1[i], i)
		}

		nodes[1].w = N
		idx := 1
		dfs = func(v, p, xor int) {
			for _, eg := range nodes[v].edges {
				if eg.v == p {
					continue
				}
				if xor&N > 0 {
					w[eg.e] = idx + N
					nodes[eg.v].w = idx
				} else {
					w[eg.e] = idx
					nodes[eg.v].w = idx + N
				}
				idx++
				dfs(eg.v, v, xor^N)
			}
		}
		dfs(1, 0, N)
		fmt.Println("1")
		for i := 1; i <= N; i++ {
			fmt.Print(nodes[i].w, " ")
		}
		fmt.Println()
		for i := 0; i < N-1; i++ {
			fmt.Print(w[i], " ")
		}
		fmt.Println()
	}
	for ; t > 0; t-- {
		sol()
	}
}

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 ia(m int) []int { return make([]int,m) }
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 vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
type edge struct {n2,eidx int}
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
	T := gi()
	for tt:=1;tt<=T;tt++ {
		P := gi(); N := 1<<P; U,V := fill2(N-1)
		for i:=0;i<N-1;i++ { U[i]--; V[i]-- }
		gr := make([][]edge,N)
		for i:=0;i<N-1;i++ { u,v := U[i],V[i]; gr[u] = append(gr[u],edge{v,i}); gr[v] = append(gr[v],edge{u,i}) }
		nans := make([]int,N)
		eans := make([]int,N-1)
		nans[0] = 1 << P
		adder := 1; big := 1 << P
		var dfs func(n,p,v int)
		dfs = func(n,p,v int) {
			for _,e := range gr[n] {
				if e.n2 != p {
					if v ^ adder < big {
						eans[e.eidx] = adder; nans[e.n2] = adder | big
					} else {
						eans[e.eidx] = adder | big; nans[e.n2] = adder
					}
					adder++
					dfs(e.n2,n,v ^ big)
				}
			}
		}
		dfs(0,-1,big)
		fmt.Fprintln(wrtr,1)
		fmt.Fprintln(wrtr,vecintstring(nans))
		fmt.Fprintln(wrtr,vecintstring(eans))
	}
}

package main

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

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

type Edge struct {
	v int
	e int
}

type Node struct {
	edges []Edge
	w     int
}

func (n *Node) Add(v, e int) {
	n.edges = append(n.edges, Edge{v, e})
}

var dfs func(int, int, int)

func main() {
	myio := NewIO(os.Stdin, os.Stdout)
	defer myio.Flush()
	t := myio.ReadInt()
	sol := func() {
		n := myio.ReadInt()
		N := 1 << n
		e1 := make([]int, 1<<n)
		e2 := make([]int, 1<<n)
		w := make([]int, 1<<n)

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

		for i := 0; i < N-1; i++ {
			e1[i] = myio.ReadInt()
			e2[i] = myio.ReadInt()
			nodes[e1[i]].Add(e2[i], i)
			nodes[e2[i]].Add(e1[i], i)
		}

		nodes[1].w = N
		idx := 1
		dfs = func(v, p, xor int) {
			for _, eg := range nodes[v].edges {
				if eg.v == p {
					continue
				}
				if xor&N > 0 {
					w[eg.e] = idx + N
					nodes[eg.v].w = idx
				} else {
					w[eg.e] = idx
					nodes[eg.v].w = idx + N
				}
				idx++
				dfs(eg.v, v, xor^N)
			}
		}
		dfs(1, 0, N)
		myio.Println("1")
		for i := 1; i <= N; i++ {
			myio.Print(nodes[i].w, " ")
		}
		myio.Println()
		for i := 0; i < N-1; i++ {
			myio.Print(w[i], " ")
		}
		myio.Println()
	}
	for ; t > 0; t-- {
		sol()
	}

}

package main

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

type Edge struct {
	v int
	e int
}

type Node struct {
	edges []Edge
	w     int
}

func (n *Node) Add(v, e int) {
	n.edges = append(n.edges, Edge{v, e})
}

var dfs func(int, int, int)

func main() {
	const eof = 0
	_r := os.Stdin
	// in.Split(bufio.ScanWords)
	// in.Buffer(nil, 1e9)
	_i, _n, buf := 0, 0, make([]byte, 1<<12) // 4KB
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 { // EOF
				return eof
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}

	nextInt := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
			if b == eof {
				return
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return x
	}

	t := nextInt()
	sol := func() {
		n := nextInt()
		N := 1 << n
		e1 := make([]int, 1<<n)
		e2 := make([]int, 1<<n)
		w := make([]int, 1<<n)

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

		for i := 0; i < N-1; i++ {
			e1[i] = nextInt()
			e2[i] = nextInt()
			nodes[e1[i]].Add(e2[i], i)
			nodes[e2[i]].Add(e1[i], i)
		}

		nodes[1].w = N
		idx := 1
		dfs = func(v, p, xor int) {
			for _, eg := range nodes[v].edges {
				if eg.v == p {
					continue
				}
				if xor&N > 0 {
					w[eg.e] = idx + N
					nodes[eg.v].w = idx
				} else {
					w[eg.e] = idx
					nodes[eg.v].w = idx + N
				}
				idx++
				dfs(eg.v, v, xor^N)
			}
		}
		dfs(1, 0, N)
		fmt.Fprintln(out, "1")
		for i := 1; i <= N; i++ {
			fmt.Fprint(out, nodes[i].w, " ")
		}
		fmt.Fprintln(out)
		for i := 0; i < N-1; i++ {
			fmt.Fprint(out, w[i], " ")
		}
		fmt.Fprintln(out)
	}
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

type Edge struct {
	v int
	e int
}

type Node struct {
	edges []Edge
	w     int
}

func (n *Node) Add(v, e int) {
	n.edges = append(n.edges, Edge{v, e})
}

var dfs func(int, int, int)

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	nextInt := func() int {
		in.Scan()
		vv, _ := strconv.Atoi(in.Text())
		return vv
	}

	t := nextInt()
	sol := func() {
		n := nextInt()
		N := 1 << n
		e1 := make([]int, 1<<n)
		e2 := make([]int, 1<<n)
		w := make([]int, 1<<n)

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

		for i := 0; i < N-1; i++ {
			e1[i] = nextInt()
			e2[i] = nextInt()
			nodes[e1[i]].Add(e2[i], i)
			nodes[e2[i]].Add(e1[i], i)
		}

		nodes[1].w = N
		idx := 1
		dfs = func(v, p, xor int) {
			for _, eg := range nodes[v].edges {
				if eg.v == p {
					continue
				}
				if xor&N > 0 {
					w[eg.e] = idx + N
					nodes[eg.v].w = idx
				} else {
					w[eg.e] = idx
					nodes[eg.v].w = idx + N
				}
				idx++
				dfs(eg.v, v, xor^N)
			}
		}
		dfs(1, 0, N)
		fmt.Fprintln(out, "1")
		for i := 1; i <= N; i++ {
			fmt.Fprint(out, nodes[i].w, " ")
		}
		fmt.Fprintln(out)
		for i := 0; i < N-1; i++ {
			fmt.Fprint(out, w[i], " ")
		}
		fmt.Fprintln(out)
	}
	for ; t > 0; t-- {
		sol()
	}
}

package main

import (
	"fmt"
	"os"
)

type Edge struct {
	v int
	e int
}

type Node struct {
	edges []Edge
	w     int
}

func (n *Node) Add(v, e int) {
	n.edges = append(n.edges, Edge{v, e})
}

var dfs func(int, int, int)

func main() {
	const eof = 0
	_r := os.Stdin
	// in.Split(bufio.ScanWords)
	// in.Buffer(nil, 1e9)
	_i, _n, buf := 0, 0, make([]byte, 1<<12) // 4KB

	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 { // EOF
				return eof
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}

	nextInt := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
			if b == eof {
				return
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return x
	}

	t := nextInt()
	sol := func() {
		n := nextInt()
		N := 1 << n
		e1 := make([]int, 1<<n)
		e2 := make([]int, 1<<n)
		w := make([]int, 1<<n)

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

		for i := 0; i < N-1; i++ {
			e1[i] = nextInt()
			e2[i] = nextInt()
			nodes[e1[i]].Add(e2[i], i)
			nodes[e2[i]].Add(e1[i], i)
		}

		nodes[1].w = N
		idx := 1
		dfs = func(v, p, xor int) {
			for _, eg := range nodes[v].edges {
				if eg.v == p {
					continue
				}
				if xor&N > 0 {
					w[eg.e] = idx + N
					nodes[eg.v].w = idx
				} else {
					w[eg.e] = idx
					nodes[eg.v].w = idx + N
				}
				idx++
				dfs(eg.v, v, xor^N)
			}
		}
		dfs(1, 0, N)
		fmt.Println("1")
		for i := 1; i <= N; i++ {
			fmt.Print(nodes[i].w, " ")
		}
		fmt.Println()
		for i := 0; i < N-1; i++ {
			fmt.Print(w[i], " ")
		}
		fmt.Println()
	}
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

type Edge struct {
	v int
	e int
}

type Node struct {
	edges []Edge
	w     int
}

func (n *Node) Add(v, e int) {
	n.edges = append(n.edges, Edge{v, e})
}

var dfs func(int, int, int)

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)

	nextInt := func() int {
		in.Scan()
		vv, _ := strconv.Atoi(in.Text())
		return vv
	}

	t := nextInt()
	sol := func() {
		n := nextInt()
		N := 1 << n
		e1 := make([]int, 1<<n)
		e2 := make([]int, 1<<n)
		w := make([]int, 1<<n)

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

		for i := 0; i < N-1; i++ {
			e1[i] = nextInt()
			e2[i] = nextInt()
			nodes[e1[i]].Add(e2[i], i)
			nodes[e2[i]].Add(e1[i], i)
		}

		nodes[1].w = N
		idx := 1
		dfs = func(v, p, xor int) {
			for _, eg := range nodes[v].edges {
				if eg.v == p {
					continue
				}
				if p&N > 0 {
					w[eg.e] = idx + N
					nodes[eg.v].w = idx
				} else {
					w[eg.e] = idx
					nodes[eg.v].w = idx + N
				}
				idx++
				dfs(eg.v, v, xor^N)
			}
		}
		dfs(1, N, N)
		fmt.Println("1")
		for i := 1; i <= N; i++ {
			fmt.Print(nodes[i].w, " ")
		}
		fmt.Println()
		for i := 0; i < N-1; i++ {
			fmt.Print(w[i], " ")
		}
		fmt.Println()
	}
	for ; t > 0; t-- {
		sol()
	}
}