package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n := readi()
		s := readll()
		_, a := readIntsll(n)
		println(solve(n, s, a) + 1)
	}
}

func solve(n int, s int64, a []int64) int {
	S := make([]int64, n+1)
	for i := range a {
		S[i+1] = S[i] + a[i]
	}

	calc := func(i, j int) (int, int64) {
		s := S[j]
		if i < j {
			s -= a[i]
			return j - 1, s
		}
		return j, s
	}

	var ans, maxv int
	for i, t := range S {
		if s < t {
			break
		}
		maxv = max(maxv, i)
	}
	ans = -1

	for i := 0; i <= n; i++ {
		k := sort.Search(n, func(j int) bool {
			_, t := calc(i, j+1)
			if s < t {
				return true
			}
			return false
		})
		v, _ := calc(i, k)
		//v, t := calc(i, k)
		if maxv < v {
			//eprintln("update", v, t)
			maxv = v
			if k <= i {
				ans = -1
			} else {
				ans = i
			}
		}
	}
	return ans
}

package main

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

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

func main() {

    defer writer.Flush()

    var t int
    var a int

    scanf("%d\n",&t)

    for br:=0;br<t;br++ {
        var n, s int
        scanf("%d %d\n",&n,&s)
        var sum int64
        sum=0;
        var mx int
        mx=0
        var ans int
        ans=0
        var taj int
        taj=0
        var ind int
        ind=0
        for i:=1;i<=n;i++ {
            scanf("%d",&a);
            sum+=int64(a);
            if mx<a {
                mx=a
                ind=i
            }
            if sum<=int64(s) {
                ans=i
                taj=0
            }
            if sum-int64(mx)<=int64(s) {
                if ans<i-1 {
                    ans=i-1
                    taj=ind
                }
            }
        }
        scanf("\n")
        printf("%d\n",taj);
    }
}

package main

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

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

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

package main

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

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

func main() {

    defer writer.Flush()

    var t int
    var a int

    scanf("%d\n",&t)

    for br:=0;br<t;br++ {
        var n, s int
        scanf("%d %d\n",&n,&s)
        var sum int64
        sum=0;
        var mx int
        mx=0
        var ans int
        ans=0
        var taj int
        taj=0
        var ind int
        ind=0
        for i:=1;i<=n;i++ {
            scanf("%d",&a);
            sum+=int64(a);
            if mx<a {
                mx=a
                ind=i
            }
            if sum<=int64(s) {
                ans=i
                taj=0
            }
            if sum-int64(mx)<=int64(s) {
                if ans<i-1 {
                    ans=i-1
                    taj=ind
                }
            }
        }
        printf("%d\n",taj);
    }
}

package main

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

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, p, k := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &p, &k)
		a := make([]int, n)
		f := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		sort.Ints(a)
		fmt.Fscanf(in, "\n")
		f[0] = a[0]
		ans := 0
		if f[0] <= p {
			ans = 1
		}
		for i := 1; i < n; i++ {
			if (i + 1) < k {
				f[i] = f[i-1] + a[i]
			} else if (i + 1) == k {
				f[i] = a[i]
			} else {
				f[i] = f[i-k] + a[i]
			}
			if f[i] <= p {
				ans = i + 1
			}
		}
		// l := 0
		// r := n
		// for l < r {
		// 	mid := (l + r + 1) / 2
		// 	cost := 0
		// 	need := mid / k
		// 	if mid%k != 0 {
		// 		need++
		// 	}
		// 	cur := mid%k - 1
		// 	if cur < 0 {
		// 		cur += k
		// 	}
		// 	for i := 0; i < need; i++ {
		// 		cost += a[cur]
		// 		cur += k
		// 	}
		// 	if cost > p {
		// 		r = mid - 1
		// 	} else {
		// 		l = mid
		// 	}
		// }
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n := readi()
		s := readi()
		_, a := readInts(n)
		println(solve(n, s, a))
	}
}

func solve(n, s int, a []int) int {
	sort.Ints(a)
	var sum int
	var i int
	for ; i < n && sum < s; i++ {
		sum += a[i]
	}
	if s < sum {
		i--
	}
	return n - i
}

package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n := readi()
		s := readi()
		_, a := readInts(n)
		println(solve(n, s, a) + 1)
	}
}

func solve(n, s int, a []int) int {
	S := make([]int, n+1)
	for i := range a {
		S[i+1] = S[i] + a[i]
	}

	calc := func(i, j int) (int, int) {
		s := S[j]
		if i < j {
			s -= a[i]
			return j - 1, s
		}
		return j, s
	}

	var ans, maxv int
	for i, t := range S {
		if s < t {
			break
		}
		maxv = max(maxv, i)
	}
	ans = -1

	for i := 0; i <= n; i++ {
		k := sort.Search(n, func(j int) bool {
			_, t := calc(i, j+1)
			if s < t {
				return true
			}
			return false
		})
		v, _ := calc(i, k)
		if maxv < v {
			//eprintln("update", v, t)
			maxv = v
			if k <= i {
				ans = -1
			} else {
				ans = i
			}
		}
	}
	return ans
}


package main

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

/*
11
3 3
4 3
5 3
6 3
7 3
8 3
9 3
10 3
11 3
12 3
13 3
---
1 1 1	lcm=1
2 1 1	lcm=2
2 2 1	lcm=2
2 2 2	lcm=2
3 3 1	lcm=4
4 2 2	lcm=4
3 3 3	lcm=3
4 4 2	lcm=4
5 5 1	lcm=5
4 4 4	lcm=4
6 6 1	lcm=6
*/

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

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

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

		switch {
		case n%2 != 0:
			fmt.Fprintln(writer, n/2, n/2, 1)
		case n%4 == 0:
			fmt.Fprintln(writer, n/4, n/4, n/2)
		case n%4 != 0:
			fmt.Fprintln(writer, n/2-1, n/2-1, 2)
		}
	}
}

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 int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int64) int64 {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

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

		if n & 0x1 == 1 {
			Fprintln(out, 1, n / 2, n / 2)
		} else {
			if n & 3 == 0 {
				Fprintln(out, n / 2, n / 4, n / 4)
			} else {
				Fprintln(out, n / 2 - 1, n / 2 - 1, 2)
			}
		}
	}
}

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

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

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

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

package main

import "fmt"

