package main

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

var in *bufio.Reader
var out *bufio.Writer

////////////////////////////////////////////////

func solve() {
	s := ReadString()
	n := len(s)

	w := ReadInt()
	m := ReadInt()

	ps := make([]int, n)
	ps[0] = int(s[0] - '0')
	for i := 1; i < n; i++ {
		ps[i] = (ps[i-1]*10 + int(s[i]-'0')) % 9
	}

	pw := make([]int, n+1)
	pw[0] = 1
	for i := 1; i <= n; i++ {
		pw[i] = (pw[i-1] * 10) % 9
	}

	get := func(l, r int) int {
		ans := ps[r-1]
		if l > 0 {
			ans -= ps[l-1] * pw[r-l]
		}
		return (ans%9 + 9) % 9
	}

	pos := make([]int, 9)
	for i, _ := range pos {
		pos[i] = -1
	}
	pos2 := make([]int, 9)
	copy(pos2, pos)

	for i := 0; i+w <= n; i++ {
		md := get(i, i+w)
		if pos[md] == -1 {
			pos[md] = i
		} else if pos2[md] == -1 {
			pos2[md] = i
		}
	}

	for i := 0; i < m; i++ {
		l := ReadInt()
		l--
		r := ReadInt()
		zal := ReadInt()

		cur := get(l, r)
		ansx := n
		ansy := n
		for x := 0; x < 9; x++ {
			if pos[x] == -1 {
				continue
			}
			if pos2[x] != -1 && (x*cur+x)%9 == zal {
				if pos[x] < ansx || (pos[x] == ansx && pos2[x] < ansy) {
					ansx, ansy = pos[x], pos2[x]
				}
			}
			for y := 0; y < 9; y++ {
				if x == y || pos[y] == -1 || (x*cur+y)%9 != zal {
					continue
				}

				if pos[x] < ansx || (pos[x] == ansx && pos[y] < ansy) {
					ansx, ansy = pos[x], pos[y]
				}
			}
		}
		if ansx == n {
			Println("-1 -1")
		} else {
			Println(ansx+1, ansy+1)
		}
	}
}

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

	t := 1
	t = ReadInt()

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

func ReadInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}

func ReadLong() int64 {
	var x int64
	fmt.Fscan(in, &x)
	return x
}

func ReadInts(n int) []int {
	a := make([]int, n)
	for i, _ := range a {
		a[i] = ReadInt()
	}
	return a
}

func ReadString() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}

func Print(a ...any) {
	fmt.Fprint(out, a...)
}

func Println(a ...any) {
	fmt.Fprintln(out, a...)
}

type IntPair struct {
	x int
	y int
}

func Iota(a []int, start int) {
	for i := 0; i < len(a); i++ {
		a[i] = start
		start++
	}
}

func NextPermutation(a []int) bool {
	n := len(a)
	pos := n - 2
	for ; pos >= 0; pos-- {
		if a[pos] < a[pos+1] {
			break
		}
	}
	if pos == -1 {
		return false
	}
	for i := n - 1; i >= 0; i-- {
		if a[i] > a[pos] {
			a[i], a[pos] = a[pos], a[i]
			Reverse(a[pos+1 : n])
			break
		}
	}
	return true
}

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

func RemoveIf(a []int, cond func(int) bool) []int {
	n := len(a)
	pos := 0
	for i := 0; i < n; i++ {
		if !cond(a[i]) {
			a[pos] = a[i]
			pos++
		}
	}
	return a[0:pos]
}

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

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

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

package main

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

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

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

		aa := make([]int, 10)
		for i := range aa {
			aa[i] = -1
		}
		bb := make([][]int, 10)
		digs := make([][10]int, len(s)+1)
		var x int
		for i := 0; i < w; i++ {
			digs[i+1] = digs[i]
			digs[i+1][s[i]-'0']++
			x += int(s[i] - '0')
			if x >= 9 {
				x -= 9
			}
		}
		aa[x] = 0
		bb[x] = append(bb[x], 0)
		for i := w; i < len(s); i++ {
			x -= int(s[i-w] - '0')
			if x < 0 {
				x += 9
			}
			digs[i+1] = digs[i]
			digs[i+1][s[i]-'0']++
			x += int(s[i] - '0')
			if x >= 9 {
				x -= 9
			}
			if aa[x] < 0 {
				aa[x] = i - w + 1
			}

			if len(bb[x]) < 2 {
				bb[x] = append(bb[x], i-w+1)
			}
		}

		mm := make([][][2]int, 10)
		for i := range mm {
			mm[i] = make([][2]int, 10)
		}

		for i := 0; i < m; i++ {
			var l, r, z int
			fmt.Fscan(in, &l, &r, &z)

			// This must be the slow section.
			var shift int
			for k := 1; k <= 9; k++ {
				shift += (digs[r][k] - digs[l-1][k]) * k
			}
			shift %= 9
			if mm[shift][z][1] > 0 {
				fmt.Fprintln(out, mm[shift][z][0], mm[shift][z][1])
				continue
			}

			a, b := math.MaxInt32, -1
			for j := 0; j < 10; j++ {
				if aa[j] < 0 {
					continue
				}

				x := (9 + z - (j*shift)%9) % 9
				if len(bb[x]) > 0 {
					if aa[j]+1 == bb[x][0]+1 {
						if len(bb[x]) > 1 && bb[x][0]+1 < a {
							a, b = bb[x][0]+1, bb[x][1]+1
						}
					} else {
						if aa[j]+1 < a {
							a, b = aa[j]+1, bb[x][0]+1
						}
					}
				}
			}

			if a == math.MaxInt32 {
				a = -1
			}
			mm[shift][z] = [2]int{a, b}
			fmt.Fprintln(out, a, b)
		}
	}
}

package main

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

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

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

		aa := make([]int, 10)
		for i := range aa {
			aa[i] = -1
		}
		bb := make([][]int, 10)
		digs := make([][10]int, len(s)+1)
		var x int
		for i := 0; i < w; i++ {
			digs[i+1] = digs[i]
			digs[i+1][s[i]-'0']++
			x += int(s[i] - '0')
			if x >= 9 {
				x -= 9
			}
		}
		aa[x] = 0
		bb[x] = append(bb[x], 0)
		for i := w; i < len(s); i++ {
			x -= int(s[i-w] - '0')
			if x < 0 {
				x += 9
			}
			digs[i+1] = digs[i]
			digs[i+1][s[i]-'0']++
			x += int(s[i] - '0')
			if x >= 9 {
				x -= 9
			}
			if aa[x] < 0 {
				aa[x] = i - w + 1
			}

			if len(bb[x]) < 2 {
				bb[x] = append(bb[x], i-w+1)
			}
		}

		mm := make([][][2]int, 10)
		for i := range mm {
			mm[i] = make([][2]int, 10)
		}
		for i := 0; i < m; i++ {
			var l, r, z int
			fmt.Fscan(in, &l, &r, &z)

			// This must be the slow section.
			var shift int
			for k := 1; k <= 9; k++ {
				shift += (digs[r][k] - digs[l-1][k]) * k
			}
			shift %= 9
			if mm[shift][z][1] > 0 {
				fmt.Fprintln(out, mm[shift][z][0], mm[shift][z][1])
				continue
			}

			a, b := math.MaxInt32, -1
			for j := 0; j < 10; j++ {
				if aa[j] < 0 {
					continue
				}

				x := (9 + z - (j*shift)%9) % 9
				// fmt.Println(i, j, (j*shift)%9, x, bb[x])
				if len(bb[x]) > 0 && (aa[j]+1 < a || bb[x][0]+1 < a) {
					if aa[j]+1 == bb[x][0]+1 {
						if len(bb[x]) > 1 {
							a, b = bb[x][0]+1, bb[x][1]+1
						}
					} else {
						a, b = aa[j]+1, bb[x][0]+1
					}
				}
			}

			if a == math.MaxInt32 {
				a = -1
			}
			mm[shift][z] = [2]int{a, b}
			fmt.Fprintln(out, a, b)
		}
	}
}

