package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var k, x int64
    fmt.Fscan(input, &k, &x)

    ok := func(v int64) bool {
        var tot int64

        if v > k {
            tot = k * (k + 1) / 2
            v -= k
            c := k - v
            tot += k * (k - 1) / 2 - (c * (c - 1) / 2)
        } else {
            tot = v * (v + 1) / 2
        }

        return tot < x
    }

    l, r := int64(0), 2*k - 1

    for r - l > 1 {
        m := (l + r) / 2
        if ok(m) {
            l = m
        } else {
            r = m
        }
    }
    fmt.Fprintln(output, r)
}

package main

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

var k, x int64

func main() {

	r := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &k, &x)

		a := solve()

		fmt.Println(a)
	}

}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() int64 {
	s := k * (k + 1)/2

	if s >= x {

		var lo, hi int64 = 1, k

		for ; hi - lo > 1; {

			m := (hi + lo)/2

			ss := m * (m + 1)/2

			if ss > x {
				hi = m

			} else if ss < x {

				lo = m

			} else {
				return m
			}
		}

		s1 := lo * (lo + 1)/2

		if s1 >= x {
			return lo
		}

		return hi

	} else {
		x -= s

		tot := (k - 1) * (k) / 2

		if tot <= x {
			return k + (k - 1)
		}

		var lo, hi int64 = 1, k

		for ;hi - lo > 1; {

			m := (lo + hi)/2

			ss := tot - m * (m + 1)/2

			if x > ss {
				hi = m

			} else if x < ss {
				lo = m

			} else {
				return k + (k - 1) - m
			}
		}

		s1 := tot - hi * (hi + 1)/2

		if s1 >= x {
			return (k - 1) - hi + k
		}

		return (k - 1) - lo + k

	}
}

//1000 000 001 000 000 000

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

import (
	"fmt"
)

func main() {
	getSum := func(l int64, r int64) int64 {
		return (r*(r+1))/2 - (l*(l-1))/2
	}
	var t int32
	fmt.Scan(&t)
	for tc := int32(0); tc < t; tc++ {
		var k, x, ans int64
		fmt.Scan(&k, &x)
		l := int64(1)
		r := 2*k - 1
		ans = 0
		check := func(mid int64) bool {
			if mid > k {
				return x > 2*getSum(1, k-1)+k-getSum(1, 2*k-1-mid)
			} else {
				return x > getSum(1, mid)
			}
		}
		for l <= r {
			mid := (l + r) / 2
			if check(mid) {
				ans = mid
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		if ans < 2*k-1 {
			ans++
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	getSum := func(l int64, r int64) int64 {
		if l > r {
			return int64(0)
		}
		return (r*(r+1))/2 - (l*(l-1))/2
	}
	var t int32
	fmt.Scan(&t)
	for tc := int32(0); tc < t; tc++ {
		var k, x, ans int64
		fmt.Scan(&k, &x)
		l := int64(1)
		r := 2*k - 1
		ans = 0
		check := func(mid int64) bool {
			if mid > k {
				return x > 2*getSum(1, k-1)+k-getSum(1, 2*k-1-mid)
			} else {
				return x > getSum(1, mid)
			}
		}
		for l <= r {
			mid := (l + r) / 2
			if check(mid) {
				ans = mid
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		if ans < 2*k-1 {
			ans++
		}
		fmt.Println(ans)
	}
}

package main

import "fmt"

func main() {
	var t, k, x int64
	fmt.Scanln(&t)
	for i := int64(0); i < t; i++ {
		fmt.Scanln(&k, &x)
		fmt.Println(binarySearch(k*2-1, x))
	}
}

func binarySearch(msgCount, banCount int64) int64 {
	left := int64(0)
	right := msgCount
	for {
		mid := (left + right) / 2
		if sumOfNMembers(mid, msgCount) > banCount {
			right = mid
		} else {
			left = mid
		}
		if right-left <= 1 {
			if sumOfNMembers(mid-1, msgCount) >= banCount {
				return mid - 1
			} else if sumOfNMembers(mid, msgCount) >= banCount {
				return mid
			} else {
				return mid + 1
			}
		}
	}
}

func nthMember(n, total int64) int64 {
	if n*2-1 <= total {
		return 1 + (n - 1)
	}
	return total/2 + 1 - (n - (total/2 + 1))
}

func sumOfNMembers(n, total int64) int64 {
	if n*2-1 <= total {
		return ((1 + nthMember(n, total)) * n) / 2
	}
	return ((1+nthMember(total/2+1, total))*(total/2+1))/2 + (nthMember(n, total)+total/2)*(n-(total/2+1))/2
}

package main

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

func countEmojis(k, n int64) int64 {
  if n <= k {
    return (1 + n) * n / 2
  }
  return k * (k - 1) / 2 - (k - n - 1) * (3*k - n) / 2
}

func solve(sc *bufio.Scanner, wr *bufio.Writer) {
  sc.Scan()
  k, _ := strconv.ParseInt(sc.Text(), 10, 64)

  sc.Scan()
  x, _ := strconv.ParseInt(sc.Text(), 10, 64)

  l, r := int64(0), 2 * k
  for r - l > 1 {
    m := (l + r) / 2
    if countEmojis(k, m) < x {
      l = m
    } else {
      r = m
    }
  }

  if r > 2*k - 1 {
    r = 2*k - 1
  }

  wr.WriteString(strconv.FormatInt(r, 10))
  wr.WriteRune('\n')
}

const once = false

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

  wr := bufio.NewWriter(os.Stdout)
  defer wr.Flush()

  if once {
    solve(sc, wr)
  } else {
    sc.Scan()
    times, _ := strconv.Atoi(sc.Text())
    for times > 0 {
      solve(sc, wr)
      times--
    }
  }
}

package main

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

/*
9
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
---
1
2
2
3
3
3
4
4
5
======
1
1 2
---
1
*/

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

	bld := strings.Builder{}

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

	for ; t > 0; t-- {
		var k, x int64
		scanf("%d %d\n", &k, &x)

		lftIdx := int64(1)
		rgtIdx := 2*k - 1

		ans := 2*k - 1

	loop:
		for lftIdx <= rgtIdx {
			midIdx := (lftIdx + rgtIdx) / 2

			midStart := int64(0)
			midEnd := int64(0)

			if midIdx <= k {
				midEnd = midIdx * (midIdx + 1) / 2
				midStart = midEnd - midIdx + 1
			} else {
				midEnd = k*(k+1)/2 + ((midIdx-k)*(abs(midIdx-2*k)+k-1))/2
				midStart = midEnd - abs(midIdx-2*k) + 1
			}

			switch {
			case x >= midStart && x <= midEnd:
				ans = midIdx
				break loop
			case x < midStart:
				rgtIdx = midIdx - 1
			case x > midEnd:
				lftIdx = midIdx + 1
			}
		}

		fmt.Fprintln(&bld, ans)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(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) int64 {
//	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 {
//	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"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

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

func scanInt8() int8 {
	i, err := strconv.ParseInt(scan(), 10, 8)
	if err != nil {
		panic(err)
	}
	return int8(i)
}

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

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

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

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

type Noop struct{}

var noop = Noop{}

func count(k int64, m int64) int64 {
	if m <= k {
		return (1 + m) * m / 2
	}
	return (1+k)*k/2 + ((k-1)+(k-(m-k)))*(m-k)/2
}

func proc() {
	k, x := scanInt64(), scanInt64()
	a := int64(1)
	b := k + k - 1
	for a < b {
		m := (a + b) / 2
		c := count(k, m)
		// fmt.Printf("a: %d b: %d m: %d c: %d\n", a, b, m, c)
		if c < x {
			a = m + 1
		} else {
			b = m
		}
	}
	fmt.Println(a)
}

func main() {
	sc.Split(bufio.ScanWords)
	t := scanInt()
	for i := 0; i < t; i++ {
		proc()
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)

func check(mid, x, k int64) bool {
	var ans = mid * (mid - 1) / 2

	if mid <= k {
		return ans < x
	} else {
		ans = k * (k + 1) / 2
		dif := mid - k
		an := k - 1
		a2 := k - dif + 1
		sum := (a2 + an) * (dif-1) / 2
		return ans + sum < x
	}
}

/*
999 1000 999 998 997 996
*/

func solve(){
	var k, x int64
	fmt.Fscan(r, &k, &x)

	var l, r int64 = 0, 2*k

	for l + 1 < r {
		mid := (l + r) / 2
		if check(mid, x, k) {
			l = mid
		} else {
			r = mid
		}
	}

	fmt.Println(l)
}

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

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

		search := func(n int64) bool {
			var tot int64

			if n > k {
				tot = k * (k + 1) / 2
				n -= k
				c := k - n
				tot += k*(k-1)/2 - (c * (c - 1) / 2)
			} else {
				tot = n * (n + 1) / 2
			}
			return tot < x
		}

		l, r := int64(0), 2*k-1
		for r-l > 1 {
			m := (r + l) / 2
			if search(m) {
				l = m
			} else {
				r = m
			}
		}

		fmt.Fprintln(out, r)
	}
}

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

		sum := k * (k + 1) / 2
		search := func(p, n int64) int64 {
			if p*(p+1)/2 <= n {
				return p
			}

			l, r := int64(1), int64(p)
			for r-l >= 1 {
				z := (l + r) / 2
				if z*(z+1)/2 < n {
					l = z + 1
				} else {
					r = z
				}
			}
			return r
		}

		var t int64
		if sum >= x {
			t = search(k, x)
		} else {
			t += k
			k = k - 1
			x -= sum
			for k*(k+1)/2 >= x {
				k--
			}
			t += k
		}

		if t > 1608737403 {
			fmt.Fprintln(out, 1608737403)
		} else {
			fmt.Fprintln(out, t)
		}
	}
}

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

		sum := k * (k + 1) / 2
		search := func(p, n int64) int64 {
			if p*(p+1)/2 <= n {
				return p
			}

			l, r := int64(1), int64(p)
			for r-l >= 1 {
				z := (l + r) / 2
				if z*(z+1)/2 < n {
					l = z + 1
				} else {
					r = z
				}
			}
			return r
		}

		var t int64
		if sum >= x {
			t = search(k, x)
		} else {
			t = k + search(k-1, x-sum)
		}

		if t > 1608737403 {
			fmt.Fprintln(out, 1608737403)
		} else {
			fmt.Fprintln(out, t)
		}
	}
}

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

		sum := k * (k + 1) / 2
		search := func(p, n int64) int64 {
			if p*(p+1)/2 <= n {
				return p
			}

			l, r := int64(1), int64(p)
			for r-l >= 1 {
				z := (l + r) / 2
				if z*(z+1)/2 < n {
					l = z + 1
				} else {
					r = z
				}
			}
			return r
		}

		var t int64
		if sum > x {
			t = search(k, x)
		} else {
			t = k + search(k-1, x-sum)
		}

		if t > 1608737403 {
			fmt.Fprintln(out, 1608737403)
		} else {
			fmt.Fprintln(out, t)
		}
	}
}

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

		sum := k * (k + 1) / 2
		search := func(p, n int64) int64 {
			if p*(p+1)/2 <= n {
				return p
			}

			l, r := int64(1), int64(p)
			for r-l >= 1 {
				z := (l + r) / 2
				if z*(z+1)/2 < n {
					l = z + 1
				} else {
					r = z
				}
			}
			return r
		}

		var t int64
		if sum > x {
			t = search(k, x)
		} else {
			t = k + search(k-1, x-sum)
		}

		fmt.Fprintln(out, t)
	}
}