func main() {
	var t, n, k int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n, &k)
		if n%2 == 1 {
			fmt.Println(1, n/2, n/2)
		} else {
			if n%4 == 0 {
				fmt.Println(n/4, n/4, n/2)
			} else {
				fmt.Println(2, (n-2)/2, (n-2)/2)
			}
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int

	fmt.Scan(&t)
	for i := 1; i <= t; i++ {
		var n, k int
		fmt.Scan(&n, &k)
		if n%2 == 1 {
			fmt.Println(1, (n-1)/2, (n-1)/2)
		} else {
			if n%4 == 0 {
				fmt.Println(n/2, n/4, n/4)
			} else {
				fmt.Println(2, (n-2)/2, (n-2)/2)
			}
		}
	}
}

package main

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

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

func solver(n int64) (a, b, c int64) {
	temp := n
	mul := int64(1)
	for temp&1 == 0 {
		temp >>= 1
		mul <<= 1
	}
	if temp == 1 {
		// if n is a power of 2
		return n >> 1, n >> 2, n >> 2
	}
	half := temp >> 1
	return mul, mul * half, mul * half
}

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

	var n, k, a, b, c int64
	for testcase := 0; testcase < testcases; testcase++ {
		fmt.Fscan(reader, &n, &k)
		a, b, c = solver(n)
		fmt.Fprintln(writer, a, b, c)
	}
}

package main

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

}

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int64
		var k int
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &k)

		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)

		if n%3 == 0 {
			j := int(n / 3)
			fmt.Println(j)
			fmt.Println(j)
			fmt.Println(j)

		} else {
			if n%2 == 1 {
				m := int(n / 2)
				fmt.Println(m)
				fmt.Println(m)
				fmt.Println(1)

			} else {
				m := int(n / 2)
				if m%2 == 1 {
					fmt.Println(m - 1)
					fmt.Println(m - 1)
					fmt.Println(2)
				} else {
					j := int(m / 2)
					fmt.Println(m)
					fmt.Println(j)
					fmt.Println(j)

				}
			}
		}

	}
}

package main

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

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

	solve := func(Case int) {
		var n, k int
		Fscan(in, &n, &k)
		if n&1 > 0 {
			Fprintln(out, 1, n/2, n/2)
		} else if n%4 == 0 {
			Fprintln(out, n/2, n/4, n/4)
		} else {
			n -= 2
			Fprintln(out, 2, n/2, n/2)
		}
	}

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

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

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

package main

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

		var a, b, c int
		if n%2 == 0 {
			if n/2%2 == 0 {
				a, b, c = n/2, n/4, n/4
			} else {
				a, b, c = 2, (n-2)/2, (n-2)/2
			}
		} else {
			a, b, c = 1, n/2, n/2
		}
		fmt.Fprintln(out, a, b, c)
	}
}

package main

import "fmt"

func main() {
	var T, n, k int
	fmt.Scanf("%d\n", &T)
	for i := 1; i <= T; i++ {
		fmt.Scanf("%d%d\n", &n, &k)
		if n%2 == 1 {
			fmt.Printf("%d %d %d\n", 1, n/2, n/2)
		} else {
			if (n/2)%2 == 0 {
				fmt.Printf("%d %d %d\n", n/4, n/4, n/2)
			} else {
				fmt.Printf("%d %d %d\n", 2, n/2-1, n/2-1)
			}
		}
	}
}

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

		var a, b, c int
		if n%2 == 0 {
			a, b, c = 2, (n-2)/2, (n-2)/2
		} else {
			a, b, c = 1, n/2, n/2
		}
		fmt.Fprintln(out, a, b, c)
	}
}

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

		var a, b, c int
		if n%2 == 0 {
			a, b = n/2, n/4
			c = n - a - b
		} else {
			a, b, c = 1, n/2, n/2
		}
		fmt.Fprintln(out, a, b, c)
	}
}

package main

import "fmt"

func main() {
	var T, n, k int
	fmt.Scanf("%d", &T)
	for i := 1; i <= T; i++ {
		fmt.Scanf("%d%d", &n, &k)
		if n%2 == 1 {
			fmt.Printf("%d %d %d", 1, n/2, n/2)
		} else {
			if (n/2)%2 == 0 {
				fmt.Printf("%d %d %d", n/4, n/4, n/2)
			} else {
				fmt.Printf("%d %d %d", 2, n/2-1, n/2-1)
			}
		}
		fmt.Println()
	}
}


package main

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

type node struct {
	left  int
	right int
}

type ByLeft []node

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

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 := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := []node{}
		for i := 0; i < n; i++ {
			l, r := 0, 0
			fmt.Fscanf(in, "%d %d\n", &l, &r)
			a = append(a, node{l, r})
		}
		sort.Sort(ByLeft(a))
		curBoard := a[0]
		curOnTopNum := 0
		curOnTopRight := a[0].left - 1
		ans := 0
		for i := 1; i < n; i++ {
			next := a[i]
			if next.left > curOnTopRight {
				if next.left <= curBoard.right {
					curOnTopNum++
					ans = max(ans, curOnTopNum)
					if next.right > curOnTopRight {
						curOnTopRight = next.right
					}
					if curOnTopRight > curBoard.right {
						nextRight := curBoard.right
						curBoard = next
						curOnTopNum = 1
						curOnTopRight = nextRight
					}
				} else {
					// change board
					curBoard = next
					curOnTopNum = 0
					curOnTopRight = curBoard.left - 1
				}
			} else {
				curOnTopRight = max(curOnTopRight, next.right)
				if curOnTopRight > curBoard.right {
					nextRight := curBoard.right
					curBoard = next
					curOnTopNum = 1
					curOnTopRight = nextRight
				}
			}
			//fmt.Println(curBoard, curOnTopNum, curOnTopRight, ans)
		}
		curAns := 1
		curRight := a[0].right
		for i := 1; i < n; i++ {
			if a[i].left > curRight {
				curAns++
			}
			curRight = max(curRight, a[i].right)
		}
		//fmt.Println(curAns)
		fmt.Fprintf(out, "%d\n", curAns+ans-1)
	}
	return
}

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

package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = 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 scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanText() 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()
}

var (
	T     int
	n     int
	hsLen int
	l     []int
	r     []int
	hs    []int
	cnt   []int
	pcnt  []int
	id    []int
	pid   []int
	ans   []int
)

func unique(a []int) []int {
	n := len(a)
	if n == 0 {
		return a
	}
	var cur []int
	cur = append(cur, a[0])
	for i := 1; i < n; i++ {
		if a[i] != a[i-1] {
			cur = append(cur, a[i])
		}
	}
	return cur
}