package main

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

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

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

		aa := make([]int, len(s)-w+1)
		bb := make([][2]int, 10)
		for i := range bb {
			bb[i] = [2]int{-1, -1}
		}
		var x int
		for i := 0; i < w; i++ {
			x += int(s[i] - '0')
		}
		aa[0] = x % 9
		bb[aa[0]][0] = 0
		for i := w; i < len(s); i++ {
			x += int(s[i]-'0') - int(s[i-w]-'0')
			d := i - w + 1
			aa[d] = x % 9
			if bb[aa[d]][0] < 0 {
				bb[aa[d]][0] = d
			} else if bb[aa[d]][1] < 0 {
				bb[aa[d]][1] = d
			}
		}

		for i := 0; i < m; i++ {
			var l, r, z int
			fmt.Fscan(in, &l, &r, &z)
			l--
			r--

			var shift int
			for i := l; i <= r; i++ {
				shift += int(s[i] - '0')
			}
			shift %= 9

			a, b := math.MaxInt32, -1
			cc := make([]bool, 10)
			for j := 0; j < len(aa); j++ {
				if cc[aa[j]] {
					continue
				}

				x := (9 + z - (aa[j]*shift)%9) % 9
				// fmt.Println(i, j, (aa[j]*shift)%9, x, bb[x])
				if bb[x][0] >= 0 {
					if j+1 == bb[x][0]+1 {
						if bb[x][1] > 0 {
							a, b = bb[x][0]+1, bb[x][1]+1
						}
					} else {
						a, b = j+1, bb[x][0]+1
					}
					break
				}
			}

			if a == math.MaxInt32 {
				a = -1
			}
			fmt.Fprintln(out, a, b)
		}
	}
}

package main

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

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

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

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

		aa := make([]int, len(s)-w+1)
		var x int
		for i := 0; i < w; i++ {
			x += int(s[i] - '0')
		}
		aa[0] = x % 9
		for i := w; i < len(s); i++ {
			x += int(s[i]-'0') - int(s[i-w]-'0')
			aa[i-w+1] = x % 9
		}

		for i := 0; i < m; i++ {
			var l, r, z int
			fmt.Fscan(in, &l, &r, &z)
			l--
			r--

			var shift int
			for i := l; i <= r; i++ {
				shift += int(s[i] - '0')
			}
			shift %= 9

			req := make([][]int, 10)
			for j := 0; j < 10; j++ {
				req[(j*shift)%9] = append(req[(j*shift)%9], j)
			}
			bb := make([]int, 10)
			for i := range bb {
				bb[i] = -1
			}
			bb[aa[0]] = 0 // keeps track of the indexes of last mod9 seen.
			a, b := math.MaxInt32, -1
			for j := 1; j < len(aa); j++ {
				x := (9 + z - aa[j]) % 9
				for _, v := range req[x] {
					if bb[v] >= 0 {
						a, b = min(a, bb[v]+1), j+1
					}
				}

				if a < math.MaxInt32 {
					break
				}
				if bb[aa[j]] < 0 {
					bb[aa[j]] = j
				}
			}

			if a == math.MaxInt32 {
				a = -1
			}
			fmt.Fprintln(out, a, b)
		}
	}
}


package main

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

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

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

type edge struct {
	from, to  int
	visited   bool
	direction bool
}

func (e *edge) String() string {
	return fmt.Sprintf("%+v", *e)
}

type adjT struct {
	to int
	e  *edge
}

func (a adjT) String() string {
	return fmt.Sprintf("[%d: %v]", a.to, a.e)
}

func (a adjT) setDirection(dir bool) {
	if a.to == a.e.to {
		a.e.direction = dir
	} else {
		a.e.direction = !dir
	}
}

func (a adjT) direction() bool {
	if a.to == a.e.to {
		return a.e.direction
	}
	return !a.e.direction
}

var (
	n, m  int
	edges []*edge
	adj   [][]adjT
)

func dfs(v int, direction bool) bool {
	// Visit every edge going out from v and make its direction opposite to direction.
	for _, nex := range adj[v] {
		if nex.e.visited {
			// If outgoing edge already has a direction set, and it's not opposite, fail.
			if nex.direction() != !direction {
				return false
			}
			continue
		}

		nex.e.visited = true
		nex.setDirection(!direction)
		if !dfs(nex.to, !direction) {
			return false
		}
	}
	return true
}

func main() {
	defer writer.Flush()

	Scanf("%d %d\n", &n, &m)

	edges = make([]*edge, m+1)
	adj = make([][]adjT, n+1)
	for i := 1; i <= m; i++ {
		var e edge
		Scanf("%d %d\n", &e.from, &e.to)
		edges[i] = &e

		adj[e.from] = append(adj[e.from], adjT{e.to, &e})
		adj[e.to] = append(adj[e.to], adjT{e.from, &e})
	}

	for i := 1; i <= m; i++ {
		if edges[i].visited {
			continue
		}
		if !dfs(edges[i].from, false) {
			Printf("NO\n")
			return
		}
	}

	Printf("YES\n")
	for i := 1; i <= m; i++ {
		if edges[i].direction {
			Printf("1")
		} else {
			Printf("0")
		}
	}
}

package main

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

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

	var n, m int
	fmt.Scanln(&n, &m)

	edges := make([][]int, n)
	for i := range edges {
		edges[i] = make([]int, 0)
	}

	conUs := make([]int, m)
	conVs := make([]int, m)
	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscanln(in, &u, &v)
		u--
		v--

		conUs[i] = u
		conVs[i] = v

		edges[u] = append(edges[u], v)
		edges[v] = append(edges[v], u)
	}

	colors := make([]int, n)
	visited := make([]bool, n)

	for i := 0; i < n; i++ {
		if colors[i] == 0 {
			colors[i] = 1
			next := make([]int, 1)
			next[0] = i

			for len(next) != 0 {
				cur := next[0]
				next = next[1:]

				if visited[cur] {
					continue
				}
				visited[cur] = true

				for _, con := range edges[cur] {
					if colors[con] == 0 {
						next = append(next, con)
						colors[con] = colors[cur] * -1
					} else if colors[con] * -1 != colors[cur] {
						fmt.Println("NO")
						return
					}
				}
			}
		}
	}
	fmt.Println("YES")
	for _, conU := range conUs {
		if colors[conU] == -1 {
			fmt.Print("0")
		} else {
			fmt.Print("1")
		}
	}
	fmt.Println()
}

package main

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

type EdgeF struct {
	next *EdgeF
	u, v int
}

func addF(u, v int, mapp [][]int) {
	if len(mapp[u]) == 0 {
		mapp[u] = make([]int, 0)
	}
	mapp[u] = append(mapp[u], v)
}
func dfs(root int, color []int, mapp [][]int) bool {
	//fmt.Printf("root=%d\n",root)
	for _, next := range mapp[root] {
		if color[next] == 0 {
			if color[root] == 2 {
				color[next] = 1
			} else {
				color[next] = 2
			}
			if false==dfs(next,color,mapp){
				return false
			}
		} else if color[next] == color[root] {
			return false
		}
	}
	return true
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	edges := make([]EdgeF, m)
	mapp := make([][]int, n+1)
	for i := 0; i < m; i++ {
		fmt.Fscanf(buf, "%d %d\n", &edges[i].u, &edges[i].v)
		addF(edges[i].u, edges[i].v, mapp)
		addF(edges[i].v, edges[i].u, mapp)
	}
	color := make([]int,n+1)
	color[1] = 1
	if false == dfs(1,color,mapp){
		fmt.Printf("NO\n")
		return
	}
	fmt.Printf("YES\n")
	for i:=0;i < m;i++{
		fmt.Printf("%d",color[edges[i].u]-1)
	}
	fmt.Printf("\n")

}

package main

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

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

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

var (
	n, m     int
	edgeFrom []int
	adj      [][]int
	visited  []bool
	color    []bool
)

func dfs(v int, ccol bool) bool {
	visited[v] = true
	// Visit every edge going out from v and make its direction opposite to direction.
	for _, nex := range adj[v] {
		if visited[nex] {
			// If outgoing edge already has a direction set, and it's not opposite, fail.
			if ccol == color[nex] {
				return false
			}
			continue
		}

		color[nex] = !ccol
		if !dfs(nex, !ccol) {
			return false
		}
	}
	return true
}

