package main

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

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

	v := make([]int, n)
	for i := range v {
		scanf("%d", &v[i])
	}

	res, x := int(1e8), 0
	for i := 1; i <= 100; i++ {
		s := 0
		for _, j := range v {
			if j > i {
				s += j - i - 1
			} else if j < i {
				s += i - j - 1
			}
		}
		if res > s {
			res = s
			x = i
		}
	}

	printf("%d %d", x, res)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := []int{}
	for i := 0; i < n; i++ {
		t := 0
		fmt.Fscanf(in, "%d", &t)
		a = append(a, t)
	}
	bestT := 1
	best := 99999999
	for t := 1; t <= 100; t++ {
		cur := 0
		for i := 0; i < n; i++ {
			if a[i] > t {
				cur += a[i] - (t + 1)
			} else if a[i] == t {
			} else {
				cur += t - 1 - a[i]
			}
		}
		if cur < best {
			best = cur
			bestT = t
		}
	}
	fmt.Fprintf(out, "%d %d\n", bestT, best)
	return
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	ansT := 0
	ansCost := 99999999
	for t := 1; t <= 100; t++ {
		cost := 0
		for _, a := range a {
			if a < t {
				cost += t - a - 1
			}
			if a > t {
				cost += a - t - 1
			}
		}
		if ansCost > cost {
			ansCost = cost
			ansT = t
		}
	}
	fmt.Println(ansT, ansCost)
}

package main

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

func dis( t1, p int) int {
	if t1 >= p-1 && t1 <= p+1{
		return 0
	}
	if t1 <p-1{
		return p-1-t1
	}else{
		return t1-(p+1)
	}
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	mat := make([]int, n+1)

	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
	}
	ans := -1
	w := -1
	for b := 1; b <=100; b++ {
		tmp := 0
		for i := 0; i < n; i++ {
			tmp += dis(mat[i],b)

		}
		if ans == -1 || ans > tmp{
			ans = tmp
			w = b
		}
	}
	fmt.Printf("%d %d\n",w, 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(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func scanf(format string, a ...interface{}) { fmt.Fscanf(reader, format, a...) }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

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

	v := make([]int, n)
	for i := range v {
		scanf("%d ", &v[i])
	}

	res, x := int(1e8), 0
	for i := 0; i <= 100; i++ {
		s := 0
		for _, j := range v {
			if j > i {
				s += j - i - 1
			} else if j < i {
				s += i - j - 1
			}
		}
		if res > s {
			res = s
			x = i
		}
	}

	printf("%d %d", x, res)
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1637F(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, w, root, fi, se int
	Fscan(in, &n)
	h := make([]int, n)
	for i := range h {
		Fscan(in, &h[i])
		if h[i] > h[root] {
			root = i
		}
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	ans := int64(0)
	var f func(int, int) int
	f = func(v, fa int) (mx int) {
		for _, w := range g[v] {
			if w != fa {
				mx = max(mx, f(w, v))
			}
		}
		if mx == 0 {
			ans += int64(h[v])
		} else if h[v] > mx {
			ans += int64(h[v] - mx)
		}
		return max(mx, h[v])
	}
	for _, w := range g[root] {
		if mx := f(w, root); mx > fi {
			fi, se = mx, fi
		} else if mx > se {
			se = mx
		}
	}
	Fprint(out, ans+int64(h[root]*2-fi-se))
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1637F(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, w, root, fi, se int
	Fscan(in, &n)
	h := make([]int, n)
	for i := range h {
		Fscan(in, &h[i])
		if h[i] > h[root] {
			root = i
		}
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	ans := int64(0)
	var f func(int, int) int
	f = func(v, fa int) (max int) {
		for _, w := range g[v] {
			if w != fa {
				if mx := f(w, v); mx > max {
					max = mx
				}
			}
		}
		if h[v] > max {
			ans += int64(h[v] - max)
			max = h[v]
		}
		return
	}
	for _, w := range g[root] {
		if mx := f(w, root); mx > fi {
			fi, se = mx, fi
		} else if mx > se {
			se = mx
		}
	}
	Fprint(out, ans+int64(h[root]*2-fi-se))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1637F(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, w, mxI, fi, se int
	Fscan(in, &n)
	h := make([]int, n)
	for i := range h {
		Fscan(in, &h[i])
		if h[i] > h[mxI] {
			mxI = i
		}
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	ans := int64(0)
	var f func(int, int) int
	f = func(v, fa int) (mx int) {
		for _, w := range g[v] {
			if w != fa {
				mx = max(mx, f(w, v))
			}
		}
		if mx == 0 {
			ans += int64(h[v])
		} else if h[v] > mx {
			ans += int64(h[v] - mx)
		}
		return max(mx, h[v])
	}
	for _, w := range g[mxI] {
		if mx := f(w, mxI); mx > fi {
			fi, se = mx, fi
		} else if mx > se {
			se = mx
		}
	}
	Fprint(out, ans+int64(h[v]*2-fi-se))
}

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

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


package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		println(solve())
	}
}

func solve() int {
	n, p, k := ReadInt(), ReadInt(), ReadInt()
	a := ReadString()
	x, y := ReadInt(), ReadInt()

	v := make([]int, n)
	for i := n - 1; i >= 0; i-- {
		if a[i] == '0' {
			v[i] += x
		}
		if i+k < n {
			v[i] += v[i+k]
		}
	}

	ans := 1 << 29
	c := 0
	for i := p - 1; i < n; i++ {
		ans = Min(ans, v[i]+y*c)
		c++
	}
	return ans
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

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

	var t, n, p, k, x, y int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &p, &k)
		fmt.Fscan(in, &s)
		a := append([]rune{' '}, []rune(s)...) // add dumb first element for convenience
		fmt.Fscan(in, &x, &y)

		minTime := n * x // upper bound of minimal time
		for i := p; i < p+k && i <= n; i++ {
			offset := i - p
			avoidedMisses := 0
			misses := 0
			for j := i; j <= n; j += k {
				if misses*x-(j-p)*y > avoidedMisses*x-offset*y {
					avoidedMisses, offset = misses, j-p
				}
				if a[j] == '0' {
					misses++
				}
			}
			if (misses-avoidedMisses)*x+offset*y < minTime {
				minTime = (misses-avoidedMisses)*x + offset*y
			}
		}

		fmt.Println(minTime)
	}
}

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

package main

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

var (
	t int

	n, p, k int
	S       []rune
	x, y    int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n, p, k = readi3()
		p--
		S = readrs()
		x, y = readi2()

		solve()
	}
}

func solve() {
	ans := INF_B30

	sum := make([][]int, k)
	A := make([][]rune, k)

	for i := 0; i < n; i++ {
		m := i % k
		A[m] = append(A[m], S[i])
	}

	for i := 0; i < k; i++ {
		sum[i] = make([]int, len(A[i])+1)
	}

	// debugf("A: %v\n", A)
	// debugf("sum: %v\n", sum)

	for i := 0; i < k; i++ {
		for j := 0; j < len(A[i]); j++ {
			if A[i][j] == '0' {
				sum[i][j+1] = sum[i][j] + 1
			} else {
				sum[i][j+1] = sum[i][j]
			}
		}
	}

	for i := p; i < n; i++ {
		ynum := i - p

		m := i % k
		xnum := sum[m][len(A[m])] - sum[m][i/k]

		res := xnum*x + ynum*y
		chmin(&ans, res)
	}

	// iは始点
	// for i := p; i < p+k; i++ {
	// 	num := 0
	// 	for j := i; j < n; j += k {
	// 		if S[j] == '0' {
	// 			num++
	// 		}
	// 	}

	// 	res := num*x + (i-p)*y
	// 	chmin(&ans, res)
	// }

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

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

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

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

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

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

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

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

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

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

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

package main

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

var (
	t int

	n, p, k int
	S       []rune
	x, y    int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n, p, k = readi3()
		p--
		S = readrs()
		x, y = readi2()

		solve()
	}
}

func solve() {
	ans := INF_B30

	// iは始点
	for i := p; i < p+k; i++ {
		num := 0
		for j := i; j < n; j += k {
			if S[j] == '0' {
				num++
			}
		}

		res := num*x + (i-p)*y
		chmin(&ans, res)
	}

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

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

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

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

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

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

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

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

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

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

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

	var t, n, p, k, x, y int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &p, &k)
		fmt.Fscan(in, &s)
		a := append([]rune{' '}, []rune(s)...) // add dumb first element for convenience
		fmt.Fscan(in, &x, &y)

		minTime := n * x // upper bound of minimal time
		for i := p; i < p+k && i <= n; i++ {
			offset := i - p
			avoidedMisses := 0
			misses := 0
			for j := i; j <= n; j += k {
				if misses*x-(j-p)*y > avoidedMisses*x-offset*y {
					avoidedMisses, offset = misses, j-p
					fmt.Println(i, j, avoidedMisses, offset)
				}
				if a[j] == '0' {
					misses++
				}
			}
			if (misses-avoidedMisses)*x+offset*y < minTime {
				minTime = (misses-avoidedMisses)*x + offset*y
			}
		}

		fmt.Println(minTime)
	}
}

