package main

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

var n, m int
var a, b []int64
var sums map[int64]bool

func main() {
	buf := bufio.NewReader(os.Stdin)
	sums = make(map[int64]bool)
	fmt.Fscanf(buf, "%d\n", &n)
	s := int64(0)
	for i := 0; i < n; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		sums[s] = true
	}
	s1 := s
	cnt := 0
	fmt.Fscanf(buf, "\n%d\n", &m)
	s = 0
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		if sums[s] {
			cnt++
		}
	}
	if cnt == 0 || s1 != s {
		cnt = -1
	}
	fmt.Println(cnt)

}

package main

import."fmt"
import"bufio"
import"os"

func main(){
	in:=bufio.NewReader(os.Stdin)
	var n,m int
	Fscan(in,&n)
	a:=map[int64]bool{}
	sumA:=int64(0)
	for i:=0;i<n;i++{
		var aI int64
		Fscan(in,&aI)
		sumA+=aI
		a[sumA]=true
	}
	Fscan(in,&m)
	sumB:=int64(0)
	ans:=0
	for i:=0;i<m;i++{
		var bI int64
		Fscan(in,&bI)
		sumB+=bI
		if a[sumB]{
			ans++
		}
	}

	if sumA==sumB{
		Print(ans)
	}else{
		Print(-1)
	}
}

package main

import."fmt"
import"bufio"
import"os"

func main(){
	in:=bufio.NewReader(os.Stdin)
	var n,m int
	Fscan(in,&n)
	a:=map[int64]struct{}{}
	sumA:=int64(0)
	for i:=0;i<n;i++{
		var aI int64
		Fscan(in,&aI)
		sumA+=aI
		a[sumA]=struct{}{}
	}
	Fscan(in,&m)
	sumB:=int64(0)
	ans:=0
	for i:=0;i<m;i++{
		var bI int64
		Fscan(in,&bI)
		sumB+=bI
		_,ok:=a[sumB]
		if ok{
			ans++
		}
	}

	if sumA==sumB{
		Print(ans)
	}else{
		Print(-1)
	}
}

package main

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

func main(){
	in := bufio.NewReader(os.Stdin)
	var n int

	fmt.Fscan(in, &n);
	var first = make([]int64, n)
	for i := 0; i < n; i++{
		fmt.Fscan(in, &first[i])
	}
	var m int
	fmt.Fscan(in, &m)
	var second = make([]int64, m)
	for i := 0; i < m; i++{
		fmt.Fscan(in, &second[i])
	}
	var sumFirst = first[0]
	var sumSecond = second[0]
	for i := 1; i < n; i++ {
		sumFirst += first[i]
	}
	for i := 1; i < m; i++ {
		sumSecond += second[i]
	}
	if sumFirst != sumSecond {
		fmt.Println(-1)
		return
	}
	var firstIndx = 1
	var secondIndx = 1
	sumFirst = first[0]
	sumSecond = second[0]
	var answ = 0
	for {
		if sumFirst == sumSecond {
			answ++
			sumFirst = 0
			sumSecond = 0
			if firstIndx == n || secondIndx == m {
				break
			}
			sumFirst += first[firstIndx]
			sumSecond += second[secondIndx]
			firstIndx++
			secondIndx++
		} else {
			if sumFirst < sumSecond {
				sumFirst += first[firstIndx]
				firstIndx++
			} else {
				sumSecond += second[secondIndx]
				secondIndx++
			}
		}
	}

	fmt.Println(answ)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
//
func main(){
	in := bufio.NewReader(os.Stdin)
	var n int

	fmt.Fscan(in, &n);
	var first = make([]int64, n)
	for i := 0; i < n; i++{
		fmt.Fscan(in, &first[i])
	}
	var m int
	fmt.Fscan(in, &m)
	var second = make([]int64, m)
	for i := 0; i < m; i++{
		fmt.Fscan(in, &second[i])
	}
	var sumFirst = first[0]
	var sumSecond = second[0]
	for i := 1; i < n; i++ {
		sumFirst += first[i]
	}
	for i := 1; i < m; i++ {
		sumSecond += second[i]
	}
	if sumFirst != sumSecond {
		fmt.Println(-1)
		return
	}
	var firstIndx = 1
	var secondIndx = 1
	sumFirst = first[0]
	sumSecond = second[0]
	var answ = 0
	for {
		if sumFirst == sumSecond {
			answ++
			sumFirst = 0
			sumSecond = 0
			if firstIndx == n || secondIndx == m {
				break
			}
			sumFirst += first[firstIndx]
			sumSecond += second[secondIndx]
			firstIndx++
			secondIndx++
		} else {
			if sumFirst < sumSecond {
				sumFirst += first[firstIndx]
				firstIndx++
			} else {
				sumSecond += second[secondIndx]
				secondIndx++
			}
		}
	}

	fmt.Println(answ)
}

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 main() {
	defer writer.Flush()
	var n, m int
	scanf("%d\n", &n)
	arr1 := [311111]int64{}

	mp := make(map[int64]bool)
	for i := 0; i < n; i = i + 1 {
		scanf("%d", &arr1[i])
		if i > 0 {
			arr1[i] = arr1[i] + arr1[i-1]
		}
		mp[arr1[i]] = true
	}
	scanf("\n")
	scanf("%d\n", &m)
	arr2 := [311111]int64{}

	var ans = 0

	for i := 0; i < m; i = i + 1 {
		scanf("%d", &arr2[i])
		if i > 0 {
			arr2[i] = arr2[i] + arr2[i-1]
		}
		_, exists := mp[arr2[i]]
		if exists {
			ans = ans + 1
		}
	}
	//scanf("\n")
	//fmt.Print(n, m)

	if arr1[n-1] != arr2[m-1] {
		printf("%d\n", -1)
	} else {
		//fmt.Print(ans)
		printf("%d\n", ans)
	}

}

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 main() {
	defer writer.Flush()
	var n, m int
	scanf("%d\n", &n)
	arr1 := [311111]int64{}

	mp := make(map[int64]bool)
	for i := 0; i < n; i = i + 1 {
		scanf("%d", &arr1[i])
		if i > 0 {
			arr1[i] = arr1[i] + arr1[i-1]
		}
		mp[arr1[i]] = true
	}
	scanf("\n")
	scanf("%d\n", &m)
	arr2 := [311111]int64{}

	var ans = 0

	for i := 0; i < m; i = i + 1 {
		scanf("%d", &arr2[i])
		if i > 0 {
			arr2[i] = arr2[i] + arr2[i-1]
		}
		_, exists := mp[arr2[i]]
		if exists {
			ans = ans + 1
		}
	}
	//scanf("\n")
	fmt.Print(n, m)

	if arr1[n-1] != arr2[m-1] {
		printf("%d\n", -1)
	} else {
		//fmt.Print(ans)
		printf("%d\n", ans)
	}

}

package main

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

var n, m int
var a, b []int64
var sums map[int64]bool

func main() {
	buf := bufio.NewReader(os.Stdin)
	sums = make(map[int64]bool)
	fmt.Fscanf(buf, "%d\n", &n)
	s := int64(0)
	for i := 0; i < n; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		sums[s] = true
	}
	cnt := 0
	fmt.Fscanf(buf, "%d\n", &m)
	s = 0
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		if sums[s] {
			cnt++
		}
	}
	if cnt == 0 {
		cnt = -1
	}
	fmt.Println(cnt)

}

package main

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

var n, m int
var a, b []int64
var sums map[int64]bool

func main() {
	buf := bufio.NewReader(os.Stdin)
	sums = make(map[int64]bool)
	fmt.Fscanf(buf, "%d\n", &n)
	s := int64(0)
	for i := 0; i < n; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		sums[s] = true
	}
	s1 := s
	cnt := 0
	fmt.Fscanf(buf, "\n%d\n", &m)
	s = 0
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		if sums[s] {
			cnt++
		}
	}
	if cnt == 0 || !sums[s1] {
		cnt = -1
	}
	fmt.Println(cnt)

}

package main

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

var n, m int
var a, b []int64
var sums map[int64]bool

func main() {
	buf := bufio.NewReader(os.Stdin)
	sums = make(map[int64]bool)
	fmt.Fscanf(buf, "%d\n", &n)
	s := int64(0)
	for i := 0; i < n; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		sums[s] = true
	}
	cnt := 0
	fmt.Fscanf(buf, "\n%d\n", &m)
	s = 0
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		if sums[s] {
			cnt++
		}
	}
	if cnt == 0 || !sums[s] {
		cnt = -1
	}
	fmt.Println(cnt)

}

package main

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

var n, m int
var a, b []int64
var sums map[int64]bool

func main() {
	buf := bufio.NewReader(os.Stdin)
	sums = make(map[int64]bool)
	fmt.Fscanf(buf, "%d\n", &n)
	s := int64(0)
	for i := 0; i < n; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		sums[s] = true
	}
	cnt := 0
	fmt.Fscanf(buf, "\n%d\n", &m)
	s = 0
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(buf,"%d", &tmp)
		s += tmp
		if sums[s] {
			cnt++
		}
	}
	if cnt == 0 {
		cnt = -1
	}
	fmt.Println(cnt)

}

package main

import (
	"fmt"
)

func main(){
	var n int

	fmt.Scanf("%d", &n);
	var first = make([]int, n)
	for i := 0; i < n; i++{
		fmt.Scanf("%d", &first[i])
	}
	var m int
	fmt.Scanf("%d", &m)
	var second = make([]int, m)
	for i := 0; i < m; i++{
		fmt.Scanf("%d", &second[i])
	}
	var sumFirst = first[0]
	var sumSecond = second[0]
	for i := 1; i < n; i++ {
		sumFirst += first[i]
	}
	for i := 1; i < m; i++ {
		sumSecond += second[i]
	}
	if sumFirst != sumSecond {
		fmt.Println(-1)
		return
	}
	var firstIndx = 1
	var secondIndx = 1
	sumFirst = first[0]
	sumSecond = second[0]
	var answ = 0
	for {
		if sumFirst == sumSecond {
			answ++
			sumFirst = 0
			sumSecond = 0
			sumFirst += first[firstIndx]
			sumSecond += second[secondIndx]
			firstIndx++
			secondIndx++
			if firstIndx == n || secondIndx == m {
				answ++
				break
			}
		} else {
			if sumFirst < sumSecond {
				sumFirst += first[firstIndx]
				firstIndx++
			} else {
				sumSecond += second[secondIndx]
				secondIndx++
			}
		}
	}

	fmt.Println(answ)
}