func main() {
	defer writer.Flush()

	Scanf("%d %d\n", &n, &m)

	visited = make([]bool, n+1)
	color = make([]bool, n+1)
	adj = make([][]int, n+1)
	edgeFrom = make([]int, m+1)
	for i := 1; i <= m; i++ {
		var from, to int
		Scanf("%d %d\n", &from, &to)

		adj[from] = append(adj[from], to)
		adj[to] = append(adj[to], from)
		edgeFrom[i] = from
	}

	for i := 1; i <= n; i++ {
		if visited[i] {
			continue
		}
		if !dfs(i, false) {
			Printf("NO\n")
			return
		}
	}

	Printf("YES\n")
	for i := 1; i <= m; i++ {
		if color[edgeFrom[i]] {
			Printf("1")
		} else {
			Printf("0")
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1144F(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, m := read(), read()
	g := make([][]int, n)
	type pair struct{ v, w int }
	edges := make([]pair, m)
	for i := 0; i < m; i++ {
		v, w := read()-1, read()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		edges[i] = pair{v, w}
	}

	colors := make([]int8, n)
	var f func(int, int8) bool
	f = func(v int, c int8) bool {
		colors[v] = c
		for _, w := range g[v] {
			if colors[w] == c {
				return false
			}
			if colors[w] == 0 {
				if !f(w, 3-c) {
					return false
				}
			}
		}
		return true
	}
	for i, c := range colors {
		if c == 0 && !f(i, 1) {
			Fprintln(out, "NO")
			return
		}
	}
	Fprintln(out, "YES")
	for _, e := range edges {
		Fprint(out, colors[e.v]-1)
	}
}

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


package main

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

func main() {
	var n, K int

	fmt.Scanf("%d %d\n", &n, &K)

	var line string
	scanner := bufio.NewScanner(os.Stdin)

	buf := make([]byte, 0, 64*1024)
	scanner.Buffer(buf, 2048*1024)

	if scanner.Scan() {
		line = scanner.Text()
	}

	strList := strings.Split(line, " ")

	list := make([]int, n)
	count := make(map[int]int)

	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(strList[i])
		count[list[i]]++
	}

	sort.Ints(list)

	swallow := 0
	for i := 0; i < n-1; i++ {
		if list[i] < list[i+1] && list[i]+K >= list[i+1] {
			swallow += count[list[i]]
		}
	}

	fmt.Println(n - swallow)
}

package main

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

func solve() {
	n := readInt()
	K := readInt()
	a := readIntArray(n)
	if n == 1 {
		fmt.Println(1)
		return
	}
	sort.Ints(a)
	cur := 0
	offset := 1
	ans := 0
	for offset < len(a) {
		if cur == offset || a[cur] == a[offset] {
			offset++
			continue
		}
		if a[cur] < a[offset] && a[cur]+K >= a[offset] {
			ans++
			cur++
		} else {
			cur++
		}
	}
	fmt.Println(n - ans)

}

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

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, K int

	fmt.Scanf("%d %d", &n, &K)

	list := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&list[i])
	}

	sort.Ints(list)

	listK := make([]int, n)
	for i := 0; i < n; i++ {
		listK[i] = list[i] + K
	}

	swallow := 0
	for i := 0; i < n-1; i++ {
		if listK[i] >= list[i+1] {
			swallow++
		}
	}

	fmt.Println(len(list) - swallow)
}


package main

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

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

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

func solve(p []int, length int) {
	m := make(map[int]bool)
	i := 0

	for _, v := range p {
		if m[v] == false {
			m[v] = true
			if i != 0 {
				printf(" ")
			}
			printf("%d", v)

			i++
		}
	}
	printf("\n")

}

func main() {
	defer writer.Flush()

	var testCases int
	scanf("%d\n", &testCases)
	for i := 0; i < testCases; i++ {
		var length int
		scanf("%d\n", &length)
		var lengthOfTestCase = length * 2
		var p = make([]int, lengthOfTestCase)
		for j := 0; j < lengthOfTestCase; j++ {
			if j < lengthOfTestCase-1 {
				scanf("%d ", &p[j])
			} else {
				scanf("%d\n", &p[j])
			}
		}
		solve(p, length)
	}
}

package main

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

func main() {
	var t, n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		ans := make([]int, 0)
		tmp := make(map[int]bool, 0)
		for j := 0; j < n*2; j++ {
			fmt.Fscan(in, &a)
			if !tmp[a] {
				tmp[a] = true
				ans = append(ans, a)
			}
		}
		for j := 0; j < n; j++ {
			fmt.Printf("%d ", ans[j])
		}
		fmt.Println()
	}
}

package main
// https://codeforces.com/contest/1380/submission/87050098
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type FastIn struct {
	scanner *bufio.Scanner
}

func MakeFastIn() (obj FastIn)  {
	obj = FastIn{}
	obj.scanner = bufio.NewScanner(os.Stdin)
	obj.scanner.Split(bufio.ScanWords)
	return
}

func (fi *FastIn) ReadText() string {
	fi.scanner.Scan()
	return fi.scanner.Text()
}

func (fi *FastIn) ReadInt() int {
	ret, err := strconv.Atoi(fi.ReadText())
	if err != nil {
		panic(err)
	}
	return ret
}

func (fi *FastIn) ReadInts(arr []int) {
	for i := 0; i < len(arr); i++ {
		arr[i] = fi.ReadInt()
	}
}
func Min (a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func (fi *FastIn) ReadInt64() int64 {
	ret, err := strconv.ParseInt(fi.ReadText(), 10, 64)
	if err != nil {
		panic(err)
	}
	return ret
}

var x,k,y int64

func GetCost(arr []int, left_b int, right_b int) (int64, bool) {
	any_gt := false
	max_bound := left_b
	if max_bound < right_b {
		max_bound = right_b
	}
	for _,v := range arr {
		if  v > max_bound {
			any_gt = true
		}
	}

	len := int64(len(arr))
	if any_gt {
		if len < k {
			return 0, false
		}
		return Min((len/k)*x+(len%k)*y,x+(len-k)*y), true
	} else {
		return Min((len/k)*x+(len%k)*y, len * y), true
	}
}

func main() {
	fin := MakeFastIn()
	T := fin.ReadInt()
	for ;T>0;T--{
		n := fin.ReadInt()
		a:= make([]int, 2*n)
		fin.ReadInts(a)

		vis:= make([]bool, n)
		for i:=0;i<2*n;i++{
			if vis[a[i]-1]{
				continue
			}
			fmt.Print(a[i]," ")
			vis[a[i]-1]=true
		}
		fmt.Print("\n")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, a int
		fmt.Fscan(in, &n)
		d := make(map[int]bool)
		for i := 0; i < 2*n; i++ {
			fmt.Fscan(in, &a)
			if !d[a] {
				fmt.Fprint(out, a, " ")
			}
			d[a] = true
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

	for t := io.nextInt(); t > 0; t-- {
		n := io.nextInt()
		a := make([]int, 2*n)
		seen := make([]bool, n+1)
		for i := 0; i < 2*n; i++ {
			a[i] = io.nextInt()
			if !seen[a[i]] {
				io.print(a[i], " ")
				seen[a[i]] = true
			}
		}
		io.println()
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p []byte
}

func newFastIO(r io.Reader, w io.Writer) fastIO {
	return fastIO{bufio.NewReader(r), bufio.NewWriter(w), make([]byte, 1)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p)
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p)
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p)
	}
	return n
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

// https://codeforces.com/contest/x/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()
	}
}

func solver() {
	var n int
	fmt.Fscan(input, &n)
	ans := make([]int, 0)
	m := make([]int, 51)
	for i := 0; i < 2*n; i++ {
		var tmp int
		fmt.Fscan(input, &tmp)
		if m[tmp] == 0 {
			m[tmp]++
			ans = append(ans, tmp)
		}
	}
	for i := 0; i < len(ans); i++ {
		fmt.Print(ans[i], " ")
	}
	fmt.Println()
}

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

package main

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

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
	}

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

		arr := make([]int, n)

		for i := range arr {
			arr[i] = -1
		}

		for i:=0; i < 2*n; i++ {
			x := input()

			if arr[x-1] == -1 {
				arr[x-1] = index
				index++
			}
		}

		finarr := make([]int, n)

		for i := range arr {
			finarr[arr[i]] = i+1
		}

		for i := range finarr {
			fmt.Print(finarr[i], " ")
		}
		fmt.Print("\n")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		var p int
		a := make([]bool, n+1)
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(in, &p)
			if !a[p] {
				a[p] = true
				fmt.Print(p, " ")
			}
		}
		fmt.Println()
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		readLine(reader)
		line := readLine(reader)
		strs := strings.Split(string(line), " ")
		m := make(map[string]struct{})
		ss := ""
		for _, s:= range strs {
			if _, ok := m[s]; ok {
				continue
			}
			ss += s + " "
			m[s] = struct{}{}
		}
		fmt.Println(ss[:len(ss)-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 "fmt"

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

	for i := 0; i < t; i++ {
		var n, count, x int
		var output = make(map[int]int)
		var out = make([]int, n)
		fmt.Scan(&n)
		for j := 0; j < (2 * n); j++ {
			fmt.Scan(&x)
			if _, ok := output[x]; !ok {
				output[x] = 1
				out = append(out, x)
				count++
			}
			if count > n {
				break
			}
		}
		for _, val := range out {
			fmt.Printf("%d ", val)
		}
		fmt.Println()
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1385B(_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)
		vis := make([]bool, n+1)
		for n *= 2; n > 0; n-- {
			Fscan(in, &v)
			if !vis[v] {
				vis[v] = true
				Fprint(out, v, " ")
			}
		}
		Fprintln(out)
	}
}

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

package main

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

var t int
var y [55]int

func null() {
	for i := 0; i < 53; i++ {
		y[i] = 0
	}
}

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		null()
		var n int
		fmt.Fscan(input, &n)

		arr := make([]int, 2*n)
		for i := 0; i < (2 * n); i++ {
			fmt.Fscan(input, &arr[i])
		}

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

		fmt.Println()
	}
}