package main

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

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

	var t, n, p, k, x, y int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &p, &k)
		fmt.Fscan(in, &s)
		a := []rune(s)
		fmt.Fscan(in, &x, &y)

		minTime := n*x + 1
		for i := p - 1; i < p-1+k; i++ {
			offset := i - p + 1
			avoidedMisses := 0
			misses := 0
			for j := i; j < n; j += k {
				if misses*x-(j-p+1)*y > avoidedMisses*x-offset*y {
					avoidedMisses, offset = misses, (j - p + 1)
					fmt.Println(i, j, avoidedMisses, offset)
				}
				if a[j] == '0' {
					misses++
				}
			}
			if (misses-avoidedMisses)*x+offset*y < minTime {
				minTime = (misses-avoidedMisses)*x + offset*y
			}
		}

		fmt.Println(minTime)
	}
}

package main

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

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

	var t, n, p, k, x, y int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &p, &k)
		fmt.Fscan(in, &s)
		a := append([]rune{' '}, []rune(s)...) // add dumb first element for convenience
		fmt.Fscan(in, &x, &y)

		minTime := n * x // upper bound of minimal time
		for i := p; i < p+k && i <= n; i++ {
			offset := i - p
			avoidedMisses := 0
			misses := 0
			for j := i; j <= n; j += k {
				if misses*x-(j-p)*y > avoidedMisses*x-offset*y {
					avoidedMisses, offset = misses, j-p
					fmt.Println(i, j, avoidedMisses, offset)
				}
				if a[j] == '0' {
					misses++
				}
				// lul speshu
				if j+k > n && misses*x-(j-p)*y > avoidedMisses*x-offset*y {
					avoidedMisses, offset = misses, j-p
					fmt.Println(i, j, avoidedMisses, offset)
				}
			}
			if (misses-avoidedMisses)*x+offset*y < minTime {
				minTime = (misses-avoidedMisses)*x + offset*y
			}
		}

		fmt.Println(minTime)
	}
}


package main

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

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

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

func toInt(buf []byte) (o int) {
    for _, v := range buf {
        o = o*10 + int(v-'0')
    }
    return
}

var dp [1000]int
var c []int

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	q := toInt(scanner.Bytes())
	dp[1] = -1
	dp[2] = -1
	dp[3] = -1
	for i:=4;i<=500;i++ {
		composite := false
		for j:=2;j<i;j++ {
			if i % j == 0 {
				composite = true
				break
			}
		}
		if composite {
			c = append(c, i)
		}
		dp[i] = -1
		for j:=range c {
			if dp[i - c[j]] != -1 {
				dp[i] = max(dp[i], dp[i-c[j]] + 1)
			}
		}
	}
	for ;q>0;q-- {
		scanner.Scan()
		a := toInt(scanner.Bytes())
		if a<=500 {
			fmt.Println(dp[a])
			continue
		}
		ans := -1
		for i:=1;i<=500;i++ {
			if dp[i] == -1 || (a - i) % 4 != 0 {
				continue
			}
			ans = max(ans, (a - i) / 4 + dp[i])
		}
		fmt.Println(ans)
	}
}

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

const debug = true

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

	n := gsli(reader)[0]

	for i := 0; i < n; i++ {
		x := gsli(reader)[0]
		fmt.Println(maxSplit(x))
	}

}

func maxSplit(x int) (y int) {
	if x == 4 || x == 9 {
		y = 1
	} else if x < 4 || x == 5 || x == 7 || x == 11 {
		y = -1
	} else {
		f := x % 4
		switch f {
		case 0:
			return x / 4
		case 1:
			return ((x - 9) / 4) + 1
		case 2:
			return ((x - 6) / 4) + 1
		case 3:
			return ((x - 6 - 9) / 4) + 2
		}
	}
	return
}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// String helpers

// Is Lowercase
// Given some string[i], return whether it is lower case or not.

func isl(b byte) bool {
	var r rune
	r = rune(b)
	return unicode.IsLower(r)
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

// Max Int
// Returns the max of two ints

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

// Distance formule
// Calculates the distance to the origin

func dist(x, y float64) float64 {
	return math.Sqrt(math.Pow(x, 2) + math.Pow(y, 2))
}

// Output helpers

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}

// Debug helpers

// From https://groups.google.com/forum/#!topic/golang-nuts/Qlxs3V77nss

func dbg(s string, a ...interface{}) {
	if debug {
		fmt.Printf(s, a...)
	}
}