package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	xs := make([]int, n)
	ys := make([]int, n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		scanner.Scan()
		x, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		scanner.Scan()
		y, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		xs[i] = x
		ys[i] = y
	}

	cnt := 0
	for i := 0; i < n; i++ {
		if is_supercental(xs, ys, i, n) {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func is_supercental(xs, ys []int, p, n int) bool {
	array := [4]bool{false, false, false, false} // Upper, Lower, Right, Left
	for i := 0; i < n; i++ {
		if i != p {
			if xs[i] == xs[p] {
				if ys[i] > ys[p] {
					array[0] = true
				} else if ys[i] < ys[p] {
					array[1] = true
				}
			}
			if ys[i] == ys[p] {
				if xs[i] > xs[p] {
					array[2] = true
				} else if xs[i] < xs[p] {
					array[3] = true
				}
			}
		}
	}
	if array[0] && array[1] && array[2] && array[3] {
		return true
	} else {
		return false
	}
}

package main

import "fmt"

func main() {
    var n int
    var x,y [205]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&x[i],&y[i])
    }
    ans := 0
    for i := 0; i < n; i++ {
        right, left, lower, upper := false, false, false, false
        for j := 0; j < n; j++ {
            if (x[j] > x[i]) && (y[j] == y[i]) { right = true }
            if (x[j] < x[i]) && (y[j] == y[i]) { left = true }
            if (x[j] == x[i]) && (y[j] < y[i]) { lower = true }
            if (x[j] == x[i]) && (y[j] > y[i]) { upper = true }
        }
        if left && right && lower && upper {
            ans++
        }
    }
    fmt.Println(ans)
}


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

const LEN = int(2e5)

func f(th int) {
	length := 0
	scanf("%d\n", &length)
	var l []int
	pre := -1
	cnt := 0
	for i := 0; i < length; i++ {
		t := 0
		scanf("%d", &t)
		if i == 0 {
			cnt = 1
			pre = t
		} else if t != pre {
			l = append(l, cnt)
			cnt = 1
			pre = t
		} else {
			cnt++
		}
	}
	scanf("\n")
	l = append(l, cnt)
	if length < 10 || len(l) < 4 {
		printf("0 0 0\n")
		return
	}
	g := l[0]
	s := 0
	i := 1
	for i = 1; i < len(l); i++ {
		s += l[i]
		if s > g {
			break
		}
	}
	if s <= g {
		printf("0 0 0\n")
		return
	}
	mx := length / 2 - g - s
	if mx <= g {
		printf("0 0 0\n")
		return
	}
	b := 0
	for i++; i < len(l); i++ {
		if b + l[i] > mx {
			break
		}
		b += l[i]
	}
	if b <= g {
		printf("0 0 0\n")
		return
	}
	printf("%d %d %d\n", g, s, b)
}

func main() {
	defer writer.Flush()

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

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

const LEN = int(2e5)

func f(th int) {
	length := 0
	scanf("%d\n", &length)
	var l []int
	pre := -1
	cnt := 0
	for i := 0; i < length; i++ {
		t := 0
		scanf("%d", &t)
		if i == 0 {
			cnt = 1
			pre = t
		} else if t != pre {
			l = append(l, cnt)
			cnt = 1
			pre = t
		} else {
			cnt++
		}
	}
	scanf("\n")
	l = append(l, cnt)
	if length < 10 || len(l) < 4 {
		fmt.Printf("0 0 0\n")
		return
	}
	g := l[0]
	s := 0
	i := 1
	for i = 1; i < len(l); i++ {
		s += l[i]
		if s > g {
			break
		}
	}
	if s <= g {
		fmt.Printf("0 0 0\n")
		return
	}
	mx := length / 2 - g - s
	if mx <= g {
		fmt.Printf("0 0 0\n")
		return
	}
	b := 0
	for i++; i < len(l); i++ {
		if b + l[i] > mx {
			break
		}
		b += l[i]
	}
	if b <= g {
		fmt.Printf("0 0 0\n")
		return
	}
	fmt.Printf("%d %d %d\n", g, s, b)
}

func main() {
	defer writer.Flush()

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

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var P []int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		P = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	g, s, b := 0, 0, 0
	limit := n / 2

	_, counts := RunLengthEncoding(P)
	// 圧縮後に最低長さ3は必要
	if len(counts) < 3 {
		fmt.Println(0, 0, 0)
		return
	}

	// gを決める
	g += counts[0]

	// sを決める、伸ばす
	idx := 1
	for idx < len(counts) {
		// gを超えたらbreak
		if s > g {
			break
		}

		s += counts[idx]
		idx++
	}

	// bを決める、伸ばす
	for idx < len(counts) {
		// gを超えたらbreak
		if b > g {
			break
		}

		b += counts[idx]
		idx++
	}

	if g == 0 || s == 0 || b == 0 {
		fmt.Println(0, 0, 0)
		return
	}
	if s <= g || b <= g {
		fmt.Println(0, 0, 0)
		return
	}
	sum := g + s + b
	if sum > limit {
		fmt.Println(0, 0, 0)
		return
	}

	// bをできるだけ伸ばす
	for idx < len(counts) {
		// 足した結果がlimitを超えるなら足さないでbreak
		if sum+counts[idx] > limit {
			break
		}

		b += counts[idx]
		sum += counts[idx]
		idx++
	}

	fmt.Println(g, s, b)
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

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 p,cnt,pre [400010]int

func main(){
	defer writer.Flush()
	p[0]=-1
	var T int
	scanf("%d\n",&T)
	for cas:=1;cas<=T;cas++{
		var n int
		scanf("%d\n",&n)
		for i:=1;i<=n;i++{if i<n{scanf("%d",&p[i])}else{scanf("%d\n",&p[i])}}
		m:=0
		for i:=1;i<=n;i++{
			if p[i]!=p[i-1] {
				m++
				cnt[m]=1
			}else{cnt[m]++}
		}
		for i:=1;i<=m;i++{pre[i]=pre[i-1]+cnt[i]}
		mk:=0
		for mk<m && pre[mk+1]<=n/2 {mk++}
		if mk<3 {printf("0 0 0\n");continue}
		flg:=2
		fd:=false
		g,s,b:=0,0,0
		for i:=1;i<m;i++{
			tg:=pre[i]
			for flg<mk && pre[flg]-tg<=tg{flg++}
			if pre[flg]>n/2 || pre[flg]-tg<=tg || flg==mk || pre[mk]-pre[flg]<=tg{break}
			fd=true
			g=tg;s=pre[flg]-tg;b=pre[mk]-pre[flg]
		}
		if fd{printf("%d %d %d\n",g,s,b)}else{printf("0 0 0\n")}
	}
}


package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	var n int32
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &n)
		w1 := do(n)
		fmt.Fprint(w, w1)
		fmt.Fprintln(w)
	}
}

func do(n int32) int {
	s := fmt.Sprintf("%d", n)
	r := -1
	for _, t := range a {
		d := dist(t, s)
		if r == -1 || r > d {
			r = d
		}
	}
	return r
}

func dist(a, b string) int {
	i := 0
	j := 0
	r := 0
	for {
		for j < len(b) && a[i] != b[j] {
			j++
			r++
		}
		if j == len(b) {
			r += len(a) - i
			break
		}
		i++
		j++
		if i == len(a) {
			r += len(b) - j
			break
		}
	}
	return r
}

var a []string

func init() {
	i := uint64(1)
	for k := 1; k <= 64; k++ {
		a = append(a, fmt.Sprintf("%d", i))
		i *= 2
	}
}

package main

import "fmt"

var data []string

func solve(str, pow string) int {
	s, p, match := 0, 0, 0
	for ; s < len(str) && p < len(pow); s++ {
		if str[s] == pow[p] {
			p++
			match++
		}
	}
	return len(str) - match + len(pow) - match
}

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

func d() {
	var str string
	fmt.Scanf("%s\n", &str)

	times := len(str) + 1
	for _, pow := range data {
		times = min(solve(str, pow), times)
	}

	fmt.Println(times)
}

func main() {
	var i int64
	for i = 1; i <= 2e18; i *= 2 {
		data = append(data, fmt.Sprintf("%d", i))
	}

	var test int
	fmt.Scanf("%d\n", &test)

	for ; test > 0; test-- {
		d()
	}
}

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	tests()
	// solve()
}

/* --- Solution D --- */
func solve() {
	num := in.next()

	bin := []string{}

	for k := 0; (1 << k) < int64(2e18); k++ {
		bin = append(bin, strconv.FormatInt(1<<k, 10))
	}

	var dist func(string, string) int
	dist = func(v, w string) (d int) {
		i, j := 0, 0
		d += len(v) + len(w)
		for i < len(v) && j < len(w) {
			if v[i] == w[j] {
				d -= 2
				j++
			}
			i++
		}
		return
	}

	sort.Slice(bin, func(i, j int) bool { return dist(num, bin[i]) < dist(num, bin[j]) })

	out.println(dist(num, bin[0]))
}

func tests() {
	tt := in.nextInt()
	for ; tt > 0; tt-- {
		solve()
	}
}

/* --- I/O --- */
type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	in := In{bufio.NewScanner(os.Stdin)}
	in.scanner.Split(bufio.ScanWords)
	return &in
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

var (
	out = bufio.NewWriter(os.Stdout)
	in  = bufio.NewReader(os.Stdin)
	arr []string
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func init() {
	arr = make([]string, 61)
	for i := 0; i <= 60; i++ {
		arr[i] = strconv.FormatInt(int64(math.Pow(2, float64(i))), 10)
	}
	//fmt.Println(arr)
}

func solve() {
	var givenNumber string
	fmt.Fscan(in, &givenNumber)
	var ans int64 = math.MaxInt64
	for i := 0; i < len(arr); i++ {
		currentNumber := arr[i]
		j := 0
		k := 0
		var noMatched int64 = 0
		for j < len(currentNumber) && k < len(givenNumber) {
			if currentNumber[j] == givenNumber[k] {
				j++
				k++
			} else {
				k++
				noMatched++
			}
		}
		var tempAns int64
		tempAns = int64(len(currentNumber) - j)
		tempAns += noMatched
		if k < len(givenNumber) {
			tempAns += int64(len(givenNumber) - k)
		}
		ans = min(tempAns, ans)
	}
	fmt.Println(ans)
}

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

func lcsMethod(s1 string, s2 string, s1Index int, s2Index int, tempAns int) int {
	if s1Index >= len(s1) || s2Index >= len(s2) {
		return tempAns
	}
	if s1[s1Index] == s2[s2Index] {
		tempAns = lcsMethod(s1, s2, s2Index+1, s2Index+1, tempAns+1)
	} else {
		tempAns = int(math.Max(float64(tempAns), math.Max(float64(lcsMethod(s1, s2, s1Index+1, s2Index, tempAns)), float64(lcsMethod(s1, s2, s1Index, s2Index+1, tempAns)))))
	}
	return tempAns
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

func (r runeSort) Len() int           { return len(r) }
func (r runeSort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r runeSort) Less(i, j int) bool { return r[i] < r[j] }

package main

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

func main() {
	defer wr.Flush()
	t := scanInt()
	for i := 0; i < t; i++ {
		fmt.Fprintln(wr, solve())
	}
}

func solve() int {
	x := itoa(scanInt())
	ret := 1<<31 - 1
	for _, y := range powOfTwo {
		need := len(x) + len(y) - 2*f(x, y)
		ret = min(ret, need)
	}
	return ret
}

var powOfTwo []string

func g(dp [][]int, p, q string, i, j int) int {
	if i == len(p) || j == len(q) {
		return 0
	} else if p[i] == q[j] {
		dp[i][j] = g(dp, p, q, i+1, j+1) + 1
		return dp[i][j]
	}
	dp[i][j] = g(dp, p, q, i+1, j)
	return dp[i][j]
}

func f(p, q string) int {
	dp := make([][]int, len(p))
	for i := range dp {
		dp[i] = make([]int, len(q))
	}
	return g(dp, p, q, 0, 0)
}

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

func init() {
	x := big.NewInt(1)
	y := big.NewInt(2)
	for i := 0; ; i++ {
		s := x.String()
		powOfTwo = append(powOfTwo, s)
		if len(s) > 21 {
			break
		}
		x = x.Mul(x, y)
	}
}

func itoa(x int) string {
	return strconv.Itoa(x)
}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x,y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out:= os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n int64
		fmt.Fscan(in,&n)
		var pow [100]int64
		pow[0]=1
		for i:=1;i<=62;i++{
			pow[i]=pow[i-1]*2
		}
		ret:=9999
		for i:=0;i<=62;i++{
			d := n
			lst:=-1
			ans:=0
			d=n
			sizen:=0
			for d >0{
				sizen++
				d/=10
			}
			sizet:=0
			d = pow[i]
			for d >0{
				sizet++
				d/=10
			}
			p:= [305]int64{}
			tempn := [305]int64{}
			d = n
			cnt := sizen
			for d>0{
				tempn[cnt]= d%10
				cnt--
				d/=10
			}
			d = pow[i]
			cnt = sizet
			for d>0{
				p[cnt]=d%10
				cnt--
				d/=10
			}
			for k:=1;k<=sizet;k++ {
				index := -1
				for j := 1; j <= sizen; j++ {
					if p[k] == tempn[j] && j > lst {
						index = j
						ans++
						break
					}
				}
				if index == -1 {
					break
				}
				lst = index
			}
			ret = min(ret,sizen-ans+sizet-ans)
		}
		fmt.Fprintln(out,ret)
	}
}