package main

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

func solve() {
	n := readInt()
	exists := make(map[int]bool)
	for i := 0; i < n*2; i++ {
		a := readInt()
		if _, ok := exists[a]; ok {
			continue
		}
		exists[a] = true
		fmt.Printf("%v ", a)
	}
}

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

func readInt() int {
	return int(readInt64())
}

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

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

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

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

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}

package main

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

func main() {
	defer writer.Flush()
	t := NextInt()
	for t > 0 {
		t--
		n := NextInt()
		used := make([]bool, n+1)
		for i := 0; i < 2*n; i++ {
			x := NextInt()
			if !used[x] {
				used[x] = true
				Print(x)
				Print(" ")
			}
		}
		Println("")
	}
}

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

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

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

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

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

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

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

func main() {
	defer out.Flush()
	var nTest int
	fmt.Fscanf(in, "%d\n", &nTest)
	for i := 0; i < nTest; i++ {
		solveCase()
	}
}
func solveCase() {
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]bool, n)
	for i := 0; i < 2*n; i++ {
		var x int
		fmt.Fscanf(in, "%d", &x)
		x--
		if !a[x] {
			a[x] = true
			fmt.Fprintf(out, "%d ", x+1)
		}
	}
	fmt.Fscanln(in)
	fmt.Fprint(out, "\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	var T int
	fmt.Fscanf(reader, "%d\n", &T)

	for _case := 1; _case <= T; _case++ {
		n := readInt()
		arr := readInts()
		ans := make([]int, n)
		used := make([]bool, n+1)

		for i,j := 0,0; i < n; i++ {
			for ; used[arr[j]]; j++ {}
			ans[i] = arr[j]
			used[arr[j]] = true
		}

		printInts(ans, " ")
		fmt.Println()
	}

	writer.Flush()
}

func readInts() []int {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func printInts(arr []int, sep string) {
	n := len(arr)
	if n == 0 { panic("printInts empty") }
	fmt.Printf("%d", arr[0])
	for i := 1; i < n; i++ {
		fmt.Printf("%s%d", sep, arr[i])
	}
}

package main

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

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

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

func solve(p []int, length int) []int {
	m := make(map[int]bool)
	var r []int

	for _, v := range p {
		if m[v] == false {
			r = append(r, v)
			m[v] = true
		}
	}

	return r

}

func main() {
	defer writer.Flush()

	var testCases int
	scanf("%d\n", &testCases)
	for i := 0; i < testCases; i++ {
		var length int
		scanf("%d\n", &length)
		var lengthOfTestCase = length * 2
		var p = make([]int, lengthOfTestCase)
		for j := 0; j < lengthOfTestCase; j++ {
			if j < lengthOfTestCase-1 {
				scanf("%d ", &p[j])
			} else {
				scanf("%d\n", &p[j])
			}
		}
		r := solve(p, length)
		printf("%v\n", r)
	}
}


package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = map[int]map[int]bool{}
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0, n+1)
            knows[a] = make(map[int]bool)
        }
        if g[b] == nil {
            g[b] = make([]int, 0, n+1)
            knows[b] = make(map[int]bool)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = make([][]bool, 4010)
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n)
    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0)
            knows[a] = make([]bool, n+1)
        }
        if g[b] == nil {
            g[b] = make([]int, 0)
            knows[b] = make([]bool, n+1)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import "fmt"

var (
    knows  = [4010][4010]bool{}
    degree = [4010]int{}
    ans    = 4010
)

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if knows[a][b] == false {
            knows[a][b] = true
            knows[b][a] = true
            degree[a]++
            degree[b]++
        }
    }

    for i := 1; i <= n; i++ {
        for j := i + 1; j <= n; j++ {
            if knows[i][j] {
                for k := j + 1; k <= n; k++ {
                    if knows[i][k] && knows[j][k] {
                        rec := degree[i] + degree[j] + degree[k] - 6
                        if ans > rec {
                            ans = rec
                        }
                    }
                }
            }
        }
    }
    if ans == 4010 {
        fmt.Println(-1)
    } else {
        fmt.Println(ans)
    }
}

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = [4010][4010]bool{}
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0, n+1)
        }
        if g[b] == nil {
            g[b] = make([]int, 0, n+1)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import "fmt"

var (
    knows  = [4010][4010]bool{}
    degree = [4010]int{}
    ans    = 4010
)

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        knows[a][b] = true
        knows[b][a] = true
        degree[a]++
        degree[b]++
    }

    for i := 1; i <= n; i++ {
        for j := i + 1; j <= n; j++ {
            if knows[i][j] {
                for k := j + 1; k <= n; k++ {
                    if knows[i][k] && knows[j][k] {
                        if ans > degree[i]+degree[j]+degree[k]-6 {
                            ans = degree[i] + degree[j] + degree[k] - 6
                        }
                    }
                }
            }
        }
    }
    if ans == 4010 {
        fmt.Println(-1)
    } else {
        fmt.Println(ans)
    }
}

package main

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

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

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

	n, m := nextInt(), nextInt()
	a, b := 0, 0
	pairs := make([][]bool, n+1)
	recogs := make([]int, n+1)
	minRecog := math.MaxInt32
	recog := 0

	for i := range pairs {
		pairs[i] = make([]bool, n+1)
	}

	for i := 0; i < m; i++ {
		a, b = nextInt(), nextInt()
		pairs[a][b] = true
		pairs[b][a] = true
		recogs[a]++
		recogs[b]++
	}
	// println(pairs)
	for i := 1; i < n+1; i++ {
		for j := i + 1; j < n+1; j++ {
			if pairs[i][j] {
				for k := j + 1; k < n+1; k++ {
					if pairs[i][k] && pairs[j][k] {
						recog = recogs[i] + recogs[j] + recogs[k] - 6
						// println(recog)
						if recog < minRecog {
							minRecog = recog
						}
					}
				}

			}
		}
	}

	if minRecog == math.MaxInt32 {
		println(-1)
	} else {
		println(minRecog)
	}
}

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

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

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

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

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

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

package main

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

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

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

	n, m := nextInt(), nextInt()
	a, b := 0, 0
	pairs := make([][]int, n+1)
	recogs := make([]int, n+1)
	minRecog := math.MaxInt32
	recog := 0

	for i := range pairs {
		pairs[i] = make([]int, n+1)
	}

	for i := 0; i < m; i++ {
		a, b = nextInt(), nextInt()
		pairs[a][b] = 1
		pairs[b][a] = 1
		recogs[a]++
		recogs[b]++
	}
	// println(pairs)
	for i := 1; i < n+1; i++ {
		for j := i + 1; j < n+1; j++ {
			if pairs[i][j] == 1 {
				for k := j + 1; k < n+1; k++ {
					if pairs[i][k] == 1 && pairs[j][k] == 1 {
						recog = recogs[i] + recogs[j] + recogs[k] - 6
						// println(recog)
						if recog < minRecog {
							minRecog = recog
						}
					}
				}

			}
		}
	}

	if minRecog == math.MaxInt32 {
		println(-1)
	} else {
		println(minRecog)
	}
}

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

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

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

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

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

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