/*
URL:
https://codeforces.com/problemset/problem/870/C
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	q, n int
)

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

		solve()
	}
}

func solve() {
	if n < 4 {
		fmt.Println(-1)
		return
	}

	ans := n / 4

	if n%4 == 0 {
	} else if n%4 == 1 {
		ans--
	} else if n%4 == 2 {
	} else {
		ans -= 2
		if ans > 0 {
			ans++
		}
	}

	if ans <= 0 {
		ans = -1
	}
	fmt.Println(ans)
}

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

// 約数の列挙: O(sqrt(n))
func divisor(n int) []int {
	var i int

	res := []int{}

	for i = 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i != (n / i) {
				res = append(res, (n / i))
			}
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/problemset/problem/870/C
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	q, n int
)

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

		solve()
	}
}

func solve() {
	if n < 4 {
		fmt.Println(-1)
		return
	}

	ans := n / 4

	if n%4 == 0 {
	} else if n%4 == 1 {
		ans--
	} else if n%4 == 2 {
	} else {
		ans -= 2
	}

	if ans < 0 {
		ans = -1
	}
	fmt.Println(ans)
}

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

// 約数の列挙: O(sqrt(n))
func divisor(n int) []int {
	var i int

	res := []int{}

	for i = 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i != (n / i) {
				res = append(res, (n / i))
			}
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/problemset/problem/870/C
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	q, n int
)

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

		solve()
	}
}

func solve() {
	if n < 4 {
		fmt.Println(-1)
		return
	}

	ans := n / 4

	if n%4 == 0 {
	} else if n%4 == 1 {
		ans--
	} else if n%4 == 2 {
	} else {
		ans -= 2
	}

	if ans <= 0 {
		ans = -1
	}
	fmt.Println(ans)
}

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

// 約数の列挙: O(sqrt(n))
func divisor(n int) []int {
	var i int

	res := []int{}

	for i = 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i != (n / i) {
				res = append(res, (n / i))
			}
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

const debug = true

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

	n := gsli(reader)[0]

	for i := 0; i < n; i++ {
		x := gsli(reader)[0]
		fmt.Println(maxSplit(x))
	}

}

func maxSplit(x int) (y int) {
	if x == 4 || x == 9 || x == 13 {
		y = 1
	} else if x < 4 || x == 5 || x == 7 || x == 11 {
		y = -1
	} else {
		f := x % 4
		switch f {
		case 0:
			return x / 4
		case 1:
			return ((x - 9) / 4) + 1
		case 2:
			return ((x - 6) / 4) + 1
		case 3:
			return ((x - 6 - 9) / 4) + 2
		}
	}
	return
}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// String helpers

// Is Lowercase
// Given some string[i], return whether it is lower case or not.

func isl(b byte) bool {
	var r rune
	r = rune(b)
	return unicode.IsLower(r)
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

// Max Int
// Returns the max of two ints

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

// Distance formule
// Calculates the distance to the origin

func dist(x, y float64) float64 {
	return math.Sqrt(math.Pow(x, 2) + math.Pow(y, 2))
}

// Output helpers

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}

// Debug helpers

// From https://groups.google.com/forum/#!topic/golang-nuts/Qlxs3V77nss

func dbg(s string, a ...interface{}) {
	if debug {
		fmt.Printf(s, a...)
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1622D(in io.Reader, out io.Writer) {
	const mod, mx = 998244353, 5000
	F := [mx + 1]int64{1}
	for i := 1; i <= mx; i++ {
		F[i] = F[i-1] * int64(i) % mod
	}
	pow := func(x, n int64) (res int64) {
		res = 1
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return
	}
	invF := [...]int64{mx: pow(F[mx], mod-2)}
	for i := mx; i > 0; i-- {
		invF[i-1] = invF[i] * int64(i) % mod
	}
	C := func(n, k int) int64 { return F[n] * invF[k] % mod * invF[n-k] % mod }

	var n, k int
	var s string
	Fscan(bufio.NewReader(in), &n, &k, &s)
	pos := []int{}
	for i, b := range s {
		if b == '1' {
			pos = append(pos, i)
		}
	}
	if k == 0 || len(pos) < k {
		Fprint(out, 1)
		return
	}
	pos = append(pos, n)
	ans := C(pos[k], k)
	for i, p := range pos[:len(pos)-k-1] {
		ans += C(pos[i+k+1]-p-1, k) - C(pos[i+k]-p-1, k-1)
	}
	Fprint(out, (ans%mod+mod)%mod)
}

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

package main

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

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

const TAM = 5010
const MOD = 998244353

func add(a, b int) int {
	return (a + b) % MOD
}

func subtract(a, b int) int {
	return (a + (MOD - b)) % MOD
}

var s string
var n, k int
var nCk [TAM][TAM]int
var next1 [TAM]int
var prev1 [TAM]int

// var sufSum [TAM]int

func solve(seg []int, prevSeg []int) int {
	// fmt.Fprintf(out, "solve %s (%v %v)\n", s[seg[0]:seg[1]+1], seg, prevSeg)
	var segLen = seg[1] - seg[0] + 1
	var ans = nCk[segLen][k]
	if len(prevSeg) > 0 {
		ans = subtract(ans, nCk[segLen-(seg[1]-prevSeg[1])][k-1])
	}
	return ans
}

func main() {
	fmt.Fscan(in, &n, &k)
	fmt.Fscan(in, &s)

	if k == 0 {
		fmt.Fprintf(out, "1\n")
		out.Flush()
		return
	}
	prev1[0] = -1
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			prev1[i+1] = i
		} else {
			prev1[i+1] = prev1[i]
		}
	}

	next1[n-1] = n
	for i := n - 1; i > 0; i-- {
		if s[i] == '1' {
			next1[i-1] = i
		} else {
			next1[i-1] = next1[i]
		}
	}

	// sufSum[n] = 0
	// for i := n - 1; i >= 0; i-- {
	// 	sufSum[i] = sufSum[i+1]
	// 	if s[i] == '1' {
	// 		sufSum[i]++
	// 	}
	// }

	for i := 0; i <= n; i++ {
		for j := 0; j <= n; j++ {
			if j == 0 || j == i {
				nCk[i][j] = 1
			} else if j > i {
				nCk[i][j] = 0
			} else {
				nCk[i][j] = add(nCk[i-1][j-1], nCk[i-1][j])
			}
		}
	}

	var ans = 0
	var ones []int
	var prevSegment []int = []int{}
	var curSegment []int = []int{-1, -1}
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			ones = append(ones, i)
			if len(ones) > k {
				ones = ones[1:]
			}

			if len(ones) == k {
				curSegment = []int{
					prev1[ones[0]] + 1,
					next1[ones[k-1]] - 1,
				}
				ans = add(ans, solve(curSegment, prevSegment))
				prevSegment = curSegment
			}
		}
	}

	if len(ones) < k {
		ans = 1
	}

	fmt.Fprintf(out, "%d\n", ans)
	out.Flush()
}

package main

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

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

const MOD int64 = 998244353

func solve(t int) {
	n, k := readInt(), readInt()
	s := readString()
	if k == 0 {
		println(1)
		return
	}

	C := make([][]int64, n+1)
	for i := 0; i <= n; i++ {
		C[i] = make([]int64, k+1)
		for j := 0; j <= k; j++ {
			if j == 0 {
				C[i][j] = 1
			} else if i == 0 {
				C[i][j] = 0
			} else {
				C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD
			}
		}
	}

	L := make([]int64, n)
	cur := 0
	sum1 := 0
	for i := 0; i < n; i++ {
		sum1 += int(s[i] - '0')
		for sum1 > k {
			sum1 -= int(s[cur] - '0')
			cur += 1
		}
		// println(i, cur, i-cur+1)
		L[i] = int64(i - cur + 1)
	}

	dp := make([]int64, n)
	sum1 = 0
	for i := 0; i < n; i++ {
		sum1 += int(s[i] - '0')
		if sum1 < k {
			dp[i] = 1
		} else if sum1 == k {
			dp[i] = C[L[i]][k]
		} else {
			if s[i] == '0' {
				dp[i] = (dp[i-1] + C[L[i]-1][k-1]) % MOD
			} else {
				dp[i] = (dp[i-1] + C[L[i]-1][k]) % MOD
			}
		}
	}

	println(dp[n-1])
}

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

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

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

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

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

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

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

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

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, k := readTwoNums(reader)
	s, _ := reader.ReadString('\n')
	res := solve(n, k, s)
	fmt.Println(res)
}

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

const MOD = 998244353

const N = 5010

var F []int64
var I []int64

func pow(a, b int) int {
	A := int64(a)
	R := int64(1)

	for b > 0 {
		if b&1 == 1 {
			R = (R * A) % MOD
		}
		A = (A * A) % MOD
		b >>= 1
	}
	return int(R)
}

func inverse(a int) int {
	return pow(a, MOD-2)
}

func init() {
	F = make([]int64, N)
	I = make([]int64, N)
	F[0] = 1
	for i := 1; i < N; i++ {
		F[i] = mul(int64(i), F[i-1])
	}
	I[N-1] = int64(inverse(int(F[N-1])))

	for i := N - 2; i >= 0; i-- {
		I[i] = mul(int64(i+1), I[i+1])
	}
}

func nCr(n, r int) int64 {
	if n < 0 || n < r {
		return 0
	}
	res := F[n]
	res = mul(res, I[r])
	res = mul(res, I[n-r])
	return res
}

func mul(a, b int64) int64 {
	a *= b
	a %= MOD
	return a
}

func add(a, b int64) int64 {
	a += b
	if a >= MOD {
		a -= MOD
	}
	return a
}

func sub(a, b int64) int64 {
	return add(a, MOD-b)
}

func solve(n int, k int, s string) int {
	var ones []int
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			ones = append(ones, i)
		}
	}

	if len(ones) < k || k == 0 {
		return 1
	}

	var tot int64 = 1
	for i, cur := range ones {
		var start int
		if i > 0 {
			start = ones[i-1] + 1
		}
		var end int = n - 1
		if i+k < len(ones) {
			end = ones[i+k] - 1
		}
		tot = add(tot, nCr(end-start+1, min(k, len(ones)-i)))
		tot = sub(tot, nCr(end-cur, min(k, len(ones)-i)-1))
	}

	return int(tot)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1622D(in io.Reader, out io.Writer) {
	const mod, mx = 998244353, 5000
	F := [mx + 1]int64{1}
	for i := 1; i <= mx; i++ {
		F[i] = F[i-1] * int64(i) % mod
	}
	pow := func(x, n int64) (res int64) {
		res = 1
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return
	}
	invF := [...]int64{mx: pow(F[mx], mod-2)}
	for i := mx; i > 0; i-- {
		invF[i-1] = invF[i] * int64(i) % mod
	}
	C := func(n, k int) int64 { return F[n] * invF[k] % mod * invF[n-k] % mod }

	var n, k int
	var s string
	Fscan(bufio.NewReader(in), &n, &k, &s)
	pos := []int{}
	for i, b := range s {
		if b == '1' {
			pos = append(pos, i)
		}
	}
	if k == 0 || len(pos) < k {
		Fprint(out, 1)
		return
	}
	pos = append(pos, n)
	ans := C(pos[k], k)
	for i := k + 1; i < len(pos); i++ {
		ans += C(pos[i]-pos[i-k-1]-1, k) - C(pos[i-1]-pos[i-k-1]-1, k-1)
	}
	Fprint(out, (ans%mod+mod)%mod)
}

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

package main

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

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

const TAM = 5010
const MOD = 998244353

func add(a, b int) int {
	return (a + b) % MOD
}

var s string
var n, k int
var nCk [TAM][TAM]int
var next1 [TAM]int
var prev1 [TAM]int

// var sufSum [TAM]int

func solve(seg []int, prevSeg []int) int {
	// fmt.Fprintf(out, "solve %s (%v %v)\n", s[seg[0]:seg[1]+1], seg, prevSeg)
	var segLen = seg[1] - seg[0] + 1
	var ans = nCk[segLen][k]
	if len(prevSeg) > 0 {
		ans -= nCk[segLen-(seg[1]-prevSeg[1])][k-1]
	}
	return ans
}

func main() {
	fmt.Fscan(in, &n, &k)
	fmt.Fscan(in, &s)

	if k == 0 {
		fmt.Fprintf(out, "1\n")
		out.Flush()
		return
	}
	prev1[0] = -1
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			prev1[i+1] = i
		} else {
			prev1[i+1] = prev1[i]
		}
	}

	next1[n-1] = n
	for i := n - 1; i > 0; i-- {
		if s[i] == '1' {
			next1[i-1] = i
		} else {
			next1[i-1] = next1[i]
		}
	}

	// sufSum[n] = 0
	// for i := n - 1; i >= 0; i-- {
	// 	sufSum[i] = sufSum[i+1]
	// 	if s[i] == '1' {
	// 		sufSum[i]++
	// 	}
	// }

	for i := 0; i <= n; i++ {
		for j := 0; j <= n; j++ {
			if j == 0 || j == i {
				nCk[i][j] = 1
			} else if j > i {
				nCk[i][j] = 0
			} else {
				nCk[i][j] = add(nCk[i-1][j-1], nCk[i-1][j])
			}
		}
	}

	var ans = 0
	var ones []int
	var prevSegment []int = []int{}
	var curSegment []int = []int{-1, -1}
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			ones = append(ones, i)
			if len(ones) > k {
				ones = ones[1:]
			}

			if len(ones) == k {
				curSegment = []int{
					prev1[ones[0]] + 1,
					next1[ones[k-1]] - 1,
				}
				ans += solve(curSegment, prevSegment)
				prevSegment = curSegment
			}
		}
	}

	if len(ones) < k {
		ans = 1
	}

	fmt.Fprintf(out, "%d\n", ans)
	out.Flush()
}

package main

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

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

const TAM = 5010
const MOD = 998244353

func add(a, b int) int {
	return (a + b) % MOD
}

var s string
var n, k int
var nCk [TAM][TAM]int
var next1 [TAM]int
var prev1 [TAM]int

// var sufSum [TAM]int

func solve(seg []int, prevSeg []int) int {
	// fmt.Fprintf(out, "solve %s (%v %v)\n", s[seg[0]:seg[1]+1], seg, prevSeg)
	var segLen = seg[1] - seg[0] + 1
	var ans = nCk[segLen][k]
	if len(prevSeg) > 0 {
		ans -= nCk[segLen-(seg[1]-prevSeg[1])][k-1]
	}
	return ans
}

func main() {
	fmt.Fscan(in, &n, &k)
	fmt.Fscan(in, &s)

	if k == 0 {
		fmt.Fprintf(out, "0\n")
		out.Flush()
		return
	}
	prev1[0] = -1
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			prev1[i+1] = i
		} else {
			prev1[i+1] = prev1[i]
		}
	}

	next1[n-1] = n
	for i := n - 1; i > 0; i-- {
		if s[i] == '1' {
			next1[i-1] = i
		} else {
			next1[i-1] = next1[i]
		}
	}

	// sufSum[n] = 0
	// for i := n - 1; i >= 0; i-- {
	// 	sufSum[i] = sufSum[i+1]
	// 	if s[i] == '1' {
	// 		sufSum[i]++
	// 	}
	// }

	for i := 0; i <= n; i++ {
		for j := 0; j <= n; j++ {
			if j == 0 || j == i {
				nCk[i][j] = 1
			} else if j > i {
				nCk[i][j] = 0
			} else {
				nCk[i][j] = add(nCk[i-1][j-1], nCk[i-1][j])
			}
		}
	}

	var ans = 0
	var ones []int
	var prevSegment []int = []int{}
	var curSegment []int = []int{-1, -1}
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			ones = append(ones, i)
			if len(ones) > k {
				ones = ones[1:]
			}

			if len(ones) == k {
				curSegment = []int{
					prev1[ones[0]] + 1,
					next1[ones[k-1]] - 1,
				}
				ans += solve(curSegment, prevSegment)
				prevSegment = curSegment
			}
		}
	}

	if len(ones) < k {
		ans = 1
	}

	fmt.Fprintf(out, "%d\n", ans)
	out.Flush()
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, k := readTwoNums(reader)
	s, _ := reader.ReadString('\n')
	res := solve(n, k, s)
	fmt.Println(res)
}

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

const MOD = 998244353

const N = 5010

var F []int64
var I []int64

func pow(a, b int) int {
	A := int64(a)
	R := int64(1)

	for b > 0 {
		if b&1 == 1 {
			R = (R * A) % MOD
		}
		A = (A * A) % MOD
		b >>= 1
	}
	return int(R)
}

func inverse(a int) int {
	return pow(a, MOD-2)
}

func init() {
	F = make([]int64, N)
	I = make([]int64, N)
	F[0] = 1
	for i := 1; i < N; i++ {
		F[i] = mul(int64(i), F[i-1])
	}
	I[N-1] = int64(inverse(int(F[N-1])))

	for i := N - 2; i >= 0; i-- {
		I[i] = mul(int64(i+1), I[i+1])
	}
}

func nCr(n, r int) int64 {
	if n < 0 || n < r {
		return 0
	}
	res := F[n]
	res = mul(res, I[r])
	res = mul(res, I[n-r])
	return res
}

func mul(a, b int64) int64 {
	a *= b
	a %= MOD
	return a
}

func add(a, b int64) int64 {
	a += b
	if a >= MOD {
		a -= MOD
	}
	return a
}

func sub(a, b int64) int64 {
	return add(a, MOD-b)
}

func solve(n int, k int, s string) int {
	var ones []int
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			ones = append(ones, i)
		}
	}

	if len(ones) < k {
		return 1
	}

	var tot int64 = 1
	for i, cur := range ones {
		var start int
		if i > 0 {
			start = ones[i-1] + 1
		}
		var end int = n - 1
		if i+k < len(ones) {
			end = ones[i+k] - 1
		}
		tot = add(tot, nCr(end-start+1, min(k, len(ones)-i)))
		tot = sub(tot, nCr(end-cur, min(k, len(ones)-i)-1))
	}

	return int(tot)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1622D(in io.Reader, out io.Writer) {
	const mod, mx = 998244353, 5000
	F := [mx + 1]int64{1}
	for i := 1; i <= mx; i++ {
		F[i] = F[i-1] * int64(i) % mod
	}
	pow := func(x, n int64) (res int64) {
		res = 1
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return
	}
	invF := [...]int64{mx: pow(F[mx], mod-2)}
	for i := mx; i > 0; i-- {
		invF[i-1] = invF[i] * int64(i) % mod
	}
	C := func(n, k int) int64 { return F[n] * invF[k] % mod * invF[n-k] % mod }

	var n, k int
	var s string
	Fscan(bufio.NewReader(in), &n, &k, &s)
	pos := []int{}
	for i, b := range s {
		if b == '1' {
			pos = append(pos, i)
		}
	}
	if k == 0 || len(pos) < k {
		Fprint(out, 1)
		return
	}
	pos = append(pos, n)
	ans := C(pos[k], k)
	for i := k + 1; i < len(pos); i++ {
		d := pos[i] - pos[i-k-1] - 1
		if i < len(pos)-1 {
			ans = (ans + C(d, k) - C(d-1, k-1)) % mod
		} else {
			ans = (ans + C(d, k) - C(pos[i-1]-pos[i-k-1]-1, k-1)) % mod
		}
	}
	ans = (ans%mod + mod) % mod
	Fprint(out, ans)
}

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


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Scan()
	args := strings.Split(strings.TrimSpace(scanner.Text()), " ")

	values := make([]int, len(args))
	for i, a := range args {
		values[i], _ = strconv.Atoi(a)
	}

	sort.Ints(values)
	n := len(args) / 2
	if values[n] > values[n - 1] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var a = make([]int, 2*n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[2*i],&a[2*i+1])
	}
	sort.Ints(a)
	if a[n-1] < a[n] {
		fmt.Printf("YES\n")
	} else {
		fmt.Printf("NO\n")
	}
}

package main

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

const maxTokenSize = 512 * 1024

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, maxTokenSize), maxTokenSize)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	a := make([]int, 2*n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		a[2*i], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		a[2*i+1], _ = strconv.Atoi(scanner.Text())
	}

	sort.Ints(a)
	if a[n-1] < a[n] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	shahmat := make([]int, n*2)
	for i := 0; i < n*2; i++ {
		fmt.Scanf("%d", &shahmat[i])
	}
	sort.Ints(shahmat)
	for i := 0; i < n; i++ {
		for j := n; j < n*2; j++ {
			if shahmat[j] <= shahmat[i] {
				fmt.Println("NO")
				os.Exit(0)
			}
		}
	}
	fmt.Println("YES")
}

package main

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

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	shahmat := make([]int, n*2)
	for i := 0; i < n*2; i++ {
		fmt.Scanf("%d", &shahmat[i])
	}
	sort.Ints(shahmat)
	for i, j := 0, n; i < n; i, j = i+1, j+1 {
		for j := n; j < n*2; j++ {
			if shahmat[j] <= shahmat[i] {
				fmt.Println("NO")
				os.Exit(0)
			}
		}
	}
	fmt.Println("YES")
}

package main

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

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	shahmat := make([]int, n*2)
	for i := 0; i < n*2; i++ {
		fmt.Scanf("%d", &shahmat[i])
	}
	sort.Ints(shahmat)
	for i, j := 0, n/2+1; i < n; i, j = i+1, j+1 {
		if shahmat[i] >= shahmat[j] {
			fmt.Println("NO")
			os.Exit(0)
		}
	}
	fmt.Println("YES")
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scanf("%d",&n)
	var a = make([]int, 2*n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d%d",&a[2*i],&a[2*i+1])
	}
	sort.Ints(a)
	if a[n-1] < a[n] {
		fmt.Printf("YES\n")
	} else {
		fmt.Printf("NO\n")
	}
}


package main

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

func main() {
	t := NextInt()
	for t > 0 {
		t--
		n := NextInt()
		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			a[i] = NextInt()
		}

		odds := make([]int, 0)
		evens := make([]int, 0)
		for i := 0; i < 2*n; i++ {
			if a[i] % 2 == 0 {
				evens = append(evens, i+1)
			} else {
				odds = append(odds, i+1)
			}
		}

		beginEven := 0
		beginOdd := 0
		if len(evens) % 2 == 0 {
			if len(evens) >= 2 {
				beginEven = 2
				beginOdd = 0
			} else {
				beginEven = 0
				beginOdd = 2
			}
		} else {
			beginEven = 1
			beginOdd = 1
		}

		for i := beginEven; i < len(evens); i += 2 {
			fmt.Println(evens[i], evens[i+1])
		}
		for i := beginOdd; i < len(odds); i += 2 {
			fmt.Println(odds[i], odds[i+1])
		}
	}
}

var sc = bufio.NewScanner(os.Stdin)

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

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

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

package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var T int
	con.Scan(&T)
	for testcase := 0; testcase < T; testcase++ {
		var n int
		con.Scan(&n)
		e := []int{}
		o := []int{}
		for i := 0; i < n+n; i++ {
			var a int
			con.Scan(&a)
			if a%2 == 0 {
				e = append(e, i+1)
			} else {
				o = append(o, i+1)
			}
		}
		if len(e)%2 == 0 && len(o)%2 == 0 {
			if len(e) > 0 {
				e = e[2:]
			} else {
				o = o[2:]
			}
		} else {
			e = e[1:]
			o = o[1:]
		}
		for i := 0; i < len(e)/2; i++ {
			con.Println(e[i*2], e[i*2+1])
		}
		for i := 0; i < len(o)/2; i++ {
			con.Println(o[i*2], o[i*2+1])
		}
	}
	return nil
}

package main

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

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

	var t, n int
	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d\n", &n)

		odds := make([]int, 0, 1000)
		even := make([]int, 0, 1000)

		var temp int
		for i := 1; i <= 2*n; i++ {
			if i == 2*n {
				fmt.Fscanf(reader, "%d\n", &temp)
			} else {
				fmt.Fscanf(reader, "%d ", &temp)
			}
			if temp%2 == 0 {
				even = append(even, i)
			} else {
				odds = append(odds, i)
			}
		}

		if len(odds)%2 == 1 {
			odds = odds[1:]
		}

		if len(even)%2 == 1 {
			even = even[1:]
		}

		if len(odds)+len(even) == 2*n {
			if len(odds) > 0 {
				odds = odds[2:]
			} else {
				even = even[2:]
			}
		}

		for i := 0; i+1 < len(odds); i += 2 {
			fmt.Printf("%d %d\n", odds[i], odds[i+1])
		}

		for i := 0; i+1 < len(even); i += 2 {
			fmt.Printf("%d %d\n", even[i], even[i+1])
		}
	}
}

package main

import (
  . "fmt"
)

var t int
func main() {
  Scan(&t)
  for tc := 0; tc < t; tc++ {
    var n int
    var a int
    evens := make([]int, n)
    odds := make([]int, n)
    Scan(&n)
    for i := 0; i < 2*n; i++ {
      Scan(&a)
      if a % 2 == 1 {
        odds = append(odds, i+1)
      } else {
        evens = append(evens, i+1)
      }
    }
    pos1,pos2 := 0,0
    if len(odds) % 2 == 1 {
      pos1++
      pos2++
    } else if len(evens) == 2*n {
      pos2+=2
    } else {
      pos1+=2
    }
    for i := pos1; i < len(odds); i += 2 {
      Println(odds[i], odds[i+1])
    }
    for i := pos2; i < len(evens); i += 2 {
      Println(evens[i], evens[i+1])
    }
  }
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, 2*n)
		res := solve(n, A)
		var buf bytes.Buffer

		for _, ans := range res {
			buf.WriteString(fmt.Sprintf("%d %d\n", ans[0], ans[1]))
		}

		fmt.Println(buf.String())
	}
}

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

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

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

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

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

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

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

	return i
}
func solve(n int, A []int) [][]int {
	ps := make([]Pair, 2*n)
	for i := 0; i < len(A); i++ {
		ps[i] = Pair{A[i], i}
	}
	sort.Sort(Pairs(ps))

	j := sort.Search(len(ps), func(j int) bool {
		return ps[j].first&1 == 0
	})

	if j&1 == 1 {
		j--
	}
	var p int
	res := make([][]int, n-1)
	for i := 0; i < j && p < n-1; i += 2 {
		res[p] = []int{ps[i].second + 1, ps[i+1].second + 1}
		p++
	}

	for i := len(ps) - 1; p < n-1; i -= 2 {
		res[p] = []int{ps[i-1].second + 1, ps[i].second + 1}
		p++
	}
	return res
}

type Pair struct {
	first, second int
}

type Pairs []Pair

func (pairs Pairs) Len() int {
	return len(pairs)
}

func (pairs Pairs) Less(i, j int) bool {
	a := pairs[i]
	b := pairs[j]

	return a.first&1 > b.first&1 || a.first&1 == b.first&1 && a.second < b.second
}

func (pairs Pairs) Swap(i, j int) {
	pairs[i], pairs[j] = pairs[j], pairs[i]
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, 2*n)
		res := solve(n, A)
		var buf bytes.Buffer

		for _, ans := range res {
			buf.WriteString(fmt.Sprintf("%d %d\n", ans[0], ans[1]))
		}

		fmt.Println(buf.String())
	}
}

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

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

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

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

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

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

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

	return i
}
func solve(n int, A []int) [][]int {
	ps := make([]Pair, 2*n)
	for i := 0; i < len(A); i++ {
		ps[i] = Pair{A[i], i}
	}
	sort.Sort(Pairs(ps))

	j := sort.Search(len(ps), func(j int) bool {
		return ps[j].first&1 == 0
	})
	var u int
	if j&1 == 1 {
		u++
	}
	var p int
	res := make([][]int, n-1)

	for p < n-1 {
		res[p] = []int{ps[u].second + 1, ps[u+1].second + 1}
		u += 2
		p++
	}

	return res
}

type Pair struct {
	first, second int
}

type Pairs []Pair

func (pairs Pairs) Len() int {
	return len(pairs)
}

func (pairs Pairs) Less(i, j int) bool {
	a := pairs[i]
	b := pairs[j]

	return a.first&1 > b.first&1 || a.first&1 == b.first&1 && a.second < b.second
}

func (pairs Pairs) Swap(i, j int) {
	pairs[i], pairs[j] = pairs[j], pairs[i]
}

// https://codeforces.com/contest/1365/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

type my struct {
	val, index int
}
func solver() {
	var n int
	fmt.Fscan(input, &n)
	even, odd := make([]my, 0), make([]my, 0)
	for i := 0; i < 2*n; i++ {
		var t int
		fmt.Fscan(input, &t)
		if t & 1 == 1 {
			odd = append(odd, my{t, i + 1})
		} else {
			even = append(even, my{t, i + 1})
		}
	}
	e, o := 0, 0
	n--
	for n > 0 && e + 1 < len(even) {
		fmt.Println(even[e].index, even[e+1].index)
		e += 2
		n--
	}
	for n > 0 && o + 1 < len(odd) {
		fmt.Println(odd[o].index, odd[o+1].index)
		o += 2
		n--
	}
}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() int {
		scanner.Scan()
		i, _ := strconv.Atoi(scanner.Text())
		return i
	}

	var t, n int

	t = input()

	for ; t > 0; t-- {
		n = input()

		arr := make([]int, 2*n)

		for i := range arr {
			arr[i] = input()
		}

		countEven := 0
		countOdd := 0

		for i := range arr {
			if arr[i]%2 == 0 {
				countEven++
			} else {
				countOdd++
			}
		}

		if countOdd == 0 {
			countEven -= 2
		} else if countOdd%2 == 0 {
			countOdd -= 2
		} else {
			countOdd--
			countEven--
		}

		numCollected := 0
		prev := 0

		for i := range arr {
			if countEven > 0 {
				if arr[i]%2 == 0 {
					if numCollected == 0 {
						prev = i
						numCollected++
					} else {
						fmt.Println(prev+1, i+1)
						numCollected = 0
						prev = 0
					}

					countEven--
				}
			} else {
				break
			}
		}

		numCollected = 0
		prev = 0
		for i := range arr {
			if countOdd > 0 {
				if arr[i]%2 == 1 {
					if numCollected == 0 {
						prev = i
						numCollected++
					} else {
						fmt.Println(prev+1, i+1)
						numCollected = 0
						prev = 0
					}

					countOdd--
				}
			} else {
				break
			}
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		evens := make([]int, 2*n)
		odds := make([]int, 2*n)
		evensLen := 0
		oddsLen := 0
		for j := 1; j <= 2*n; j++ {
			var x int
			fmt.Scan(&x)
			if x%2 == 0 {
				evens[evensLen] = j
				evensLen++
			} else {
				odds[oddsLen] = j
				oddsLen++
			}
		}
		if evensLen%2 == 0 && evensLen > 0 {
			evensLen -= 2
		} else if oddsLen%2 == 0 {
			oddsLen -= 2
		}
		// fmt.Println(evensLen, evens)
		// fmt.Println(oddsLen, odds)

		for j := 0; j < evensLen/2; j++ {
			fmt.Println(evens[2*j], evens[2*j+1])
		}
		for j := 0; j < oddsLen/2; j++ {
			fmt.Println(odds[2*j], odds[2*j+1])
		}
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		ns := readLine(reader)
		line := readLine(reader)
		arrs := strings.Split(string(line), " ")
		odds := make([]int, 0)
		evens := make([]int, 0)
		n, _ := strconv.Atoi(string(ns))
		for i := 0; i < 2*n; i++ {
			number, _ := strconv.Atoi(arrs[i])
			if number % 2 == 1 {
				odds = append(odds, i+1)
			} else {
				evens = append(evens, i+1)
			}
		}
		if len(odds) % 2 == 0 && len(odds) > 0 {
			odds = odds[:len(odds)-2]
		} else if len(evens) % 2 == 0 && len(evens) > 0 {
			evens = evens[:len(evens)-2]
		} else if len(odds) % 2 == 1 {
			odds = odds[:len(odds)-1]
			evens = evens[:len(evens)-1]
		}
		for i:=0;i<len(odds);i+=2 {
			fmt.Println(odds[i], odds[i+1])
		}
		for i:=0;i<len(evens);i+=2 {
			fmt.Println(evens[i], evens[i+1])
		}
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		as := ReadInts(2 * n)
		solve(n, as)
	}
}

func solve(n int, as []int) {
	copied := Dup(as)
	sort.Sort(sort.IntSlice(copied))
	maxCombi := copied[len(copied)-1] + copied[len(copied)-2]

	_, primes := Sieve(maxCombi)
	for _, prime := range primes {
		if check(prime, n, as) {
			return
		}
	}
}

func check(div int, n int, as []int) bool {
	ans := [][]int{}
	used := make(map[int]bool)
	for i := 0; i < len(as)-1; i++ {
		if used[i] {
			continue
		}
		for j := i + 1; j < len(as); j++ {
			if used[j] {
				continue
			}
			if (as[i]+as[j])%div == 0 {
				ans = append(ans, []int{i, j})
				used[i] = true
				used[j] = true
				break
			}
		}
	}
	if len(ans) >= n-1 {
		for i := 0; i < n-1; i++ {
			fmt.Println(ans[i][0]+1, ans[i][1]+1)
		}
		return true
	}
	return false
}

func Dup(xs []int) []int {
	return append([]int{}, xs...)
}

// Sieve returns isPrime, primes
func Sieve(max int) ([]bool, []int) {
	isPrime := make([]bool, max+1)
	for i := 2; i <= max; i++ {
		isPrime[i] = true
	}
	primes := []int{}
	for i := 2; i <= max; i++ {
		if !isPrime[i] {
			continue
		}
		for j := 2 * i; j <= max; j += i {
			isPrime[j] = false
		}
		primes = append(primes, i)
	}
	return isPrime, primes
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	a, err := strconv.Atoi(Read())
	if err != nil {
		panic(err)
	}
	return a
}

func ReadInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = ReadInt()
	}
	return ret
}

func ReadInt64() int64 {
	a, err := strconv.ParseInt(Read(), 10, 64)
	if err != nil {
		panic(err)
	}
	return a
}

func ReadInt64s(n int) []int64 {
	ret := make([]int64, n)
	for i := 0; i < n; i++ {
		ret[i] = ReadInt64()
	}
	return ret
}

package main

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

var nTest, n int

type pair struct {
	val int
	id  int
}

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n)
		odd := []int{}
		even := []int{}
		var x int
		for i := 0; i < n*2; i++ {
			fmt.Fscan(in, &x)

			if x&1 == 0 {
				even = append(even, i+1)
			} else {
				odd = append(odd, i+1)
			}
		}

		nOdd := len(odd) / 2 * 2
		nEven := 2*n - 2 - nOdd
		if nEven < 0 {
			nEven = 0
			nOdd -= 2
		}
		// fmt.Println("AHIHI", nOdd, nEven)
		for i := 0; i < nOdd/2; i++ {
			fmt.Fprintln(out, odd[i*2], odd[i*2+1])
		}
		for i := 0; i < nEven/2; i++ {
			fmt.Fprintln(out, even[i*2], even[i*2+1])
		}
	}

	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1370B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n, v int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		id := [2][]int{}
		for i := 1; i <= 2*n; i++ {
			Fscan(in, &v)
			id[v&1] = append(id[v&1], i)
		}
		if len(id[0])&1 == 0 {
			if len(id[0]) > 0 {
				id[0] = id[0][2:]
			} else {
				id[1] = id[1][2:]
			}
		} else {
			id[0] = id[0][1:]
			id[1] = id[1][1:]
		}
		for _, v := range id {
			for i := 0; i < len(v); i += 2 {
				Fprintln(out, v[i], v[i+1])
			}
		}
	}
}

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

package main

import (
	"fmt"
	"math"
)

const PI = math.Pi
const mod = 1e9 + 7

func main() {
	//rand.Seed(time.Now().UnixNano())
	var t int
	for fmt.Scan(&t);t>0;t-- {
		var n int
		fmt.Scan(&n)
		var j []int
		var o []int
		for i := 0; i < 2*n; i++ {
			k := 0
			fmt.Scan(&k)
			if k % 2 == 0 {
				o = append(o, i+1)
			}else {
				j = append(j, i+1)
			}
		}
		if len(j)%2 == 0 {
			for i := 2; i < len(j); i+=2 {
				fmt.Println(j[i],j[i+1])
			}
			k := 0
			if len(j) == 0 {
				k = 2
			}
			for i := k; i < len(o); i+=2 {
				fmt.Println(o[i],o[i+1])
			}
		}else{
			for i := 1; i < len(j); i+=2 {
				fmt.Println(j[i],j[i+1])
			}
			for i := 1; i < len(o); i+=2 {
				fmt.Println(o[i],o[i+1])
			}
		}
	}
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)
var reader = bufio.NewReader(os.Stdin)

func readInt(delim byte) int {
    text, _ := reader.ReadString(delim)
    n, _ := strconv.ParseInt(strings.TrimSpace(text), 0, 32)
    return int(n)
}

func main() {
    t := readInt('\r')
    for i := 0; i < t; i++ {
        n := readInt('\r')
        lastOdd := -1
        lastEven := -1
        for j := 0; j < 2 * n - 2; j++ {
            curParity := readInt(' ') % 2
            if curParity == 0 {
                if lastEven != -1 {
                    fmt.Println(lastEven, j + 1)
                    lastEven = -1
                } else {
                    lastEven = j + 1
                }
            } else {
                if lastOdd != -1 {
                    fmt.Println(lastOdd, j + 1)
                    lastOdd = -1
                } else {
                    lastOdd = j + 1
                }
            }
        }
        prev := readInt(' ') % 2
        _ = readInt('\r')
        if lastOdd == -1 && lastEven == -1 {
            continue
        }
        if prev == 0 {
            fmt.Println(lastEven, 2*n - 1)
        } else {
            fmt.Println(lastOdd, 2*n - 1)
        }
    }
}

package main

import (
  . "fmt"
)

var t int
func main() {
  Scan(&t)
  for tc := 0; tc < t; tc++ {
    var n int
    var a int
    evens := make([]int, n)
    odds := make([]int, n)
    Scan(&n)
    for i := 0; i < 2*n; i++ {
      Scan(&a)
      if a % 2 == 1 {
        odds = append(odds, a)
      } else {
        evens = append(evens, a)
      }
    }
    pos1,pos2 := 0,0
    if len(odds) % 2 == 1 {
      //Println(odds[0], evens[0])
      pos1++
      pos2++
    } else {
      //Println(odds[0], odds[1])
      pos1+=2
    }
    for i := pos1; i < len(odds); i += 2 {
      Println(odds[i], odds[i+1])
    }
    for i := pos2; i < len(evens); i += 2 {
      Println(evens[i], evens[i+1])
    }
  }
}

package main

import (
  . "fmt"
)

var t int
func main() {
  Scan(&t)
  for tc := 0; tc < t; tc++ {
    var n int
    var a int
    evens := make([]int, n)
    odds := make([]int, n)
    Scan(&n)
    for i := 0; i < 2*n; i++ {
      Scan(&a)
      if a % 2 == 1 {
        odds = append(odds, i+1)
      } else {
        evens = append(evens, i+1)
      }
    }
    pos1,pos2 := 0,0
    if len(odds) % 2 == 1 {
      pos1++
      pos2++
    } else {
      pos1+=2
    }
    for i := pos1; i < len(odds); i += 2 {
      Println(odds[i], odds[i+1])
    }
    for i := pos2; i < len(evens); i += 2 {
      Println(evens[i], evens[i+1])
    }
  }
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() int {
		scanner.Scan()
		i, _ := strconv.Atoi(scanner.Text())
		return i
	}

	var t, n int

	t = input()

	for ; t > 0; t-- {
		n = input()

		arr := make([]int, 2*n)

		for i := range arr {
			arr[i] = input()
		}

		countEven := 0
		countOdd := 0

		for i := range arr {
			if arr[i]%2 == 0 {
				countEven++
			} else {
				countOdd++
			}
		}

		if countOdd%2 == 0 {
			countOdd -= 2
		} else {
			countOdd--
			countEven--
		}

		numCollected := 0
		prev := 0

		for i := range arr {
			if countEven > 0 {
				if arr[i]%2 == 0 {
					if numCollected == 0 {
						prev = i
						numCollected++
					} else {
						fmt.Println(prev+1, i+1)
						numCollected = 0
						prev = 0
					}

					countEven--
				}
			} else {
				break
			}
		}

		numCollected = 0
		prev = 0
		for i := range arr {
			if countOdd > 0 {
				if arr[i]%2 == 1 {
					if numCollected == 0 {
						prev = i
						numCollected++
					} else {
						fmt.Println(prev+1, i+1)
						numCollected = 0
						prev = 0
					}

					countOdd--
				}
			} else {
				break
			}
		}
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		as := ReadInts(2 * n)
		solve(n, as)
	}
}

func solve(n int, as []int) {
	sort.Sort(sort.IntSlice(as))
	maxCombi := as[len(as)-1] + as[len(as)-2]

	_, primes := Sieve(maxCombi)
	for _, prime := range primes {
		if check(prime, n, as) {
			return
		}
	}
}

func check(div int, n int, as []int) bool {
	ans := [][]int{}
	used := make(map[int]bool)
	for i := 0; i < len(as)-1; i++ {
		if used[i] {
			continue
		}
		for j := i + 1; j < len(as); j++ {
			if used[j] {
				continue
			}
			if (as[i]+as[j])%div == 0 {
				ans = append(ans, []int{i, j})
				used[i] = true
				used[j] = true
				break
			}
		}
	}
	if len(ans) >= n-1 {
		for i := 0; i < n-1; i++ {
			fmt.Println(ans[i][0]+1, ans[i][1]+1)
		}
		return true
	}
	return false
}

// Sieve returns isPrime, primes
func Sieve(max int) ([]bool, []int) {
	isPrime := make([]bool, max+1)
	for i := 2; i <= max; i++ {
		isPrime[i] = true
	}
	primes := []int{}
	for i := 2; i <= max; i++ {
		if !isPrime[i] {
			continue
		}
		for j := 2 * i; j <= max; j += i {
			isPrime[j] = false
		}
		primes = append(primes, i)
	}
	return isPrime, primes
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	a, err := strconv.Atoi(Read())
	if err != nil {
		panic(err)
	}
	return a
}

func ReadInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = ReadInt()
	}
	return ret
}

func ReadInt64() int64 {
	a, err := strconv.ParseInt(Read(), 10, 64)
	if err != nil {
		panic(err)
	}
	return a
}

func ReadInt64s(n int) []int64 {
	ret := make([]int64, n)
	for i := 0; i < n; i++ {
		ret[i] = ReadInt64()
	}
	return ret
}

package main

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

var nTest, n int

type pair struct {
	val int
	id  int
}

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n)
		odd := []pair{}
		even := []pair{}
		var x int
		for i := 0; i < n*2; i++ {
			fmt.Fscan(in, &x)

			if x&1 == 0 {
				even = append(even, pair{val: x, id: i + 1})
			} else {
				odd = append(odd, pair{val: x, id: i + 1})
			}
		}

		nOdd := len(odd) / 2 * 2
		nEven := 2*n - 2 - nOdd

		for i := 0; i < nOdd/2; i++ {
			fmt.Fprintln(out, odd[i*2].id, odd[i*2+1].id)
		}
		for i := 0; i < nEven/2; i++ {
			fmt.Fprintln(out, even[i*2].id, even[i*2+1].id)
		}
	}

	out.Flush()
}

package main

import (
	"fmt"
	"math"
)

const PI = math.Pi
const mod = 1e9 + 7

func main() {
	//rand.Seed(time.Now().UnixNano())
	var t int
	for fmt.Scan(&t);t>0;t-- {
		var n int
		fmt.Scan(&n)
		var j []int
		var o []int
		for i := 0; i < 2*n; i++ {
			k := 0
			fmt.Scan(&k)
			if k % 2 == 0 {
				o = append(o, i+1)
			}else {
				j = append(j, i+1)
			}
		}
		if len(j)%2 == 0 {
			for i := 0; i < len(j)-2; i+=2 {
				fmt.Println(j[i],j[i+1])
			}
			for i := 0; i < len(o); i+=2 {
				fmt.Println(o[i],o[i+1])
			}
		}else{
			for i := 0; i < len(j)-1; i+=2 {
				fmt.Println(j[i],j[i+1])
			}
			for i := 0; i < len(o)-1; i+=2 {
				fmt.Println(o[i],o[i+1])
			}
		}
	}
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)
var reader = bufio.NewReader(os.Stdin)

func readInt(delim byte) int {
    text, _ := reader.ReadString(delim)
    n, _ := strconv.ParseInt(strings.TrimSpace(text), 0, 32)
    return int(n)
}

func main() {
    t := readInt('\r')
    for i := 0; i < t; i++ {
        n := readInt('\r')
        lastOdd := -1
        lastEven := -1
        for j := 0; j < 2 * n - 2; j++ {
            curParity := readInt(' ') % 2
            if curParity == 0 {
                if lastEven != -1 {
                    fmt.Println(lastEven, j + 1)
                    lastEven = -1
                } else {
                    lastEven = j + 1
                }
            } else {
                if lastOdd != -1 {
                    fmt.Println(lastOdd, j + 1)
                    lastOdd = -1
                } else {
                    lastOdd = j + 1
                }
            }
        }
        if lastOdd == -1 && lastEven == -1 {
            _ = readInt(' ')
            _ = readInt('\r')
            continue
        }
        prev := readInt(' ') % 2
        if prev == 0 {
            fmt.Println(lastEven, 2*n - 1)
        }
        _ = readInt('\r')
    }
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)
var reader = bufio.NewReader(os.Stdin)

func readInt(delim byte) int {
    text, _ := reader.ReadString(delim)
    n, _ := strconv.ParseInt(strings.TrimSpace(text), 0, 32)
    return int(n)
}

func main() {
    t := readInt('\r')
    for i := 0; i < t; i++ {
        n := readInt('\r')
        lastOdd := -1
        lastEven := -1
        for j := 0; j < 2 * n - 2; j++ {
            curParity := readInt(' ') % 2
            if curParity == 0 {
                if lastEven != -1 {
                    fmt.Println(lastEven, j + 1)
                    lastEven = -1
                } else {
                    lastEven = j + 1
                }
            } else {
                if lastOdd != -1 {
                    fmt.Println(lastOdd, j + 1)
                    lastOdd = -1
                } else {
                    lastOdd = j + 1
                }
            }
        }
        if lastOdd == -1 && lastEven == -1 {
            continue
        }
        prev := readInt(' ') % 2
        if prev == 0 {
            fmt.Println(lastEven, 2*n - 1)
        }
        _ = readInt('\r')
    }
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)
var reader = bufio.NewReader(os.Stdin)

func readInt(delim byte) int {
    text, _ := reader.ReadString(delim)
    n, _ := strconv.ParseInt(strings.TrimSpace(text), 0, 32)
    return int(n)
}

func main() {
    t := readInt('\r')
    for i := 0; i < t; i++ {
        n := readInt('\r')
        lastOdd := -1
        lastEven := -1
        for j := 0; j < 2 * n - 2; j++ {
            curParity := readInt(' ') % 2
            if curParity == 0 {
                if lastEven != -1 {
                    fmt.Println(lastEven, j + 1)
                    lastEven = -1
                } else {
                    lastEven = j + 1
                }
            } else {
                if lastOdd != -1 {
                    fmt.Println(lastOdd, j + 1)
                    lastOdd = -1
                } else {
                    lastOdd = j + 1
                }
            }
        }
        prev := readInt(' ') % 2
        _ = readInt('\r')
        if (lastOdd == -1) != (lastEven == -1) {
            panic(1)
        }
        if lastOdd == -1 && lastEven == -1 {
            continue
        }
        if prev == 0 {
            fmt.Println(lastEven, 2*n - 1)
        }
    }
}