package main

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

var k, x int64

func main() {

	r := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &k, &x)

		a := solve()

		fmt.Println(a)
	}

}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() int64 {
	s := k * (k + 1)/2

	if s >= x {

		var lo, hi int64 = 1, k

		for ; hi - lo > 1; {

			m := (hi + lo)/2

			ss := m * (m + 1)/2

			if ss > x {
				hi = m

			} else if ss < x {

				lo = m

			} else {
				return m
			}
		}

		s1 := lo * (lo + 1)/2

		if s1 >= x {
			return lo
		}

		return hi

	} else {
		x -= s

		tot := (k - 1) * (k) / 2

		if tot < x {
			return k + (k - 1)
		}

		var lo, hi int64 = 1, k

		for ;hi - lo > 1; {

			m := (lo + hi)/2

			ss := tot - m * (m + 1)/2

			if x > ss {
				hi = m

			} else if x < ss {
				lo = m

			} else {
				return k + (k - 1) - m
			}
		}

		s1 := tot - hi * (hi + 1)/2

		if s1 >= x {
			return (k - 1) - hi + k
		}

		return (k - 1) - lo + k

	}
}

//1000 000 001 000 000 000

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

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

var k, x int64

func main() {

	r := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &k, &x)

		a := solve()

		fmt.Println(a)
	}

}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() int64 {
	s := k * (k + 1)/2

	if s > x {

		var lo, hi int64 = 1, k

		for ; hi - lo > 1; {

			m := (hi + lo)/2

			ss := m * (m + 1)/2

			if ss > x {
				hi = m

			} else if ss < x {

				lo = m

			} else {
				return m
			}
		}

		s1 := lo * (lo + 1)/2

		if s1 >= x {
			return lo
		}

		return hi

	} else {
		x -= s

		tot := (k - 1) * (k) / 2

		if tot < x {
			return k + (k - 1)
		}

		var lo, hi int64 = 1, k

		for ;hi - lo > 1; {

			m := (lo + hi)/2

			ss := tot - m * (m + 1)/2

			if x > ss {
				hi = m

			} else if x < ss {
				lo = m

			} else {
				return k + (k - 1) - m
			}
		}

		s1 := tot - hi * (hi + 1)/2

		if s1 >= x {
			return (k - 1) - hi + k
		}

		return (k - 1) - lo + k

	}
}

//1000 000 001 000 000 000

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

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

var k, x int64

func main() {

	r := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &k, &x)

		a := solve()

		fmt.Println(a)
	}

}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() int64 {
	s := k * (k + 1)/2

	if s > x {

		var lo, hi int64 = 1, k

		for ; hi - lo > 1; {

			m := (hi + lo)/2

			ss := m * (m + 1)/2

			if ss > x {
				hi = m

			} else if ss < x {

				lo = m

			} else {
				return m
			}
		}

		s1 := lo * (lo + 1)/2

		if s1 >= x {
			return lo
		}

		return hi

	} else {
		x -= s

		tot := (k - 1) * (k) / 2

		if tot < x {
			return k + (k - 1)
		}

		var lo, hi int64 = 1, k

		for ;hi - lo > 1; {

			m := (lo + hi)/2

			ss := tot - m * (m + 1)/2

			if x > ss {
				hi = m

			} else if x < ss {
				lo = m

			} else {
				return k + m
			}
		}

		s1 := tot - hi * (hi + 1)/2

		if s1 >= x {
			return (k - 1) - hi + k
		}

		return (k - 1) - lo + k

	}
}

