package main

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

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

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

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

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

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

func solve() {
	var n int
	scan(&n)

	var (
		rs     = make([][2]int, 0, n/3-2)
		s0, s1 = -1, -1
	)
	for x := 1; x <= n; x += 3 {
		r := request(x, x+1, x+2)
		if r == 0 && s0 == -1 {
			s0 = x
			continue
		}
		if r == 1 && s1 == -1 {
			s1 = x
			continue
		}
		rs = append(rs, [2]int{x, r})
	}

	var (
		a0, b0, c0   = s0, s0 + 1, s0 + 2
		a1, b1, c1   = s1, s1 + 1, s1 + 2
		tmpval       = make([][2]int, 0, 4)
		meet0, meet1 = false, false
	)
	for _, x := range [...]int{b0, c0, b1, c1} {
		r := request(a0, a1, x)
		tmpval = append(tmpval, [2]int{x, r})
		meet0 = meet0 || r == 0
		meet1 = meet1 || r == 1
	}
	var (
		val   = make([]int, n+1)
		valof = [2]int{-1, -1}
	)
	if meet0 && meet1 {
		for _, i := range tmpval {
			x, r := i[0], i[1]
			val[x] = r
			if r == 0 {
				valof[0] = x
			}
			if r == 1 {
				valof[1] = x
			}
		}
		val[a0] = request(valof[0], valof[1], a0)
		val[a1] = request(valof[0], valof[1], a1)
	} else if meet0 {
		valof[0], valof[1] = a1, b1
		val[a0] = 0
		val[b0] = request(valof[0], valof[1], b0)
		val[c0] = request(valof[0], valof[1], c0)
		val[a1] = 0
		val[b1] = 1
		val[c1] = 1
	} else {
		valof[0], valof[1] = b0, a0
		val[a0] = 1
		val[b0] = 0
		val[c0] = 0
		val[a1] = 1
		val[b1] = request(valof[0], valof[1], b1)
		val[c1] = request(valof[0], valof[1], c1)
	}
	// no case for (!meet0 && !meet1)

	for _, i := range rs {
		a, r := i[0], i[1]
		b, c := a+1, a+2
		ab, bc := request(valof[r^1], a, b), request(valof[r^1], b, c)
		if ab == r^1 && bc == r^1 {
			val[a] = r
			val[b] = r ^ 1
			val[c] = r
		} else if ab == r^1 {
			val[a] = r ^ 1
			val[b] = r
			val[c] = r
		} else if bc == r^1 {
			val[a] = r
			val[b] = r
			val[c] = r ^ 1
		} else {
			val[a] = r
			val[b] = r
			val[c] = r
		}
	}

	var k int
	for i := 1; i <= n; i++ {
		if val[i] == 0 {
			k++
		}
	}

	printf("! %v ", k)
	for i := 1; i <= n; i++ {
		if val[i] == 0 {
			printf("%v ", i)
		}
	}
	printf("\n")
	writer.Flush()
}

func request(a, b, c int) (x int) {
	printf("? %v %v %v\n", a, b, c)
	writer.Flush()
	scan(&x)
	return
}

package main

import (
	"fmt"
	"os"
)

var n int
var ans []int

func ask(a, b, c int) int {
	fmt.Printf("? %d %d %d\n", a, b, c)
	var r int
	fmt.Scan(&r)
	if r == -1 {
		os.Exit(0)
	}
	return r
}

func setAnswer(i, v int) {
	ans[i] = v
}

func solveDifferentTrios(i, j, ansi int) (int, int) {
	var fixedi = i
	if ask(i, i+1, j) == ansi && ask(i, i+1, j+1) == ansi {
		setAnswer(i, ansi)
		setAnswer(i+1, ansi)
	} else if ask(i, i+2, j) == ansi && ask(i, i+2, j+1) == ansi {
		setAnswer(i, ansi)
		setAnswer(i+2, ansi)
	} else {
		setAnswer(i, ansi^1)
		fixedi = i + 1
		setAnswer(i+1, ansi)
		setAnswer(i+2, ansi)
	}

	var fixedj = j
	if ask(fixedi, j, j+1) != ansi {
		setAnswer(j, ansi^1)
		setAnswer(j+1, ansi^1)
	} else if ask(fixedi, j, j+2) != ansi {
		setAnswer(j, ansi^1)
		setAnswer(j+2, ansi^1)
	} else {
		setAnswer(j, ansi)
		fixedj = j + 1
		setAnswer(j+1, ansi^1)
		setAnswer(j+2, ansi^1)
	}

	for _, k := range []int{i, i + 1, i + 2, j, j + 1, j + 2} {
		if ans[k] == -1 {
			ans[k] = ask(fixedi, fixedj, k)
		}
	}

	if ansi == 0 {
		return fixedi, fixedj
	}
	return fixedj, fixedi
}

func printAnswer() {
	fmt.Printf("!")
	var count0 = 0
	for i := 1; i <= n; i++ {
		if ans[i] == 0 {
			count0 += 1
		}
	}

	fmt.Printf(" %d", count0)
	for i := 1; i <= n; i++ {
		if ans[i] == 0 {
			fmt.Printf(" %d", i)
		}
	}
	fmt.Println()
}

func solveCase() {
	fmt.Scan(&n)
	ans = make([]int, n+1)
	for i := 1; i <= n; i++ {
		ans[i] = -1
	}
	var ans123 = ask(1, 2, 3)
	var differentTrioStart = 4
	for ask(differentTrioStart, differentTrioStart+1, differentTrioStart+2) == ans123 {
		differentTrioStart += 3
	}

	idx0, idx1 := solveDifferentTrios(1, differentTrioStart, ans123)

	for i := differentTrioStart + 3; i <= n; i++ {
		ans[i] = ask(idx0, idx1, i)
	}

	var idx = idx0
	if ans123 == 0 {
		idx = idx1
	}

	for i := 4; i < differentTrioStart; i += 3 {
		if ask(i, i+1, idx) == ans123 {
			ans[i] = ans123
			ans[i+1] = ans123
			ans[i+2] = ask(idx0, idx1, i+2)
		} else {
			ans[i] = ask(idx0, idx1, i)
			ans[i+1] = ans[i] ^ 1
			ans[i+2] = ans123
		}
	}
	printAnswer()
}