package main

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

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

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  n, m := getI(), getI()
  edges := make([][]int, m)
  neighbor := make([]map[int]bool, n + 1)
  for u := 1; u <= n; u++ {
    neighbor[u] = map[int]bool{}
  }
  for i := range edges {
    u, v := getI(), getI()
    edges[i] = []int{ u, v }
    neighbor[u][v] = true
    neighbor[v][u] = true
  }
  min_sum := -1

  for _, edge := range edges {
    u, v := edge[0], edge[1]
    for w := 1; w <= n; w++ {
      if neighbor[u][w] && neighbor[v][w] {
        sum := -6 + len(neighbor[u]) + len(neighbor[v]) + len(neighbor[w])
        if min_sum == -1 || sum < min_sum {
          min_sum = sum
        }
      }
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n", min_sum))
}

package main

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

// Took from here: https://www.codementor.io/tucnak/using-golang-for-competitive-programming-h8lhvxzt3
var reader *bufio.Reader = bufio.NewReaderSize(os.Stdin, 10000000)
var writer *bufio.Writer = bufio.NewWriterSize(os.Stdout,10000000)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

var n, m int
var matrix [4001][4001]int
var warriors [4001]int

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

  scanf("%d %d\n", &n, &m)
  for i := 1; i <= m; i++ {
    var a, b int
    scanf("%d %d\n", &a, &b)
    matrix[a][b] = 1
    matrix[b][a] = 1
    warriors[a]++
    warriors[b]++
  }
  min := -1
  for i := 1; i <= n;  i++ {
    for j := 1; j <= n; j++ {
      if matrix[i][j] == 1 {
        for k := 1; k <= n; k++ {
          if matrix[j][k] == 1 && matrix[i][k] == 1 {
            sum := warriors[i] + warriors[j] + warriors[k]
            sum -= 6 // remove as contagens dos warriors escolhidos
            if sum < min || min == -1 {
              min = sum
            }
          }
        }
      }
    }
  }
  printf(strconv.Itoa(min))
}

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = [4010][4010]bool{}
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n)
    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0)
        }
        if g[b] == nil {
            g[b] = make([]int, 0)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = [4010][4010]bool{}
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0)
        }
        if g[b] == nil {
            g[b] = make([]int, 0)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import (
    "fmt"
)

var (
    knows  = [4010][4010]bool{}
    degree = [4010]int{}
    ans    = 4010
)

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        knows[a][b] = true
        knows[b][a] = true
        degree[a]++
        degree[b]++
    }

    for i := 1; i <= n; i++ {
        for j := i + 1; j <= n; j++ {
            if knows[i][j] {
                for k := j + 1; k <= n; k++ {
                    if knows[i][k] && knows[j][k] {
                        if ans > degree[i]+degree[j]+degree[k] {
                            ans = degree[i] + degree[j] + degree[k]
                        }
                    }
                }
            }
        }
    }
    if ans == 4010 {
        fmt.Println(-1)
    } else {
        fmt.Println(ans - 6)
    }
}

package main

import "fmt"

var (
	g     = make([][]int, 4010)
	knows = map[int]map[int]bool{}
	three = [3]int{0, 0, 0}
	ans   = -1
)

func dfs(idx, depth int) {
	three[depth] = idx
	if depth >= 2 {
		if knows[idx][three[0]] && idx != three[0] {
			rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
			if ans == -1 || ans > rec {
				ans = rec
			}
		}
		return
	}
	for _, x := range g[idx] {
		dfs(x, depth+1)
	}
}

func main() {
	n, m := 0, 0
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		a, b := 0, 0
		fmt.Scan(&a, &b)
		if g[a] == nil {
			g[a] = make([]int, 0)
			knows[a] = make(map[int]bool)
		}
		if g[b] == nil {
			g[b] = make([]int, 0)
			knows[b] = make(map[int]bool)
		}
		if knows[a][b] == false {
			g[a] = append(g[a], b)
			g[b] = append(g[b], a)
			knows[a][b] = true
			knows[b][a] = true
		}

	}
	for i := 1; i <= n; i++ {
		dfs(i, 0)
	}

	fmt.Println(ans)
}

package main

import "fmt"

var (
    knows  = [4010][4010]bool{}
    degree = [4010]int{}
    three  = [3]int{0, 0, 0}
    ans    = 4010
)

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if knows[a][b] == false {
            knows[a][b] = true
            knows[b][a] = true
            degree[a]++
            degree[b]++
        }
    }

    for i := 1; i <= n; i++ {
        for j := i + 1; j <= n; j++ {
            if knows[i][j] {
                for k := 1; k <= n; k++ {
                    if knows[i][k] && knows[j][k] {
                        rec := degree[i] + degree[j] + degree[k] - 6
                        if ans > rec {
                            ans = rec
                        }
                    }
                }
            }
        }
    }
    if ans == 4010 {
        fmt.Println(-1)
    } else {
        fmt.Println(ans)
    }
}

package main

import "fmt"

var (
	g     = make([][]int, 4010)
	knows = [4010][4010]bool{}
	three = [3]int{0, 0, 0}
	ans   = -1
)

func dfs(idx, depth int) {
	three[depth] = idx
	if depth >= 2 {
		if knows[idx][three[0]] && idx != three[0] {
			rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
			if ans == -1 || ans > rec {
				ans = rec
			}
		}
		return
	}
	for _, x := range g[idx] {
		dfs(x, depth+1)
	}
}

func main() {
	n, m := 0, 0
	fmt.Scanf("%d %d", &n, &m)
	for i := 0; i < m; i++ {
		a, b := 0, 0
		fmt.Scanf("%d %d", &a, &b)
		if g[a] == nil {
			g[a] = make([]int, 0)
		}
		if g[b] == nil {
			g[b] = make([]int, 0)
		}
		if knows[a][b] == false {
			g[a] = append(g[a], b)
			g[b] = append(g[b], a)
			knows[a][b] = true
			knows[b][a] = true
		}

	}
	for i := 1; i <= n; i++ {
		dfs(i, 0)
	}

	fmt.Println(ans)
}


package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(n, a)
		fmt.Fprintln(w, w1)
	}
}
func do(n int, a []int) int {
	d := make([]int, n)
	r := 0
	for i := range a {
		d[i] = 1
		k := i - 512
		if k < 0 {
			k = 0
		}
		for j := k; j < i; j++ {
			if a[j]^i < a[i]^j {
				if d[i] < d[j]+1 {
					d[i] = d[j] + 1
				}
			}
		}
		if r < d[i] {
			r = d[i]
		}
	}
	return r
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	nums := make([]int, n)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
	}
	dp := make([]int, n)
	ans := 0
	for i := range nums {
		dp[i] = max(dp[i], 1)
		for j:=1;j<256&&i+j<n;j++ {
			if nums[i]^(i+j) < nums[i+j]^i {
				dp[i+j] = max(dp[i+j], dp[i]+1)
			}
		}
		ans = max(ans, dp[i])
	}
	fmt.Fprintln(ww, ans)
}

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

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		sort.Ints(a)
		tmp := make([]int, 0)
		fmt.Printf("%d ", a[0])
		for j := 1; j < n; j++ {
			if a[j] != a[j-1] {
				fmt.Printf("%d ", a[j])
			} else {
				tmp = append(tmp, a[j])
			}
		}
		for _, v := range tmp {
			fmt.Printf("%d ", v)
		}
		fmt.Println()
	}
}

package main

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

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

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

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

		unique := []int{}
		rest := []int{}
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			idx := sort.SearchInts(unique, v)
			if idx >= len(unique) {
				unique = append(unique, v)
			} else if unique[idx] != v {
				unique = append(unique[:idx], append([]int{v}, unique[idx:]...)...)
			} else {
				rest = append(rest, v)
			}
		}

		for _, v := range unique {
			fmt.Fprintf(out, "%d ", v)
		}

		for _, v := range rest {
			fmt.Fprintf(out, "%d ", v)
		}

		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

		tally := make([]int, 101)
		var maxN, maxF int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v > maxN {
				maxN = v
			}

			tally[v]++
			if tally[v] > maxF {
				maxF = tally[v]
			}
		}

		for i := 0; i < maxF; i++ {
			for j := 0; j <= maxN; j++ {
				if tally[j] > 0 {
					fmt.Fprintf(out, "%d ", j)
					tally[j]--
				}
			}
		}
		fmt.Fprintln(out)
	}
}