//1000 000 001 000 000 000

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

import "fmt"

func main() {
	var t, k, x int64
	fmt.Scanln(&t)
	for i := int64(0); i < t; i++ {
		fmt.Scanln(&k, &x)
		println(binarySearch(k*2-1, x))
	}
}

func binarySearch(msgCount, banCount int64) int64 {
	left := int64(0)
	right := msgCount
	for {
		mid := (left + right) / 2
		if sumOfNMembers(mid, msgCount) > banCount {
			right = mid
		} else {
			left = mid
		}
		if right-left <= 1 {
			if sumOfNMembers(mid-1, msgCount) >= banCount {
				return mid - 1
			} else if sumOfNMembers(mid, msgCount) >= banCount {
				return mid
			} else {
				return mid + 1
			}
		}
	}
}

func nthMember(n, total int64) int64 {
	if n*2-1 <= total {
		return 1 + (n - 1)
	}
	return total/2 + 1 - (n - (total/2 + 1))
}

func sumOfNMembers(n, total int64) int64 {
	if n*2-1 <= total {
		return ((1 + nthMember(n, total)) * n) / 2
	}
	return ((1+nthMember(total/2+1, total))*(total/2+1))/2 + (nthMember(n, total)+total/2)*(n-(total/2+1))/2
}


package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

var ts = 0

type fenwick [][2]int

func (f fenwick) get(x int) int {
	if f[x][0] < ts {
		f[x][0] = ts
		f[x][1] = 0
	}
	res := f[x][1]
	for x &= x - 1; x > 0; x &= x - 1 {
		if f[x][0] < ts {
			f[x][0] = ts
			f[x][1] = 0
		}
		res += f[x][1]
	}
	return res
}

func (f fenwick) add(x, n int) {
	for x < len(f) {
		if f[x][0] < ts {
			f[x][0] = ts
			f[x][1] = 0
		}
		f[x][1] += n
		x += x & (-x)
	}
}

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

	n := readInt()
	ops := make(map[int][][3]int, n)
	var times []int
	nRes := 0
	for i := 0; i < n; i++ {
		a := readInt()
		t := readInt()
		x := readInt()
		val := [3]int{a, t, 0}
		if a == 3 {
			val[2] = nRes
			nRes++
		}
		ops[x] = append(ops[x], val)
		times = append(times, t)
	}

	sort.Ints(times)
	tm := make(map[int]int)
	for i, t := range times {
		tm[t] = i+1
	}

	res := make([]int, nRes)
	fen := make(fenwick, n+3)
	for _, ops := range ops {
		for i := range ops {
			t := tm[ops[i][1]]
			switch ops[i][0] {
			case 1:
				fen.add(t, 1)
			case 2:
				fen.add(t, -1)
			case 3:
				res[ops[i][2]] = fen.get(t)
			default:
				panic("switch")
			}
		}
		ts++
	}
	for i := range res {
		fmt.Fprintln(out, res[i])
	}
}

package main

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

func main() {
	defer out.Flush()
	Q := in.NextInt()
	qs := make([]Query, Q)
	xTimes := make(map[int][]int)
	for i := range qs {
		qs[i].a = in.NextInt()
		qs[i].t = in.NextInt()
		qs[i].x = in.NextInt()
		xTimes[qs[i].x] = append(xTimes[qs[i].x], qs[i].t)
	}
	timeToXTime := make(map[int]int)
	fs := make(map[int]*Fenwick)
	for x, times := range xTimes {
		sort.Ints(times)
		for i, t := range times {
			timeToXTime[t] = i
		}
		fs[x] = NewFenwick(len(times))
	}
	for i := range qs {
		q := qs[i]
		f := fs[q.x]
		xt := timeToXTime[q.t]
		switch q.a {
		case 1:
			f.Set(xt, 1)
		case 2:
			f.Set(xt, -1)
		case 3:
			fmt.Fprintln(out, f.Sum(0, xt))
		}
	}
}

type Query struct {
	a, t, x int
}

type Fenwick struct {
	size int
	sum  []int
}

func NewFenwick(size int) *Fenwick {
	return &Fenwick{
		size,
		make([]int, size+1),
	}
}

func step(x int) int {
	return x & -x
}

func (f *Fenwick) Add(pos int, value int) {
	for i := pos + 1; i <= f.size; i += step(i) {
		f.sum[i] += value
	}
}

func (f *Fenwick) Set(pos int, value int) {
	f.Add(pos, value-f.Get(pos))
}

func (f *Fenwick) prefixSum(pos int) int {
	var result int
	for i := pos + 1; i > 0; i -= step(i) {
		result += f.sum[i]
	}
	return result
}

func (f *Fenwick) Sum(a, b int) int {
	return f.prefixSum(b) - f.prefixSum(a-1)
}

func (f *Fenwick) Get(a int) int {
	return f.Sum(a, a)
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	var err error
	for len(r.buf) == 0 && err != io.EOF {
		buf := new(bytes.Buffer)
		for {
			var chunk []byte
			var more bool
			chunk, more, err = r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}


package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func maxFloat(a float64, nums ...float64) float64 {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

func query(l int, r int, p []int) int {
	ans := p[r]
	if l > 0 {
		ans -= p[l-1]
	}
	return ans
}

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

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

		arr := make([]int, n)
		sum := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			sum[i] = arr[i]
			if i > 0 {
				sum[i] += sum[i-1]
			}
		}

		ans := math.MaxInt32
		ansFound := false
		for i := 0; i < n; i++ {
			l := i
			r := n - 1
			pos := -1
			for l <= r {
				mid := l + (r-l)/2

				if query(i, mid, sum) <= s {
					pos = mid
					l = mid + 1
				} else {
					r = mid - 1
				}
			}
			if pos == -1 || query(i, pos, sum) != s {
				continue
			}
			ansFound = true
			ans = min(ans, n-(pos-i+1))
		}
		if ansFound {
			fmt.Fprintln(out, ans)
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

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

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

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

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

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

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

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

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

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

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

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

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

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() {
	n, s := ri(), ri()
	a := ria(n)
	d := make([]int, 0)
	d = append(d, -1)
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			d = append(d, i)
		}
	}
	d = append(d, n)

	// myio.Println(d, len(d), s)

	if len(d)-2 < s {
		myio.Println(-1)
		return
	}
	l := 0
	for i := 0; i+s+1 < len(d); i++ {
		l1 := d[i+s+1] - d[i] - 1
		// myio.Println(d[i]+1, d[i+s+1]-1)
		if l1 > l {
			l = l1
		}
	}
	myio.Println(n - l)
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

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

func main() {
	defer writer.Flush()

	var Q int
	fmt.Fscan(reader, &Q)

	const INF int = 1000000000

	for ; Q > 0; Q-- {
		var n, s int
		fmt.Fscan(reader, &n, &s)

		a := make([]int, n+1)
		m := 0

		for i := 1; i <= n; i++ {
			fmt.Fscan(reader, &a[i])
			m += a[i]
			a[i] += a[i-1]
		}

		last := make([]int, m+1)
		for i := 1; i <= m; i++ {
			last[i] = -1
		}

		ans := INF
		for r := 1; r <= n; r++ {
			if a[r]-s >= 0 && last[a[r]-s] != -1 {
				if ans > last[a[r]-s]+n-r {
					ans = last[a[r]-s] + n - r
				}
			}
			if last[a[r]] == -1 {
				last[a[r]] = r
			}
		}

		if ans == INF {
			fmt.Fprintf(writer, "%d\n", -1)
		} else {
			fmt.Fprintf(writer, "%d\n", ans)
		}
	}
}

package main

import (
    "fmt"
    _"math"
)

func UNUSED(x ...interface{}) {}

func main() {

	var a [200007]int
	var t, n, s int
	fmt.Scan(&t)
	for(t > 0) {
		t --
		var sum, ind, res int
		res = 1000007

		fmt.Scan(&n, &s)
		for i := 0; i < n; i ++ {
			fmt.Scan(&a[i])
			sum += a[i]
		}
		if sum < s {
			fmt.Println(-1)
			continue
		}
		var b []int = a[:n]
		var fromtop [200007]int

		fromtop[ind] = 0
		ind ++

		for i, x := range b {
			if x == 1 {
				fromtop[ind] = i + 1
				ind ++
			}
		}
		fromtop[ind] = len(b) + 1
		ind ++

		sum -= s

		for i := 0; i <= sum; i ++ {
			res = min(res, fromtop[i] + len(b) - fromtop[ind - sum - 1 + i] + 1)
		}

		fmt.Println(res)
	}
}

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

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, s int
		fmt.Fscan(r, &n, &s)
		var a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(a, n, s)
		fmt.Fprintln(w, w1)
	}
}