func main() {
	var ntc int
	fmt.Scan(&ntc)
	for t := 0; t < ntc; t++ {
		solveCase()
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
type (
	initData struct{ n int }
	request  struct{ i, j, k int }
	response struct{ v int }
	answer   struct{ ans []int }
)

type interaction interface {
	readInitData() initData
	query(request) response
	printAnswer(answer)
}

type io struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (io io) readInitData() (d initData) {
	Fscan(io.in, &d.n)
	return
}

func (io io) query(req request) (resp response) {
	Fprintln(io.out, "?", req.i, req.j, req.k)
	io.out.Flush()
	Fscan(io.in, &resp.v)
	if resp.v < 0 {
		panic(-1)
	}
	return
}

func (io io) printAnswer(a answer) {
	Fprint(io.out, "! ", len(a.ans))
	for _, v := range a.ans {
		Fprint(io.out, " ", v)
	}
	Fprintln(io.out)
	io.out.Flush()
}

func doInteraction(it interaction) {
	q := func(i, j, k int) (good bool) { return it.query(request{i, j, k}).v == 1 }
	dt := it.readInitData()
	n := dt.n
	ans := []int{}
	defer func() { it.printAnswer(answer{ans}) }()

	if n == 6 {
		// 特判？
	}

	var goods, bads [][3]int
	for i := 1; ; i += 3 {
		if q(i, i+1, i+2) {
			goods = append(goods, [3]int{i, i + 1, i + 2})
		} else {
			bads = append(bads, [3]int{i, i + 1, i + 2})
		}
		if goods != nil && bads != nil {
			break
		}
	}

	var badman, goodman int
	good := goods[0]
	bad := bads[0]
	for _, id := range good {
		if q(bad[0], bad[1], id) {
			goodman = id
			badman = bad[2]
			break
		}
	}
	if goodman == 0 {
		badman = bad[0]
		if q(good[0], good[1], badman) {
			goodman = good[0]
		} else if q(good[0], good[2], badman) {
			goodman = good[0]
		} else {
			goodman = good[1]
		}
	}

	vis := make([]bool, n+1)
	vis[goodman] = true
	vis[badman] = true
	ans = append(ans, badman)

	if len(bads) > 1 {
		for _, b := range bads[1:] {
			if q(goodman, b[0], b[1]) {
				ans = append(ans, b[2]) // bad!
				if q(goodman, badman, b[0]) { // b[0] is good
					ans = append(ans, b[1]) // bad!
				} else {
					ans = append(ans, b[0])
				}
				for _, i := range b {
					vis[i] = true
				}
			} else {
				ans = append(ans, b[0], b[1])
				// b[2] 后面问
				vis[b[0]] = true
				vis[b[1]] = true
			}
		}
	}
	if len(goods) > 1 {
		for _, b := range goods[1:] {
			if !q(badman, b[0], b[1]) {
				//ans = append(ans, b[2]) // bad!
				if q(goodman, badman, b[0]) { // b[0] is good
					ans = append(ans, b[1]) // bad!
				} else {
					ans = append(ans, b[0])
				}
				for _, i := range b {
					vis[i] = true
				}
			} else { // good
				// b[2] 后面问
				vis[b[0]] = true
				vis[b[1]] = true
			}
		}
	}

	for i := 1; i <= n; i++ {
		if !vis[i] {
			if !q(goodman, badman, i) {
				ans = append(ans, i)
			}
		}
	}
}

// TODO: check output format before submit
func run() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	T := 1
	Fscan(in, &T)
	for ; T > 0; T-- {
		doInteraction(io{in, out})
	}
}

func main() { run() }


package main
import (
	"fmt"
	//"bufio"
	//"os"
	//"strconv"
	"sort"
)

func main() {
	pi:=3.14159265358979323846
	var n,p int
	fmt.Scan(&n)
	r:=make([]int,n+1)
	for i:=1;i<=n;i++ {
		fmt.Scan(&r[i])
	}
	r[0]=0
	sort.Ints(r)
	for i:=n;i>=1;i-=2 {
		p+=r[i]*r[i]-r[i-1]*r[i-1]
	}
	//fmt.Println(p)
	hsl:=float64(p)*pi
	fmt.Println(hsl)
}

package main

import (
    "fmt"
    "math"
    "sort"
)

func main() {
    var n int
    fmt.Scan(&n)
    r := make([]float64,n)
    for i := 0; i < n; i++ { fmt.Scan(&r[i]) }
    sort.Float64s(r)
    ans, sign := float64(0), float64(1)
    for i := n-1; i >= 0; i-- {
        ans += sign*(math.Pi*r[i]*r[i])
        sign *= -1
    }
    fmt.Println(ans)
}

// 157B-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n int
    pi := 3.1415926536
    fmt.Scan(&n)
    a := make([]float64, n+1)
    var area float64
    a[0] = 0.0
    for i := 1; i <= n; i++ {
        fmt.Scan(&a[i])
    }
    sort.Sort(sort.Float64Slice(a))
    for i := n; i > 0; i = i - 2 {
        area += pi*a[i]*a[i] - pi*a[i-1]*a[i-1]
    }
    fmt.Println(area)

}


package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	c := map[int]int{}
	for i := range a {
		Fscan(in, &a[i])
		c[a[i]]++
	}
	b := []int{}
	for k := range c {
		b = append(b, k)
	}
	sort.Ints(b)
	if len(b) == 2 && b[0]+2 == b[1] {
		b = []int{b[0], b[0] + 1, b[1]}
	}
	if len(b) == 3 {
		min02 := c[b[0]]
		if c[b[2]] < min02 {
			min02 = c[b[2]]
		}
		if c[b[1]]/2 > min02 {
			c[b[1]] &^= 1
			n -= c[b[1]]
			for i, v := range a {
				if v == b[1] && c[v] > 0 {
					a[i] = b[c[v]&1<<1]
					c[v]--
				}
			}
		} else {
			n -= 2 * min02
			c[b[0]] = min02
			c[b[2]] = min02
			for i, v := range a {
				if v != b[1] && c[v] > 0 {
					a[i] = b[1]
					c[v]--
				}
			}
		}
	}
	Fprintln(out, n)
	for _, v := range a {
		Fprint(out, v, " ")
	}
}

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

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	x := make([]int, n)
	var max, min int
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%d", &x[i])
		if i == 0 {
			max, min = x[0], x[0]
		} else {
			if max < x[i] {
				max = x[i]
			}
			if min > x[i] {
				min = x[i]
			}
		}
	}
	if max - min < 2 {
		fmt.Printf("%d\n", n)
		for i := 0;i < n;i ++ {
			fmt.Printf("%d ", x[i])
		}
		return
	}
	var maxCount, minCount, midCount int
	for i := 0;i < n;i ++ {
		switch x[i] {
		case max:
			maxCount ++
		case min:
			minCount ++
		default:
			midCount ++
		}
	}
	merge := maxCount
	if merge > minCount {
		merge = minCount
	}
	split := midCount / 2
	if split > merge {
		fmt.Printf("%d\n", n - 2 * split)
		maxCount, minCount, midCount = maxCount + split, minCount + split, midCount - 2 * split
	} else {
		fmt.Printf("%d\n", n - 2 * merge)
		maxCount, minCount, midCount = maxCount - merge, minCount - merge, midCount + 2 * merge
	}
	for i := 0;i < maxCount;i ++ {
		fmt.Printf("%d ", max)
	}
	for i := 0;i < minCount;i ++ {
		fmt.Printf("%d ", min)
	}
	for i := 0;i < midCount;i ++ {
		fmt.Printf("%d ", min + 1)
	}

}

package main

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

var n int
var a map[int]int