func lowerBound(a []int, value int) int {
	low, high, mid := 0, len(a), 0
	for low <= high {
		mid = (low + high) >> 1
		if a[mid] < value {
			low = mid + 1
		} else if a[mid] > value {
			high = mid - 1
		} else {
			break
		}
	}
	return mid
}

func calc(l, r int) int {
	ret := -1
	if l-1 >= 0 && cnt[l-1] > 0 || pcnt[l] > 1 {
		ret++
	}
	if r+1 < hsLen-1 && cnt[r+1] > 0 || pcnt[r+1] > 1 {
		ret++
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	T = scanInt()
	for cas := 0; cas < T; cas++ {
		n = scanInt()
		l = make([]int, n)
		r = make([]int, n)
		ans = make([]int, n)
		hs = make([]int, 0)
		for i := 0; i < n; i++ {
			l[i] = scanInt()
			r[i] = scanInt()
			hs = append(hs, l[i])
			hs = append(hs, r[i])
			hs = append(hs, r[i]+1)
		}
		sort.Ints(hs)
		hs = unique(hs)
		hsLen = len(hs)
		cnt = make([]int, len(hs))
		id = make([]int, len(hs))
		pid = make([]int, len(hs))
		pcnt = make([]int, len(hs))
		for i := 0; i < n; i++ {
			l[i] = lowerBound(hs, l[i])
			r[i] = lowerBound(hs, r[i])
			cnt[l[i]]++
			cnt[r[i]]--
			pcnt[l[i]]++
			pcnt[r[i]+1]--
			id[l[i]] += i
			id[r[i]] -= i
			pid[l[i]] += i
			pid[r[i]+1] -= i
		}
		for i := 1; i < hsLen; i++ {
			cnt[i] += cnt[i-1]
			id[i] += id[i-1]
			pcnt[i] += pcnt[i-1]
			pid[i] += pid[i-1]
		}

		cur := 0
		for i, j := 0, 0; i < hsLen-1; i = j + 1 {
			j = i
			if cnt[i] == 0 {
				continue
			}
			cur++
			for j+1 < hsLen-1 && cnt[j+1] != 0 {
				j++
			}
		}
		for i := 0; i < hsLen; i++ {
			if pcnt[i] > 0 {
				if (i == 0 || cnt[i-1] == 0) && cnt[i] == 0 {
					cur++
				}
			}
		}
		for i, j := 0, 0; i < hsLen-1; i = j + 1 {
			j = i
			if cnt[i] != 1 {
				continue
			}
			for j+1 < hsLen-1 && cnt[j+1] == 1 && id[j+1] == id[i] && pcnt[j+1] == 1 {
				j++
			}
			ans[id[i]] += calc(i, j)
		}
		ret := 0
		for i := 0; i < n; i++ {
			ans[i] += cur
			if l[i] == r[i] {
				p := l[i]
				if pcnt[p] == 1 && (p == 0 || cnt[p-1] == 0) && cnt[p] == 0 {
					ans[i]--
				}
			}
			if ans[i] > ret {
				ret = ans[i]
			}
		}
		fmt.Println(ret)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"sync"
)
type node struct {
	l int
	r int
}
type Node []node
func (a Node) Len() int { return len(a) }
func (a Node) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Node) Less(i, j int) bool {
	if a[i].l == a[j].l {
		return a[i].r < a[j].r
	}
	return a[i].l < a[j].l
}

type Seg struct {
	tag, sum, L, R int
}
var cat [400001 * 4]Seg
func pushdown(o, ls, rs int) {
	if cat[o].tag == 1 {
		cat[ls].sum, cat[ls].tag, cat[rs].sum, cat[rs].tag = 1, 1, 1, 1
		cat[ls].L = min(cat[ls].L, cat[o].L)
		cat[ls].R = max(cat[ls].R, cat[o].R)
		cat[rs].L = min(cat[rs].L, cat[o].L)
		cat[rs].R = max(cat[rs].R, cat[o].R)
		cat[o].tag = 0
	}
}
func pushup(ls, rs Seg) Seg {
	tmp := Seg{}
	tmp.tag = 0
	tmp.sum = ls.sum + rs.sum
	tmp.L = ls.L
	tmp.R = rs.R
	if ls.R > rs.L {
		tmp.sum--
	}
	return tmp
}
func up(o, l, r, ql, qr int) {
	if l >= ql && r <= qr {
		cat[o].tag, cat[o].sum = 1, 1
		cat[o].L = min(cat[o].L, ql)
		cat[o].R = max(cat[o].R, qr)
		return
	}
	mid, ls, rs := (l + r) / 2, o * 2, o * 2 + 1
	pushdown(o, ls, rs)
	if ql <= mid {
		up(ls, l, mid, ql, qr)
	}
	if qr > mid {
		up(rs, mid + 1, r, ql, qr)
	}
	cat[o] = pushup(cat[ls], cat[rs])
}
func qu(o, l, r, ql, qr int) Seg {
	if l >= ql && r <= qr {
		return cat[o]
	}
	mid, ls, rs := (l + r) / 2, o * 2, o * 2 + 1
	pushdown(o, ls, rs)
	if qr <= mid {
		return qu(ls, l, mid, ql, qr)
	} else if ql > mid {
		return qu(rs, mid + 1, r, ql, qr)
	} else {
		Ls := qu(ls, l, mid, ql, qr)
		Rs := qu(rs, mid + 1, r, ql, qr)
		return pushup(Ls, Rs)
	}
}
const inf int = 1000000001
func work() {
	n := ReadInt()
	a := []node{}
	x := []int{}

    a = append(a, node{-inf, 0})
    x = append(x, -inf)
	for i := 1; i <= n; i++ {
		l := ReadInt()
		r := ReadInt()
		a = append(a, node{l, r})
		x = append(x, l)
		x = append(x, r)
	}
	sort.Ints(x)
	sort.Sort(Node(a))
	mp := map[int]int{}
	for i := 1; i <= 2 * n; i++ {
		mp[x[i]] = i
	}
	A := make([]int, n + 1)
	m := 2 * n
	Mx := make([]int, n + 1)
	Mn := make([]int, m + 1)
	for i := 1; i <= m; i++ {
		Mn[i] = i
	}
	mx, L := 0, 0
	for i := 1; i <= n; i++ {
		a[i].l = mp[a[i].l]
		a[i].r = mp[a[i].r]
		A[i] = A[i - 1]
		if a[i].l > mx {
			A[i]++
			L = a[i].l
		}
		mx = max(mx, a[i].r)
		Mx[i] = mx
		Mn[mx] = L
	}
	for i := 1; i <= 4 * m; i++ {
		cat[i].R, cat[i].sum, cat[i].tag = 0, 0, 0
		cat[i].L = m + 1
	}
	ans := 0
	for i := n; i > 0; i-- {
		flag := 0
		if i > 1 {
			flag = qu(1, 1, m,Mn[Mx[i - 1]], Mx[i - 1]).sum
		}
		ans = max(ans, A[i - 1] + cat[1].sum - flag)
		up(1, 1, m, a[i].l, a[i].r)
	}
	fmt.Println(ans)
}
func main() {
	for i := ReadInt(); i > 0; i-- {
		work()
	}
	close(out)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _  := strconv.Atoi(intStr)
	return i
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

package main

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

type node struct {
	left  int
	right int
}

type ByLeft []node

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

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 := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := []node{}
		for i := 0; i < n; i++ {
			l, r := 0, 0
			fmt.Fscanf(in, "%d %d\n", &l, &r)
			a = append(a, node{l, r})
		}
		sort.Sort(ByLeft(a))
		curBoard := a[0]
		curOnTopNum := 0
		curOnTopRight := a[0].left - 1
		ans := 0
		for i := 1; i < n; i++ {
			next := a[i]
			if next.left > curOnTopRight {
				if next.left <= curBoard.right {
					curOnTopNum++
					ans = max(ans, curOnTopNum)
					if next.right > curOnTopRight {
						curOnTopRight = next.right
					}
					if curOnTopRight > curBoard.right {
						nextRight := curBoard.right
						curBoard = next
						curOnTopNum = 1
						curOnTopRight = nextRight
					}
				} else {
					if curOnTopNum > ans {
						ans = curOnTopNum
					}
					// change board
					curBoard = next
					curOnTopNum = 0
					curOnTopRight = curBoard.left - 1
				}
			} else {
				curOnTopRight = max(curOnTopRight, next.right)
				if curOnTopRight > curBoard.right {
					nextRight := curBoard.right
					curBoard = next
					curOnTopNum = 1
					curOnTopRight = nextRight
				}
			}
		}
		curAns := 1
		curRight := a[0].right
		for i := 1; i < n; i++ {
			if a[i].left > curRight {
				curAns++
			}
			curRight = max(curRight, a[i].right)
		}
		if ans == 0 {
			ans = 1
		}
		fmt.Fprintf(out, "%d\n", curAns+ans-1)
	}
	return
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"sync"
)
type node struct {
	l int
	r int
}
type Node []node
func (a Node) Len() int { return len(a) }
func (a Node) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Node) Less(i, j int) bool {
	if a[i].l == a[j].l {
		return a[i].r < a[j].r
	}
	return a[i].l < a[j].l
}