func do(a []int, n, s int) int {
	j := 0
	t := 0
	ans := -1
	// log.Print(a)
	for i := 0; i < n; i++ {
		t += a[i]
		// log.Print(i, t, s, j, ans)
		if t > s {
			for a[j] != 1 {
				j++
			}
			j++
			t--
		}
		if t == s {
			if ans == -1 {
				ans = n
			}
			if ans > j+n-i-1 {
				ans = j + n - i - 1
			}
		}
	}
	return ans
}

package main

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

/*
2
11 4
1 0 1 0 1 0 0 1 1 0 1
11 3
1 0 1 0 1 0 0 1 1 0 1
---
2
4

10101001101
11223334556

========
1
5 1
0 0 1 1 0
*/

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

	a := make([]int, n)
	psa := make([]int, n)
	sumA := 0

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

		psa[i] = a[i]
		if i != 0 {
			psa[i] += psa[i-1]
		}

		sumA += a[i]
	}
	scanf("\n")

	if s > sumA {
		fmt.Fprintln(writer, -1)
		return
	} else if s == sumA {
		fmt.Fprintln(writer, 0)
		return
	}

	removeCnt := sumA - s

	i := 0
	for ; i < n; i++ {
		if psa[i] == removeCnt {
			break
		}
	}

	bestOpCnt := i + 1

	k := n - 1
	for j := i - 1; j >= -1; j-- {
		leftSum := 0
		if j >= 0 {
			leftSum = psa[j]
		}

		for k >= 0 && leftSum+(psa[n-1]-psa[k]+a[k]) != removeCnt {
			k--
		}

		opCnt := (j + 1) + n - k
		bestOpCnt = min(bestOpCnt, opCnt)
	}

	fmt.Fprintln(writer, bestOpCnt)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

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

func slove() {
	var n, s int
	fmt.Fscan(r, &n, &s)
	nums := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	l, r := 0, -1
	cnt := 0
	ans := n
	for r < len(nums) - 1 {
		r++
		if nums[r] == 1 {
			cnt++
		}
		for cnt > s {
			if nums[l] == 1 {
				cnt--
			}
			l++
		}
		if cnt == s {
			ans = min(ans, n - (r-l+1))
		}
	}
	if ans == n {
			fmt.Fprintln(w, -1)
	} else {
		fmt.Fprintln(w, ans)
	}
}

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

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

package main

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

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

	solve := func(curCase int) {
		var n , tar int
		Fscan(in, &n,&tar)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		l := 0
		s := 0
		ans := -1
		for r, v := range a {
			s+=v
			for l<n && s > tar {
				s-=a[l]
				l++
			}
			if s == tar {
				ans = max(ans, r-l+1)
			}
		}
		if ans == -1 {
			Fprintln(out, -1)
		} else {
			Fprintln(out, n-ans)
		}
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

func main() { run(os.Stdin, os.Stdout) }
func max(a, b int) int {
	if b > a {
		return b
	}
	return a
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for t := 0; t < testCases; t++ {
		var n, s int
		Fscan(in, &n, &s)
		nums := make([]int, n)

		sum := 0
		for i := 0; i < n; i++ {
			Fscan(in, &nums[i])
			sum += nums[i]
		}

		if sum < s {
			Fprintln(out, -1)
			continue
		}

		window := -1
		i := 0
		j := 0
		cur := 0
		for j < n {
			cur += nums[j]
			if cur < s {
				j++
				continue
			}
			if cur == s {
				window = max(window, j-i+1)
				j++
				continue
			}
			if cur > s {
				cur -= nums[j]
				cur -= nums[i]
				i++
			}

		}

		Fprintln(out, n-window)
	}

}

func max(a, b int) int {
	if a > b {
		return a
	}
	return 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 n, x int
		fmt.Fscan(in, &n, &x)

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

			if v == 1 {
				a[pos] = i + 1
				pos++
			}
		}

		if x > n || a[x-1] == 0 {
			fmt.Fprintln(out, -1)
			continue
		}

		if a[x] == 0 && a[x-1] > 0 {
			fmt.Fprintln(out, 0)
			continue
		}
		ans := math.MaxInt32
		for i := 0; i < n; i++ {
			if a[i] == 0 || i+x+1 > n || a[i+x-1] == 0 {
				break
			}

			var tot int
			if i > 0 {
				tot += a[i-1]
			}

			if a[i+x] > 0 {
				tot += n - a[i+x] + 1
			}
			ans = min(ans, tot)
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func maxFloat(a float64, nums ...float64) float64 {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

func query(l int, r int, p []int) int {
	ans := p[r]
	if l > 0 {
		ans -= p[l-1]
	}
	return ans
}

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

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

		arr := make([]int, n)
		sum := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			sum[i] = arr[i]
			if i > 0 {
				sum[i] += sum[i-1]
			}
		}

		ans := math.MaxInt32
		for i := 0; i < n; i++ {
			l := i
			r := n - 1
			pos := -1
			for l <= r {
				mid := l + (r-l)/2

				if query(i, mid, sum) <= s {
					pos = mid
					l = mid + 1
				} else {
					r = mid - 1
				}
			}
			if pos == -1 || query(i, pos, sum) != s {
				continue
			}
			ans = min(ans, n-(pos-i+1))
		}
		if ans == math.MaxInt32 {
			ans = -1
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for t := 0; t < testCases; t++ {
		var n, s int
		Fscan(in, &n, &s)
		nums := make([]int, n)
		distanceOfOneFromFront := make([]int, n)
		distanceOfOneFromBack := make([]int, n)

		cnt := 5 * n
		sum := 0
		for i := 0; i < n; i++ {
			Fscan(in, &nums[i])
			sum += nums[i]
			if nums[i] == 1 {
				cnt = 0
			} else {
				cnt++
			}
			distanceOfOneFromBack[i] = cnt
		}

		if sum < s {
			Fprintln(out, -1)
			continue
		}

		cnt = 5 * n
		for i := n - 1; i >= 0; i-- {
			if nums[i] == 1 {
				cnt = 0
			} else {
				cnt++
			}
			distanceOfOneFromFront[i] = cnt
		}

		l := 0
		r := n - 1
		cnt = 0
		for sum > s {
			if distanceOfOneFromFront[l] > distanceOfOneFromBack[r] {
				sum -= nums[r]
				r--
			} else {
				sum -= nums[l]
				l++
			}
			cnt++
		}

		Fprintln(out, cnt)
	}

}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for t := 0; t < testCases; t++ {
		var n, s int
		Fscan(in, &n, &s)
		nums := make([]int, n)
		distanceOfOneFromFront := make([]int, n)
		distanceOfOneFromBack := make([]int, n)

		cnt := 5 * n
		sum := 0
		for i := 0; i < n; i++ {
			Fscan(in, &nums[i])
			sum += nums[i]
			if nums[i] == 1 {
				cnt = 0
			} else {
				cnt++
			}
			distanceOfOneFromBack[i] = cnt
		}

		if sum < s {
			Fprintln(out, -1)
			continue
		}

		cnt = 5 * n
		for i := n - 1; i >= 0; i-- {
			if nums[i] == 1 {
				cnt = 0
			} else {
				cnt++
			}
			distanceOfOneFromFront[i] = cnt
		}

		fmt.Println(distanceOfOneFromFront)
		fmt.Println(distanceOfOneFromBack)
		l := 0
		r := n - 1
		cnt = 0
		for sum > s {
			if distanceOfOneFromFront[l] > distanceOfOneFromBack[r] {
				sum -= nums[r]
				r--
			} else {
				sum -= nums[l]
				l++
			}
			cnt++
		}

		Fprintln(out, cnt)
	}

}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for t := 0; t < testCases; t++ {
		var n, s int
		Fscan(in, &n, &s)
		nums := make([]int, n)
		distanceOfOneFromFront := make([]int, n)
		distanceOfOneFromBack := make([]int, n)

		cnt := n + 5
		sum := 0
		for i := 0; i < n; i++ {
			Fscan(in, &nums[i])
			sum += nums[i]
			if nums[i] == 1 {
				cnt = 0
			} else {
				cnt++
			}
			distanceOfOneFromBack[i] = cnt
		}

		if sum < s {
			Fprintln(out, -1)
			continue
		}

		cnt = n + 5
		for i := n - 1; i >= 0; i-- {
			if nums[i] == 1 {
				cnt = 0
			} else {
				cnt++
			}
			distanceOfOneFromFront[i] = cnt
		}

		l := 0
		r := n - 1
		cnt = 0
		for sum > s {
			if distanceOfOneFromFront[l] > distanceOfOneFromBack[r] {
				sum -= nums[r]
				r--
			} else {
				sum -= nums[l]
				l++
			}
			cnt++
		}

		Fprintln(out, cnt)
	}

}

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, x int
		fmt.Fscan(in, &n, &x)

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

		if x > c {
			fmt.Fprintln(out, -1)
			continue
		}
		var tot int
		l, r := 0, n-1
		for c > x {
			l2 := l
			for a[l2] == 0 {
				l2++
			}
			r2 := r
			for a[r2] == 0 {
				r2--
			}

			if l2-l <= r-r2 {
				tot += l2 - l + 1
				l = l2 + 1
				// fmt.Println("Selecting left: ", tot, l2-l+1)
			} else {
				tot += r - r2 + 1
				r = r2 - 1
				// fmt.Println("Selecting right: ", tot, r-r2+1)
			}
			c--
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

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

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

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

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

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

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

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

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

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

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

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

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

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() {
	n, s := ri(), ri()
	a := ria(n)
	d := make([]int, 0)
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			d = append(d, i)
		}
	}
	if len(d) < s {
		fmt.Println(-1)
		return
	}
	if len(d) == s {
		fmt.Println(0)
		return
	}
	if len(d) == s+1 {
		a := d[0] + 1
		b := n - d[s]
		if a < b {
			fmt.Println(a)
		} else {
			fmt.Println(b)
		}
		return
	}
	l := d[s] - 1
	// fmt.Println("l=", l)
	for i := 0; i+s+1 < len(d); i++ {
		l1 := d[i+s+1] - d[i] - 1
		// myio.Println(d[i]+1, d[i+s+1]-1)
		if l1 > l {
			l = l1
		}
	}
	fmt.Println(n - l)
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		sol()
	}
}