func printSolution(eq int, a map[int]int) {
	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() }()

	fmt.Fprintln(outBuf, eq)

	for k, v := range a {
		for i := 0; i < v; i++ {
			fmt.Fprintf(outBuf, "%d ", k)
		}
	}
}

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	a := make(map[int]int)
	fmt.Fscanf(inBuf, "%d\n", &n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(inBuf, "%d", &tmp)
		a[tmp]++
	}
	keys := make([]int, 0)
	for k, _ := range a {
		keys = append(keys, k)
	}
	sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })

	if len(a) < 3 {
		if len(a) == 2 && keys[1] - keys[0] == 2 {
			t1 := a[keys[0]]
			if t1 > a[keys[1]] {
				t1 = a[keys[1]]
			}
			a[keys[0]+1] += 2*t1
			a[keys[0]] -= t1
			a[keys[1]] -= t1
			n -= 2*t1
		}
		printSolution(n, a)
		return
	}

	t1 := a[keys[0]]
	if t1 > a[keys[2]] {
		t1 = a[keys[2]]
	}
	t2 := a[keys[1]] / 2
	ans := 0
	if t2 > t1 {
		ans = n - 2 * t2
		a[keys[0]] += t2
		a[keys[2]] += t2
		a[keys[1]] -= 2*t2
	}  else {
		ans = n - 2*t1
		a[keys[0]] -= t1
		a[keys[2]] -= t1
		a[keys[1]] += 2*t1
	}
	printSolution(ans, a)
}

package main

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

const (
  INF = 1234567890
)

func Init() {
}

func Solve(io *FastIO) {
  N := io.NextInt()
  X := io.NextIntArray(N)

  lo := INF
  hi := -INF
  for _, v := range X {
    lo = Min(lo, v)
    hi = Max(hi, v)
  }

  if hi - lo < 2 {
    io.Println(N)
    for _, v := range X {
      io.Printf("%d ", v)
    }
    io.Println()
    return
  }

  neg := 0
  zero := 0
  pos := 0
  for i := range X {
    X[i] -= lo + 1
    if X[i] < 0 {
      neg++
    } else if X[i] > 0 {
      pos++
    } else {
      zero++
    }
  }

  // extraNeg := 0
  // extraPos := 0
  // if neg > pos {
  //   extraNeg = neg - pos
  //   neg = pos
  // } else {
  //   extraPos = pos - neg
  //   pos = neg
  // }

  // fmt.Println(X)
  // fmt.Printf("neg = %d, pos = %d\n", neg, pos)

  n, z, p := neg, zero, pos
  for n > 0 && p > 0 {
    n--
    z += 2
    p--
  }

  bn, bz, bp := -1, -1, -1
  bestDiff := -1
  for z >= 0 {
    d := Diff(neg, zero, pos, n, z, p)
    if d >= bestDiff {
      bestDiff = d
      bn, bz, bp = n, z, p
    }
    n++
    z -= 2
    p++
  }

  io.Println(N - bestDiff)
  for i := 0; i < bn; i++ {
    io.Printf("%d ", lo)
  }
  for i := 0; i < bz; i++ {
    io.Printf("%d ", lo + 1)
  }
  for i := 0; i < bp; i++ {
    io.Printf("%d ", hi)
  }
  io.Println()

  // bestNZ := 0
  // bestDiff := -1
  // for i := 0; (i << 1) <= N; i++ {
  //   d := Diff(neg, zero, pos, i, zero + (i << 1), i)
  //   // fmt.Printf("i = %d, d = %d\n", i, d)
  //   if d >= bestDiff {
  //     bestDiff = d
  //     bestNZ = i
  //   }
  // }

  // io.Println(N - bestDiff)

  // cnt := 0
  // for i := 0; i < bestNZ; i++ {
  //   io.Printf("%d %d ", lo, hi)
  //   cnt += 2
  // }
  // for i := 0; i < extraNeg; i++ {
  //   io.Printf("%d ", lo)
  //   cnt++
  // }
  // for i := 0; i < extraPos; i++ {
  //   io.Printf("%d ", hi)
  //   cnt++
  // }
  // for cnt < N {
  //   io.Printf("%d ", lo + 1)
  //   cnt++
  // }
  // io.Println()
}

func Diff(n0, z0, p0, n1, z1, p1 int) int {
  n0 -= Min(n0, n1)
  z0 -= Min(z0, z1)
  p0 -= Min(p0, p1)
  return n0 + z0 + p0
}

func Min(args ...int) int {
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	c := map[int]int{}
	for i := range a {
		Fscan(in, &a[i])
		c[a[i]]++
	}
	if len(c) == 3 {
		b := []int{}
		for k := range c {
			b = append(b, k)
		}
		sort.Ints(b)
		min02 := c[b[0]]
		if c[b[2]] < min02 {
			min02 = c[b[2]]
		}
		if c[b[1]]/2 > min02 {
			c[b[1]] &^= 1
			n -= c[b[1]]
			for i, v := range a {
				if v == b[1] && c[v] > 0 {
					a[i] = b[c[v]&1<<1]
					c[v]--
				}
			}
		} else {
			n -= 2 * min02
			c[b[0]] = min02
			c[b[2]] = min02
			for i, v := range a {
				if v != b[1] && c[v] > 0 {
					a[i] = b[1]
					c[v]--
				}
			}
		}
	}
	Fprintln(out, n)
	for _, v := range a {
		Fprint(out, v, " ")
	}
}

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

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	c := map[int]int{}
	for i := range a {
		Fscan(in, &a[i])
		c[a[i]]++
	}
	if len(c) == 3 {
		b := []int{}
		for k := range c {
			b = append(b, k)
		}
		sort.Ints(b)
		if c[b[0]] < c[b[2]] {
			c[b[2]] = c[b[0]]
		} else {
			c[b[0]] = c[b[2]]
		}
		n -= 2 * c[b[0]]
		for i, v := range a {
			if v != b[1] && c[v] > 0 {
				a[i] = b[1]
				c[v]--
			}
		}
	}
	Fprintln(out, n)
	for _, v := range a {
		Fprint(out, v, " ")
	}
}

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

package main

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

const (
  INF = 1234567890
)

func Init() {
}

func Solve(io *FastIO) {
  N := io.NextInt()
  X := io.NextIntArray(N)

  lo := INF
  hi := -INF
  for _, v := range X {
    lo = Min(lo, v)
    hi = Max(hi, v)
  }

  if hi - lo < 2 {
    io.Println(N)
    for _, v := range X {
      io.Printf("%d ", v)
    }
    io.Println()
    return
  }

  neg := 0
  zero := 0
  pos := 0
  for i := range X {
    X[i] -= lo + 1
    if X[i] < 0 {
      neg++
    } else if X[i] > 0 {
      pos++
    } else {
      zero++
    }
  }

  extraNeg := 0
  extraPos := 0
  if neg > pos {
    extraNeg = neg - pos
    neg = pos
  } else {
    extraPos = pos - neg
    pos = neg
  }

  // fmt.Println(X)
  // fmt.Printf("neg = %d, pos = %d\n", neg, pos)

  bestNZ := 0
  bestDiff := -1
  for i := 0; i <= neg; i++ {
    d := Diff(neg, zero, pos, i, zero + (i << 1), i)
    // fmt.Printf("i = %d, d = %d\n", i, d)
    if d >= bestDiff {
      bestDiff = d
      bestNZ = i
    }
  }

  io.Println(N - bestDiff)

  cnt := 0
  for i := 0; i < bestNZ; i++ {
    io.Printf("%d %d ", lo, hi)
    cnt += 2
  }
  for i := 0; i < extraNeg; i++ {
    io.Printf("%d ", lo)
    cnt++
  }
  for i := 0; i < extraPos; i++ {
    io.Printf("%d ", hi)
    cnt++
  }
  for cnt < N {
    io.Printf("%d ", lo + 1)
    cnt++
  }
  io.Println()
}