type Seg struct {
	tag, sum, L, R int
}
var cat [200001 * 4]Seg
func pushdown(o, ls, rs int) {
	if cat[o].tag == 1 {
		cat[ls].sum, cat[ls].tag, cat[rs].sum, cat[rs].tag = 1, 1, 1, 1
		cat[ls].L = min(cat[ls].L, cat[o].L)
		cat[ls].R = max(cat[ls].R, cat[o].R)
		cat[rs].L = min(cat[rs].L, cat[o].L)
		cat[rs].R = max(cat[rs].R, cat[o].R)
		cat[o].tag = 0
	}
}
func pushup(ls, rs Seg) Seg {
	tmp := Seg{}
	tmp.tag = 0
	tmp.sum = ls.sum + rs.sum
	tmp.L = ls.L
	tmp.R = rs.R
	if ls.R > rs.L {
		tmp.sum--
	}
	return tmp
}
func up(o, l, r, ql, qr int) {
	if l >= ql && r <= qr {
		cat[o].tag, cat[o].sum = 1, 1
		cat[o].L = min(cat[o].L, ql)
		cat[o].R = max(cat[o].R, qr)
		return
	}
	mid, ls, rs := (l + r) / 2, o * 2, o * 2 + 1
	pushdown(o, ls, rs)
	if ql <= mid {
		up(ls, l, mid, ql, qr)
	}
	if qr > mid {
		up(rs, mid + 1, r, ql, qr)
	}
	cat[o] = pushup(cat[ls], cat[rs])
}
func qu(o, l, r, ql, qr int) Seg {
	if l >= ql && r <= qr {
		return cat[o]
	}
	mid, ls, rs := (l + r) / 2, o * 2, o * 2 + 1
	pushdown(o, ls, rs)
	if qr <= mid {
		return qu(ls, l, mid, ql, qr)
	} else if ql > mid {
		return qu(rs, mid + 1, r, ql, qr)
	} else {
		Ls := qu(ls, l, mid, ql, qr)
		Rs := qu(rs, mid + 1, r, ql, qr)
		return pushup(Ls, Rs)
	}
}
func work() {
	n := ReadInt()
	a := []node{}
	x := []int{}

    a = append(a, node{0, 0})
    x = append(x, 0)
	for i := 1; i <= n; i++ {
		l := ReadInt()
		r := ReadInt()
		a = append(a, node{l, r})
		x = append(x, l)
		x = append(x, r)
	}
	sort.Ints(x)
	sort.Sort(Node(a))
	mp := map[int]int{}
	for i := 1; i <= 2 * n; i++ {
		mp[x[i]] = i
	}
	A := make([]int, n + 1)
	m := 2 * n
	Mx := make([]int, n + 1)
	Mn := make([]int, m + 1)
	for i := 1; i <= m; i++ {
		Mn[i] = i
	}
	mx, L := 0, 0
	for i := 1; i <= n; i++ {
		a[i].l = mp[a[i].l]
		a[i].r = mp[a[i].r]
		A[i] = A[i - 1]
		if a[i].l > mx {
			A[i]++
			L = a[i].l
		}
		mx = max(mx, a[i].r)
		Mx[i] = mx
		Mn[mx] = L
	}
	for i := 1; i <= 4 * m; i++ {
		cat[i].R, cat[i].sum, cat[i].tag = 0, 0, 0
		cat[i].L = m + 1
	}
	ans := 0
	for i := n; i > 0; i-- {
		flag := 0
		if i > 1 {
			flag = qu(1, 1, m,Mn[Mx[i - 1]], Mx[i - 1]).sum
		}
		ans = max(ans, A[i - 1] + cat[1].sum - flag)
		up(1, 1, m, a[i].l, a[i].r)
	}
	fmt.Println(ans)
}
func main() {
	for i := ReadInt(); i > 0; i-- {
		work()
	}
	close(out)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _  := strconv.Atoi(intStr)
	return i
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}