package main

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

func min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func calc(x, y int64) int64 {
	s, t := strconv.FormatInt(x, 10), strconv.FormatInt(y, 10)
	p := 0
	for q := 0; p < len(s) && q < len(t); q++ {
		if t[q] == s[p] {
			p++
		}
	}
	return int64(len(t) + len(s) - 2 * p);
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	var p2 []int64
	var tmp, ans int64
	tmp = 1
	p2 = append(p2, tmp)
	for tmp < 1e18 {
		tmp <<= 1
		p2 = append(p2, tmp)
	}
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int64
		fmt.Fscan(in, &n)
		ans = 10
		for _, j := range p2 {
			 ans = min(ans, calc(j, n))
		}
		fmt.Fprintln(out, ans)
	}
}

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

                            Online Go Lang Compiler.
                Code, Compile, Run and Debug Go Lang program online.
Write your code in this editor and press "Run" button to execute it.

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

package main

import "fmt"
import "bufio"
import "os"
//import "sort"

const M int = 62

var s[M] string

func to_string(x int64) string{
    var ans string
    for ; x > 0; x /= 10{
        ans += string('0' + x % 10)
    }
    return ans
}

func min(x, y int) int{
    if (x < y) {
        return x
    } else {
        return y
    }
}

func dist(x, y string) int{
    j := 1
    for i := 1; i <= len(x); i++ {
        for ; j <= len(y) && y[len(y) - j] != x[len(x) - i]; j++ {
        }
        if (j > len(y)) {
            return i - 1
        }
        j++
    }
    return min(len(x), len(y))
}

func main() {
    in := bufio.NewReader(os.Stdin)
    var c int64 = 1;
    for i := 1; i < M; i++{
        s[i] = to_string(c)
        c *= 2
    }
    var t int
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        var n int64
        fmt.Fscan(in, &n)
        ans := M
        n1 := to_string(n)
        for i := 1; i < M; i++{
            g := len(s[i]) + len(n1) - (dist(s[i], n1) * 2)
            if ans > g {
                ans = g
            }
        }
        fmt.Println(ans)
    }

}

package main

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

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		res := int64(10)
		var n string
		fmt.Fscan(r, &n)
		for j := 0; j < 63; j++ {
			str := strconv.FormatInt(int64(1)<<j, 10)
			l := int64(0)
			for k := 0; k < len(n); k++ {
				if n[k] == str[l]  {
					l++
					if l>=int64(len(str)){
						break
					}
				}
			}
			res = min(res, int64(len(n))+int64(len(str))-2*l)
		}
		fmt.Println(res)
	}
}

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

	return a
}

package main

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

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

	var T int
	var s []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		ans := 99
		for k := 0; k < 61; k++ {
			t := strconv.FormatInt(1<<k, 10)
			j := 0
			for _, x := range s {
				if j < len(t) && t[j] == x {
					j++
				}
			}
			ans = min(ans, len(s)+len(t)-j*2)
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

func longestPrefix(l, r string) int {
	n := len(l)
	m := len(r)
	f := make([][]int, n+1)

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

	res := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if l[i] == r[j] {
				if j == 0 {
					f[i][j] = 1
					if j+1 > res {
						res = j + 1
					}
					continue
				}

				for k := 0; k < i; k++ {
					if f[k][j-1] != 0 {
						f[i][j] = 1
						if j+1 > res {
							res = j + 1
						}
					}
				}
			}
		}
	}

	return res
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T, n int

	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		fmt.Fscanf(r, "%d\n", &n)

		res := 256
		l := fmt.Sprintf("%d", n)
		for i := 0; i < 62; i++ {
			r := fmt.Sprintf("%d", int64(1)<<i)

			p := longestPrefix(l, r)

			x := len(r) - p + len(l) - p
			//	fmt.Println(l, r, p, x)

			if x < res {
				res = x
			}
		}
		fmt.Println(res)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	start := 2
	res := int64(2)
	count := 0
	arr := []int64{}
	final := math.Floor(math.Log2(math.MaxInt64))
	for float64(count) < final {
		res = int64(math.Pow(float64(start), float64((count))))
		arr = append(arr, res)
		count++
	}
	var n int
	fmt.Scan(&n)
	len := len(arr)
	for i := 0; i < n; i++ {
		var number int
		fmt.Scan(&number)
		min := int64(math.MaxInt64)
		for j := 0; j < len; j++ {
			min = getMin(handle(int64(number), arr[j]), min)
		}
		fmt.Println(min)
	}
}

func getMin(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func handle(num, powerNum int64) int64 {
	numArr := []int64{}
	for num != 0 {
		numArr = append(numArr, num%10)
		num = num / 10
	}
	len0 := len(numArr) - 1
	for i, j := 0, len0; i < j; i, j = i+1, j-1 {
		numArr[i], numArr[j] = numArr[j], numArr[i]
	}

	powerNumArr := []int64{}
	for powerNum != 0 {
		powerNumArr = append(powerNumArr, powerNum%10)
		powerNum = powerNum / 10
	}
	len1 := len(powerNumArr) - 1
	for i, j := 0, len1; i < j; i, j = i+1, j-1 {
		powerNumArr[i], powerNumArr[j] = powerNumArr[j], powerNumArr[i]
	}
	count := int64(0)
	len2 := len(powerNumArr)
	for i := 0; i < len2; i++ {
		if len(numArr)-1 < i {
			numArr = append(numArr, powerNumArr[i])
			count++
		}
		if powerNumArr[i] != numArr[i] {
			numArr = append(numArr[:i], numArr[i+1:]...)
			count++
			i--
		}
	}
	count = count + int64(len(numArr)-len(powerNumArr))
	return count
}

package main

import (
	"fmt"
	"math"
	"strings"
)

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

	var strArr [][]string
	for i := int64(1); i < math.MaxInt64/2; i *= 2 {
		str := fmt.Sprint(i)
		strArr = append(strArr, strings.Split(str, ""))
	}

	for i := 1; i <= t; i++ {
		var n string
		fmt.Scan(&n)
		minn := math.MaxInt32
		for _, v := range strArr {
			minn = min(minn, calculate(strings.Split(n, ""), v))
		}
		fmt.Println(minn)
	}
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func calculate(source, target []string) int {
	ptr := 0
	for _, v := range source {
		if ptr < len(target) && v == target[ptr] {
			ptr++
		}
	}
	return len(source) + len(target) - 2*ptr
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n string
		Fscan(in, &n)

		res := 10
		for i := 0; i < 64; i++ {
			s := strconv.FormatInt(int64(1)<<i, 10)
			k := 0
			for j := 0; j < len(n); j++ {
				if k < len(s) && s[k] == n[j] {
					k++
				}
			}
			res = min(res, len(n) + len(s) - (k<<1))
		}
		Fprintln(out, res)
	}
}

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

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n string
		Fscan(in, &n)

		res := 10
		for i := 0; i < 64; i++ {
			s := strconv.FormatInt(int64(1)<<i, 10)
			k := 0
			for j := 0; j < len(n); j++ {
				if k < len(s) && s[k] == n[j] {
					k++
				}
			}
			res = min(res, len(n) - k + len(s) - k)
		}
		Fprintln(out, res)
	}
}

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

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

package main

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

func CF1063A(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n string
		Fscan(in, &n)

		res := int(1e9)
		for i := 0; i < 64; i++ {
			k := 0
			s := strconv.FormatInt(int64(1)<<i, 10)
			for j := 0; j < len(n); j++ {
				if k < len(s) && s[k] == n[j] {
					k++
				}
			}
			res = min(res, len(s) + len(n) - 2 * k)
		}
		Fprintln(out, res)
	}
}

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

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n string
		Fscan(in, &n)

		res := int(1e9)
		for i := 0; i < 64; i++ {
			s := strconv.FormatInt(int64(1)<<i, 10)
			k := 0
			for j := 0; j < len(n); j++ {
				if k < len(s) && s[k] == n[j] {
					k++
				}
			}
			res = int(math.Min(float64(res), float64(len(n) + len(s) - 2 * k)))
		}
		Fprintln(out, res)
	}
}

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

package main

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

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

	m := make([]string, 64)
	p := int64(1)
	for i := 0; i < 64; i++ {
		m[i] = strconv.FormatInt(p, 10)
		p *= 2
	}

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

		match := func(s string) int {
			min := len(s) + 1

			for _, pw := range m {
				var tp, sp, tot int

				for sp < len(s) && tp < len(pw) {
					if s[sp] == pw[tp] {
						tot++
						tp++
					}
					sp++
				}

				if len(s)-tot+len(pw)-tot < min {
					min = len(s) - tot + len(pw) - tot
				}
			}
			return min
		}

		fmt.Fprintln(out, match(s))
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

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

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

		a := solve(n)

		fmt.Println(a)
	}
}