func Diff(n0, z0, p0, n1, z1, p1 int) int {
  n0 -= Min(n0, n1)
  z0 -= Min(z0, z1)
  p0 -= Min(p0, p1)
  return n0 + z0 + p0
}

func Min(args ...int) int {
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

var n int
var a map[int]int

func printSolution(eq int, a map[int]int) {
	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() }()

	fmt.Fprintln(outBuf, eq)

	for k, v := range a {
		for i := 0; i < v; i++ {
			fmt.Fprintf(outBuf, "%d ", k)
		}
	}
}

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	a := make(map[int]int)
	fmt.Fscanf(inBuf, "%d\n", &n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(inBuf, "%d", &tmp)
		a[tmp]++
	}

	if len(a) < 3 {
		printSolution(n, a)
		return
	}

	keys := make([]int, 0)
	for k, _ := range a {
		keys = append(keys, k)
	}
	sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })

	t1 := a[keys[0]]
	if t1 > a[keys[2]] {
		t1 = a[keys[2]]
	}
	t2 := a[keys[1]] / 2
	ans := 0
	if t2 > t1 {
		ans = n - a[keys[1]]
		a[keys[0]] += t2
		a[keys[2]] += t2
		a[keys[1]] -= 2*t2
	}  else {
		ans = n - 2*t1
		a[keys[0]] -= t1
		a[keys[2]] -= t1
		a[keys[1]] += 2*t1
	}
	printSolution(ans, a)
}

package main

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

var n int
var a map[int]int

func printSolution(eq int, a map[int]int) {
	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() }()

	fmt.Fprintln(outBuf, eq)

	for k, v := range a {
		for i := 0; i < v; i++ {
			fmt.Fprintf(outBuf, "%d ", k)
		}
	}
}

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	a := make(map[int]int)
	fmt.Fscanf(inBuf, "%d\n", &n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(inBuf, "%d", &tmp)
		a[tmp]++
	}

	if len(a) < 3 {
		printSolution(n, a)
		return
	}

	keys := make([]int, 0)
	for k, _ := range a {
		keys = append(keys, k)
	}
	sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })

	t1 := a[keys[0]]
	if t1 > a[keys[2]] {
		t1 = a[keys[2]]
	}
	t2 := a[keys[1]] / 2
	ans := 0
	if t2 > t1 {
		ans = n - 2 * t2
		a[keys[0]] += t2
		a[keys[2]] += t2
		a[keys[1]] -= 2*t2
	}  else {
		ans = n - 2*t1
		a[keys[0]] -= t1
		a[keys[2]] -= t1
		a[keys[1]] += 2*t1
	}
	printSolution(ans, a)
}


package main

import (
	"fmt"
	"math"
)

func calcBitCount(num int64) int {
	count := 0
	for num > 0 {
		if num%2 == 1 {
			count++
		}
		num /= 2
	}
	return count
}

func main() {
	C := 0
	fmt.Scan(&C)
	for i := 0; i < C; i++ {
		num := int64(0)
		fmt.Scan(&num)
		if num == 0 {
			fmt.Println(1)
			continue
		}
		bitCount := calcBitCount(num)
		fmt.Println(int64(math.Exp2(float64(bitCount))))
	}
}

package main

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

var scanner *bufio.Scanner

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

func nextInt() int {
	num, err := strconv.Atoi(next())
	if err != nil {
		panic(err.Error())
	}
	return num
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	T := nextInt()
	for ; T>0; T-- {
		num := nextInt()
		calc := 1 << uint(bits.OnesCount(uint(num)))
		fmt.Println(calc)
	}

}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d\n", &n)

    var arr [100005]int
    for i:= 1; i <= n; i++ {
        fmt.Scanf("%d\n", &arr[i])
    }

    for i:= 1; i <= n; i++ {
        bitCnt := 0
        for j:= 0; j < 30; j++ {
            if arr[i] & (1 << uint(j)) > 0 {
                bitCnt++;
            }
        }
        fmt.Printf("%d\n", 1<<uint(bitCnt))
    }
}