package main

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

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

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

func main() {
	var n, a, b, k int
	scanf("%d %d %d %d\n", &n, &a, &b, &k)
	h := make([]int, n)
	for i := range h {
		scanf("%d", &h[i])
	}
	move := make([]int, n)
	for i, v := range h {
		v = v % (a + b)
		if v == 0 {
			v = a + b
		}
		num := v / a
		if v % a > 0 {
			num++
		}
		move[i] = num - 1
	}
	cnt := 0
	ans := 0
	sort.Ints(move)
	for _, v := range move {
		// printf("%d ", v)
		cnt += v
		if cnt > k {
			break
		}
		ans++
	}
	printf("%d\n", ans)
	writer.Flush()
}

package main

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

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

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

func scanInt64() int64 {
	sc.Scan(); a,_ := strconv.ParseInt(sc.Text(),10,64); return a
}

func scanFloat64() float64 {
	sc.Scan(); a,_ := strconv.ParseFloat(sc.Text(),64); return a
}

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

func scanString() string {
	sc.Scan(); return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e); if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr); wr.Flush()
}

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	n := scanInt()
	a := scanInt()
	b := scanInt()
	k := scanInt()
	hs := scanInts(n)

	for i := 0; i < n; i++ {
		hs[i] %= a+b
		if hs[i] == 0 {
			hs[i] = a+b
		}
		hs[i] = (hs[i]+a-1)/a - 1
	}

	sort.Ints(hs)

	ans := 0

	for i := 0; i < n; i++ {
		if hs[i] <=k {
			k -= hs[i]
			ans++
		}
	}

	fmt.Println(ans)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    capacity := 5000 * 1024
    scanner.Buffer(make([]byte, capacity), capacity)
    scanner.Scan()
    line := scanner.Text()
    parts := strings.Split(line, " ")
    n, _ := strconv.Atoi(parts[0])
    a, _ := strconv.Atoi(parts[1])
    b, _ := strconv.Atoi(parts[2])
    k, _ := strconv.Atoi(parts[3])

    scanner.Scan()
    line = scanner.Text()
    parts = strings.Split(line, " ")
    h := make([]int, n)
    for i := 0; i < n; i++ {
        h[i], _ = strconv.Atoi(parts[i])
    }
    //~ fmt.Println(n, a, b, k, h)

    skip_counts := make([]int, n)
    for i := 0; i < n; i++ {
        skip_counts[i] = skips_needed(a, b, h[i])
    }

    sort.Ints(skip_counts)
    //~ fmt.Println(skip_counts)

    wins := 0
    sum_skips := 0
    for i := 0; i < n; i++ {
        if sum_skips + skip_counts[i] <= k {
            wins++
            sum_skips += skip_counts[i]
        } else {
            break
        }
    }

    fmt.Println(wins)
}

func skips_needed(a, b, h int) int {
    m := h % (a + b)
    if m == 0 {
        m = a + b
    }
    skips := m / a
    if m % a == 0 {
        skips--
    }
    return skips
}

package main

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

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

	var n, a, b, k int
	fmt.Fscanf(reader, "%d %d %d %d\n", &n, &a, &b, &k)
	hs := make([]int, n)
	for j := 0; j < n; j++ {
		fmt.Fscanf(reader, "%d", &hs[j])
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fprintf(writer, "%d\n", findMaxToBeat(hs, a, b, k))
}