func solve(n int64) int {

	var ans int = 1e6

	for i := 0; i <= 63; i++ {
		var t int64 = 1 << uint(i)
		pow := strconv.FormatInt(t, 10)
		given := strconv.FormatInt(n, 10)

		//10121252 -- given
		//128 -- pow

		local := len(given) + len(pow)
		if local < ans {
			ans = local
		}

		for k := 0; k < len(given); k++ {
			cur := given[k]

			if pow[0] == cur {
				ops := k

				i, j := k, 0
				i++
				j++

				for ;i < len(given) && j < len(pow); {
					if given[i] == pow[j] {
						i++
						j++
						continue
					}
					i++
					ops++
					continue
				}

				if j <= len(pow) - 1{
					ops += len(pow) - j
				}
				if i <= len(given) - 1 {
					ops += len(given) - i
				}

				if ops < ans {
					ans = ops
				}
			}
		}
	}

	return ans
}

func editDistDP(str1, str2 string) int {
// Create a table to store results of subproblems
	dp := make([][]int, len(str1)+1)

	for i := 0; i < len(str1)+1; i++ {
		dp[i] = make([]int, len(str2)+1)
	}

	m := len(str1)
	n := len(str2)

	// Fill d[][] in bottom up manner
	for i := 0; i <= m; i++ {
		for j := 0; j <= n; j++ {
			// If first string is empty, only option is
			// to insert all characters of second string
			if i == 0 {
				dp[i][j] = j
			} else if j == 0 {
				dp[i][j] = i
			} else if str1[i-1] == str2[j-1] {
				dp[i][j] = dp[i-1][j-1]

			} else {
				dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j]) // Replace
			}
		}
	}

	return dp[m][n]
}

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

package main

import (
	"fmt"
	"math"
)

func main() {
	start := 2
	res := int64(2)
	count := 0
	arr := []int64{}
	for res <= 100000000000 {
		res = int64(math.Pow(float64(start), float64((count))))
		arr = append(arr, res)
		count++
	}
	var n int
	fmt.Scan(&n)
	len := len(arr)
	// fmt.Print64ln(arr)
	for i := 0; i < n; i++ {
		var number int
		fmt.Scan(&number)
		min := int64(math.MaxInt64)
		for j := 0; j < len; j++ {
			min = getMin(handle(int64(number), arr[j]), min)
		}
		fmt.Println(min)
	}
}

func getMin(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func handle(num, powerNum int64) int64 {
	numArr := []int64{}
	for num != 0 {
		numArr = append(numArr, num%10)
		num = num / 10
	}
	for i, j := 0, len(numArr)-1; i < j; i, j = i+1, j-1 {
		numArr[i], numArr[j] = numArr[j], numArr[i]
	}

	powerNumArr := []int64{}
	for powerNum != 0 {
		powerNumArr = append(powerNumArr, powerNum%10)
		powerNum = powerNum / 10
	}
	for i, j := 0, len(powerNumArr)-1; i < j; i, j = i+1, j-1 {
		powerNumArr[i], powerNumArr[j] = powerNumArr[j], powerNumArr[i]
	}
	count := int64(0)
	for i := 0; i < len(powerNumArr); i++ {
		if len(numArr)-1 < i {
			numArr = append(numArr, powerNumArr[i])
			count++
		}
		if powerNumArr[i] != numArr[i] {
			numArr = append(numArr[:i], numArr[i+1:]...)
			count++
			i--
		}
	}
	count = count + int64(len(numArr)-len(powerNumArr))
	return count
}

package main

import (
	"fmt"
	"math"
)

func main() {
	start := 2
	res := int64(2)
	count := 0
	arr := []int64{}
	for res <= 10000000000 {
		res = int64(math.Pow(float64(start), float64((count))))
		arr = append(arr, res)
		count++
	}
	var n int
	fmt.Scan(&n)
	len := len(arr)
	// fmt.Print64ln(arr)
	for i := 0; i < n; i++ {
		var number int
		fmt.Scan(&number)
		min := int64(math.MaxInt64)
		for j := 0; j < len; j++ {
			min = getMin(handle(int64(number), arr[j]), min)
		}
		fmt.Println(min)
	}
}

func getMin(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func handle(num, powerNum int64) int64 {
	numArr := []int64{}
	for num != 0 {
		numArr = append(numArr, num%10)
		num = num / 10
	}
	for i, j := 0, len(numArr)-1; i < j; i, j = i+1, j-1 {
		numArr[i], numArr[j] = numArr[j], numArr[i]
	}

	powerNumArr := []int64{}
	for powerNum != 0 {
		powerNumArr = append(powerNumArr, powerNum%10)
		powerNum = powerNum / 10
	}
	for i, j := 0, len(powerNumArr)-1; i < j; i, j = i+1, j-1 {
		powerNumArr[i], powerNumArr[j] = powerNumArr[j], powerNumArr[i]
	}
	count := int64(0)
	for i := 0; i < len(powerNumArr); i++ {
		if len(numArr)-1 < i {
			numArr = append(numArr, powerNumArr[i])
			count++
		}
		if powerNumArr[i] != numArr[i] {
			numArr = append(numArr[:i], numArr[i+1:]...)
			count++
			i--
		}
	}
	count = count + int64(len(numArr)-len(powerNumArr))
	return count
}

package main

import (
	"fmt"
	"math"
)

func main() {
	start := 2
	res := 2
	count := 0
	arr := []int{}
	for res <= 1000000000 {
		res = int(math.Pow(float64(start), float64((count))))
		arr = append(arr, res)
		count++
	}
	var n int
	fmt.Scan(&n)
	len := len(arr)
	for i := 0; i < n; i++ {
		var number int
		fmt.Scan(&number)
		min := int(math.MaxInt32)
		for j := 0; j < len; j++ {
			min = getMin(handle(number, arr[j]), min)
		}
		fmt.Println(min)
	}
}

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

func handle(num, powerNum int) int {
	numArr := []int{}
	for num != 0 {
		numArr = append(numArr, num%10)
		num = num / 10
	}
	for i, j := 0, len(numArr)-1; i < j; i, j = i+1, j-1 {
		numArr[i], numArr[j] = numArr[j], numArr[i]
	}

	powerNumArr := []int{}
	for powerNum != 0 {
		powerNumArr = append(powerNumArr, powerNum%10)
		powerNum = powerNum / 10
	}
	for i, j := 0, len(powerNumArr)-1; i < j; i, j = i+1, j-1 {
		powerNumArr[i], powerNumArr[j] = powerNumArr[j], powerNumArr[i]
	}
	count := 0
	for i := 0; i < len(powerNumArr); i++ {
		if len(numArr)-1 < i {
			numArr = append(numArr, powerNumArr[i])
			count++
		}
		if powerNumArr[i] != numArr[i] {
			numArr = append(numArr[:i], numArr[i+1:]...)
			count++
			i--
		}
	}
	count = count + len(numArr) - len(powerNumArr)
	return count
}

package main

import (
	"fmt"
	"math"
	"strings"
)

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

	var strArr [][]string
	for i := int64(1); i <= int64(1e10); i *= 2 {
		str := fmt.Sprint(i)
		strArr = append(strArr, strings.Split(str, ""))
	}

	for i := 1; i <= t; i++ {
		var n string
		fmt.Scan(&n)
		minn := math.MaxInt32
		for _, v := range strArr {
			minn = min(minn, calculate(strings.Split(n, ""), v))
		}
		fmt.Println(minn)
	}
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func calculate(source, target []string) int {
	ptr := 0
	for _, v := range source {
		if ptr < len(target) && v == target[ptr] {
			ptr++
		}
	}
	return len(source) + len(target) - 2*ptr
}

package main

import (
	"fmt"
	"math"
	"strings"
)

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

	var strArr [][]string
	for i := int64(1); i <= int64(math.MaxInt32); i *= 2 {
		str := fmt.Sprint(i)
		strArr = append(strArr, strings.Split(str, ""))
	}

	for i := 1; i <= t; i++ {
		var n string
		fmt.Scan(&n)
		minn := math.MaxInt32
		for _, v := range strArr {
			minn = min(minn, calculate(strings.Split(n, ""), v))
		}
		fmt.Println(minn)
	}
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func calculate(source, target []string) int {
	ptr := 0
	for _, v := range source {
		if ptr < len(target) && v == target[ptr] {
			ptr++
		}
	}
	return len(source) + len(target) - 2*ptr
}

package main

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

func CF1063A(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n string
		Fscan(in, &n)

		res := int(1e9)
		for i := 0; i < 64; i++ {
			k := 0
			s := strconv.FormatInt(int64(i)<<i, 10)
			for j := 0; j < len(n); j++ {
				if k < len(s) && s[k] == n[j] {
					k++
				}
			}
			res = min(res, len(s) + len(n) - 2 * k)
		}
		Fprintln(out, res)
	}
}

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

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

package main

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

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

	m := make([]string, 40)
	p := int64(1)
	for i := 0; i < 40; i++ {
		m[i] = strconv.FormatInt(p, 10)
		p *= 2
	}

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

		match := func(s string) int {
			min := len(s) + 1

			for _, pw := range m {
				var tp, sp, tot int

				for sp < len(s) && tp < len(pw) {
					if s[sp] == pw[tp] {
						tot++
						tp++
					}
					sp++
				}

				if len(s)-tot+len(pw)-tot < min {
					min = len(s) - tot + len(pw) - tot
				}
			}
			return min
		}

		fmt.Fprintln(out, match(s))
	}
}

package main

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

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

	m := make([]string, 40)
	p := int64(1)
	for i := 0; i < 40; i++ {
		m[i] = strconv.FormatInt(p, 10)
		p *= 2
	}

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

		match := func(s string) int {
			min := len(s) + 1

			for _, pw := range m {
				a, b := s, pw
				if len(b) > len(a) {
					a, b = b, a
				}

				var tot int
				var x int
				for i := 0; i < len(a); i++ {
					if x < len(b) && a[i] == b[x] {
						x++
					} else {
						tot++
					}
				}

				if tot+len(b)-x < min {
					min = tot + len(b) - x
				}
			}
			return min
		}

		fmt.Fprintln(out, match(s))
	}
}

package main

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

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

	m := make([]string, 40)
	p := 1
	for i := 0; i < 40; i++ {
		m[i] = strconv.Itoa(p)
		p *= 2
	}

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

		match := func(s string) int {
			min := len(s) + 1

			for _, pw := range m {
				a, b := s, pw
				if len(b) > len(a) {
					a, b = b, a
				}

				var tot int
				var x int
				for i := 0; i < len(a); i++ {
					if x < len(b) && a[i] == b[x] {
						x++
					} else {
						tot++
					}
				}

				if tot+len(b)-x < min {
					min = tot + len(b) - x
				}
			}
			return min
		}

		fmt.Fprintln(out, match(s))
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

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

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

		a := solve(n)

		fmt.Println(a)
	}
}