package main

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

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

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

	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Fscan(in, &n, &k)
		arr := make([]int, 0, n)
		for j := 0; j < n; j++ {
			var num int
			fmt.Fscan(in, &num)
			arr = append(arr, num)
		}
		sort.Ints(arr)

		// solve
		var flag bool
		if len(arr) == 1 {
			flag = arr[0] == k
		}
		for i, j := 0, 1; i < n && j < n; {
			if arr[i] + k == arr[j] {
				flag = true
				break
			}
			if arr[i] + k < arr[j] {
				i ++
			} else {
				j ++
			}
		}
		if flag {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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

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

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

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
		var k int64
		fmt.Fscan(in, &n, &k)

		m := make(map[int64]bool)
		var f bool
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			if m[v-k] || m[v+k] {
				f = true
			}
			m[v] = true
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

var k, t, n int

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

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

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

func main() {
	ip := bufio.NewReader(os.Stdin)
	t = readInt(ip)
	for ; t > 0; t-- {
		tmp := readArrInt(ip)
		n = tmp[0]
		k = tmp[1]
		a := readArrInt(ip)
		f := false
		l, r := 0, 1
		if n == 1 {
			f = a[0] == k
			goto there
		}
		sort.Ints(a)

		for l < n && r < n {
			if a[l]+abs(k) == a[r] {
				f = true
				goto there
			} else if a[l]+abs(k) > a[r] {
				r++
			} else {
				l++
			}
		}

	there:
		if f {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

func main(){
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)

	defer write.Flush()

	var tc int

	for Fscan (read, &tc); tc > 0; tc -- {
		var n, k int

		Fscan (read, &n, &k)

		mp, ans := map[int]bool{}, 0
		for i := 1; i <= n; i++ {
		    var val int
		    Fscan (read, &val)
		    mp[val] = true
		}

		for key, _ := range mp {
		    if mp[key + k] {
		        ans = 1
		    }
		}

		if ans == 1 {
		    Fprintln(write, "YES")
		} else {
		    Fprintln(write, "NO")
		}
	}
}

package main

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

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

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

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

		numbers := make([]int, n)
		for i := range numbers {
			_, _ = fmt.Fscan(r, &numbers[i])
		}

		answer := subtractOperation(n, k, numbers)
		fmt.Println(answer)
	}
}

func subtractOperation(n int, k int, numbers []int) string {
	if n == 1 {
		if numbers[0] == k {
			return "YES"
		} else {
			return "NO"
		}
	}

	sort.Ints(numbers)

	i, j := 0, 1
	for j < n {
		if i >= j {
			j++
			continue
		}

		diff := numbers[j] - numbers[i]
		if diff == k {
			return "YES"
		}

		if diff < k {
			j++
		} else {
			i++
			j--
		}
	}

	return "NO"
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n, k int
		fmt.Fscan(in, &n, &k)
		c := map[int]bool{}
		for i := 0; i < n; i++ {
			num := 0
			fmt.Fscan(in, &num)
			c[num] = true
		}
		find := false
		for num := range c {
			if c[num-k] {
				fmt.Fprintln(out, "YES")
				find = true
				break
			}
		}
		if !find {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

/*
5 4
3 1 3 2 5
---
YES

*/

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

	a := make([]int64, n)
	numToCnt := make(map[int64]int)

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

	for _, num1 := range a {
		num2 := num1 - k
		if num1 != num2 && numToCnt[num2] > 0 || num1 == num2 && numToCnt[num2] > 1 {
			fmt.Fprintln(writer, "YES")
			return
		}
	}
	fmt.Fprintln(writer, "NO")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

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

	return minNumIdx
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

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

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

func solve(istream *bufio.Reader) {
	tmp := readArrInt(istream)
	n := tmp[0]
	k := tmp[1]
	values := readArrInt(istream)
	sort.Ints(values)
	rbound := 0
	for i := 0; i < n; i++ {
		for rbound < n && values[i]+k > values[rbound] {
			rbound++
		}
		if rbound < n && values[i]+k == values[rbound] {
			fmt.Printf("yes\n")
			return
		}
	}
	fmt.Printf("no\n")
}

func main() {
	istream := bufio.NewReader(os.Stdin)
	t := readInt(istream)
	for i := 0; i < t; i++ {
		solve(istream)
	}
}

package main
import "fmt"
import "os"
import "bufio"
import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	ouput = bufio.NewWriter(os.Stdout)
)
func main() {
	defer ouput.Flush()
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		n := 0
		k := 0
		fmt.Fscan(input,&n)
		fmt.Fscan(input,&k)
		arr := make([]int,0,n)
		for n>0 {
			n--
			v := 0
			fmt.Fscan(input,&v)
			arr = append(arr,v)
		}
		sort.Ints(arr)
		ans := "NO"
		for l,r:=0,1;l<len(arr)&&r<len(arr); {
			if arr[l] + k == arr[r] {
				ans = "YES"
				break
			}
			if arr[l] + k < arr[r] {
				l ++
			} else {
				r ++
			}
		}
		fmt.Fprintln(ouput,ans)
	}
}

package main
import "fmt"
import "os"
import "bufio"
import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	ouput = bufio.NewWriter(os.Stdout)
)
func main() {
	defer ouput.Flush()
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		n := 0
		k := 0
		fmt.Fscan(input,&n)
		fmt.Fscan(input,&k)
		arr := make([]int,0,n)
		for n>0 {
			n--
			v := 0
			fmt.Fscan(input,&v)
			arr = append(arr,v)
		}
		sort.Ints(arr)
		l,r := 0,len(arr)-1
		f := "no"
		for l<r {
			if arr[l]+k == arr[r] {
				f = "yes"
				break
			}
			if arr[l]+k<arr[r] {
				l ++
			} else {
				r --
			}
		}
		fmt.Fprintln(ouput,f)
	}
}

package main
import "fmt"
import "os"
import "bufio"
import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	ouput = bufio.NewWriter(os.Stdout)
)

/*
4
4 5
4 2 2 7
5 4
1 9 1 3 4
2 17
17 0
2 17
18 18
 */
func main() {
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		n := 0
		k := 0
		fmt.Fscan(input,&n)
		fmt.Fscan(input,&k)
		arr := make([]int,0,n)
		for n>0 {
			n--
			v := 0
			fmt.Fscan(input,&v)
			arr = append(arr,v)
		}
		sort.Ints(arr)
		l,r := 0,len(arr)-1
		f := "no"
		for l<r {
			if arr[l]+k == arr[r] {
				f = "yes"
				break
			}
			if arr[l]+k<arr[r] {
				l ++
			} else {
				r --
			}
		}
		fmt.Printf("%s\n",f)
	}
}

package main
import "fmt"
import "os"
import "bufio"
import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	ouput = bufio.NewWriter(os.Stdout)
)

/*
4
4 5
4 2 2 7
5 4
1 9 1 3 4
2 17
17 0
2 17
18 18
 */
func main() {
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		n := 0
		k := 0
		fmt.Fscan(input,&n)
		fmt.Fscan(input,&k)
		arr := make([]int,0,n)
		for n>0 {
			n--
			v := 0
			fmt.Fscan(input,&v)
			arr = append(arr,v)
		}
		sort.Ints(arr)
		l,r := 0,len(arr)-1
		f := "no"
		for l<r {
			if arr[l]+k == arr[r] {
				f = "yes"
				break
			}
			if arr[l]+k<arr[r] {
				l ++
			} else {
				r --
			}
		}
		fmt.Println(f)
	}
}

package main
import "fmt"
import "os"
import "bufio"
import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	ouput = bufio.NewWriter(os.Stdout)
)

/*
4
4 5
4 2 2 7
5 4
1 9 1 3 4
2 17
17 0
2 17
18 18
 */