package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var t int
	var x, y, k, ans int64
	scan(&t)
	for ; t > 0; t--{
		scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		print(ans, "\n")
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		x, y, k := readThreeNums(reader)

		res := solve(x, y, k)

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(x int, y int, k int) int64 {
	X, Y, K := int64(x), int64(y), int64(k)

	N := (K*Y + K - 1 + X - 2) / (X - 1)
	return N + K
}

package main

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

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

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

func main() {
	defer writer.Flush()

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

	for i := 0; i < t; i++ {
		var x, y, k int64
		scanf("%d %d %d\n", &x, &y, &k)

		printf("%d\n", calc(x, y, k))
	}
}

func calc(x, y, k int64) int64 {
	reqS := k + (k * y)                // required sticks
	reqC := k + ((reqS - 1) / (x - 1)) // required conversions

	if (reqS-1)%(x-1) != 0 {
		reqC++
	}

	return reqC
}

package main

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

func main(){
	var (
		t int
		x,y,k,ans uint64
	)
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &t)
	for i:=1;i<=t;i++{
		fmt.Fscan(in, &x, &y, &k)
		ans = k
		k = (k*(y+1)-1)
		x--
		if(k%x==0){
			ans = ans + k/x
		}else{
			ans = ans + k/x + 1
		}
		fmt.Fprintln(out, ans)
	}
	out.Flush()
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func solveCase() {
	x, y, k := rw.NextInt64(), rw.NextInt64(), rw.NextInt64()
	// y * k <= (x - 1) * t
	t := (y*k + x - 2) / (x - 1)
	s := t*(x-1) + 1 - y*k
	if s < k {
		t += (k - s + x - 2) / (x - 1)
	}
	rw.Println(t + k)
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

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

package main

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

var (
	t int

	x, y, k int64
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		x, y, k = readll3()

		solve()
	}
}

func solve() {
	bunshi := k*(1+y) - 1
	bunbo := x - 1

	s := Kiriage(bunshi, bunbo)

	fmt.Println(s + k)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		x := readInt64()
		y := readInt64()
		k := readInt64()
		reqX := k + y * k - 1

		steps := (reqX + (x - 2)) / (x - 1)
		fmt.Println(steps + k)
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

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

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

	var T, x, y, k int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x, &y, &k)
		t := ((y+1)*k-2)/(x-1) + 1
		Fprintln(out, t+k)
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(w, f, a...) }

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var t int
	var x, y, k, ans int64
	scan(&t)
	for ; t > 0; t--{
		scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		print(ans, "\n")
	}
}

package main

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

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

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

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

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

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func Sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	x, y, k := nextLong()-1, nextLong(), nextLong()
	printf("%d\n", k+((y+1)*k+x-2)/x)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "foreign"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create(name + ".out")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// 	printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	var testCases int64
	fmt.Sscanf(tc, "%d", &testCases)
	for testCases > 0 {
		input, _ := reader.ReadString('\n')
		var x, y, k int64
		var mul, result, rem int64

		fmt.Sscanf(input, "%d %d %d", &x, &y, &k)

		mul = k * (y + 1)
		rem = (mul - 1) % (x - 1)

		if rem == 0 {
			result = (mul-1)/(x-1) + k
		} else {
			result = (mul-1)/(x-1) + k + 1
		}

		fmt.Println(result)

		testCases--

	}

}

package main

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

func ceild(num, denom int64) int64 {
	return (num + denom - 1) / denom
}