func findMaxToBeat(hs []int, a, b, k int) int {
	n := len(hs)

	costs := make([]int, 0, n)
	for _, h := range hs {
		x := h / (a + b)
		if x*(a+b) == h {
			x--
		}
		y := (h - x*(a+b) + a - 1) / a

		costs = append(costs, y-1)
	}

	sort.Slice(costs, func(e1, e2 int) bool {
		return costs[e1] < costs[e2]
	})

	ans := 0
	for _, c := range costs {
		if k >= c {
			ans++
			k -= c
		}
	}

	return ans
}

/*
https://codeforces.com/contest/1296/problem/D
*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line1, _ := reader.ReadString('\n')
	line1_arr := strings.Fields(line1)
	//fmt.Println(line1_arr)
	line2, _ := reader.ReadString('\n')
	line2_arr := strings.Fields(line2)
	//fmt.Println(line2_arr)

	N, _ := strconv.Atoi(line1_arr[0])
	//fmt.Println("N: ", N)
	a, _ := strconv.Atoi(line1_arr[1])
	//fmt.Println("a: ", a)
	b, _ := strconv.Atoi(line1_arr[2])
	//fmt.Println("b: ", b)
	k, _ := strconv.Atoi(line1_arr[3])
	//fmt.Println("k: ", k)

	arr := make([]int, N)

	for i := 0; i < N; i++ {
		h, _ := strconv.Atoi(line2_arr[i])
		//fmt.Println("h: ", h)
		d := a + b
		rem := h % d
		if rem == 0 {
			//fmt.Println("rem: ", rem)
			rem = d
		}
		num_skip := rem/a - 1
		if rem%a != 0 {
			num_skip++
		}

		arr[i] = num_skip
	}

	//fmt.Println("before sorting arr: ", arr)
	sort.Ints(arr)
	//fmt.Println("arr: ", arr)
	ret := 0
	for i := 0; i < N; i++ {
		if k >= arr[i] {
			ret++
			k -= arr[i]
		}
	}
	fmt.Println(ret)
}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	var n, a, b, k int;
	fmt.Fscan(in, &n, &a, &b, &k);
	h := make([]int, n);
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &h[i]);
		h[i] = h[i] % (a + b);
		if (h[i] == 0) {
			h[i] = a + b;
		}
	}

	sort.Ints(h);

	ans := 0;
	for _, x := range h {
		if (x <= a) {
			ans++;
			continue;
		}
		k -= (x + a - 1) / a - 1;
		if (k < 0) {
			break;
		}
		ans++;
	}
	fmt.Println(ans);
}

package main

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

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

	var n, a, b, k int
	fmt.Fscanf(reader, "%d %d %d %d\n", &n, &a, &b, &k)
	hs := make([]int, n)
	for j := 0; j < n; j++ {
		fmt.Fscanf(reader, "%d", &hs[j])
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fprintf(writer, "%d\n", findMaxToBeat(hs, a, b, k))
}

func findMaxToBeat(hs []int, a, b, k int) int {
	n := len(hs)

	costs := make([]int, 0, n)
	for _, h := range hs {
		x := h / (a + b)
		if x*(a+b) == h {
			x--
		}
		y := (h - x*(a+b) + a - 1) / a

		costs = append(costs, y-1)
	}

	sort.Slice(costs, func(e1, e2 int) bool {
		return e1 < e2
	})

	ans := 0
	for _, c := range costs {
		if k >= c {
			ans++
			k -= c
		}
	}

	return ans
}

package main

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

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

	var n, a, b, k int64
	fmt.Fscanf(reader, "%d %d %d %d\n", &n, &a, &b, &k)
	hs := make([]int64, n)
	for j := 0; j < int(n); j++ {
		fmt.Fscanf(reader, "%d", &hs[j])
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fprintf(writer, "%d\n", findMaxToBeat(hs, a, b, k))
}

func findMaxToBeat(hs []int64, a, b, k int64) int {
	n := len(hs)

	costs := make([]int64, 0, n)
	for _, h := range hs {
		x := h / (a + b)
		if x*(a+b) == h {
			x--
		}
		y := (h - x*(a+b) + a - 1) / a

		costs = append(costs, y-1)
	}

	sort.Slice(costs, func(e1, e2 int) bool {
		return e1 < e2
	})

	ans := 0
	for _, c := range costs {
		if k >= c {
			ans++
			k -= c
		}
	}

	return ans
}


package main

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

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

	var n, m int
	var tot, def, atk int64
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
		tot += a[i]
	}
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	for Fscan(in, &m); m > 0; m-- {
		Fscan(in, &def, &atk)
		i := sort.Search(n, func(i int) bool { return a[i] >= def })
		res := int64(2e18)
		if i < n {
			res = atk - (tot - a[i])
		}
		if i > 0 {
			if cost := def - a[i-1] + max(atk-(tot-a[i-1]), 0); cost < res {
				res = cost
			}
		}
		Fprintln(out, max(res, 0))
	}
}

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

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

package main

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

var a []int64
var b []*drag
var n,m int

type LL []int64

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

type drag struct {
	x, y int64
}

func main() {

	r := bufio.NewReader(os.Stdin)

	fmt.Fscan(r, &n)

	a = make([]int64, n)

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

	fmt.Fscan(r, &m)

	b = make([]*drag, m)

	for j := 0; j < m; j++ {
		var x, y int64
		fmt.Fscan(r, &x, &y)

		d := &drag{x, y}
		b[j] = d
	}

	solve()

}

func solve() {
	sort.Sort(LL(a))

	var sum int64

	for i := 0; i < n; i++ {
		sum += a[i]
	}

	for i := 0; i < m; i++ {
		dr := b[i]

		attack := dr.y
		def := dr.x

		idx := sort.Search(n, func(i int) bool {
			return a[i] >= def
		})

		var cost int64

		if idx == n {
			largest := a[n - 1]

			cost += def - largest
			s := sum - largest

			if attack > s {
				cost += attack - s
			}

			//15 20   30 10
			//15 10
			//80 85

		} else {

			guy := a[idx]

			s := sum - guy

			if attack > s {
				cost += attack - s
			}

			if idx > 0 {
				prev := a[idx - 1]

				var a int64

				if attack > (sum - prev) {
					a = attack - (sum - prev)
				}

				temp := def - prev + a

				cost = min(cost, temp)
			}

		}
		// ..... 93 94  100   95 200

		fmt.Println(cost)
	}
}

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

package main

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

func val(x int64) int64 {
	if x < 0 {
		return -x
	}
	return 0
}

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

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

	//for t := 0; t < T; t++ {
	var n int
	fmt.Fscanf(r, "%d\n", &n)
	arr := make([]int64, n)
	sum := int64(0)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &arr[i])
		sum += arr[i]
	}
	fmt.Fscanf(r, "\n")

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

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

	for i := 0; i < d; i++ {
		var x, y int64
		fmt.Fscanf(r, "%d %d\n", &x, &y)

		j := sort.Search(n, func(j int) bool {
			return arr[j] >= x
		})

		res := int64(-1)
		for k := j - 1; k <= j+1 && k < n; k++ {
			if k >= 0 {
				z := val(arr[k]-x) + val(sum-y-arr[k])

				if res == -1 || res > z {
					res = z
				}
			}
		}

		fmt.Println(res)
	}

	//}
}

package main

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

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func abs(n int64) int64 {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

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

	var m int
	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		var d, a int64
		fmt.Fscan(in, &d, &a)

		idx := sort.Search(n, func(i int) bool { return h[i] >= d })
		if idx >= n {
			idx--
		}

		c := max(0, d-h[idx]) + max(0, a-(z-h[idx]))
		if idx > 0 {
			c = min(c, max(0, d-h[idx-1]+max(0, a-(z-h[idx-1]))))
		}

		// if idx < n-1 {
		// 	c = min(c, max(0, d-h[idx+1]+max(0, a-(z-h[idx+1]))))
		// }

		fmt.Fprintln(out, c)
	}
}

package main

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

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func abs(n int64) int64 {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

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

	var m int
	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		var d, a int64
		fmt.Fscan(in, &d, &a)

		idx := sort.Search(n, func(i int) bool { return h[i] >= d })
		if idx >= n {
			idx--
		}

		c := max(0, d-h[idx]) + max(0, a-(z-h[idx]))
		if idx > 0 {
			c = min(c, max(0, d-h[idx-1]+max(0, a-(z-h[idx-1]))))
		}

		if idx < n-1 {
			c = min(c, max(0, d-h[idx+1]+max(9, a-(z-h[idx+1]))))
		}

		fmt.Fprintln(out, c)
	}
}

package main

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

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

func abs(n int64) int64 {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

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

	var m int
	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		var d, a int64
		fmt.Fscan(in, &d, &a)

		var c int64
		idx := sort.Search(n, func(i int) bool { return h[i] >= d })
		if idx >= n {
			idx--
		}

		if idx > 0 && abs(h[idx-1]-d) < abs(h[idx]-d) {
			idx--
		}

		x := h[idx]
		c += max(0, d-x)
		c += max(0, a-(z-x))
		fmt.Fprintln(out, c)
	}
}

package main

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

var a []int64
var b []*drag
var n,m int

type LL []int64

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

type drag struct {
	x, y int64
}

func main() {

	r := bufio.NewReader(os.Stdin)

	fmt.Fscan(r, &n)

	a = make([]int64, n)

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

	fmt.Fscan(r, &m)

	b = make([]*drag, m)

	for j := 0; j < m; j++ {
		var x, y int64
		fmt.Fscan(r, &x, &y)

		d := &drag{x, y}
		b[j] = d
	}

	solve()

}

func solve() {
	sort.Sort(LL(a))

	var sum int64

	for i := 0; i < n; i++ {
		sum += a[i]
	}

	for i := 0; i < m; i++ {
		dr := b[i]

		attack := dr.y
		def := dr.x

		idx := sort.Search(n, func(i int) bool {
			return a[i] >= def
		})

		var cost int64

		if idx == n {
			largest := a[n - 1]

			cost += def - largest
			s := sum - largest

			if attack > s {
				cost += attack - s
			}

		} else {

			guy := a[idx]

			s := sum - guy

			if attack > s {
				cost += attack - s
			}

			if idx > 0 {
				prev := a[idx - 1]

				temp := def - prev + attack - (sum - prev)

				cost = min(cost, temp)
			}

		}

		fmt.Println(cost)
	}
}

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


package main

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

func main() {

	t := NextInt()
	for t > 0 {
		t--
		n, x := NextInt(), NextInt()

		a := make([]int, n+1)

		for i := 1; i <= n; i++ {
			a[i] = NextInt()
		}

		for i := 1; i <= n; i++ {
			a[i] = (a[i] + a[i-1]) % x
		}

		ans := -1
		for i := 0; i <= n; i++ {
			if a[i] != 0 && i > ans {
				ans = i
			}
			if a[i] != a[n] && n-i > ans {
				ans = n-i
			}
		}
		fmt.Println(ans)
	}
}

var sc = bufio.NewScanner(os.Stdin)

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

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

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var n, x int
		var sum int64
		fmt.Fscanf(in, "%d %d\n", &n, &x)
		var minN, maxN = n - 1, 0
		mas := make([]int, n + 1)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &mas[i])
			sum += int64(mas[i])
			if mas[i]%x != 0 {
				minN = int(math.Min(float64(minN), float64(i)))
				maxN = int(math.Max(float64(maxN), float64(i)))
			}
		}
		fmt.Fscanf(in, "\n")
		if sum%int64(x) != 0 {
			fmt.Fprintln(out, n)
		} else {
			if minN == n-1 && maxN == 0 {
				fmt.Fprintln(out, -1)
			} else {
				fmt.Fprintln(out, int(math.Max(math.Abs(float64(n-1-minN)), float64(maxN))))
			}
		}

	}
	return
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n int
    fmt.Fscan(in, &n)
    for i:=0; i<n; i++ {
        l, d := 0, 0
        fmt.Fscan(in, &l)
        fmt.Fscan(in, &d)
        a := make([]int, l)
        for j:=0; j<l; j++ {fmt.Fscan(in, &a[j])}
        pre, suf := -1, -1
        sum := 0
        for k,v := range a {
            sum += v
            if sum % d != 0 {pre = k}
        }
        sum = 0
        for j:=l-1; j>=0; j-- {
            v := a[j]
            sum += v
            if sum % d != 0 {suf = j}
        }
		if suf == -1 && pre == -1 {fmt.Fprint(out, "-1\n"); continue}
        if (pre+1) > (l-suf) {fmt.Fprint(out, pre+1); fmt.Fprint(out, "\n")} else {fmt.Fprint(out, l-suf); fmt.Fprint(out, "\n")}
    }
}

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, x := readTwoNums(reader)
		A := readNNums(reader, n)
		fmt.Println(solve(n, x, A))
	}
}

func solve(n, x int, A []int) int {
	var sum int
	for i := 0; i < n; i++ {
		sum += A[i]
		sum %= x
	}

	if sum != 0 {
		return n
	}
	var l int
	for l < n && A[l] % x == 0 {
		l++
	}
	if l == n {
		return -1
	}
	var r = n - 1
	for A[r] % x == 0 {
		r--
	}
	return max(n - (l + 1), r)
}

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

package main

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

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

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		arr := strings.Split(string(line), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.Atoi(arr[1])
		line = readLine(reader)
		ans := strings.Split(string(line), " ")
		first, end, sum := 0, n-1, 0
		for j := 0; j < n; j++ {
			aj, _ := strconv.Atoi(ans[j])
			sum = (aj + sum) % x
		}
		if sum != 0 {
			fmt.Println(n)
			continue
		}
		for ; first < n; first++ {
			ai, _ := strconv.Atoi(ans[first])
			if ai % x != 0 {
				break
			}
		}
		if first == n {
			fmt.Println(-1)
			continue
		}
		left := n - 1 - first
		for ; end >= 0; end-- {
			ai, _ := strconv.Atoi(ans[end])
			if ai % x != 0 {
				break
			}
		}
		right := end
		if right > left {
			fmt.Println(right)
		} else {
			fmt.Println(left)
		}
	}
}

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

package main

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

func main() {

	t := NextInt()
	for t > 0 {
		t--
		n, x := NextInt(), NextInt()

		a := make([]int, n+1)

		for i := 1; i <= n; i++ {
			a[i] = NextInt()
		}

		for i := 1; i <= n; i++ {
			a[i] = (a[i] + a[i-1]) % x
		}

		ans := -1
		for i := 0; i <= n; i++ {
			if a[i] != 0 && i > ans {
				ans = i
			}
			if a[i] != a[n] && n-i > ans {
				ans = n-i
			}
		}
		fmt.Println(ans)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

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

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, x := nextInt(), nextInt()
		As := nextInts(n)
		fmt.Println(solve(x, As))
	}
}

func solve(x int, As []int) int {
	sum := 0
	for i := 0; i < len(As); i++ {
		sum = (sum + As[i]) % x
	}
	if sum > 0 {
		return len(As)
	}

	lCount := 0
	for i := 0; i < len(As); i++ {
		if As[i]%x == 0 {
			lCount++
		} else {
			break
		}
	}
	if lCount == len(As)-1 {
		return -1
	}

	rCount := 0
	for i := len(As) - 1; i >= 0; i-- {
		if As[i]%x == 0 {
			rCount++
		} else {
			break
		}
	}

	return len(As) - Min(lCount, rCount) - 1
}

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

var sc = bufio.NewScanner(os.Stdin)

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

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

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

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

/*
URL:
https://codeforces.com/contest/1364/problem/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	if x == 1 {
		fmt.Println(-1)
		return
	}

	R := make([]int, n)
	for i := 0; i < n; i++ {
		R[i] = A[i] % x
	}

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

	total := rs[n]
	if total%x != 0 {
		fmt.Println(n)
		return
	}

	// for i := 0; i < n; i++ {
	// 	if R[i] > 0 {
	// 		if n-1 > 0 {
	// 			fmt.Println(n - 1)
	// 		} else {
	// 			fmt.Println(-1)
	// 		}
	// 		return
	// 	}
	// }
	// fmt.Println(-1)

	// 前から消す
	bef := 0
	for i := 0; i < n; i++ {
		if R[i] != 0 {
			bef = n - (i + 1)
			break
		}
	}

	// 後ろから消す
	aft := 0
	for i := n - 1; i >= 0; i-- {
		if R[i] != 0 {
			aft = i
			break
		}
	}

	ans := Max(bef, aft)
	if ans > 0 {
		fmt.Println(ans)
		return
	}

	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

var nTest, n, x int
var a [100000]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Fscan(in, &n, &x)

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

		sum1 := sum
		i1 := 0
		for sum1%x == 0 && i1 < n {
			sum1 -= a[i1]
			i1++
		}

		sum2 := sum
		i2 := n - 1
		for sum2%x == 0 && i2 >= 0 {
			sum2 -= a[i2]
			i2--
		}

		len1 := 0
		len2 := 0
		if i1 < n {
			len1 = n - i1
		}

		if i2 >= 0 {
			len2 = i2 + 1
		}

		if len1 == 0 && len2 == 0 {
			fmt.Fprintln(out, -1)
		} else if len1 < len2 {
			fmt.Fprintln(out, len2)
		} else {
			fmt.Fprintln(out, len1)
		}
	}
	out.Flush()
}

package main

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

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

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

func main() {
	tt := NextInt()
	for ; tt > 0; tt-- {
		n, x := NextInt(), NextInt()

		a := make([]int, n + 1)
		sum := make([]int, n + 1)
		for i := 1; i <= n; i++ {
			a[i] = NextInt()
		}
		for i := 1; i <= n; i++ {
			sum[i] = sum[i - 1] + a[i]
		}

		if sum[n] % x != 0 {
			fmt.Println(n)
		} else {
			ret := -1
			for i := 1; i <= n; i++{
				if sum[i] % x != 0 {
					ret = i
					break
				}
			}
			for j := n; j >= 1; j-- {
				t := sum[n] - sum[j - 1]
				if t % x != 0 {
					if ret != -1 {
						ret = min(ret, n - j + 1)
					} else {
						ret = n - j + 1
					}
					break
				}
			}
			if ret == -1 {
				fmt.Println("-1")
			} else {
				fmt.Println(n - ret)
			}
		}

	}
}

package main

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

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

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

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, x := nextInt(), nextInt()
		As := nextInts(n)
		fmt.Println(solve(x, As))
	}
}

func solve(x int, As []int) int {
	l := -1
	r := len(As)
	sum := 0
	for i := 0; i < len(As); i++ {
		sum = (sum + As[i]) % x
		if As[i]%x == 0 {
			if i == l+1 {
				l = i
			}
			if i == r-1 {
				r = i
			}
		}
	}

	if sum > 0 {
		return len(As)
	}
	if l == len(As)-1 {
		return -1
	}
	lcount := l + 1
	rcount := len(As) - r
	return len(As) - Min(lcount, rcount) - 1
}

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

var sc = bufio.NewScanner(os.Stdin)

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

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

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

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

/*
URL:
https://codeforces.com/contest/1364/problem/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	if x == 1 {
		fmt.Println(-1)
		return
	}

	R := make([]int, n)
	for i := 0; i < n; i++ {
		R[i] = A[i] % x
	}

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

	total := rs[n]
	if total%x != 0 {
		fmt.Println(n)
		return
	}

	for i := 0; i < n; i++ {
		if R[i] > 0 {
			fmt.Println(n - 1)
			return
		}
	}

	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/contest/1364/problem/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	if x == 1 {
		fmt.Println(-1)
		return
	}

	R := make([]int, n)
	for i := 0; i < n; i++ {
		R[i] = A[i] % x
	}

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

	total := rs[n]
	if total%x != 0 {
		fmt.Println(n)
		return
	}

	for i := 0; i < n; i++ {
		if R[i] > 0 {
			if n-1 > 0 {
				fmt.Println(n - 1)
			} else {
				fmt.Println(-1)
			}
			return
		}
	}

	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/contest/1364/problem/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	R := make([]int, n)
	for i := 0; i < n; i++ {
		R[i] = A[i] % x
	}

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

	total := rs[n]
	if total%x != 0 {
		fmt.Println(n)
		return
	}

	for i := 0; i < n; i++ {
		if R[i] > 0 {
			fmt.Println(n - 1)
			return
		}
	}

	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n int
    fmt.Fscan(in, &n)
    for i:=0; i<n; i++ {
        l, d := 0, 0
        fmt.Fscan(in, &l)
        fmt.Fscan(in, &d)
        a := make([]int, l)
        for j:=0; j<l; j++ {fmt.Fscan(in, &a[j])}
        pre, suf := -1, -1
        sum := 0
        for k,v := range a {
            sum += v
            if sum % d != 0 {pre = k}
        }
        sum = 0
        for j:=l-1; j>=0; j-- {
            v := a[j]
            sum += v
            if sum % d != 0 {suf = j}
        }
		if suf == -1 && pre == -1 {fmt.Fprint(out, "-1\n"); continue}
        if pre > (l-suf) {fmt.Fprint(out, pre); fmt.Fprint(out, "\n")} else {fmt.Fprint(out, l-suf); fmt.Fprint(out, "\n")}
    }
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n int
    fmt.Fscan(in, &n)
    for i:=0; i<n; i++ {
        l, d := 0, 0
        fmt.Fscan(in, &l)
        fmt.Fscan(in, &d)
        a := make([]int, l)
        for j:=0; j<l; j++ {fmt.Fscan(in, &a[j])}
        pre, suf := -1, -1
        sum := 0
        for k,v := range a {
            sum += v
            if sum % d != 0 {pre = k}
        }
        sum = 0
        for j:=l-1; j>=0; j-- {
            v := a[j]
            sum += v
            if sum % d != 0 {suf = j}
        }
		if suf == -1 && pre == -1 {fmt.Fprint(out, "-1\n"); continue}
		fmt.Println(pre, suf)
        if pre > (l-suf) {fmt.Fprint(out, pre); fmt.Fprint(out, "\n")} else {fmt.Fprint(out, l-suf); fmt.Fprint(out, "\n")}
    }
}

package main

import "fmt"

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

	for t > 0 {
		t--
		fmt.Scanf("%d%d\n", &n, &x)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
		}

		for i := 1; i <= n; i++ {
			a[i] = (a[i] + a[i-1]) % x
		}

		ans := -1
		for i := 0; i <= n; i++ {
			if a[i] != 0 && i > ans {
				ans = i
			}
			if a[i] != a[n] && n-i > ans {
				ans = n-i
			}
		}
		fmt.Println(ans)
	}
}