func main() {
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		n := 0
		k := 0
		fmt.Fscan(input,&n)
		fmt.Fscan(input,&k)
		arr := make([]int,0,n)
		for n>0 {
			n--
			v := 0
			fmt.Fscan(input,&v)
			arr = append(arr,v)
		}
		sort.Ints(arr)
		l,r := 0,len(arr)-1
		f := "no"
		for l<r {
			if arr[l]+k == arr[r] {
				f = "yes"
				break
			}
			if arr[l]+k<arr[r] {
				l ++
			} else {
				r --
			}
		}
		fmt.Fprintln(ouput,f)
	}
}

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
		var k int64
		fmt.Fscan(in, &n, &k)

		m := make(map[int64]bool)
		var f bool
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			if (v >= k && m[v-k]) || (v < k && m[v+k]) {
				f = true
			}
			m[v] = true
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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
		var k int64
		fmt.Fscan(in, &n, &k)

		m := make(map[int64]bool)
		var f bool
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			if (v >= k && m[v-k]) || (v < k && m[v+k]) {
				f = true
				break
			}
			m[v] = true
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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
		var k int64
		fmt.Fscan(in, &n, &k)

		m := make(map[int64]bool)
		var f bool
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			m[v] = true
			if (v >= k && m[v-k]) || (v < k && m[v+k]) {
				f = true
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

var k,t,n int
func main(){
    ip:=bufio.NewScanner(os.Stdin)
    ip.Scan()
    t,_=strconv.Atoi(ip.Text())
    for ;t>0;t--{
        ip.Scan()
        n,_=strconv.Atoi(strings.Split(ip.Text()," ")[0])
        k,_=strconv.Atoi(strings.Split(ip.Text()," ")[1])
        a:=make([]int,n)
        ip.Scan()
        f:=false
        l,r:=0,1
        ss:=strings.Split(ip.Text()," ")
        for i:=range ss{a[i],_=strconv.Atoi(ss[i])}
        if n==1{
            f= a[0]==k
            goto there
        }
        sort.Ints(a)

        for l<n && r<n{
            if a[l]+abs(k)==a[r]{
                f=true
                goto there
            }else if a[l]+abs(k)>a[r]{
                r++
            }else{
                l++
            }
        }

        there:
        if f{
            fmt.Println("YES")
        }else{
            fmt.Println("NO")
        }
    }
}

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

package main

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

var k,t,n int
func main(){
    ip:=bufio.NewScanner(os.Stdin)
    ip.Scan()
    t,_=strconv.Atoi(ip.Text())
    for ;t>0;t--{
        ip.Scan()
        n,_=strconv.Atoi(strings.Split(ip.Text()," ")[0])
        k,_=strconv.Atoi(strings.Split(ip.Text()," ")[1])
        a:=make([]int,n)
        ip.Scan()
        f:=false
        i,j:=0,1
        ss:=strings.Split(ip.Text()," ")
        for i:=range ss{a[i],_=strconv.Atoi(ss[i])}
        if n==1{
            f=(a[0]==k)
            goto there
        }
        sort.Ints(a)

        for i<n && j<n{
            if a[i]+abs(k)==a[j]{
                f=true
                goto there
            }else if a[i]+abs(k)>a[j]{
                j++
            }else{
                i++
            }
        }

        there:
        if f{
            fmt.Println("YES")
        }else{
            fmt.Println("NO")
        }
    }
}

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

package main

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

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

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

	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Fscan(in, &n, &k)
		arr := make([]int, 0, n)
		for j := 0; j < n; j++ {
			var num int
			fmt.Fscan(in, &num)
			arr = append(arr, num)
		}
		sort.Ints(arr)
		idx := 0
		for i := 0; i < len(arr); i ++ {
			arr[idx] = arr[i]
			idx ++
			for i < len(arr)-1 && arr[i] == arr[i+1] {
				i ++
			}
		}
		arr = arr[:idx]
		// solve
		target := arr[len(arr)-1] - k
		//fmt.Fprintln(out, arr, t, target)
		presum := make([]int, len(arr))
		for k, v := range arr[:len(arr)-1] {
			presum[k+1] = presum[k] + abs(v)
		}
		sufsum := make([]int, len(arr))
		for i := len(arr)-2; i >= 0; i -- {
			sufsum[i] = sufsum[i+1] + abs(arr[i])
		}
		var flag bool
		for k := range arr[:len(arr)-1] {
			if sufsum[k] - presum[k] == target {
				flag = true
				break
			}
		}
		if flag {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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

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

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


package main

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

// github.com/EndlessCheng/codeforces-go
func Sol920E(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

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

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprintln(out, n)
		Fprintln(out, strings.Repeat("1 ", n))
		return
	}

	merge0 := func(v int, edges []int) {
		sort.Ints(edges)
		j := 0
		for i := 0; i < n; i++ {
			if i == v {
				continue
			}
			if j == len(edges) || i < edges[j] {
				merge(i, v)
			} else {
				j++
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	vs := map[int]bool{maxDeg0V: true}
	for _, w := range g[maxDeg0V] {
		vs[w] = true
	}
	for v, edges := range g {
		if same(v, maxDeg0V) {
			continue
		}
		cnt := 1
		for _, w := range edges {
			if !vs[w] {
				cnt++
			}
		}
		if cnt < n-len(g[maxDeg0V]) {
			merge(v, maxDeg0V)
		} else {
			merge0(v, edges)
		}
	}

	cnt := map[int]int{}
	for i := range fa {
		cnt[find(i)]++
	}
	values := make([]int, 0, len(cnt))
	for _, v := range cnt {
		values = append(values, v)
	}
	sort.Ints(values)
	Fprintln(out, len(values))
	for _, v := range values {
		Fprint(out, v, " ")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol920E(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

	n, m := read(), read()
	g := make([][]int, n)
	for ; m > 0; m-- {
		v, w := read()-1, read()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprintln(out, n)
		Fprintln(out, strings.Repeat("1 ", n))
		return
	}

	merge0 := func(v int, edges []int) {
		vs := map[int]bool{v: true}
		for _, w := range edges {
			vs[w] = true
		}
		for i := 0; i < n; i++ {
			if !vs[i] {
				merge(i, v)
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	for v, edges := range g {
		if !same(v, maxDeg0V) {
			merge0(v, edges)
		}
	}

	cnt := map[int]int{}
	for i := range fa {
		cnt[find(i)]++
	}
	values := make([]int, 0, len(cnt))
	for _, v := range cnt {
		values = append(values, v)
	}
	sort.Ints(values)
	Fprintln(out, len(values))
	for _, v := range values {
		Fprint(out, v, " ")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol920E(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

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

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprintln(out, 1)
		Fprintln(out, n)
		return
	}

	merge0 := func(v int, edges []int) {
		sort.Ints(edges)
		j := 0
		for i := 0; i < n; i++ {
			if i == v {
				continue
			}
			if j == len(edges) || i < edges[j] {
				merge(i, v)
			} else {
				j++
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	vs := map[int]bool{maxDeg0V: true}
	for _, w := range g[maxDeg0V] {
		vs[w] = true
	}
	for v, edges := range g {
		if same(v, maxDeg0V) {
			continue
		}
		cnt := 1
		for _, w := range edges {
			if !vs[w] {
				cnt++
			}
		}
		if cnt < n-len(g[maxDeg0V]) {
			merge(v, maxDeg0V)
		} else {
			merge0(v, edges)
		}
	}

	cnt := map[int]int{}
	for i := range fa {
		cnt[find(i)]++
	}
	values := make([]int, 0, len(cnt))
	for _, v := range cnt {
		values = append(values, v)
	}
	sort.Ints(values)
	Fprintln(out, len(values))
	for _, v := range values {
		Fprint(out, v, " ")
	}
}

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


package main

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

var reader = bufio.NewReader(os.Stdin)

func ri() int {
	var x int
	c, _ := reader.ReadByte()
	for c < '0' || c > '9' {
		c, _ = reader.ReadByte()
	}
	for '0' <= c && c <= '9' {
		x = (x << 3) + (x << 1) + int(c) - '0'
		c, _ = reader.ReadByte()
	}
	return x
}

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

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

const MAXN = 2e5 + 5

type Node struct {
	x, y int
}

func Solve() {
	n, c := ri(), int64(ri())
	var a, b []int64
	for i := 1; i <= n; i++ {
		a = append(a, int64(ri()))
	}
	for i := 1; i < n; i++ {
		b = append(b, int64(ri()))
	}
	ans := int64(math.Ceil(float64(c) / float64(a[0])))
	sum, res := int64(0), int64(0)
	for i := 1; i < n; i++ {
		sum += 1
		if res >= b[i-1] {
			res -= b[i-1]
		} else {
			b[i-1] -= res
			res = 0
			tmp := int64(math.Ceil(float64(b[i-1]) / float64(a[i-1])))
			sum += tmp
			res = tmp*a[i-1] - b[i-1]
		}
		if c >= res {
			ans = min(ans, sum+int64(math.Ceil(float64(c-res)/float64(a[i]))))
		} else {
			ans = min(ans, sum)
		}
	}
	fmt.Println(ans)
}

func main() {
	var T = 0
	if T == 0 {
		fmt.Scan(&T)
	}
	for t := 1; t <= T; t++ {
		Solve()
	}
}
//114514

package main

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

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

	var T, n, c int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &c)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, n-1)
		for i := range b {
			Fscan(in, &b[i])
		}

		ans := int(2e9)
		cur, day := 0, 0
		for i, v := range a {
			if cur >= c {
				break
			}
			if i < n-1 {
				res := (c - cur + v - 1) / v
				ans = min(ans, res+day)
				if b[i] >= c {
					break
				}
				if cur < b[i] {
					d := (b[i] - cur + v - 1) / v
					day += d + 1
					cur += d*v - b[i]
				} else {
					cur -= b[i]
					day++
				}
			} else {
				res := (c - cur + v - 1) / v
				ans = min(ans, res+day)
			}
		}
		Fprintln(out, ans)
	}
}

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

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, c int
		Fscan(in, &n, &c)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, n-1)
		for i := range b {
			Fscan(in, &b[i])
		}

		ans := int(2e9)
		cur, day := 0, 0
		for i, v := range a {
			if cur >= c {
				break
			}
			if i < n-1 {
				res := (c - cur + v - 1) / v
				ans = min(ans, res+day)
				if b[i] >= c {
					break
				}
				if cur < b[i] {
					d := (b[i] - cur + v - 1) / v
					day += d + 1
					cur += d*v - b[i]
				} else {
					cur -= b[i]
					day++
				}
			} else {
				res := (c - cur + v - 1) / v
				ans = min(ans, res+day)
			}
		}
		Fprintln(out, ans)
	}

	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) }
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var c int64
		fmt.Fscan(in, &n, &c)
		a := make([]int64, n)
		b := make([]int64, n-1)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		for i := range b {
			fmt.Fscan(in, &b[i])
		}
		var has int64
		var days int64
		res := int64(math.MaxInt64)
		for i := 0; i < n; i++ {
			needDays := (c-has+a[i]-1)/a[i]
			if needDays < 0 {
				needDays = 0
			}
			curRes := days + needDays
			if res > curRes {
				res = curRes
			}
			if i != n-1 {
				needDays = (b[i]-has+a[i]-1)/a[i]
				if needDays < 0 {
					needDays = 0
				}
				has += needDays * a[i] - b[i]
				days += needDays + 1
			}
		}
		fmt.Println(res)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func ri() int {
	var x int
	c, _ := reader.ReadByte()
	for c < '0' || c > '9' {
		c, _ = reader.ReadByte()
	}
	for '0' <= c && c <= '9' {
		x = (x << 3) + (x << 1) + int(c) - '0'
		c, _ = reader.ReadByte()
	}
	return x
}

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

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

const MAXN = 2e5 + 5

type Node struct {
	x, y int
}

func Solve() {
	n, c := ri(), ri()
	var a, b []int
	for i := 1; i <= n; i++ {
		a = append(a, ri())
	}
	for i := 1; i < n; i++ {
		b = append(b, ri())
	}
	ans := int(math.Ceil(float64(c) / float64(a[0])))
	sum, res := 0, 0
	for i := 1; i < n; i++ {
		sum += 1
		if res >= b[i-1] {
			res -= b[i-1]
		} else {
			b[i-1] -= res
			res = 0
			tmp := int(math.Ceil(float64(b[i-1]) / float64(a[i-1])))
			sum += tmp
			res = tmp*a[i-1] - b[i-1]
		}
		if c >= res {
			ans = min(ans, sum+int(math.Ceil(float64(c-res)/float64(a[i]))))
		} else {
			ans = min(ans, sum)
		}
	}
	fmt.Println(ans)
}

func main() {
	var T = 0
	if T == 0 {
		fmt.Scan(&T)
	}
	for t := 1; t <= T; t++ {
		Solve()
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func ri() int {
	var x int
	c, _ := reader.ReadByte()
	for c < '0' || c > '9' {
		c, _ = reader.ReadByte()
	}
	for '0' <= c && c <= '9' {
		x = (x << 3) + (x << 1) + int(c) - '0'
		c, _ = reader.ReadByte()
	}
	return x
}

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

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

const MAXN = 2e5 + 5

type Node struct {
	x, y int
}

func Solve() {
	n, c := ri(), ri()
	var a, b []int
	for i := 1; i <= n; i++ {
		a = append(a, ri())
	}
	for i := 1; i < n; i++ {
		b = append(b, ri())
	}
	ans := int(math.Ceil(float64(c) / float64(a[0])))
	sum, res := 0, 0
	for i := 1; i < n; i++ {
		sum += 1
		if res >= b[i-1] {
			res -= b[i-1]
		} else {
			b[i-1] -= res
			res = 0
			tmp := int(math.Ceil(float64(b[i-1]) / float64(a[i-1])))
			sum += tmp
			res = tmp*a[i-1] - b[i-1]
		}
		ans = min(ans, sum+int(math.Ceil(float64(c-res)/float64(a[i]))))
	}
	fmt.Println(ans)
}

func main() {
	var T = 0
	if T == 0 {
		fmt.Scan(&T)
	}
	for t := 1; t <= T; t++ {
		Solve()
	}
}

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, c int
		Fscan(in, &n, &c)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, n-1)
		for i := range b {
			Fscan(in, &b[i])
		}

		ans := int(2e9)
		cur, day := 0, 0
		for i, v := range a {
			if i < n-1 {
				res := (c-cur-1)/v + 1
				ans = min(ans, res+day)
				if cur < b[i] {
					d := (b[i]-cur-1)/v + 1
					day += d + 1
					cur += d*v - b[i]
				} else {
					cur -= b[i]
					day++
				}
			} else {
				res := (c-cur-1)/v + 1
				ans = min(ans, res+day)
			}
		}
		Fprintln(out, ans)
	}

	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) }
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(0)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, x := int(0), int(0)
		fmt.Fscanf(in, "%d %d\n", &n, &x)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		sort.Ints(a)
		ans := 1
		for i := n - 2; i >= 0; i-- {
			if a[i] == a[i+1] {
				continue
			}
			if x*ans >= a[i] {
				break
			}
			ans++
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

package main

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

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		solveOne()
	}
}

func solveOne() {

	n, r := readInt(), readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	sort.Ints(a)

	k := 0
	for i := n - 1; i >= 0 && a[i]-k*r > 0; i-- {
		k++
		for i > 0 && a[i] == a[i-1] {
			i--
		}
	}

	printInt(k)

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func process(monsters []int, shift int) int {
    sort.Ints(monsters)
    posAdd := 0
    shoots := 0
    for i:=len(monsters) - 1; i >= 0; {
        cur := monsters[i]
        if cur - posAdd <= 0 {
            break
        }
        shoots++
        posAdd += shift
        for i >= 0 && cur == monsters[i] {
            i--
        }
    }
    return shoots
}

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

    testsCnt := scanInt(scanner)

    for t := 0; t < testsCnt; t++ {
        n := scanInt(scanner)
        r := scanInt(scanner)

        buf := make(map[int]bool, n)

        for i := 0; i < n; i++ {
            pos := scanInt(scanner)
            buf[pos] = true
        }

        monsters := make([]int, len(buf))
        i := 0
        for pos := range buf {
            monsters[i] = pos
            i++
        }
        fmt.Println(process(monsters, r))
    }
    if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "reading standard input:", err)
	}
}