func solve(r *bufio.Reader, w *bufio.Writer) {
	var x, y, k int64
	fmt.Fscanln(r, &x, &y, &k)
	trades := ceild(k*(y+1)-1, x-1)
	trades += k
	fmt.Fprintln(w, trades)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		solve(reader, writer)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	lst := strings.Split(tc, " ")
	testCases, _ := strconv.Atoi(lst[0])
	for testCases > 0 {
		input, _ := reader.ReadString('\n')

		list := strings.Split(input, " ")
		var a, b, c int
		var x, y, k int64
		a, _ = strconv.Atoi(list[0])
		b, _ = strconv.Atoi(list[1])
		c, _ = strconv.Atoi(list[2])

		x, y, k = int64(a), int64(b), int64(c)
		var result, sticks, coals int64 = 0, 1, 0
		var tarSticks, tarCoals int64 = k, k

		for {
			if sticks >= tarSticks && coals >= tarCoals {
				fmt.Println(result)
				break
			}

			if !(sticks >= k) {

				sticks--
				sticks += x
				result++

			}

			if !(coals >= k) {
				sticks -= y
				coals++
				result++

			}
		}
		testCases--
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	lst := strings.Split(tc, " ")
	testCases, _ := strconv.Atoi(lst[0])
	for testCases > 0 {
		input, _ := reader.ReadString('\n')

		list := strings.Split(input, " ")
		var x, y, k int64
		x, _ = strconv.ParseInt(list[0], 10, 64)
		y, _ = strconv.ParseInt(list[1], 10, 64)
		k, _ = strconv.ParseInt(list[2], 10, 64)

		var result, sticks, coals int64 = 0, 1, 0
		var tarSticks, tarCoals int64 = k, k

		for {
			if sticks >= tarSticks && coals >= tarCoals {
				fmt.Println(result)
				break
			}

			if !(sticks >= k) {

				sticks--
				sticks += x
				result++

			}

			if !(coals >= k) {
				sticks -= y
				coals++
				result++

			}
		}
		testCases--
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	lst := strings.Split(tc, " ")
	testCases, _ := strconv.Atoi(lst[0])
	for testCases > 0 {
		input, _ := reader.ReadString('\n')

		list := strings.Split(input, " ")
		var x, y, k int64
		x, _ = strconv.ParseInt(list[0], 10, 64)
		y, _ = strconv.ParseInt(list[1], 10, 64)
		k, _ = strconv.ParseInt(list[2], 10, 64)

		var result, sticks, coals int64 = 0, 1, 0
		var tarSticks, tarCoals int64 = k, k

		for {
			if sticks >= tarSticks && coals >= tarCoals {
				fmt.Printf("%d\n", result)
				break
			}

			if !(sticks >= k) {

				sticks--
				sticks += x
				result++

			}

			if !(coals >= k) {
				sticks -= y
				coals++
				result++

			}
		}
		testCases--
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	lst := strings.Split(tc, " ")
	testCases, _ := strconv.Atoi(lst[0])
	for testCases > 0 {
		input, _ := reader.ReadString('\n')

		list := strings.Split(input, " ")
		var x, y, k int64
		x, _ = strconv.ParseInt(list[0], 10, 64)
		y, _ = strconv.ParseInt(list[1], 10, 64)
		k, _ = strconv.ParseInt(list[2], 10, 64)

		var result, sticks, coals int64 = 0, 1, 0
		var tarSticks, tarCoals int64 = k, k

		for {

			if x == 1 && y == 1 && k == 1 {
				break
			}

			if sticks >= tarSticks && coals >= tarCoals {
				fmt.Printf("%d\n", result)
				break
			}

			if !(sticks >= k) {

				sticks--
				sticks += x
				result++

			}

			if !(coals >= k) {
				sticks -= y
				coals++
				result++

			}
		}
		testCases--
	}

}

package main

import "fmt"

func main() {
	var x, y, k int64
	fmt.Scanf("%d %d %d", &x, &y, &k)
	var result, sticks, coals int64 = 0, 1, 0
	var tarSticks, tarCoals int64 = k, k

	for {
		if sticks >= tarSticks && coals >= tarCoals {
			fmt.Println(result)
			break
		}

		if !(sticks >= k) {

			sticks--
			sticks += x
			result++

		}

		if !(coals >= k) {
			sticks -= y
			coals++
			result++

		}
	}
}

package main

import "fmt"

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

	for i := 0; i < t; i++ {
		var x, y, k int
		_, err := fmt.Scanf("%d %d %d\n", &x, &y, &k)
		if err != nil {
			panic(err)
		}

		fmt.Println(calc(x, y, k))
	}
}

func calc(x, y, k int) int {
	reqS := k + (k * y)                // required sticks
	reqC := k + ((reqS - 1) / (x - 1)) // required conversions

	if (reqS-1)%(x-1) != 0 {
		reqC += 1
	}

	return reqC
}

package main

import "fmt"

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

	for i := 0; i < t; i++ {
		var x, y, k int
		_, err := fmt.Scanf("%d %d %d\n", &x, &y, &k)
		if err != nil {
			panic(err)
		}

		fmt.Printf("%d\n", calc(x, y, k))
	}
}

func calc(x, y, k int) int {
	reqS := k + (k * y)                // required sticks
	reqC := k + ((reqS - 1) / (x - 1)) // required conversions

	if (reqS-1)%(x-1) != 0 {
		reqC++
	}

	return reqC
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++{
		var x, y, k, ans int64
		fmt.Scan(x,y,k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++{
		var x, y, k, ans int
		fmt.Scan(&x, &y, &k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var x, y, k, ans int64
	fmt.Scan(&t)
	for ; t > 1; t--{
		fmt.Scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		fmt.Println(ans)
	}
}

package main

import "fmt"

func main() {
	var t int16
	fmt.Scan(&t)
	for ; t > 0; t--{
		var x, y, k, ans int64
		fmt.Scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var a string
	var t int16
	var x, y, k, ans int64
	fmt.Scan(&t)
	for ; t > 0; t--{
		fmt.Scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		a += string(ans) + " "
	}
	fmt.Println(a)
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++{
		var x, y, k, ans int
		fmt.Scan(&x)
		fmt.Scan(&y)
		fmt.Scan(&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var a string
	fmt.Scan(&a)

	var h = "hello"
	var index = 0
	for i := 0; i < len(a) && index < 5; i++{
		if h[index] == a[i]  {
			index++
		}
	}
	if index >= 5 {
		print("YES")
	}else {
		print("NO")
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var x, y, k, ans int64
	fmt.Scan(&t)
	for ; t > 1; t--{
		fmt.Scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		fmt.Println(ans,t)
	}
}


package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k, t float64
	fmt.Scanf("%f%f%f", &n, &k, &t)

	var _nk, nk float64
	var lnk int
	_nk = n * t / 100
	nk = _nk - float64(int(_nk))
	lnk = int(_nk)

	var r []string

	for i := 0; i < lnk; i++ {
		r = append(r, strconv.Itoa(int(k)))
	}

	if nk > 0 {
		r = append(r, strconv.Itoa(int(nk*k)))
	}

	l := int(n) - len(r)
	for x := 0; x < l; x++ {
		r = append(r, strconv.Itoa(0))
	}

	fmt.Println(strings.Join(r, " "))
}

package main
import "fmt"

func main(){
	var n,k,t,pr float64
	fmt.Scan(&n,&k,&t)
	pr= n*t/100
	x:=int(pr)
	for i:=0 ;i<int(n);i++ {
		if i<x {
			fmt.Print(k," ")
		}else if i==x {
			ans:= int((pr-float64(x)) * k)
			fmt.Print(ans, " ")
		}else{
			fmt.Print(0)
			if i==int(n) {
				fmt.Println()
			}else{
				fmt.Print(" ")
			}
		}
	}
}

package main

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

var scanner *bufio.Scanner

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

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

  n, k, t := getI(), getI(), getI()
  line := make([]int, n)
  sum := int(float64(n*k*t)/100)
  for i := 0; sum != 0; i++ {
    if sum > k {
      line[i] = k
      sum -= k
    } else {
      line[i] = sum
      sum = 0
    }
  }
  writer.WriteString(fmt.Sprintf("%d", line[0]))
  for i := 1; i < n; i++ {
    writer.WriteString(fmt.Sprintf(" %d", line[i]))
  }
  writer.WriteString("\n")
}

// 71B
package main

import (
	"fmt"
)

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func main() {
	var n, k, t, i int
	fmt.Scan(&n, &k, &t)
	t = n * k * t / 100
	for i = 0; i < n; i++ {
		fmt.Print(min(t, k), " ")
		t -= min(t, k)
	}
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k, t float64
	fmt.Scanf("%f%f%f", &n, &k, &t)

	var _nk, nk float64
	var lnk int
	_nk = n * t / 100
	nk = _nk - float64(int(_nk))
	lnk = int(_nk)

	var r []string

	for i := 0; i < lnk; i++ {
		r = append(r, strconv.Itoa(int(k)))
	}

	r = append(r, strconv.Itoa(int(nk*k)))

	l := int(n) - len(r)
	for x := 0; x < l; x++ {
		r = append(r, strconv.Itoa(0))
	}

	fmt.Println(strings.Join(r, " "))
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k, t float64
	fmt.Scanf("%f%f%f", &n, &k, &t)

	var _nk float64
	var nk, lnk int
	_nk = n * t / 100
	nk = int((_nk - float64(int(_nk))) * 10)
	lnk = int(_nk)

	var r []string

	for i := 0; i < lnk; i++ {
		r = append(r, strconv.Itoa(int(k)))
	}

	r = append(r, strconv.Itoa(nk))

	l := 10 - len(r)
	for x := 0; x < l; x++ {
		r = append(r, strconv.Itoa(0))
	}

	fmt.Println(strings.Join(r, " "))
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k, t float64
	fmt.Scanf("%f%f%f", &n, &k, &t)

	var _nk float64
	var nk, lnk int
	_nk = n * t / 100
	nk = int((_nk - float64(int(_nk))) * 10)
	lnk = int(_nk)

	var r []string

	for i := 0; i < lnk; i++ {
		r = append(r, strconv.Itoa(int(k)))
	}

	r = append(r, strconv.Itoa(nk))

	l := int(n) - len(r)
	for x := 0; x < l; x++ {
		r = append(r, strconv.Itoa(0))
	}

	fmt.Println(strings.Join(r, " "))
}


package main

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

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

func ans() {
	var n int
	var s string
	ans := 0
	Fscan(in, &n)
	Fscan(in, &s)
	for l := 0; l < len(s); l++ {
		var cnt []int = make([]int, 10)
		uniq := 0
		for r := l; r < len(s) && r < l+110; r++ {
			if cnt[s[r]-'0'] == 0 {
				uniq++
			}
			cnt[s[r]-'0']++
			good := true
			for d := 0; d < 10; d++ {
				if cnt[d] > uniq {
					good = false
					break
				}
			}
			if good {
				ans++
			}
		}
	}
	Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for i := 0; i < t; i++ {
		ans()
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, 1000000), 0)
	for i := 0; scanner.Scan(); i++ {
		if i == 0 || i%2 == 1 {
			continue
		}
		fmt.Printf("%d\n", count(digits(scanner.Text())))
	}
	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
}

func digits(s string) []byte {
	bs := make([]byte, len(s))
	for i := range s {
		bs[i] = s[i] - '0'
	}
	return bs
}

func count(bs []byte) int {
	numD := byte(10)
	numDSq := numD * numD
	n := 0
	for s := 0; s < len(bs); s++ {
		occur := uint64(0)
		seen := uint16(0)
		maxOccur := byte(0)
		for l := 1; l <= int(numDSq) && s+l-1 < len(bs); l++ {
			x := bs[s+l-1] % numD
			c := occur
			c >>= (4 * x)
			c++
			d := byte(c & 15)
			if d > maxOccur {
				maxOccur = d
			}
			occur = c<<(4*x) | (occur & (1<<(4*x) - 1))
			seen |= (1 << x)
			if maxOccur > numD {
				break
			}
			if maxOccur <= byte(bits.OnesCount16(seen)) {
				n++
			}
		}
	}
	return n
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

package main

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

func Solve(reader *bufio.Reader, writer *bufio.Writer) {
	zero := []byte("0")[0]
	var n int
	var str string
	fmt.Fscan(reader, &n)
	fmt.Fscan(reader, &str)
	bstr := []byte(str)

	for i := range bstr {
		bstr[i] -= zero
	}

	var ans int
	for i := 0; i < n; i++ {
		u := 1
		isThere := make([]bool, 10)
		isThere[bstr[i]] = true
		count := make([]int, 10)
		mx := 0
		for j := i; j < i+100 && j < n; j++ {
			count[bstr[j]]++
			if count[bstr[j]] > mx {
				mx = count[bstr[j]]
			}
			if !isThere[bstr[j]] {
				u++
				isThere[bstr[j]] = true
			}
			if u >= mx {
				ans++
			}
		}
	}

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

func main() {
	var reader *bufio.Reader
	var writer *bufio.Writer

	filename_in := "data.in"
	filename_out := "data.out"

	stdinout := true
	readtests := true
	tests := 1

	if (!stdinout || inArgs("local")) && !inArgs("std") {
		infile, inerr := os.Open(filename_in)
		if inerr != nil {
			if os.IsNotExist(inerr) {
				os.Create(filename_in)
			}
			fmt.Println(inerr)
			return
		}
		defer infile.Close()

		outfile, outerr := os.OpenFile(filename_out, os.O_WRONLY, os.ModeAppend)
		if outerr != nil {
			if os.IsNotExist(outerr) {
				outfile, outerr = os.Create(filename_out)
				if outerr != nil {
					fmt.Println(outerr)
					return
				}
			}
		}
		defer outfile.Close()

		reader = bufio.NewReader(infile)
		writer = bufio.NewWriter(outfile)
	} else if stdinout || inArgs("std") {
		reader = bufio.NewReader(os.Stdin)
		writer = bufio.NewWriter(os.Stdout)
	}
	defer func() {
		err := writer.Flush()
		if err != nil {
			fmt.Println(err)
		}
	}()

	if readtests || inArgs("local") {
		fmt.Fscanf(reader, "%d\n", &tests)
	}

	for i := 0; i < tests; i++ {
		Solve(reader, writer)
		fmt.Fscanf(reader, "\n")
	}

}

func inArgs(arg string) bool {
	for _, a := range os.Args {
		if a == arg {
			return true
		}
	}
	return false
}

package main

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

func solve(r *bufio.Reader) {
	var n int
	var s string
	fmt.Fscan(r, &n, &s)
	total := 0
	for i := 0; i < n; i++ {
		max := 0
		occ := make(map[byte]int)
		for j := i; j < n; j++ {
			occ[s[j]]++
			if occ[s[j]] > max {
				max = occ[s[j]]
			}
			if max > 10 {
				break
			}
			if max <= len(occ) {
				total++
			}
		}
	}
	fmt.Println(total)
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

import "fmt"

func main() {
  var T int
  fmt.Scan(&T)
  for t := 0; t < T; t += 1 {
    var N int
    fmt.Scan(&N)
    var S string
    fmt.Scan(&S)
    ans := 0
    for l := 0; l < N; l += 1 {
      var occ [10]int
      max := 0
      num := 0
      for r := l; r < N && max <= 10; r += 1 {
        d := S[r] - '0'
        if occ[d] == 0 {
          num += 1
        }
        occ[d] += 1
        if occ[d] > max {
          max = occ[d]
        }
        if max <= num {
          ans += 1
        }
      }
    }
    fmt.Println(ans)
  }
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var s string
		fmt.Fscan(in, &s)
		sum := 0
		for j := 0; j < n; j++ {
			pd := make([]bool, 10)
			sl := make([]int, 10)
			zl := 0
			mx := 0
			for k := j; k < j+100 && k < n; k++ {
				sl[s[k]-'0']++
				if mx < sl[s[k]-'0'] {
					mx = sl[s[k]-'0']
				}
				if !pd[s[k]-'0'] {
					zl++
					pd[s[k]-'0'] = true
				}
				if zl >= mx {
					sum++
				}
			}
		}
		fmt.Println(sum)
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	n := readInt(reader)
	s := readString(reader)

	var ans int
	for i := 0; i < n; i++ {
		var a [10]int
		for j := i; j < n && j-i < 100; j++ {
			a[s[j]-'0']++
			var cnt, maxx int
			for _, v := range a {
				if v > 0 {
					cnt++
				}
				maxx = max(maxx, v)
			}
			if maxx <= cnt {
				ans++
			}
		}
	}

	fmt.Fprintln(writer, ans)
}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func min[T int | int64](a, b T) T {
	if a < b {
		return a
	}

	return b
}

func max[T int | int64](a, b T) T {
	if a > b {
		return a
	}

	return b
}

func abs[T int | int64](a T) T {
	if a < 0 {
		return a * -1
	} else {
		return a
	}
}

func gcd[T int | int64](x, y T) T {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm[T int | int64](x, y T) T {
	return x * y / gcd(x, y)
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

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

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

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	var str string
	fmt.Fscan(in, &str)
	prefix := make([][]int, 10)
	for i := range prefix {
		prefix[i] = make([]int, n)
	}
	for i := range str {
		integer := int(str[i] - '0')
		if i > 0 {
			for j := range prefix {
				prefix[j][i] = prefix[j][i-1]
			}
		}
		prefix[integer][i]++
	}

	ans := 0
	for i := 0; i < n; i++ {
		for cur := max(0, i-101); cur <= i; cur++ {
			diff := 0
			mx := 0
			for j := range prefix {
				curPref := prefix[j][i]
				if cur > 0 {
					curPref -= prefix[j][cur-1]
				}
				if curPref > 0 {
					diff++
				}
				mx = max(mx, curPref)
			}
			if mx > diff {
				continue
			} else {
				ans++
			}
		}
	}

	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; scanner.Scan(); i++ {
		if i == 0 || i%2 == 1 {
			continue
		}
		fmt.Printf("%d\n", count(digits(scanner.Text())))
	}
}

func digits(s string) []byte {
	bs := make([]byte, len(s))
	for i := range s {
		bs[i] = s[i] - '0'
	}
	return bs
}

func count(bs []byte) int {
	n := 0
	for s := 0; s < len(bs); s++ {
		occur := uint64(0)
		seen := uint16(0)
		maxOccur := byte(0)
		for l := 1; l <= 100 && s+l-1 < len(bs); l++ {
			x := bs[s+l-1]
			c := occur
			c >>= (4 * x)
			c++
			d := byte(c & 15)
			if d > maxOccur {
				maxOccur = d
			}
			occur = c<<(4*x) | (occur & (1<<(4*x) - 1))
			seen |= (1 << x)
			if maxOccur > 10 {
				break
			}
			if maxOccur <= byte(bits.OnesCount16(seen)) {
				n++
			}
		}
	}
	return n
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; scanner.Scan(); i++ {
		if i == 0 || i%2 == 1 {
			continue
		}
		fmt.Printf("%d\n", count(digits(scanner.Text())))
	}
}

func digits(s string) []byte {
	bs := make([]byte, len(s))
	for i := range s {
		bs[i] = s[i] - '0'
	}
	return bs
}

func count(bs []byte) int {
	n := 0
	for s := 0; s < len(bs); s++ {
		occur := map[byte]int{}
		maxOccur := 0
		for l := 1; l <= 100 && s+l <= len(bs); l++ {
			x := bs[s+l-1]
			occur[x]++
			if occur[x] > maxOccur {
				maxOccur = occur[x]
			}
			if maxOccur > len(occur) {
				if maxOccur > 10 {
					break
				}
				continue
			}
			n++
		}
	}
	return n
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

package main

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

func Solve(reader *bufio.Reader, writer *bufio.Writer) {
	zero := []byte("0")[0]
	var n int
	var str string
	fmt.Fscan(reader, &n)
	fmt.Fscan(reader, &str)
	bstr := []byte(str)

	for i := range bstr {
		bstr[i] -= zero
	}

	var ans int
	for i := 0; i < n; i++ {
		u := 1
		isThere := make([]bool, 10)
		isThere[bstr[i]] = true
		count := make([]int, 10)
		mx := 0
		for j := i; j < i+100 && j < n; j++ {
			count[bstr[j]]++
			if count[bstr[j]] > mx {
				mx = count[bstr[j]]
			}
			if !isThere[bstr[j]] {
				u++
				isThere[bstr[j]] = true
			}
			fmt.Println(i, j, u, mx)
			if u >= mx {
				ans++
				fmt.Println("^ cool ^")
			}
		}
	}

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

func main() {
	var reader *bufio.Reader
	var writer *bufio.Writer

	filename_in := "data.in"
	filename_out := "data.out"

	stdinout := true
	readtests := true
	tests := 1

	if (!stdinout || inArgs("local")) && !inArgs("std") {
		infile, inerr := os.Open(filename_in)
		if inerr != nil {
			if os.IsNotExist(inerr) {
				os.Create(filename_in)
			}
			fmt.Println(inerr)
			return
		}
		defer infile.Close()

		outfile, outerr := os.OpenFile(filename_out, os.O_WRONLY, os.ModeAppend)
		if outerr != nil {
			if os.IsNotExist(outerr) {
				outfile, outerr = os.Create(filename_out)
				if outerr != nil {
					fmt.Println(outerr)
					return
				}
			}
		}
		defer outfile.Close()

		reader = bufio.NewReader(infile)
		writer = bufio.NewWriter(outfile)
	} else if stdinout || inArgs("std") {
		reader = bufio.NewReader(os.Stdin)
		writer = bufio.NewWriter(os.Stdout)
	}
	defer func() {
		err := writer.Flush()
		if err != nil {
			fmt.Println(err)
		}
	}()

	if readtests || inArgs("local") {
		fmt.Fscanf(reader, "%d\n", &tests)
	}

	for i := 0; i < tests; i++ {
		Solve(reader, writer)
		fmt.Fscanf(reader, "\n")
	}

}

func inArgs(arg string) bool {
	for _, a := range os.Args {
		if a == arg {
			return true
		}
	}
	return false
}