func solve(n int64) int {

	var ans int = 1e6

	for i := 0; i <= 64; i++ {
		var t int64 = 1 << uint(i)
		pow := strconv.FormatInt(t, 10)
		given := strconv.FormatInt(n, 10)

		//10121252 -- given
		//128 -- pow

		local := len(given) + len(pow)
		if local < ans {
			ans = local
		}

		for k := 0; k < len(given); k++ {
			cur := given[k]

			if pow[0] == cur {
				ops := k

				i, j := k, 0
				i++
				j++

				for ;i < len(given) && j < len(pow); {
					if given[i] == pow[j] {
						i++
						j++
						continue
					}
					i++
					ops++
					continue
				}

				if j <= len(pow) - 1{
					ops += len(pow) - j
				}
				if i <= len(given) - 1 {
					ops += len(given) - i
				}

				if ops < ans {
					ans = ops
				}
			}
		}
	}

	return ans
}

func editDistDP(str1, str2 string) int {
// Create a table to store results of subproblems
	dp := make([][]int, len(str1)+1)

	for i := 0; i < len(str1)+1; i++ {
		dp[i] = make([]int, len(str2)+1)
	}

	m := len(str1)
	n := len(str2)

	// Fill d[][] in bottom up manner
	for i := 0; i <= m; i++ {
		for j := 0; j <= n; j++ {
			// If first string is empty, only option is
			// to insert all characters of second string
			if i == 0 {
				dp[i][j] = j
			} else if j == 0 {
				dp[i][j] = i
			} else if str1[i-1] == str2[j-1] {
				dp[i][j] = dp[i-1][j-1]

			} else {
				dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j]) // Replace
			}
		}
	}

	return dp[m][n]
}

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

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

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

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

		a := solve(n)

		fmt.Println(a)
	}
}

func solve(n int64) int {

	var ans int = 1e6

	for i := 0; i <= 50; i++ {
		var t int64 = 1 << uint(i)
		pow := strconv.FormatInt(t, 10)
		given := strconv.FormatInt(n, 10)

		//10121252 -- given
		//128 -- pow

		local := len(given) + len(pow)
		if local < ans {
			ans = local
		}

		for k := 0; k < len(given); k++ {
			cur := given[k]

			if pow[0] == cur {
				ops := k

				i, j := k, 0
				i++
				j++

				for ;i < len(given) && j < len(pow); {
					if given[i] == pow[j] {
						i++
						j++
						continue
					}
					i++
					ops++
					continue
				}

				if j <= len(pow) - 1{
					ops += len(pow) - j
				}
				if i <= len(given) - 1 {
					ops += len(given) - i
				}

				if ops < ans {
					ans = ops
				}
			}
		}
	}

	return ans
}

func editDistDP(str1, str2 string) int {
// Create a table to store results of subproblems
	dp := make([][]int, len(str1)+1)

	for i := 0; i < len(str1)+1; i++ {
		dp[i] = make([]int, len(str2)+1)
	}

	m := len(str1)
	n := len(str2)

	// Fill d[][] in bottom up manner
	for i := 0; i <= m; i++ {
		for j := 0; j <= n; j++ {
			// If first string is empty, only option is
			// to insert all characters of second string
			if i == 0 {
				dp[i][j] = j
			} else if j == 0 {
				dp[i][j] = i
			} else if str1[i-1] == str2[j-1] {
				dp[i][j] = dp[i-1][j-1]

			} else {
				dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j]) // Replace
			}
		}
	}

	return dp[m][n]
}

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

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

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

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

		a := solve(n)

		fmt.Println(a)
	}
}

func solve(n int) int {

	var ans int = 1e6

	for i := 0; i <= 50; i++ {
		t := 1 << uint(i)
		pow := strconv.Itoa(t)
		given := strconv.Itoa(n)

		//10121252 -- given
		//128 -- pow

		local := len(given) + len(pow)
		if local < ans {
			ans = local
		}

		for k := 0; k < len(given); k++ {
			cur := given[k]

			if pow[0] == cur {
				ops := k

				i, j := k, 0
				i++
				j++

				for ;i < len(given) && j < len(pow); {
					if given[i] == pow[j] {
						i++
						j++
						continue
					}
					i++
					ops++
					continue
				}

				if j <= len(pow) - 1{
					ops += len(pow) - j
				}
				if i <= len(given) - 1 {
					ops += len(given) - i
				}

				if ops < ans {
					ans = ops
				}
			}
		}
	}

	return ans
}

func editDistDP(str1, str2 string) int {
// Create a table to store results of subproblems
	dp := make([][]int, len(str1)+1)

	for i := 0; i < len(str1)+1; i++ {
		dp[i] = make([]int, len(str2)+1)
	}

	m := len(str1)
	n := len(str2)

	// Fill d[][] in bottom up manner
	for i := 0; i <= m; i++ {
		for j := 0; j <= n; j++ {
			// If first string is empty, only option is
			// to insert all characters of second string
			if i == 0 {
				dp[i][j] = j
			} else if j == 0 {
				dp[i][j] = i
			} else if str1[i-1] == str2[j-1] {
				dp[i][j] = dp[i-1][j-1]

			} else {
				dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j]) // Replace
			}
		}
	}

	return dp[m][n]
}

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

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	tests()
	// solve()
}

/* --- Solution D --- */
func solve() {
	num := in.next()

	bin := []string{}

	for k := int64(0); (1 << k) < int64(2e18); k++ {
		bin = append(bin, strconv.Itoa(1<<k))
	}

	var dist func(string, string) int
	dist = func(v, w string) (d int) {
		i, j := 0, 0
		d += len(v) + len(w)
		for i < len(v) && j < len(w) {
			if v[i] == w[j] {
				d -= 2
				j++
			}
			i++
		}
		return
	}

	sort.Slice(bin, func(i, j int) bool { return dist(num, bin[i]) < dist(num, bin[j]) })

	out.println(dist(num, bin[0]))
}

func tests() {
	tt := in.nextInt()
	for ; tt > 0; tt-- {
		solve()
	}
}

/* --- I/O --- */
type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	in := In{bufio.NewScanner(os.Stdin)}
	in.scanner.Split(bufio.ScanWords)
	return &in
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	tests()
	// solve()
}

/* --- Solution D --- */
func solve() {
	num := in.next()

	bin := []string{}

	for k := 0; (1 << k) < int64(2e18); k++ {
		bin = append(bin, strconv.Itoa(1<<k))
	}

	var dist func(string, string) int
	dist = func(v, w string) (d int) {
		i, j := 0, 0
		d += len(v) + len(w)
		for i < len(v) && j < len(w) {
			if v[i] == w[j] {
				d -= 2
				j++
			}
			i++
		}
		return
	}

	sort.Slice(bin, func(i, j int) bool { return dist(num, bin[i]) < dist(num, bin[j]) })

	out.println(dist(num, bin[0]))
}

func tests() {
	tt := in.nextInt()
	for ; tt > 0; tt-- {
		solve()
	}
}

/* --- I/O --- */
type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	in := In{bufio.NewScanner(os.Stdin)}
	in.scanner.Split(bufio.ScanWords)
	return &in
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

var (
	out = bufio.NewWriter(os.Stdout)
	in  = bufio.NewReader(os.Stdin)
	arr []string
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func init() {
	arr = make([]string, 61)
	for i := 0; i <= 60; i++ {
		arr[i] = strconv.Itoa(int(math.Pow(2, float64(i))))
	}
}

func solve() {
	var givenNumber string
	fmt.Fscan(in, &givenNumber)
	var ans int64 = math.MaxInt64
	for i := 0; i < len(arr); i++ {
		currentNumber := arr[i]
		j := 0
		k := 0
		noMatched := 0
		for j < len(currentNumber) && k < len(givenNumber) {
			if currentNumber[j] == givenNumber[k] {
				j++
				k++
			} else {
				k++
				noMatched++
			}
		}
		tempAns := len(currentNumber) - j
		tempAns += noMatched
		if k < len(givenNumber) {
			tempAns += len(givenNumber) - k
		}
		ans = int64(math.Min(float64(tempAns), float64(ans)))
	}
	fmt.Println(ans)
}

func lcsMethod(s1 string, s2 string, s1Index int, s2Index int, tempAns int) int {
	if s1Index >= len(s1) || s2Index >= len(s2) {
		return tempAns
	}
	if s1[s1Index] == s2[s2Index] {
		tempAns = lcsMethod(s1, s2, s2Index+1, s2Index+1, tempAns+1)
	} else {
		tempAns = int(math.Max(float64(tempAns), math.Max(float64(lcsMethod(s1, s2, s1Index+1, s2Index, tempAns)), float64(lcsMethod(s1, s2, s1Index, s2Index+1, tempAns)))))
	}
	return tempAns
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

func (r runeSort) Len() int           { return len(r) }
func (r runeSort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r runeSort) Less(i, j int) bool { return r[i] < r[j] }

package main

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

func main() {
	defer wr.Flush()
	t := scanInt()
	for i := 0; i < t; i++ {
		fmt.Fprintln(wr, solve())
	}
}

func solve() int {
	x := itoa(scanInt())
	ret := 1<<31 - 1
	for _, y := range powOfTwo {
		need := len(x) + len(y) - 2*f(x, y)
		ret = min(ret, need)
	}
	return ret
}

var powOfTwo []string

func g(dp [][]int, p, q string, i, j int) int {
	if i == len(p) || j == len(q) {
		return 0
	} else if p[i] == q[j] {
		dp[i][j] = g(dp, p, q, i+1, j+1) + 1
		return dp[i][j]
	}
	dp[i][j] = g(dp, p, q, i+1, j)
	return dp[i][j]
}

func f(p, q string) int {
	dp := make([][]int, len(p))
	for i := range dp {
		dp[i] = make([]int, len(q))
	}
	return g(dp, p, q, 0, 0)
}

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

func init() {
	for i := 0; i < 63; i++ {
		s := itoa(1 << i)
		powOfTwo = append(powOfTwo, s)
	}
}

func itoa(x int) string {
	return strconv.Itoa(x)
}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

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

package main

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

func min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func calc(x, y int64) int64 {
	s, t := string(x), string(y)
	p := 0
	for q := 0; p < len(s) && q < len(t); q++ {
		if t[q] == s[p] {
			p++
		}
	}
	return int64(len(t) + len(s) - 2 * p);
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	var p2 []int64
	var tmp, ans int64
	tmp = 1
	p2 = append(p2, tmp)
	for tmp < 1e18 {
		tmp <<= 1
		p2 = append(p2, tmp)
	}
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int64
		fmt.Fscan(in, &n)
		ans = 10
		for _, j := range p2 {
			 ans = min(ans, calc(j, n))
		}
		fmt.Fprintln(out, ans)
	}
}

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

                            Online Go Lang Compiler.
                Code, Compile, Run and Debug Go Lang program online.
Write your code in this editor and press "Run" button to execute it.

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

package main

import "fmt"
import "bufio"
import "os"
//import "sort"

const M int = 50

var s[M] string

func to_string(x int) string{
    var ans string
    for ; x > 0; x /= 10{
        ans += string('0' + x % 10)
    }
    return ans
}

func min(x, y int) int{
    if (x < y) {
        return x
    } else {
        return y
    }
}

func dist(x, y string) int{
    j := 1
    for i := 1; i <= len(x); i++ {
        for ; j <= len(y) && y[len(y) - j] != x[len(x) - i]; j++ {
        }
        if (j > len(y)) {
            return i - 1
        }
        j++
    }
    return min(len(x), len(y))
}

func main() {
    in := bufio.NewReader(os.Stdin)
    c := 1;
    for i := 1; i < M; i++{
        s[i] = to_string(c)
        c *= 2
    }
    var t int
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        var n int
        fmt.Fscan(in, &n)
        ans := M * 2
        n1 := to_string(n)
        for i := 1; i < M; i++{
            g := len(s[i]) + len(n1) - (dist(s[i], n1) * 2)
            if ans > g {
                ans = g
            }
        }
        fmt.Println(ans)
    }

}