package main
import (
    "os"
    "fmt"
    "sort"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        a := make([]int, n)
        for i := range a {
            fmt.Fscan(rd, &a[i])
        }
        sort.Ints(a)
        var res []int
        for i := range a {
            if i == 0 || a[i] != a[i - 1] {
                res = append(res, a[i])
            }
        }
        for i := range a {
            if i > 0 && a[i] == a[i - 1] {
                res = append(res, a[i])
            }
        }
        for _, v := range res {
            fmt.Print(v, " ")
        }
        fmt.Println()
    }
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var T, n int
	var num, temp []int
	fmt.Scanf("%d\n", &T)
	temp = make([]int, 107)
	num = make([]int, 107)
	var count int = 0
	for i := 1; i <= T; i++ {
		count = 0
		fmt.Scanf("%d\n", &n)

		for j := 0; j < n; j++ {
			if j != n-1 {
				fmt.Scanf("%d", &num[j])
			} else {
				fmt.Scanf("%d\n", &num[j])
			}
		}
		sort.Ints(num[0:n])
		for j := 0; j < n; j++ {
			if j > 0 && num[j] == num[j-1] {
				temp[count] = num[j]
				count++
			} else {
				fmt.Printf("%d ", num[j])
			}
		}
		for j := 0; j < count; j++ {
			fmt.Printf("%d ", temp[j])
		}
		fmt.Println()
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "sort"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		sort.Ints(list)
		count:=0
		for j:=1;j<n;j++{
			if list[j] == list[j-1] {
				list = append(list[:j],append(list[j+1:],[]int{list[j]}...)...)
				j--
			}
			count++
			if count == n-1 {
				break
			}
		}
		for j:=0;j<len(list);j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out,)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		l, mex, o := 0, -1, map[int]int{}
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			o[p]++
		}
		for {
			_, ok := o[l]
			if !ok {
				mex = l
				break
			}
			l++
		}
		if mex == -1 {
			mex = n
		}
		for j := 0; j < mex; j++ {
			fmt.Fprint(w, j, " ")
			o[j]--
		}
		for k, v := range o {
			if v > 0 {
				fmt.Fprint(w, strings.Repeat(fmt.Sprintf("%d ", k), v))
			}
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func solve(n int, a []int) string {
	x := make([]int, 101)
	for _, i := range a {
		x[i]++
	}
	k := ""
	for i := 0; i < 101; i++ {
		if x[i] > 0 {
			k += fmt.Sprintf("%d ", i)
			x[i]--
		}
	}
	for i := 0; i < 101; i++ {
		if x[i] > 0 {
			for j := 0; j < x[i]; j++ {
				k += fmt.Sprintf("%d ", i)
			}
		}
	}
	return k
}

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

package main

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

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

func (in *CF1497A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1497A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1497A
 Date: 21/08/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1497/A
 Problem: CF1497A
**/
func (in *CF1497A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		arr := []int{}
		for i := 0; i < n; i++ {
			num := in.NextInt()
			arr = append(arr, num)
		}
		sort.Ints(arr)
		last := []int{}
		index := 0
		for i := 0; i < n-1; i++ {
			if arr[i] == arr[i+1] {
				num := arr[i]
				last = append(last, num)
				arr[i] = -1
				index++
			}
		}
		sort.Ints(arr)
		for i := index; i < n; i++ {
			fmt.Print(arr[i], " ")
		}
		for i := 0; i < len(last); i++ {
			fmt.Print(last[i], " ")
		}
		fmt.Println()
	}

}

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

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

package main

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

var bytes []byte

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

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

	b := nextByte()

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

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

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

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

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

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

	return builder.String()
}

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

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

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

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

		for i := 0; i < n; i++ {
			a := ScanInt()
			count[a]++
		}

		for k := range count {
			b = append(b, k)
		}

		sort.Ints(b)

		for k, v := range count {
			for i := 1; i < v; i++ {
				b = append(b, k)
			}
		}

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

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

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

func main() {
	defer out.Flush()

	var testc uint64
	fmt.Fscan(in, &testc)
	for ; testc > 0; testc-- {
		var n int
		var counts [101]int
		fmt.Fscan(in, &n)
		for i := 0; i < n; i ++ {
			var d int
			fmt.Fscan(in, &d)
			counts[d]++
		}
		for i := 0; i <= 100; i++ {
			if counts[i] > 0 {
				fmt.Fprintf(out, "%d ", i)
				counts[i] --
			}
		}
		for i := 0; i <= 100; i++ {
			for counts[i] > 0 {
				fmt.Fprintf(out, "%d ", i)
				counts[i]--
			}
		}
		fmt.Fprintf(out, "\n")
	}
}

package main

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

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

func main() {
	defer writer.Flush()
	var testcases int
	fmt.Fscan(reader, &testcases)

	for testcase := 0; testcase < testcases; testcase++ {
		var n int
		fmt.Fscan(reader, &n)
		list := make([]int, n)
		for i := range list {
			fmt.Fscan(reader, &(list[i]))
		}
		sort.Slice(list, func(i, j int) bool { return list[i] < list[j] })

		num := 0
		buf := make([]int, 0)
		for i, v := range list {
			if v == num {
				num++
				buf = append(buf, i)
			}
		}

		relist := make([]int, 0, n)
		for i := range buf {
			relist = append(relist, i)
		}
		cnt := 0
		for i, v := range list {
			if cnt < len(buf) && i == buf[cnt] {
				cnt++
				continue
			}
			relist = append(relist, v)
		}

		s := fmt.Sprint(relist)
		fmt.Fprintln(writer, s[1:len(s)-1])
	}
}

package main
import (
    "fmt"
    "sort"
)
func main() {
    var t, n int
    var a[100] int
    var use[100] bool
    fmt.Scan(&t)
    for j := 1; j <= t; j++ {
        fmt.Scan(&n)
        for i := 0; i < n; i++ {
            fmt.Scan(&a[i])
            use[i] = false
        }
        sort.Ints(a[:n])
        fmt.Printf("%d", a[0])
        use[0] = true
        for i := 1; i < n; i++ {
            if a[i] > a[i - 1] {
                use[i] = true
                fmt.Printf(" %d", a[i])
            }
        }
        for i := 1; i < n; i++ {
            if !use[i] {
                fmt.Printf(" %d", a[i])
            }
        }
        fmt.Println()
    }
}

package main

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

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

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

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

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

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

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

func in(a ...interface{})            { fmt.Fscan(reader, a...) }
func insf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func out(a ...interface{})            { fmt.Fprint(writer, a...) }
func outln(a ...interface{})          { fmt.Fprintln(writer, a...) }
func outf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

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

func solve() {
	n := 0
	in(&n)
	m := make(map[int]int, 101)
	for i := 0; i < n; i++ {
		t := 0
		in(&t)
		m[t]++
	}
	for {
		if !o(m){
			outln()
			return
		}
	}
}

func o(m map[int]int) bool{
	b := false
	for i := 0; i < 101; i++ {
		if m[i] != 0 {
			out(i, " ")
			m[i]--
			b = true
		}
	}
	return b
}

package main

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

}

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)
		ARRAY := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])

		}
		sort.Ints(ARRAY)
		newARRAY := make([]int, 0)
		fmt.Println(ARRAY[0])
		for i := 1; i < n; i++ {
			if ARRAY[i] != ARRAY[i-1] {
				fmt.Println(ARRAY[i])
			} else {
				newARRAY = append(newARRAY, ARRAY[i])
			}
		}
		k := len(newARRAY)
		for j := 0; j < k; j++ {
			fmt.Println(newARRAY[j])
		}
	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		cnt := map[int]int{}
		for _, v := range a {
			cnt[v]++
		}
		for i := 0; i <= 100; i++ {
			if cnt[i] > 0 {
				cnt[i]--
				Fprint(out, i, " ")
			}
		}
		for i, c := range cnt {
			for;c>0;c--{
				Fprint(out, i, " ")
			}
		}
		Fprintln(out, )
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main
import (
    "os"
    "fmt"
    "sort"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        a := make([]int, n)
        for i := range a {
            fmt.Fscan(rd, &a[i])
        }
        sort.Ints(a)
        var res []int
        for i := range a {
            if i == 0 || a[i] != a[i - 1] {
                res = append(res, a[i])
            }
        }
        for i := range a {
            if i > 0 && a[i] == a[i - 1] {
                res = append(res, a[i])
            }
        }
        for _, v := range a {
            fmt.Print(v, " ")
        }
        fmt.Println()
    }
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var T, n int
	var num, temp []int
	fmt.Scanf("%d\n", &T)
	for i := 1; i <= T; i++ {
		fmt.Scanf("%d\n", &n)
		num = make([]int, n)
		temp = make([]int, 0)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &num[j])
		}
		sort.Ints(num)
		lenN := len(num)
		for j := 0; j < lenN; j++ {
			if j > 0 && num[j] == num[j-1] {
				temp = append(temp, num[j])
			} else {
				fmt.Printf("%d ", num[j])
			}
		}
		lenT := len(temp)
		for j := 0; j < lenT; j++ {
			fmt.Printf("%d ", temp[j])
		}
		fmt.Println()
	}
}


// 00
package main

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

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		ans := 0

		rows := n / 2
		cols := n / 2
		if n%2 == 1 {
			cols++
		}
		for i := 0; i < rows; i++ {
			for j := 0; j < cols; j++ {
				count := 0
				if a[i][j] == '1' {
					count++
				}
				if a[j][n-1-i] == '1' {
					count++
				}
				if a[n-1-i][n-1-j] == '1' {
					count++
				}
				if a[n-1-j][i] == '1' {
					count++
				}
				ans += min(count, 4-count)
				//				fmt.Println(count, 4-count)
			}
		}

		fmt.Println(ans)
	}
}

package main

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

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

func Read[T any]() T{
	var i T
	fmt.Fscan(in, &i)
	return i
}