func scanInt64(scanner *bufio.Scanner) int64 {
    scanner.Scan()
    return parseInt(scanner.Text())
}

func scanInt(scanner *bufio.Scanner) int {
    return int(scanInt64(scanner))
}

func parseInt(s string) int64 {
    v, err := strconv.ParseInt(s, 10, 64)
    if err != nil {
        panic(err)
    }
    return v
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

/*******************************************************************/
func bsearch(x []int, ran int) int {
	n := len(x)
	l, r := 1, n-1
	ret := n
	for l <= r {
		m := (l + r) / 2
		if x[n-m-1]-m*ran <= 0 {
			r = m - 1
			if ret > m {
				ret = m
			}
		} else {
			l = m + 1
		}
	}
	return ret
}

func main() {
	for q := ReadInt(); q > 0; q-- {
		n, r := ReadInt2()
		x := ReadIntSlice(n)
		table := make(map[int]bool)
		for _, v := range x {
			table[v] = true
		}
		y := make([]int, 0, n)
		for k, _ := range table {
			y = append(y, k)
		}
		sort.Ints(y)
		num := bsearch(y, r)
		fmt.Println(num)
	}
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

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

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

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

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

func readInt_64() int64 {
	return readIntNbits(64)
}

func ReadInt2_64() (int64, int64) {
	return readInt_64(), readInt_64()
}

func ReadInt3_64() (int64, int64, int64) {
	return readInt_64(), readInt_64(), readInt_64()
}

func readInt() int {
	return int(readIntNbits(32))
}

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

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

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

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

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

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

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

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

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

	return string(res)
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

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

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

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

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

	if e == 0 {
		return 1
	}

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

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

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var q int

func main() {
	q = ReadInt()

	for i := 0; i < q; i++ {
		n, r := ReadInt2()
		X := ReadIntSlice(n)
		memo := make(map[int]int)
		for _, x := range X {
			memo[x] = 1
		}
		XX := []int{}
		for k := range memo {
			XX = append(XX, k)
		}

		sort.Sort(sort.IntSlice(XX))
		nn := len(XX)

		// m は中央を意味する何らかの値
		isOK := func(m int) bool {
			// 後ろのモンスターから爆殺
			cnt := 0
			for j := nn - 1; j >= 0; j-- {
				// j番目に殺すモンスターの座標
				xx := XX[j] - cnt*r

				if xx > 0 {
					// 爆殺する
					cnt++
				}
			}

			if cnt <= m {
				return true
			}
			return false
		}

		ng, ok := 0, len(X)
		for int(math.Abs(float64(ok-ng))) > 1 {
			mid := (ok + ng) / 2
			if isOK(mid) {
				ok = mid
			} else {
				ng = mid
			}
		}
		fmt.Println(ok)
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

func solve(reader io.Reader, writer io.Writer) {
	unique := func(arr []int) (uniqueArr []int) {
		n := len(arr)
		if n == 0 {
			return
		}
		uniqueArr = make([]int, 1, n)
		uniqueArr[0] = arr[0]
		for i := 1; i < n; i++ {
			if arr[i] != arr[i-1] {
				uniqueArr = append(uniqueArr, arr[i])
			}
		}
		return
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var q, n int
	for Fscan(in, &q); q > 0; q-- {
		var r int64
		Fscan(in, &n, &r)
		x := make([]int, n)
		for i := range x {
			Fscan(in, &x[i])
		}
		sort.Ints(x)
		x = unique(x)
		n = len(x)
		ans := sort.Search(n, func(i int) bool {
			if i == 0 {
				return false
			}
			return int64(x[n-1-i]) <= int64(i)*int64(r)
		})
		Fprintln(out, ans)
	}
}

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

package main

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

func main() {
	defer Flush()
	q := readi()
	for i := 0; i < q; i++ {
		n := readi()
		r := readi()
		_, x := readInts(n)
		println(solve(n, r, x))
	}

}

func solve(n, r int, x []int) int {
	var res int
	sort.Ints(x)
	d := 0
	for i, j := 0, n-1; i <= j; {
		res++
		d += r
		j--
		for 0 <= j && x[j] == x[j+1] {
			j--
		}
		for i <= j && x[i] <= d {
			i++
		}
	}
	return res
}

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

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

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

/*******************************************************************/
func bsearch(x []int, n, r int) int {
	l, r := 1, n-1
	ret := n
	for l <= r {
		m := (l + r) / 2
		if x[n-m-1]-2*m <= 0 {
			r = m - 1
			if ret > m {
				ret = m
			}
		} else {
			l = m + 1
		}
	}
	return ret
}

func main() {
	for q := ReadInt(); q > 0; q-- {
		n, r := ReadInt2()
		x := ReadIntSlice(n)
		num := bsearch(x, n, r)
		fmt.Println(num)
	}

}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

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

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

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

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

func readInt_64() int64 {
	return readIntNbits(64)
}

func ReadInt2_64() (int64, int64) {
	return readInt_64(), readInt_64()
}

func ReadInt3_64() (int64, int64, int64) {
	return readInt_64(), readInt_64(), readInt_64()
}

func readInt() int {
	return int(readIntNbits(32))
}

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

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

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

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

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

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

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

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

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

	return string(res)
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

/*******************************************************************/
func bsearch(x []int, n, ran int) int {
	l, r := 1, n-1
	ret := n
	for l <= r {
		m := (l + r) / 2
		if x[n-m-1]-m*ran <= 0 {
			r = m - 1
			if ret > m {
				ret = m
			}
		} else {
			l = m + 1
		}
	}
	return ret
}

func main() {
	for q := ReadInt(); q > 0; q-- {
		n, r := ReadInt2()
		x := ReadIntSlice(n)
		sort.Ints(x)
		num := bsearch(x, n, r)
		fmt.Println(num)
	}
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

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

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

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

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

func readInt_64() int64 {
	return readIntNbits(64)
}

func ReadInt2_64() (int64, int64) {
	return readInt_64(), readInt_64()
}

func ReadInt3_64() (int64, int64, int64) {
	return readInt_64(), readInt_64(), readInt_64()
}

func readInt() int {
	return int(readIntNbits(32))
}

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

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

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

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

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

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

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

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

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

	return string(res)
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

/*******************************************************************/
func bsearch(x []int, n, ran int) int {
	l, r := 1, n-1
	ret := n
	for l <= r {
		m := (l + r) / 2
		if x[n-m-1]-m*ran <= 0 {
			r = m - 1
			if ret > m {
				ret = m
			}
		} else {
			l = m + 1
		}
	}
	return ret
}

func main() {
	for q := ReadInt(); q > 0; q-- {
		n, r := ReadInt2()
		x := ReadIntSlice(n)
		num := bsearch(x, n, r)
		fmt.Println(num)
	}
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

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

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

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

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

func readInt_64() int64 {
	return readIntNbits(64)
}

func ReadInt2_64() (int64, int64) {
	return readInt_64(), readInt_64()
}

func ReadInt3_64() (int64, int64, int64) {
	return readInt_64(), readInt_64(), readInt_64()
}

func readInt() int {
	return int(readIntNbits(32))
}

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

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

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

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

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

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

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

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

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

	return string(res)
}