package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n int
	Fscan(r, &n)
	t := 0
	var p int
	for t < n {
		t++
		Fscan(r, &p)
		a := make([]int, p+1)
		flag := make([]int, p+1)
		k := make([]int, p+1)
		for i := 1; i <= p; i++ {
			Fscan(r, &a[i])
			flag[a[i]] = 1
		}
		if p == 1{
			Fprintln(w, 1)
			Fprintln(w, 1)
			Fprintln(w, 1)
			Fprintln(w, )
			continue
		}
		q := 0
		aa := make([][]int, 0)
		for i := 1; i <= p; i++ {
			if flag[i] == 0 {
				q++
				s := make([]int, 0)
				s = append(s, i)
				temp := i
				k[temp] = 1
				for a[temp] != temp && k[a[temp]] == 0 {
					temp = a[temp]
					s = append(s, temp)
					k[temp] = 1
				}
				reverse(s)
				aa = append(aa, s)

			}
		}
		Fprintln(w, q)
		for i := range aa{
			Fprintln(w, len(aa[i]))
			for j := range aa[i] {
				if j != len(aa[i])-1 {
					Fprintf(w, "%d ", aa[i][j])
				} else {
					Fprintln(w, aa[i][j])
				}
			}
		}
		Fprintln(w, )
	}
}

func reverse(a []int) {
	length := len(a)
	for i := 0; i < length/2; i++ {
		a[i], a[length-i-1] = a[length-i-1], a[i]
	}
}

/*
	hello,it's main package!
*/
package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr =bufio.NewWriter(os.Stdout)

func nextInt()int{
	sc.Scan()
	if n,err:= strconv.Atoi(sc.Text());err==nil{
		return n
	}
	fmt.Fprint(wr,"scanf error!\n")
	return 0
}

func main(){
	defer wr.Flush()
	sc.Buffer(make([]byte,0),1000000009)
	sc.Split(bufio.ScanWords)

	T:=nextInt()
	for i:=0;i<T;i++{
		solve()
		fmt.Fprint(wr,"\n")
	}
}
func solve(){
	n:=nextInt()
	fa:=make([]int,n+1)
	notLeaf:=make([]bool,n+1)
	for i:=1;i<=n;i++{
		fa[i]=nextInt()
		if(fa[i]!=i){
			notLeaf[fa[i]]=true
		}
	}
	vis:=make([] bool,n+1)
	ans:=-1
	for _,val:=range notLeaf{
		if !val {
			ans++
		}
	}
	fmt.Fprint(wr,ans,"\n")
	for idx,val:=range notLeaf{
		if(idx<1||idx>n){
			continue
		}
		if !val{
			ch:= make([] int,0)
			x:=idx
			ch=append(ch, x)
			vis[x]= true
			res:=1
			for x!=fa[x] && !vis[fa[x]] {
				x=fa[x]
				vis[x] = true
				// fmt.Fprint(wr," ",x)
				ch=append(ch, x)
				res++
			}
			fmt.Fprint(wr,res,"\n")
			// close(ch)
			for idx:=len(ch)-1;idx>=0;idx--{
				fmt.Fprint(wr,ch[idx]," ")
			}
			fmt.Fprint(wr,"\n")
		}

	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove(end int) {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	child := make([][]int, n)
	root := 0
	for i := range nums {
		if nums[i] == i+1 {
			root = i
			continue
		}
		child[nums[i]-1] = append(child[nums[i]-1], i)
	}
	ans := make([][]int, 1)
	cur := 0
	var dfs func(i int)
	dfs = func(i int){
		if len(child[i]) == 0 {
			ans[cur] = append(ans[cur], i)
			ans = append(ans, make([]int, 0))
			cur++
			return
		}
		ans[cur] = append(ans[cur], i)
		for _, j := range child[i] {
			dfs(j)
		}
	}
	dfs(root)
	ans = ans[:len(ans)-1]
	fmt.Fprintln(w, len(ans))
	for i := range ans {
		fmt.Fprintln(w, len(ans[i]))
		for j := range ans[i] {
			fmt.Fprintf(w, "%d", ans[i][j]+1)
			if j == len(ans[i])-1 {
				fmt.Fprintf(w, "\n")
			} else {
				fmt.Fprintf(w, " ")
			}
		}
	}
	if end != 0 {
		fmt.Fprintf(w, "\n")
	}

}

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove(n-i)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1675D(_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)
		p := make([]int, n)
		vis := make([]bool, n)
		for i := range p {
			Fscan(in, &p[i])
			p[i]--
			if p[i] != i {
				vis[p[i]] = true
			}
		}

		ls := []int{}
		for v, b := range vis {
			if !b {
				ls = append(ls, v)
			}
		}
		Fprintln(out, len(ls))

		for _, v := range ls {
			path := []int{v}
			for v = p[v]; vis[v]; v = p[v] {
				path = append(path, v)
				vis[v] = false
				if p[v] == v {
					break
				}
			}
			Fprintln(out, len(path))
			for i := len(path) - 1; i >= 0; i-- {
				Fprint(out, path[i]+1, " ")
			}
			Fprintln(out)
		}
		Fprintln(out)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1675D(_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)
		p := make([]int, n)
		d := make([]int, n)
		for i := range p {
			Fscan(in, &p[i])
			p[i]--
			if p[i] != i {
				d[p[i]]++
			}
		}
		ans := 1
		ls := []int{}
		for v, d := range d {
			if d > 0 {
				ans += d - 1
			} else {
				ls = append(ls, v)
			}
		}
		Fprintln(out, ans)
		for _, v := range ls {
			path := []int{}
			for ; d[v] >= 0; v = p[v] {
				path = append(path, v)
				d[v] = -1
				if p[v] == v {
					break
				}
			}
			Fprintln(out, len(path))
			for i := len(path) - 1; i >= 0; i-- {
				Fprint(out, path[i]+1, " ")
			}
			Fprintln(out)
		}
		Fprintln(out)
	}
}

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

package main

import (
	"bufio"
	"container/list"
	. "fmt"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n int
		Fscan(in, &n)
		f := make([]int, n+1)
		v := make([]bool, n+1)
		use := make([]bool, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &f[i])
			v[f[i]] = true
		}
		if n == 1 {
			Fprintln(out, 1)
			Fprintln(out, 1)
			Fprintln(out, 1)
			continue
		}
		cnt := 0
		for i := 1; i <= n; i++ {
			if !v[i] {
				cnt++
			}
		}

		Fprintln(out, cnt)
		for i := 1; i <= n; i++ {
			if !v[i] {
				path := list.New()
				k := i
				use[k] = true
				path.PushFront(k)
				for !use[f[k]] && f[k] != k {
					use[f[k]] = true
					path.PushFront(f[k])
					k = f[k]
				}
				Fprintln(out, path.Len())
				for e := path.Front(); e != nil; e = e.Next() {
					Fprint(out, e.Value, " ")
				}
				Fprintln(out, "")
			}
		}
		Fprintln(out, "")
	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

package main

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

type deque[T any] struct {
	q []T
}

func (q *deque[T]) emplace(n T) {
	q.q = append(q.q, n)
}

func (q deque[T]) empty() bool {
	return len(q.q) == 0
}

func (q deque[T]) back() T {
	if q.empty() {
		panic("back() performed on empty deque")
	}
	return q.q[len(q.q)-1]
}

func (q *deque[T]) popback() T {
	if q.empty() {
		panic("popback() performed on empty deque")
	}
	res := q.back()
	q.q = q.q[:len(q.q)-1]
	return res
}

func (q deque[T]) front() T {
	if q.empty() {
		panic("front() performed on empty deque")
	}
	return q.q[0]
}

func (q *deque[T]) popfront() T {
	if q.empty() {
		panic("popfront() performed on empty deque")
	}
	res := q.front()
	q.q = q.q[1:]
	return res
}

func getdeque[T any](capacity int) deque[T] {
	return deque[T]{ make([]T, 0, capacity) }
}

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)

		p := make([]int, n+1)
		for i := 1; i <= n; i++ { fmt.Fscan(r, &p[i]) }

		notaleaf := make([]bool, n+1)
		for i := 1; i <= n; i++ {
			if i != p[i] { notaleaf[p[i]] = true }
		}

		leaves := 0
		for i := 1; i <= n; i++ {
			if ! notaleaf[i] { leaves++ }
		}

		fmt.Fprintln(w, leaves)
		stk := getdeque[int](n)
		vis := make([]bool, n+1)
		for i := 1; i <= n; i++ {
			if ! notaleaf[i] {
				plen := 1
				t := i
				for {
					stk.emplace(t)
					vis[t] = true
					if t == p[t] || vis[p[t]] { break }
					plen++
					t = p[t]
				}
				fmt.Fprintln(w, plen)
				for ! stk.empty() { fmt.Fprintf(w, "%d ", stk.popback()) }
				fmt.Fprintln(w, "")
			}
		}
	}

}

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 vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
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()
	reverse := func(a []int) { i,j := 0,len(a)-1; for i<j { a[i],a[j] = a[j],a[i]; i++; j--} }
	for tt:=1;tt<=T;tt++ {
		N := gi(); P := gis(N); for i:=0;i<N;i++ { P[i]-- }
		gr := make([][]int,N); root := -1
		for i,p := range P { if i == p { root = p } else { gr[p] = append(gr[p],i) } }
		paths := make([][]int,0)
		var dfs func(int) []int
		dfs = func(n int) []int {
			if len(gr[n]) == 0 { return []int{n} }
			for i:=1;i<len(gr[n]);i++ { x := dfs(gr[n][i]); paths = append(paths,x) }
			x := dfs(gr[n][0]); x = append(x,n); return x
		}
		paths = append(paths,dfs(root))
		fmt.Fprintln(wrtr,len(paths))
		for _,p := range paths {
			reverse(p)
			for i:=0;i<len(p);i++ { p[i]++ }
			fmt.Fprintln(wrtr,len(p))
			fmt.Fprintln(wrtr,vecintstring(p))
		}
		fmt.Fprintln(wrtr,"")
	}

}

package main

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