func ReadArray[T any](N int) []T{
	ans := make([]T, N)
	for i := 0; i < N; i++{
		ans[i] = Read[T]()
	}
	return ans
}

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

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
const N int = 101
func solve() {
	n := Read[int]()
	var arr [N]string

	for i := 0; i < n; i++ {
		arr[i] = Read[string]()
	}

	dive := n / 2
	if n & 1 == 0 {
		dive--
	}

	ans := 0
	for i := 0; i <= dive; i++ {
		var slices [4][]byte

		for j := i; j < n - i; j++ {
			slices[0] = append(slices[0], arr[i][j])
			slices[2] = append(slices[2], arr[n - (i + 1)][n - (j + 1)])

			slices[1] = append(slices[1], arr[j][n - (i + 1)])
			slices[3] = append(slices[3], arr[n - (j + 1)][i])
		}

		// fmt.Fprintln(out, slices)
		tmp_ans := 0

		ln := len(slices[0])
		for j := 0; j < ln - 1; j++ {
			zero := 0
			one := 0

			for k := 0; k < 4; k++ {
				if slices[k][j] == 48 {
					zero++
				} else {
					one++
				}
			}

			tmp_ans += Min(one, zero)
		}
		ans += tmp_ans
	}

	fmt.Fprintln(out, ans)

}
func main(){
	defer out.Flush()
	tt := 1
	tt = Read[int]()
	for tt > 0 {
		solve()
		tt--
	}
}

package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		b := make([]string, n)
		for i := range b {
			fmt.Fscan(r, &b[i])
		}
		w1 := do(b)
		fmt.Fprintln(w, w1)
	}
}

func do(s []string) int {
	b := make([][]byte, len(s))
	for i := range b {
		b[i] = []byte(s[i])
	}
	n := len(b)
	d := n - 1
	v := make([][]int, 4)
	ans := 0
	for i := 0; i <= n/2; i++ {
		for j := 0; j <= n/2; j++ {
			v[0] = []int{i*2 - d, j*2 - d}
			v[1] = []int{v[0][1], -v[0][0]}
			v[2] = []int{-v[0][0], -v[0][1]}
			v[3] = []int{-v[1][0], -v[1][1]}
			c := 0
			for _, v := range v {
				v[0] = (v[0] + d) / 2
				v[1] = (v[1] + d) / 2
				if b[v[0]][v[1]] == '1' {
					c++
				}
			}
			e := byte('0')
			if c > 2 {
				ans += 4 - c
			} else {
				ans += c
				e = '1'
			}
			for _, v := range v {
				b[v[0]][v[1]] = e
			}
		}
	}
	return ans
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		grid := make([]string, n)
		for i := 0; i < n; i++ {
			grid[i] = readString(reader)
		}
		res := solve(grid)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

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
}

func solve(grid []string) int {
	n := len(grid)

	var res int

	cnt := make([]int, 2)

	for i := 0; i < n/2; i++ {
		for j := 0; j < n/2; j++ {
			// (i, j) => (u, v)

			for k := 0; k < 2; k++ {
				cnt[k] = 0
			}
			u, v := i, j
			cnt[int(grid[u][v]-'0')]++
			u, v = v, n-1-u
			cnt[int(grid[u][v]-'0')]++
			u, v = v, n-1-u
			cnt[int(grid[u][v]-'0')]++
			u, v = n-1-j, i
			cnt[int(grid[u][v]-'0')]++
			res += 4 - max(cnt[0], cnt[1])
		}
	}

	if n&1 == 1 {
		for r := 0; r < n/2; r++ {
			cnt[0] = 0
			cnt[1] = 0
			cnt[int(grid[r][n/2]-'0')]++
			cnt[int(grid[n-1-r][n/2]-'0')]++
			cnt[int(grid[n/2][r]-'0')]++
			cnt[int(grid[n/2][n-1-r]-'0')]++
			res += 4 - max(cnt[0], cnt[1])
		}
	}

	return res
}

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

package main

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

const mod = 998244353
const mx = int64(1e9 + 7)

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	Fscan(in, &n)
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		var s string
		Fscan(in, &s)
		for j := 0; j < n; j++ {
			arr[i][j] = int(s[j] - '0')
		}
	}
	ans := 0
	for i := 0; i < (n+1)/2; i++ {
		for j := 0; j < n/2; j++ {
			o := arr[i][j] + arr[j][n-1-i] + arr[n-1-i][n-1-j] + arr[n-1-j][i]
			z := 4 - o
			if o <= z {
				ans += o
			} else {
				ans += z
			}
		}
	}
	Fprintln(out, ans)
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

func ReadInt() int{
	var i int
	fmt.Fscan(in, &i)
	return i
}

func ReadIntArray(N int) []int{
	ans := make([]int, N)
	for i := 0; i < N; i++{
		ans[i] = ReadInt()
	}
	return ans
}

func ReadString() string{
	var s string
	fmt.Fscan(in, &s)
	return s
}

func ReadStringArray(N int) []string{
	ans := make([]string, N)
	for i := 0; i < N; i++{
		ans[i] = ReadString()
	}
	return ans
}

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

func main(){
	defer out.Flush()
	testCases := ReadInt()
	for ; testCases > 0; testCases--{
		N := ReadInt()
		board := ReadStringArray(N)
		tot := 0
		for r := 0; r < (N + 1) / 2; r++{
			for c := 0; c < N / 2; c++{
				ones := int((board[r][c] - '0') +
							(board[c][N - 1 - r] - '0') +
							(board[N - 1 - r][N - 1 - c] - '0') +
							(board[N - 1 - c][r] - '0'))
				tot += Min(ones, 4 - ones)
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	grid := make([]string, n)
	for i := range grid {
		fmt.Fscan(rr, &grid[i])
	}
	ans := 0
	for i:=0;i<n/2;i++ {
		for j:=0;j<n/2;j++ {
			cur := int(grid[i][j]) + int(grid[n-j-1][i]) + int(grid[n-i-1][n-j-1]) + int(grid[j][n-i-1])
			cur -= '0' * 4
			ans += min(cur, 4-cur)
		}
	}
	if n % 2 == 1 {
		for i:=0;i<n/2;i++ {
			cur := int(grid[i][n/2]) + int(grid[n-n/2-1][i]) + int(grid[n-i-1][n-n/2-1]) + int(grid[n/2][n-i-1])
			cur -= '0' * 4
			ans += min(cur, 4-cur)
		}
	}

	fmt.Fprintln(ww, ans)
}

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

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([][]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := 0
		for i := 0; i < n/2; i++ {
			for j := 0; j < (n+1)/2; j++ {
				cnt := int(a[i][j]&1 + a[j][n-1-i]&1 + a[n-1-i][n-1-j]&1 + a[n-1-j][i]&1)
				ans += min(cnt, 4-cnt)
			}
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

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

func Read[T any]() T{
	var i T
	fmt.Fscan(in, &i)
	return i
}

func ReadArray[T any](N int) []T{
	ans := make([]T, N)
	for i := 0; i < N; i++{
		ans[i] = Read[T]()
	}
	return ans
}

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

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
const N int = 101
func solve() {
	n := Read[int]()
	var arr [N]string

	for i := 0; i < n; i++ {
		arr[i] = Read[string]()
	}

	dive := n / 2
	if n & 1 == 0 {
		dive--
	}

	ans := 0
	for i := 0; i < dive; i++ {
		var slices [4][]byte

		for j := i; j < n - i; j++ {
			slices[0] = append(slices[0], arr[i][j])
			slices[2] = append(slices[2], arr[n - (i + 1)][n - (j + 1)])

			slices[1] = append(slices[1], arr[j][n - (i + 1)])
			slices[3] = append(slices[3], arr[n - (j + 1)][i])
		}

		tmp_ans := 0

		ln := len(slices[0])
		for j := 0; j < ln - 1; j++ {
			zero := 0
			one := 0

			for k := 0; k < 4; k++ {
				if slices[k][j] == 48 {
					zero++
				} else {
					one++
				}
			}

			tmp_ans += Min(one, zero)
		}
		ans += tmp_ans
	}

	fmt.Fprintln(out, ans)

}
func main(){
	defer out.Flush()
	tt := 1
	tt = Read[int]()
	for tt > 0 {
		solve()
		tt--
	}
}


package main

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

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

	var f, n, n1 int
	fmt.Fscan(reader, &f, &n, &n1)

	arr := make([]int, f)
	for i := 0; i < f; i++ {
		fmt.Fscan(reader, &arr[i])
	}

	sort.Ints(arr)

	fi := sm(arr[f-min(n, n1):])
	se := sm(arr[f-(n+n1) : f-min(n, n1)])

	fmt.Printf("%.8f", fi+se)
}

func sm(arr []int) float64 {
	var count int64
	for _, vl := range arr {
		count += int64(vl)
	}

	return float64(count) / float64(len(arr))
}

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

package main

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

func solve() {
    n, n1, n2 := readInt(), readInt(), readInt()
    a := readIntArray(n)
    sort.Sort(sort.Reverse(sort.IntSlice(a)))
    mean := func(l, r int) float64 {
        sum := float64(0)
        for i := l; i < r; i++ {
            sum += float64(a[i])
        }
        return sum / float64(r-l)
    }
    ans := mean(0, n1) + mean(n1, n1+n2)
    if s2 := mean(0, n2) + mean(n2, n1+n2); s2 > ans {
        ans = s2
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

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

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// Sort

type Ints64 []int64

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

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

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, n1, n2 int
	var sum1, sum2 int64
	fmt.Scan(&n, &n1, &n2);
	arr := make([]int, n)
	if n1 > n2 {
		tmp := n1;
		n1 = n2;
		n2 = tmp;
	}

	for i := 0; i < n; i++ {
		fmt.Scan(&(arr[i]))
	}
	sort.Ints(arr)
	for i := 0; i < n1; i++ {
		sum1 += int64(arr[n - 1 - i]);
	}
	for i := n1; i < n1 + n2; i++ {
		sum2 += int64(arr[n - 1 - i]);
	}
	fmt.Println(float64(sum1)/float64(n1) + float64(sum2)/float64(n2))
}

package main

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

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

	w := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		w[i] = a
	}

	merge_sort(w, 0, n-1)
	if c[0] > c[1] {
		c[0], c[1] = c[1], c[0]
	}

	var sum [2]int64
	p := 0
	for i := 0; i < 2; i++ {
		for j := 0; j < c[i]; j++ {
			sum[i] += int64(w[p])
			p++
		}
	}

	mean := float64(sum[0])/float64(c[0]) + float64(sum[1])/float64(c[1])

	fmt.Printf("%.8f\n", mean)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] >= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

import "fmt"
import "sort"

func main() {
	var n, n1, n2 int
	fmt.Scan(&n, &n1, &n2)
	wealth := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&wealth[i])
	}
	if n1 > n2 {
		n1, n2 = n2, n1
	}
	sort.Ints(wealth)
	sum := float64(0)
	for i := n - 1; i >= n-n1; i-- {
		sum += float64(wealth[i])
	}
	ans := sum / float64(n1)
	sum = float64(0)
	for i := n - n1 - 1; i >= n-n2-n1; i-- {
		sum += float64(wealth[i])
	}
	ans += sum / float64(n2)
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"sort"
	"strings"
)

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	if len(b) == 0 {
		test()
	} else {
		solve(bytes.NewReader(b), os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n, n1, n2 int
	fmt.Fscanln(r, &n, &n1, &n2)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &as[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(as)))

	if n1 > n2 {
		n1, n2 = n2, n1
	}

	n1score := float64(0)
	for i := 0; i < n1; i++ {
		n1score += float64(as[i])
	}
	n1score /= float64(n1)

	n2score := float64(0)
	for i := 0; i < n2; i++ {
		n2score += float64(as[i+n1])
	}
	n2score /= float64(n2)

	fmt.Fprintln(w, n1score+n2score)
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `
2 1 1
1 5
`,
			want: `6.00000000`,
		},
		{
			in: `
4 2 1
1 4 2 3
`,
			want: `6.50000000`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(chomp(tt.in)), buf)
		if got, want := chomp(buf.String()), chomp(tt.want); got != want {
			fmt.Printf("%d: got %v, want %v\n", i, got, want)
		}
	}
}

func chomp(s string) string {
	return strings.Trim(s, "\n")
}

func assert(b bool) {
	if !b {
		_, file, line, ok := runtime.Caller(1)
		if ok {
			f, _ := os.Open(file)
			defer f.Close()
			s := bufio.NewScanner(f)
			lnum := 0
			for s.Scan() {
				lnum++
				if lnum == line {
					wd, _ := os.Getwd()
					fname, _ := filepath.Rel(wd, file)
					fmt.Printf("assertion fails: %s:%d: %v\n", fname, line, s.Text())
					break
				}
			}
		}
	}
}

func pow(a, b int) int {
	r := 1
	for i := 0; i < b; i++ {
		r *= a
	}
	return r
}

// Codeforces 735 B Urbanization, uses sort
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
	"sort"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n,n1,n2 int
var a []int
var maxSum float64

func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading field
	n,n1,n2,_,_ = readFive()
	a = readLineNumbs(n)
}

func solve() {
	ra := sort.Reverse(sort.IntSlice(a))
	sort.Sort(ra)
	if n1>n2 {
		n1,n2 = n2,n1
	}
	// count max sum
	maxSum = 0
	var i int
	var sum1,sum2 float64
	sum1=0
	for i=0; i<n1; i++ {
		sum1 += float64(a[i])
	}
	sum2=0
	for i=0; i<n2; i++ {
		sum2 += float64(a[n1+i])
	}
	maxSum = (sum1/float64(n1)) + (sum2/float64(n2))
}

func printRes() {
	fmt.Println(maxSum)
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

func ave(v []float64) float64 {
	sm := float64(0)
	for i := 0; i < len(v); i++ {
		sm += v[i]
	}
	return float64(sm) / float64(len(v))
}

func main() {
	sc := NewScanner()
	n, n1, n2 := sc.NextInt(), sc.NextInt(), sc.NextInt()
	b := sc.NextInt64Array()
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = float64(b[i])
	}
	if n1 > n2 {
		n1, n2 = n2, n1
	}

	sort.Float64s(a)

	fmt.Println(ave(a[n - n1 - n2:n - n1]) + ave(a[n - n1:]))

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func solve() {
    n, n1, n2 := readInt(), readInt(), readInt()
    a := readIntArray(n)
    sort.Ints(a)
    mean := func(l, r int) float64 {
        sum := float64(0)
        for i := l; i < r; i++ {
            sum += float64(a[i])
        }
        return sum / float64(r-l)
    }
    ans := mean(0, n1) + mean(n1, n1+n2)
    if s2 := mean(0, n2) + mean(n2, n1+n2); s2 > ans {
        ans = s2
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

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

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// Sort

type Ints64 []int64

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

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

package main

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

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

	w := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		w[i] = a
	}

	merge_sort(w, 0, n-1)
	if c[0] > c[1] {
		c[0], c[1] = c[1], c[0]
	}

	var sum [2]int
	p := 0
	for i := 0; i < 2; i++ {
		for j := 0; j < c[i]; j++ {
			sum[i] += w[p]
			p++
		}
	}

	mean := float64(sum[0]*c[1]+sum[1]*c[0]) / float64(c[0]*c[1])

	fmt.Printf("%1.8f\n", mean)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] >= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

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

	w := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		w[i] = a
	}

	merge_sort(w, 0, n-1)
	if c[0] > c[1] {
		c[0], c[1] = c[1], c[0]
	}

	var sum [2]int64
	p := 0
	for i := 0; i < 2; i++ {
		for j := 0; j < c[i]; j++ {
			sum[i] += int64(w[p])
			p++
		}
	}

	mean := float64(sum[0]*int64(c[1])+sum[1]*int64(c[0])) / float64(c[0]*c[1])

	fmt.Printf("%1.8f\n", mean)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] >= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

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

	var f, n, n1 int
	fmt.Fscan(reader, &f, &n, &n1)

	arr := make([]int, f)
	for i := 0; i < f; i++ {
		fmt.Fscan(reader, &arr[i])
	}

	sort.Ints(arr)

	fi := sm(arr[f-n1:])
	se := sm(arr[f-(n+n1) : f-n1])

	fmt.Printf("%.6f", fi+se)
}

func sm(arr []int) float64 {
	var count int
	for _, vl := range arr {
		count += vl
	}

	return float64(count) / float64(len(arr))
}

package main

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

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

	var f, n, n1 int
	fmt.Fscan(reader, &f, &n, &n1)

	arr := make([]int, f)
	for i := 0; i < f; i++ {
		fmt.Fscan(reader, &arr[i])
	}

	sort.Ints(arr)

	fi := sm(arr[f-min(n, n1):])
	se := sm(arr[f-(n+n1) : f-min(n, n1)])

	fmt.Printf("%.8f", fi+se)
}

func sm(arr []int) float64 {
	var count int
	for _, vl := range arr {
		count += vl
	}

	return float64(count) / float64(len(arr))
}

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

package main

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

func ave(v []int) float64 {
	sm := 0
	for i := 0; i < len(v); i++ {
		sm += v[i]
	}
	return float64(sm) / float64(len(v))
}

func main() {
	sc := NewScanner()
	n, n1, n2 := sc.NextInt(), sc.NextInt(), sc.NextInt()
	a := sc.NextIntArray()

	if n1 > n2 {
		n1, n2 = n2, n1
	}

	sort.Ints(a)

	fmt.Println(ave(a[n - n1 - n2:n - n1]) + ave(a[n - n1:]))

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}