/*

 */

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

	p := make([]int, n)

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

	nodeToChild := make(map[int][]int)

	for i, par := range p {
		if i+1 != par {
			nodeToChild[par-1] = append(nodeToChild[par], i)
		}
	}

	used := make([]bool, n)

	paths := make([][]int, 0)

	for i := range p {
		isLeaf := len(nodeToChild[i]) == 0
		if isLeaf {
			path := []int{i + 1}
			used[i] = true

			j := i
			for !used[p[j]-1] {
				used[p[j]-1] = true
				path = append(path, p[j])
				j = p[j] - 1
			}

			revPath := make([]int, 0)
			for k := len(path) - 1; k >= 0; k-- {
				node := path[k]
				revPath = append(revPath, node)
			}

			paths = append(paths, revPath)
		}
	}

	fmt.Fprintln(writer, len(paths))

	for _, path := range paths {
		fmt.Fprintln(writer, len(path))
		for _, node := range path {
			fmt.Fprintf(writer, "%d ", node)
		}
		fmt.Fprintln(writer)
	}
	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 int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

	for i := int64(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))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		tree := make([][]int, n)
		root := 0
		for i := 0; i < n; i++ {
			p := 0
			fmt.Fscan(in, &p)
			p--
			if p == i {
				root = p
				continue
			}
			tree[p] = append(tree[p], i)
		}
		//fmt.Println(tree, root)
		var ans [][]int
		var dfs func(i int, temp []int)
		dfs = func(i int, temp []int) {
			temp = append(temp, i)
			count := len(tree[i])
			if count == 0 {
				ans = append(ans, temp)
				return
			}
			dfs(tree[i][0], temp)
			for j := 1; j < len(tree[i]); j++ {
				dfs(tree[i][j], []int{})
			}
		}
		dfs(root, []int{})
		fmt.Fprintln(out, len(ans))
		for _, an := range ans {
			fmt.Fprintln(out, len(an))
			for i := range an {
				fmt.Fprint(out, an[i]+1)
				if i == len(an)-1 {
					fmt.Fprintln(out)
				} else {
					fmt.Fprint(out, " ")
				}
			}
		}
	}
}

/*
	hello,it's main package!
*/
package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr =bufio.NewWriter(os.Stdout)

func nextInt()int{
	sc.Scan()
	if n,err:= strconv.Atoi(sc.Text());err==nil{
		return n
	}
	fmt.Fprint(wr,"scanf error!\n")
	return 0
}

func main(){
	defer wr.Flush()
	sc.Buffer(make([]byte,0),1000000009)
	sc.Split(bufio.ScanWords)

	T:=nextInt()
	for i:=0;i<T;i++{
		solve()
		fmt.Fprint(wr,"\n")
	}
}
func solve(){
	n:=nextInt()
	fa:=make([]int,n+1)
	notLeaf:=make([]bool,n+1)
	for i:=1;i<=n;i++{
		fa[i]=nextInt()
		if(fa[i]!=i){
			notLeaf[fa[i]]=true
		}
	}
	vis:=make([] bool,n+1)
	ans:=-1
	for _,val:=range notLeaf{
		if !val {
			ans++
		}
	}
	fmt.Fprint(wr,ans,"\n")
	for idx,val:=range notLeaf{
		if(idx<1||idx>n){
			continue
		}
		if !val{
			ch:= make([] int,0)
			x:=idx
			ch=append(ch, x)
			vis[x]= true
			res:=1
			for x!=fa[x] && !vis[fa[x]] {
				x=fa[x]
				vis[x] = true
				// fmt.Fprint(wr," ",x)
				ch=append(ch, x)
				res++
			}
			fmt.Fprint(wr,res,"\n")
			// close(ch)
			for _,val:=range ch{
				fmt.Fprint(wr,val," ")
			}
			fmt.Fprint(wr,"\n")
		}

	}
}

/*
	hello,it's main package!
*/
package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr =bufio.NewWriter(os.Stdout)

func nextInt()int{
	sc.Scan()
	if n,err:= strconv.Atoi(sc.Text());err==nil{
		return n
	}
	fmt.Fprint(wr,"scanf error!\n")
	return 0
}

func main(){
	defer wr.Flush()
	sc.Buffer(make([]byte,0),1000000009)
	sc.Split(bufio.ScanWords)

	T:=nextInt()
	for i:=0;i<T;i++{
		solve()
	}
}
func solve(){
	n:=nextInt()
	fa:=make([]int,n+1)
	notLeaf:=make([]bool,n+1)
	for i:=1;i<=n;i++{
		fa[i]=nextInt()
		if(fa[i]!=i){
			notLeaf[fa[i]]=true
		}
	}
	vis:=make([] bool,n+1)
	ans:=-1
	for _,val:=range notLeaf{
		if !val {
			ans++
		}
	}
	fmt.Fprint(wr,ans,"\n")
	for idx,val:=range notLeaf{
		if(idx<1||idx>n){
			continue
		}
		if !val{
			ch:= make([] int,0)
			x:=idx
			ch=append(ch, x)
			vis[x]= true
			res:=1
			for x!=fa[x] && !vis[fa[x]] {
				x=fa[x]
				vis[x] = true
				// fmt.Fprint(wr," ",x)
				ch=append(ch, x)
				res++
			}
			fmt.Fprint(wr,res,"\n")
			// close(ch)
			for _,val:=range ch{
				fmt.Fprint(wr,val," ")
			}
			fmt.Fprint(wr,"\n")
		}

	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove(end int) {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	child := make([][]int, n)
	root := 0
	for i := range nums {
		if nums[i] == i+1 {
			root = i
			continue
		}
		child[nums[i]-1] = append(child[nums[i]-1], i)
	}
	ans := make([][]int, 1)
	cur := 0
	var dfs func(i int)
	dfs = func(i int){
		if len(child[i]) == 0 {
			ans[cur] = append(ans[cur], i)
			ans = append(ans, make([]int, 0))
			cur++
			return
		}
		ans[cur] = append(ans[cur], i)
		for _, j := range child[i] {
			dfs(j)
		}
	}
	dfs(root)
	ans = ans[:len(ans)-1]
	fmt.Fprintln(w, len(ans)-1)
	for i := range ans {
		fmt.Fprintln(w, len(ans[i]))
		for j := range ans[i] {
			fmt.Fprintf(w, "%d", ans[i][j]+1)
			if j == len(ans[i])-1 {
				fmt.Fprintf(w, "\n")
			} else {
				fmt.Fprintf(w, " ")
			}
		}
	}
	if end != 0 {
		fmt.Fprintf(w, "\n")
	}

}

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove(n-i)
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n int
	Fscan(r, &n)
	t := 0
	var p int
	for t < n {
		t++
		Fscan(r, &p)
		a := make([]int, p+1)
		flag := make([]int, p+1)
		k := make([]int, p+1)
		for i := 1; i <= p; i++ {
			Fscan(r, &a[i])
			flag[a[i]] = 1
			if a[i] == i{
				flag[a[i]] = 0
			}
		}
		q := 0
		aa := make([][]int, 0)
		for i := 1; i <= p; i++ {
			if flag[i] == 0 {
				q++
				s := make([]int, 0)
				s = append(s, i)
				temp := i
				k[temp] = 1
				for a[temp] != temp && k[a[temp]] == 0 {
					temp = a[temp]
					s = append(s, temp)
					k[temp] = 1
				}
				reverse(s)
				aa = append(aa, s)

			}
		}
		Fprintln(w, q)
		for i := range aa{
			Fprintln(w, len(aa[i]))
			for j := range aa[i] {
				if j != len(aa[i])-1 {
					Fprintf(w, "%d ", aa[i][j])
				} else {
					Fprintln(w, aa[i][j])
				}
			}
		}
		Fprintln(w, )
	}
}

func reverse(a []int) {
	length := len(a)
	for i := 0; i < length/2; i++ {
		a[i], a[length-i-1] = a[length-i-1], a[i]
	}
}

package main

import (
	"bufio"
	"container/list"
	. "fmt"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n int
		Fscan(in, &n)
		f := make([]int, n+1)
		v := make([]bool, n+1)
		use := make([]bool, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &f[i])
			v[f[i]] = true
		}
		if n == 1 {
			Fprintln(out, 1)
			Fprintln(out, 1)
			Fprintln(out, "")
			continue
		}
		cnt := 0
		for i := 1; i <= n; i++ {
			if !v[i] {
				cnt++
			}
		}

		Fprintln(out, cnt)
		for i := 1; i <= n; i++ {
			if !v[i] {
				path := list.New()
				k := i
				use[k] = true
				path.PushFront(k)
				for !use[f[k]] && f[k] != k {
					use[f[k]] = true
					path.PushFront(f[k])
					k = f[k]
				}
				Fprintln(out, path.Len())
				for e := path.Front(); e != nil; e = e.Next() {
					Fprint(out, e.Value, " ")
				}
				Fprintln(out, "")
			}
		}
		Fprintln(out, "")
	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}


package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, m := scanInt(scanner), scanInt(scanner)
	center := (m+1)/2
	pos := center
	for i := 0; i < n; i++ {
		writer.WriteString(fmt.Sprintf("%d\n", pos))
		if pos == center && m%2 == 1 {
			pos--
		} else if pos <= center {
			pos = m-pos+1
		} else {
			pos = m-pos
		}
		if pos == 0 {
			pos = center
		}
	}
}

package main

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

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

// type Comparable interface {
// 	compare(p2 *P) int
// 	getValue() int
// }

type P struct {
	x, pos, id int
}

func (p1 *P) compare(p2 *P) int {
	if p1.x < p2.x {
		return -1
	}
	if p1.x > p2.x {
		return 1
	}
	if p1.id < p2.id {
		return -1
	}
	if p1.id > p2.id {
		return 1
	}
	if p1.pos < p2.pos {
		return -1
	}
	if p1.pos > p2.pos {
		return 1
	}
	return 0
}

func (p *P) getValue() int {
	return p.pos
}

type Heap struct {
	size int
	a [200010]P
}

func (heap *Heap) poll() P {
	var ret P = heap.a[1]
	heap.size -= 1
	heap.a[1] = heap.a[heap.size]
	heap.siftDown(1)

	return ret
}

func (heap *Heap) siftDown(v int) {
	for 2 * v < heap.size {
		var j int = v
		if heap.a[2 * v].compare(&heap.a[j]) < 0 {
			j = 2 * v
		}

		if 2 * v + 1 < heap.size && heap.a[2 * v + 1].compare(&heap.a[j]) < 0 {
			j = 2 * v + 1
		}
		if j == v {
			return
		}
		heap.a[j], heap.a[v] = heap.a[v], heap.a[j]
		v = j
	}
}

func (heap *Heap) add(p P) {
	heap.a[heap.size] = p
	heap.siftUp(heap.size-1)
	heap.size += 1
}

func (heap *Heap) siftUp(v int) {
	for v > 1 && heap.a[v/2].compare(&heap.a[v]) > 0 {
		heap.a[v / 2], heap.a[v] = heap.a[v], heap.a[v / 2]
		v = v / 2
	}
}

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n, m int = nextInt(), nextInt()
	var heap = Heap{size: 1}
	for i := 1; i <= m; i++ {
		var p = P{0, i, abs(m + 1 - 2 * i)}
		heap.add(p)
	}

	for i := 1; i <= n; i++ {
		var top P = heap.poll()
		fmt.Println(top.getValue())
		top.x += 1
		heap.add(top)
	}
}

func next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

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

package main

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

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

// type Comparable interface {
// 	compare(p2 *P) int
// 	getValue() int
// }

type P struct {
	x, pos, id int
}

func (p1 *P) compare(p2 *P) int {
	if p1.x < p2.x {
		return -1
	}
	if p1.x > p2.x {
		return 1
	}
	if p1.id < p2.id {
		return -1
	}
	if p1.id > p2.id {
		return 1
	}
	if p1.pos < p2.pos {
		return -1
	}
	if p1.pos > p2.pos {
		return 1
	}
	return 0
}

func (p *P) getValue() int {
	return p.pos
}

type Heap struct {
	size int
	a [200010]P
}

func (heap *Heap) poll() P {
	var ret P = heap.a[1]
	heap.size -= 1
	heap.a[1] = heap.a[heap.size]
	heap.siftDown(1)

	return ret
}

func (heap *Heap) siftDown(v int) {
	for 2 * v < heap.size {
		var j int = v
		if heap.a[2 * v].compare(&heap.a[j]) < 0 {
			j = 2 * v
		}

		if 2 * v + 1 < heap.size && heap.a[2 * v + 1].compare(&heap.a[j]) < 0 {
			j = 2 * v + 1
		}
		if j == v {
			return
		}
		heap.a[j], heap.a[v] = heap.a[v], heap.a[j]
		v = j
	}
}

func (heap *Heap) add(p P) {
	heap.a[heap.size] = p
	heap.siftUp(heap.size-1)
	heap.size += 1
}

func (heap *Heap) siftUp(v int) {
	for v > 1 && heap.a[v/2].compare(&heap.a[v]) > 0 {
		heap.a[v / 2], heap.a[v] = heap.a[v], heap.a[v / 2]
		v = v / 2
	}
}

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n, m int = nextInt(), nextInt()
	var heap = Heap{size: 1}
	for i := 1; i <= m; i++ {
		var p = P{0, i, abs(m + 1 - 2 * i)}
		heap.add(p)
	}

	for i := 1; i <= n; i++ {
		var top P = heap.poll()
		fmt.Fprintln(out, top.getValue())
		top.x += 1
		heap.add(top)
	}
}

func next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

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

package main

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

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

type P struct {
	x, pos, id int
}

func (p1 *P) compare(p2 *P) int {
	if p1.x < p2.x {
		return -1
	}
	if p1.x > p2.x {
		return 1
	}
	if p1.id < p2.id {
		return -1
	}
	if p1.id > p2.id {
		return 1
	}
	if p1.pos < p2.pos {
		return -1
	}
	if p1.pos > p2.pos {
		return 1
	}
	return 0
}

type Heap struct {
	size int
	a [200010]P
}

func (heap *Heap) poll() P {
	var ret P = heap.a[1]
	heap.size -= 1
	heap.a[1] = heap.a[heap.size]
	heap.siftDown(1)

	return ret
}

func (heap *Heap) siftDown(v int) {
	for 2 * v < heap.size {
		var j int = v
		if heap.a[2 * v].compare(&heap.a[j]) < 0 {
			j = 2 * v
		}
		if 2 * v + 1 < heap.size && heap.a[2 * v + 1].compare(&heap.a[j]) < 0 {
			j = 2 * v + 1
		}
		if j == v {
			break
		}
		heap.a[v], heap.a[j] = heap.a[j], heap.a[v]
		v = j
	}
}

func (heap *Heap) add(p P) {
	heap.a[heap.size] = p
	// fmt.Println("before size=", heap.size)
	// fmt.Println("elm=", heap.a[heap.size])
	// fmt.Println("elm=", heap.a[heap.size-1])
	heap.siftUp(heap.size - 1)
	heap.size += 1

}

func (heap *Heap) siftUp(v int) {
	for v > 1 && heap.a[v/2].compare(&heap.a[v]) > 0 {
		heap.a[v/2], heap.a[v] = heap.a[v], heap.a[v/2]
		v /= 2
	}
}

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n, m int = nextInt(), nextInt()
	var heap = Heap{size: 1}
	for i := 1; i <= m; i++ {
		var p = P{0, i, abs(m + 1 - 2 * i)}
		heap.add(p)
	}

	for i := 1; i <= n; i++ {
		var p P = heap.poll()
		fmt.Fprintln(out, p.pos)
		p.x += 1
		heap.add(p)
	}
}

func next() string {
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

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

package main

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

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

// type Comparable interface {
// 	compare(p2 *P) int
// 	getValue() int
// }

type P struct {
	x, pos, id int
}

func (p1 *P) compare(p2 *P) int {
	if p1.x < p2.x {
		return -1
	}
	if p1.x > p2.x {
		return 1
	}
	if p1.id < p2.id {
		return -1
	}
	if p1.id > p2.id {
		return 1
	}
	if p1.pos < p2.pos {
		return -1
	}
	if p1.pos > p2.pos {
		return 1
	}
	return 0
}

func (p *P) getValue() int {
	return p.pos
}

type Heap struct {
	size int
	a [200010]P
}

func (heap *Heap) poll() P {
	var ret P = heap.a[1]
	heap.size -= 1
	heap.a[1] = heap.a[heap.size]
	heap.siftDown(1)

	return ret
}

func (heap *Heap) siftDown(v int) {
	for 2 * v < heap.size {
		var j int = v
		if heap.a[2 * v].compare(&heap.a[j]) < 0 {
			j = 2 * v
		}

		if 2 * v + 1 < heap.size && heap.a[2 * v + 1].compare(&heap.a[j]) < 0 {
			j = 2 * v + 1
		}
		if j == v {
			return
		}
		heap.a[j], heap.a[v] = heap.a[v], heap.a[j]
	}
}

func (heap *Heap) add(p P) {
	heap.a[heap.size] = p
	heap.siftUp(heap.size-1)
	heap.size += 1
}

func (heap *Heap) siftUp(v int) {
	for v > 1 && heap.a[v/2].compare(&heap.a[v]) > 0 {
		heap.a[v / 2], heap.a[v] = heap.a[v], heap.a[v / 2]
		v = v / 2
	}
}

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n, m int = nextInt(), nextInt()
	var heap = Heap{size: 1}
	for i := 1; i <= m; i++ {
		var p = P{0, i, abs(m + 1 - 2 * i)}
		heap.add(p)
	}

	for i := 1; i <= n; i++ {
		var top P = heap.poll()
		fmt.Println(top.getValue())
		top.x += 1
		heap.add(top)
	}
}

func next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

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

package main

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

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

// type Comparable interface {
// 	compare(p2 *P) int
// 	getValue() int
// }

type P struct {
	x, pos, id int
}

func (p1 *P) compare(p2 *P) int {
	if p1.x < p2.x {
		return -1
	}
	if p1.x > p2.x {
		return 1
	}
	if p1.id < p2.id {
		return -1
	}
	if p1.id > p2.id {
		return 1
	}
	if p1.pos < p2.pos {
		return -1
	}
	if p1.pos > p2.pos {
		return 1
	}
	return 0
}

func (p *P) getValue() int {
	return p.pos
}

type Heap struct {
	size int
	a [200010]P
}

func (heap *Heap) poll() P {
	var ret P = heap.a[1]
	heap.size -= 1
	heap.a[1] = heap.a[heap.size]
	heap.sieveDown(1)

	return ret
}

func (heap *Heap) sieveDown(v int) {
	for 2 * v < heap.size {
		var j int = v
		if heap.a[2 * v].compare(&heap.a[j]) < 0 {
			j = 2 * v
		}

		if 2 * v + 1 < heap.size && heap.a[2 * v + 1].compare(&heap.a[j]) < 0 {
			j = 2 * v + 1
		}
		if j == v {
			return
		}
		heap.a[j], heap.a[v] = heap.a[v], heap.a[j]
	}
}

func (heap *Heap) add(p P) {
	heap.a[heap.size] = p
	heap.size += 1
	heap.sieveUp(heap.size-1)
}

func (heap *Heap) sieveUp(v int) {
	for v > 1 && heap.a[v/2].compare(&heap.a[v]) > 0 {
		heap.a[v / 2], heap.a[v] = heap.a[v], heap.a[v / 2]
		v = v / 2
	}
}

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n, m int = nextInt(), nextInt()
	var heap = Heap{size: 1}
	for i := 1; i <= m; i++ {
		var p = P{0, i, abs(m + 1 - 2 * i)}
		heap.add(p)
	}

	for i := 1; i <= n; i++ {
		var top P = heap.poll()
		fmt.Println(top.getValue())
		top.x += 1
		heap.add(top)
	}
}

func next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

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

package main

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

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

type P struct {
	x, pos, id int
}

func (p1 *P) compare(p2 *P) int {
	if p1.x < p2.x {
		return -1
	}
	if p1.x > p2.x {
		return 1
	}
	if p1.id < p2.id {
		return -1
	}
	if p1.id > p2.id {
		return 1
	}
	if p1.pos < p2.pos {
		return -1
	}
	if p1.pos > p2.pos {
		return 1
	}
	return 0
}

type Heap struct {
	size int
	a [200010]P
}

func (heap *Heap) poll() P {
	var ret P = heap.a[1]
	heap.size -= 1
	heap.a[1] = heap.a[heap.size]
	heap.siftDown(1)

	return ret
}

func (heap *Heap) siftDown(v int) {
	for 2 * v < heap.size {
		var j int = v
		if heap.a[2 * v].compare(&heap.a[j]) > 0 {
			j = 2 * v
		}
		if 2 * v + 1 < heap.size && heap.a[2 * v + 1].compare(&heap.a[j]) > 0 {
			j = 2 * v + 1
		}
		if j == v {
			break
		}
		heap.a[v], heap.a[j] = heap.a[j], heap.a[v]
		v = j
	}
}

func (heap *Heap) add(p P) {
	heap.a[heap.size] = p
	// fmt.Println("before size=", heap.size)
	// fmt.Println("elm=", heap.a[heap.size])
	// fmt.Println("elm=", heap.a[heap.size-1])
	heap.siftUp(heap.size - 1)
	heap.size += 1

}

func (heap *Heap) siftUp(v int) {
	for v > 1 && heap.a[v/2].compare(&heap.a[v]) > 0 {
		heap.a[v/2], heap.a[v] = heap.a[v], heap.a[v/2]
		v /= 2
	}
}

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n, m int = nextInt(), nextInt()
	var heap = Heap{size: 1}
	for i := 1; i <= m; i++ {
		var p = P{0, i, abs(m + 1 - 2 * i)}
		heap.add(p)
	}

	for i := 1; i <= n; i++ {
		var p P = heap.poll()
		fmt.Fprintln(out, p.pos)
		p.x += 1
		heap.add(p)
	}
}

func next() string {
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

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