You are given a binary string of length $$$n$$$ (i. e. a string consisting of $$$n$$$ characters '0' and '1').In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than $$$k$$$ moves? It is possible that you do not perform any moves at all.Note that you can swap the same pair of adjacent characters with indices $$$i$$$ and $$$i+1$$$ arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases. The first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^6, 1 \le k \le n^2$$$) — the length of the string and the number of moves you can perform. The second line of the test case contains one string consisting of $$$n$$$ characters '0' and '1'. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$ ($$$\sum n \le 10^6$$$).

For each test case, print the answer on it: the lexicographically minimum possible string of length $$$n$$$ you can obtain from the given one if you can perform no more than $$$k$$$ moves.

NoteIn the first example, you can change the string as follows: $$$1\underline{10}11010 \rightarrow \underline{10}111010 \rightarrow 0111\underline{10}10 \rightarrow 011\underline{10}110 \rightarrow 01\underline{10}1110 \rightarrow 01011110$$$. In the third example, there are enough operations to make the string sorted.

package main

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

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

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

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

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

func sol(n int64, k int64, in []byte) []byte {
	// Find the position of first '1' in the string.
	// Invariant: f1Pos is always position of first one in the string.
	f1Pos := int64(bytes.IndexByte(in, '1'))
	if f1Pos == -1 {
		// This string is all zeroes.
		return in
	}

	// Invariant: kNow is how many moves we can do at this point.
	kNow := k
	// Invariant: f0Pos is always position of first zero after one at f1Pos.
	f0Pos := f1Pos + 1
	for {
		// Find the position of the first '0' after '1' in the string.
		for i := f0Pos; i < int64(len(in)); i++ {
			if in[i] == '0' {
				f0Pos = i
				break
			}
		}
		if f0Pos == int64(len(in)) {
			// This string is all ones (and maybe some leading zeroes).
			return in
		}

		// We want to move f0Pos to f1Pos, but kNow may be too low.
		if f0Pos-f1Pos > kNow {
			// kNow, the maximum number of moves, may be too low.
			in[f0Pos], in[f0Pos-kNow] = in[f0Pos-kNow], in[f0Pos]
			return in
		}
		in[f0Pos], in[f1Pos] = in[f1Pos], in[f0Pos]
		// fix invariants
		kNow -= f0Pos - f1Pos
		f1Pos++ // We have replaced the leading one with zero
		f0Pos++ // We have moved the leading one to (former) f0Pos.
	}
}

func main() {
	defer writer.Flush()
	var q int
	Scanf("%d\n", &q)

	for i := 0; i < q; i++ {
		var n int64
		var k int64
		var in []byte
		Scanf("%d %d\n", &n, &k)
		Scanf("%s\n", &in)
		Printf("%s\n", string(sol(n, k, in)))
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var q int
var n, k int64
var S []rune

func main() {
	q = ReadInt()
	for tc := 0; tc < q; tc++ {
		n, k = ReadInt64_2()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	zeroNum := 0
	for i := int64(0); i < n; i++ {
		if S[i] == '0' {
			zeroNum++
		}
	}
	zeros := make([]int64, zeroNum)

	j := int64(0)
	for i := int64(0); i < n; i++ {
		if S[i] == '0' {
			zeros[j] = i - j
			j++
		}
	}

	zeroSums := make([]int64, zeroNum+1)
	for i := 0; i < zeroNum; i++ {
		zeroSums[i+1] = zeroSums[i] + zeros[i]
	}

	// c: 確実に先頭に持ってくることができる0の数
	c := 0
	for i := 0; i < len(zeroSums); i++ {
		if zeroSums[i] > k {
			break
		} else {
			c = i
		}
	}

	answers := []rune{}
	for i := 0; i < c; i++ {
		answers = append(answers, '0')
	}
	skipped := 0
	for i := int64(0); i < n; i++ {
		if S[i] == '0' && skipped < c {
			skipped++
		} else {
			answers = append(answers, S[i])
		}
	}

	if c == zeroNum {
		fmt.Println(string(answers))
		return
	}

	k -= zeroSums[c]
	for i := int64(c); i < n; i++ {
		if answers[i] == '0' {
			for j := i; j > 0; j-- {
				if k == 0 {
					break
				}
				if answers[j-1] > answers[j] {
					answers[j], answers[j-1] = answers[j-1], answers[j]
					k--
				}
			}

			fmt.Println(string(answers))
			return
		}
	}
}

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = 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 q int
	scan(&q)
	for i := 0; i < q; i++ {
		var str string
		var l, left, j int
		var c int64
		left = 0;
		j = 0;
		scan(&l, &c, &str)
		var s = []rune(str)
		var haschanged =true
		for ; haschanged && c > 0; {
			haschanged = false
			s[left] = s[left]
			for ; left < l ;left++{
				if s[left] == '1' {
					break
				}
			};
			for ; j < l ;j++ {
				if j > left && s[j] == '0' {
					if c >= int64(j - left) {
						s[j],s[left] = s[left], s[j]
						c = c - int64(j - left)
					}else{
						s[j],s[int64(j) - c] = s[int64(j) - c], s[j]
						c = 0
					}
					haschanged = true
					break
				}
			}
		}
		print(string(s),"\n")
	}
}

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n, k := ScanInt64(), ScanInt64()
		a := []rune(ScanWord())

		for i, j := int64(0), int64(0); i < n; i++ {
			if a[i] == '0' {

				l := Min(i-j, k)
				a[i], a[i-l] = a[i-l], a[i]
				k -= l
				j++
			}
		}
		Pl(string(a))
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

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

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

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

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

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

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n, k := ScanInt64(), ScanInt64()
		a := []byte(ScanWord())

		for i, j := int64(0), int64(0); i < n; i++ {
			if a[i] == '0' {

				l := Min(i-j, k)
				a[i], a[i-l] = a[i-l], a[i]
				k -= l
				j++
			}
		}
		Pl(string(a))
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+7))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

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

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

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

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

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

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n, k := ScanInt64(), ScanInt64()
		a := []byte(ScanWord())

		for i, j := int64(0), int64(0); i < n; i++ {
			if a[i] == '0' {

				l := Min(i-j, k)
				a[i], a[i-l] = a[i-l], a[i]
				k -= l
				j++
			}
		}
		Pl(string(a))
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

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

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

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

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

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

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n, k := ScanInt64(), ScanInt64()
		a := []rune(ScanWord())

		for i, j := int64(0), int64(0); i < n; i++ {
			if a[i] == '0' {

				l := Min(i-j, k)
				a[i], a[i-l] = a[i-l], a[i]
				k -= l
				j++
			}
		}
		Pl(string(a))
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 0, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

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

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

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

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1256/problem/D

package main

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

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

func initArray(size int64) []string {
	arr := make([]string, size)
	for i := int64(0); i < size; i++ {
		arr[i] = "1"
	}
	return arr
}

func Solve(n int64, k int64, s string) string {
	answer := initArray(n)
	zeros := int64(0)
	for i := int64(0); i < n; i++ {
		if string(s[i]) == "0" {
			swaps := min(k, i-zeros)
			k -= swaps
			answer[i-swaps] = "0"
			zeros += 1
		}
	}
	return strings.Join(answer, "")
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n, k int64
		var s string
		fmt.Fscanf(reader, "%d %d\n%s\n", &n, &k, &s)
		fmt.Fprintf(writer, "%s\n", Solve(n, k, s))
	}
}

package main

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

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

func main() {
	//bs, _ := ioutil.ReadFile("in.txt")
	//treader := bytes.NewBuffer(bs)
	//reader := bufio.NewReader(treader)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var q, n, k int64
	var bin []byte
	var str string
	_ , _= fmt.Fscanf(reader, "%d\n", &q)
	for  q > 0 {
		q--
		_, _ = fmt.Fscanf(reader, "%d %d\n", &n, &k)
		_, _ = fmt.Fscanf(reader, "%s\n", &str)
		bin = []byte(str)
		pos := int64(0)

		for i := pos; i < int64(len(bin)); i++ {
			if bin[i] == '0' {
				l := min(i - pos, k)
				bin[i], bin[i - l] = bin[i - l], bin[i]
				k -= l
				pos++
			}
		}
		_, _ = fmt.Fprintf(writer, "%s\n", bin)
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var q int
var n, k int64
var S []rune

func main() {
	q = ReadInt()
	for tc := 0; tc < q; tc++ {
		n, k = ReadInt64_2()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	zeroNum := 0
	for i := int64(0); i < n; i++ {
		if S[i] == '0' {
			zeroNum++
		}
	}
	zeros := make([]int64, zeroNum)

	j := int64(0)
	for i := int64(0); i < n; i++ {
		if S[i] == '0' {
			zeros[j] = i - j
			j++
		}
	}

	zeroSums := make([]int64, zeroNum+1)
	for i := 0; i < zeroNum; i++ {
		zeroSums[i+1] = zeroSums[i] + zeros[i]
	}

	// c: 確実に先頭に持ってくることができる0の数
	c := 0
	for i := 0; i < len(zeroSums); i++ {
		if zeroSums[i] > k {
			break
		} else {
			c = i
		}
	}

	answers := []rune{}
	for i := 0; i < c; i++ {
		answers = append(answers, '0')
	}
	skipped := 0
	for i := int64(0); i < n; i++ {
		if S[i] == '0' && skipped < c {
			skipped++
		} else {
			answers = append(answers, S[i])
		}
	}

	if c == zeroNum {
		fmt.Println(string(answers))
		return
	}

	k -= zeroSums[c]
	for i := int64(c); i < n; i++ {
		if answers[i] == '0' {
			for j := i; j > 0; j-- {
				if answers[j-1] > answers[j] {
					answers[j], answers[j-1] = answers[j-1], answers[j]
					k--
				}
				if k == 0 {
					break
				}
			}

			fmt.Println(string(answers))
			return
		}
	}
}

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

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

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var q int
var n, k int64
var S []rune

func main() {
	q = ReadInt()
	for tc := 0; tc < q; tc++ {
		n, k = ReadInt64_2()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	zeroNum := 0
	for i := int64(0); i < n; i++ {
		if S[i] == '0' {
			zeroNum++
		}
	}
	zeros := make([]int64, zeroNum)

	j := int64(0)
	for i := int64(0); i < n; i++ {
		if S[i] == '0' {
			zeros[j] = i - j
			j++
		}
	}

	zeroSums := make([]int64, zeroNum+1)
	for i := 0; i < zeroNum; i++ {
		zeroSums[i+1] = zeroSums[i] + zeros[i]
	}

	// c: 確実に先頭に持ってくることができる0の数
	c := 0
	for i := 0; i < len(zeroSums); i++ {
		if zeroSums[i] > k {
			break
		} else {
			c = i
		}
	}
	fmt.Println(zeroSums)

	answers := []rune{}
	for i := 0; i < c; i++ {
		answers = append(answers, '0')
	}
	skipped := 0
	for i := int64(0); i < n; i++ {
		if S[i] == '0' && skipped < c {
			skipped++
		} else {
			answers = append(answers, S[i])
		}
	}

	if c == zeroNum {
		fmt.Println(string(answers))
		return
	}

	k -= zeroSums[c]
	for i := int64(c); i < n; i++ {
		if answers[i] == '0' {
			for j := i; j > 0; j-- {
				if k == 0 {
					break
				}
				if answers[j-1] > answers[j] {
					answers[j], answers[j-1] = answers[j-1], answers[j]
					k--
				}
			}

			fmt.Println(string(answers))
			return
		}
	}
}

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

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

// Author: sighduck
// URL: https://codeforces.com/contest/1256/problem/D

package main

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

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

func initArray(size int) []string {
	arr := make([]string, size)
	for i := 0; i < size; i++ {
		arr[i] = "1"
	}
	return arr
}

func Solve(n int, k int, s string) string {
	answer := initArray(n)
	zeros := 0
	for i, elem := range s {
		if string(elem) == "0" {
			swaps := min(k, i-zeros)
			k -= swaps
			answer[i-swaps] = "0"
			zeros += 1
		}
	}
	return strings.Join(answer, "")
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n, k int
		var s string
		fmt.Fscanf(reader, "%d %d\n%s\n", &n, &k, &s)
		fmt.Fprintf(writer, "%s\n", Solve(n, k, s))
	}
}

package main

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

func main() {
	// bs, _ := ioutil.ReadFile("in.txt")
	// treader := bytes.NewBuffer(bs)
	// reader := bufio.NewReader(treader)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var q, n, k int64
	var bin []byte
	_ , _= fmt.Fscanf(reader, "%d\n", &q)
	for  q > 0 {
		q--
		_, _ = fmt.Fscanf(reader, "%d %d\n", &n, &k)
		bin, _, _ = reader.ReadLine()
		pos := int64(0)
		for k > 0 {
			remain0Pos := int64(-1)
			for i := pos;i < int64(len(bin));i++ {
				if bin[i] == '0' {
					remain0Pos = i
					break
				}
			}
			if remain0Pos == -1 {
				break
			}
			if k >= int64(remain0Pos - pos) {
				k -= int64(remain0Pos - pos)
				bin[pos], bin[remain0Pos] = bin[remain0Pos], bin[pos]
			} else {
				bin[remain0Pos], bin[remain0Pos - k] = bin[remain0Pos - k], bin[remain0Pos]
				k = 0
			}
			pos++
		}
		_, _ = fmt.Fprintf(writer, "%s\n", bin)
	}
}

package main

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

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

func main() {
	//bs, _ := ioutil.ReadFile("in.txt")
	 //treader := bytes.NewBuffer(bs)
	 //reader := bufio.NewReader(treader)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var q, n, k int64
	var bin []byte
	_ , _= fmt.Fscanf(reader, "%d\n", &q)
	for  q > 0 {
		q--
		_, _ = fmt.Fscanf(reader, "%d %d\n", &n, &k)
		bin, _, _ = reader.ReadLine()
		pos := int64(0)

		for i := pos; i < int64(len(bin)); i++ {
			if bin[i] == '0' {
				l := min(i - pos, k)
				bin[i], bin[i - l] = bin[i - l], bin[i]
				k -= l
				pos++
			}
		}
		_, _ = fmt.Fprintf(writer, "%s\n", bin)
	}
}


You are given an integer array $$$a_1, a_2, \dots, a_n$$$ and integer $$$k$$$.In one step you can   either choose some index $$$i$$$ and decrease $$$a_i$$$ by one (make $$$a_i = a_i - 1$$$);  or choose two indices $$$i$$$ and $$$j$$$ and set $$$a_i$$$ equal to $$$a_j$$$ (make $$$a_i = a_j$$$). What is the minimum number of steps you need to make the sum of array $$$\sum\limits_{i=1}^{n}{a_i} \le k$$$? (You are allowed to make values of array negative).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le k \le 10^{15}$$$) — the size of array $$$a$$$ and upper bound on its sum. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the minimum number of steps to make $$$\sum\limits_{i=1}^{n}{a_i} \le k$$$.

NoteIn the first test case, you should decrease $$$a_1$$$ $$$10$$$ times to get the sum lower or equal to $$$k = 10$$$.In the second test case, the sum of array $$$a$$$ is already less or equal to $$$69$$$, so you don't need to change it.In the third test case, you can, for example:   set $$$a_4 = a_3 = 1$$$;  decrease $$$a_4$$$ by one, and get $$$a_4 = 0$$$.  As a result, you'll get array $$$[1, 2, 1, 0, 1, 2, 1]$$$ with sum less or equal to $$$8$$$ in $$$1 + 1 = 2$$$ steps.In the fourth test case, you can, for example:   choose $$$a_7$$$ and decrease in by one $$$3$$$ times; you'll get $$$a_7 = -2$$$;  choose $$$4$$$ elements $$$a_6$$$, $$$a_8$$$, $$$a_9$$$ and $$$a_{10}$$$ and them equal to $$$a_7 = -2$$$.  As a result, you'll get array $$$[1, 2, 3, 1, 2, -2, -2, -2, -2, -2]$$$ with sum less or equal to $$$1$$$ in $$$3 + 4 = 7$$$ steps.

package main

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

var in = bufio.NewReader(os.Stdin)

func solve() {
	var n int
	var k int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &k)

	a := make([]int64, n)
	var aSum int64 = 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		aSum += a[i]
	}
	if aSum <= k {
		fmt.Println(0)
		return
	}

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

	result := aSum - k
	for i := 1; i < n; i++ {
		aSum -= a[n-i] - a[0]

		var decCnt int64 = 0
		if aSum > k {
			minCnt := int64(i + 1)
			decCnt = (aSum - k + minCnt - 1) / minCnt
		}

		cost := decCnt + int64(i)
		if cost < result {
			result = cost
		}
	}
	fmt.Println(result)
}

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
func min(x, y int64)int64{
	if x<y{
		return x
	}
	return y
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n int64
		var k int64
		fmt.Fscan(in,&n,&k)
		a := make([]int64,n+5)
		var i int64
		var sum int64
		sum = 0
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
			sum+=a[i]
		}
		sort.Slice(a[1:n+1],func(i,j int)bool{
			return a[i+1]<a[j+1]
		})
		//fmt.Println(a)
		var l, r int64
		l = 0
		r = 2000000000000000
		var ans int64
		ans = 0
		for l<=r{
			mid := (l+r)>>1
			var cnt int64
			cnt=0
			tar := sum
			for i=n;i>=2;i--{
				if mid<=cnt{
					break
				}
				if a[i]-a[1]+(cnt+2)*(mid-cnt-1)<((cnt+1)*(mid-cnt)){
					break
				}
				tar -= a[i]-a[1]
				cnt++
			}
			tar = tar -(cnt+1)*(mid-cnt)
			if tar<=k{
				ans = mid
				r=mid-1
			}else{
				l=mid+1
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

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

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

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

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

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

func solve() {
	var (
		n int
		k int64
	)
	scan(&n, &k)

	var a = make([]int64, n)
	for i := range a {
		scan(&a[i])
	}

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

	var suffsum = make([]int64, n)
	suffsum[n-1] = a[n-1]
	for i := n - 2; i >= 0; i-- {
		suffsum[i] = suffsum[i+1] + a[i]
	}

	var (
		ans int64 = max(0, suffsum[0]-k)
		eq  int64
	)
	for i := len(a) - 1; i >= 1; i-- {
		if a[i] == a[0] {
			eq++
		}
		var (
			cnt = int64(len(a) - i)
			s   = suffsum[0] - suffsum[i] + cnt*a[0]
			res = cnt - eq
		)
		if s > k {
			dmin := (s - k + cnt) / (cnt + 1)
			res = cnt + dmin
		}
		ans = min(ans, res)
	}

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

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

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

package main

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

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

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

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

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

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

func solve() {
	var (
		n int
		k int64
	)
	scan(&n, &k)

	var a = make([]int64, n)
	for i := range a {
		scan(&a[i])
	}

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

	if n == 1 {
		printf("%v\n", max(0, a[0]-k))
		return
	}

	var suffsum = make([]int64, n)
	suffsum[n-1] = a[n-1]
	for i := n - 2; i >= 0; i-- {
		suffsum[i] = suffsum[i+1] + a[i]
	}

	var (
		ans int64 = max(0, suffsum[0]-k)
		eq  int64
	)
	for i := len(a) - 1; i >= 1; i-- {
		if a[i] == a[0] {
			eq++
		}
		var (
			cnt = int64(len(a) - i)
			s   = suffsum[0] - suffsum[i] + cnt*a[0]
			res = cnt - eq
		)
		if s > k {
			dmin := (s - k + cnt) / (cnt + 1)
			res = cnt + dmin
		}
		ans = min(ans, res)
	}

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

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

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

package main

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

func solve(A []int, K int64) int64 {
	n := len(A)
	if n == 1 {
		return max(0, int64(A[0])-K)
	}
	sort.Ints(A)
	var sum int64

	for _, num := range A {
		sum += int64(num)
	}

	if sum <= K {
		return 0
	}

	var best int64 = sum - K

	sum -= int64(A[0])

	for i := n - 1; i > 0; i-- {
		// decrease first to some m
		// and set A[i...]  to A[0]
		// (n - i + 1) * x + sum <= K
		sum -= int64(A[i])
		x := (K - sum) / int64(n-i+1)
		if x*int64(n-i+1) > (K - sum) {
			x--
		}
		a := max(0, int64(A[0])-x)
		best = min(best, a+int64(n-i))
	}

	return best
}

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

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)

	for tc > 0 {
		tc--
		var n int
		var K uint64
		s, _ := reader.ReadBytes('\n')
		pos := readInt(s, 0, &n) + 1
		readUint64(s, pos, &K)
		A := readNNums(reader, n)
		res := solve(A, int64(K))
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

package main

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

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

	t := readInt(reader)

	for t > 0 {
		n, k := readTwoInt64(reader)
		a := readArrayInt64(reader)

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

		var sum int64
		for i := int64(0); i < n; i++ {
			sum += a[i]
		}

		ans := int64(2e9)
		for t := int64(0); t < n; t++ {
			partSum := sum + a[0]*t
			cnt := t
			if partSum > k {
				cnt += (partSum - k + t) / (t + 1)
			}

			if ans > cnt {
				ans = cnt
			}

			sum -= a[n-t-1]
		}

		fmt.Fprintln(writer, ans)

		t--
	}

	writer.Flush()
}

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"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

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

func main() {
	defer out.Flush()
	//redirectInputToFile(in, "input.txt")

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

func solve() {
	xx := readArrInt64()
	n := xx[0]
	target := xx[1]
	arr := readArrInt64()
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
	prefixSum := make([]int64, n+1)
	for i := int64(0); i < n; i++ {
		prefixSum[i+1] = prefixSum[i] + arr[i]
	}
	//println(prefixSum)
	ans := int64(math.MaxInt)
	for i := int64(0); i < n; i++ {
		if prefixSum[n-i]+arr[0]*i < target {
			ans = min(ans, i)
		} else {
			gap := (prefixSum[n-i] + arr[0]*i - target + i) / (i + 1)
			ans = min(gap+i, ans)
		}
	}
	println(ans)

}

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

func reverse(s string) string {
	r := []rune(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)
}

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

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

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

func readFloat(in *bufio.Reader) float64 {
	nStr := readStr()
	n, _ := strconv.ParseFloat(nStr, 64)
	return n
}

func readInt() int {
	nStr := readStr()
	n, _ := strconv.Atoi(nStr)
	return n
}

func readStr() string {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return nStr
}

func readLineNumbs() []string {
	line := readStr()
	numbs := strings.Split(line, " ")
	return numbs
}

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

func readArrFloat() {
	numbs := readLineNumbs()
	arr := make([]float64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseFloat(n, 64)
		arr[i] = val
	}
}

func readArrInt64() []int64 {
	numbs := readLineNumbs()
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

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

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

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

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

package main

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

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

	var T, n int
	var k int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		tot := int64(0)
		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] })
		if tot <= k {
			Fprintln(out, 0)
			continue
		}
		ans := tot - k
		for i, s := n-1, a[0]-ans; i > 0; i-- {
			s += a[i]
			var x int64
			y := int64(n - i + 1)
			if s >= 0 {
				x = s / y
			} else {
				x = (s - y + 1) / y
			}
			x = min(x, a[0])
			ans = min(ans, a[0]-x+y-1)
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

func CF1622C(rawIn io.Reader, rawOut io.Writer) {
	in := bufio.NewReader(rawIn)
	out := bufio.NewWriter(rawOut)
	defer out.Flush()

	var cases int
	fmt.Fscan(in, &cases)
	for cc := 0; cc < cases; cc++ {
		var n, k int64
		fmt.Fscan(in, &n, &k)
		arr := make([]int64, n)
		sum := int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(in, &arr[i])
			sum += arr[i]
		}
		fmt.Fprintln(out, findMinOps(n, k, sum, arr))
	}
}

func findMinOps(n, k, sum int64, arr []int64) int64 {
	if sum <= k {
		return 0
	}
	// Upper bound achieved by only use "reduce by 1" rule
	var result int64 = sum - k

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

	subsetSum := make([]int64, n)
	subsetSum[0] = arr[0]
	for i := int64(1); i < n; i++ {
		subsetSum[i] = subsetSum[i-1] + arr[i]
	}

	for numSetToMin := int64(1); numSetToMin < n; numSetToMin++ {
		candidate := result
		afterResets := subsetSum[n-numSetToMin-1] + numSetToMin*arr[0]
		if afterResets <= k {
			candidate = numSetToMin
		} else {
			toReduceTotal := subsetSum[n-numSetToMin-1] - arr[0] - k
			reduceMinTarget := -int64(math.Ceil(float64(toReduceTotal) / float64(numSetToMin+1)))
			reduceMin := int64(math.Abs(float64(arr[0] - reduceMinTarget)))

			candidate = reduceMin + numSetToMin
		}

		if candidate < result {
			result = candidate
		}
	}
	return result
}

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

package main

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

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

func solve(t int) {
	n := readInt()
	k := readInt64()
	a := make([]int64, n)
	var sum int64 = 0

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

	if sum <= k {
		println(0)
		return
	}
	var result int64 = sum - k

	sort.Slice(a, func(i, j int) bool {
		return a[i] > a[j]
	})
	var min int64 = a[len(a)-1]

	for i := 0; i < n-1; i++ {
		sum -= a[i] - min
		var candidateResult int64
		if sum > k {
			candidateResult = int64(i+1) + int64((sum-k+int64(i)+1)/int64(i+2))
		} else {
			candidateResult = int64(i + 1)
		}
		if candidateResult < result {
			// println(a, i, sum, k, candidateResult)
			result = candidateResult
		}
	}

	println(result)
}

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

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

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

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

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

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

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

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

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

package main

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

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

const TAM = 2e5 + 100

var n int
var k int64
var a [TAM]int64
var sufSum [TAM]int64
var prefSum [TAM]int64

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

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

func solveOnlyDecrease() int64 {
	return max(0, prefSum[n]-k)
}

func solveOnlySet() int64 {
	if a[1]*int64(n) > k {
		return prefSum[n]
	}
	var sum = prefSum[n]
	var ans int64 = 0
	for i := n; i >= 0 && sum > k; i-- {
		sum += a[1] - a[i]
		ans++
	}
	return ans
}

func applyOperations(first, prefSum, sets, subtracts int64) int64 {
	return (prefSum - subtracts) + (first-subtracts)*sets
}

func minSubtractOperations(first, prefSum, sets int64) int64 {
	var hi int64 = prefSum
	var lo int64 = 0
	var mi int64

	for lo < hi {
		mi = (lo + hi) / 2

		var sum = applyOperations(first, prefSum, sets, mi)
		if sum > k {
			lo = mi + 1
		} else {
			hi = mi
		}
	}

	return lo
}

func solve() int64 {
	var tmp = a[1:(n + 1)]
	sort.Slice(tmp, func(i, j int) bool {
		return tmp[i] < tmp[j]
	})

	prefSum[0] = 0
	sufSum[n+1] = 0
	for i := 1; i <= n; i++ {
		prefSum[i] = a[i] + prefSum[i-1]
	}

	for i := n; i >= 1; i-- {
		sufSum[i] = a[i] + sufSum[i+1]
	}

	var ans = min(solveOnlySet(), solveOnlyDecrease())
	// fmt.Fprintf(out, "init %d\n", ans)
	for sets := 1; sets < n; sets++ {
		var subs = minSubtractOperations(a[1], prefSum[n-sets], int64(sets))
		// fmt.Fprintf(out, "subs for %d are %d\n", subs, sets)
		ans = min(ans, int64(sets)+subs)
	}
	return ans
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fscan(in, &n, &k)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve())
	}
	out.Flush()
}

package main

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

var in = bufio.NewReader(os.Stdin)

func solve() {
	var n int
	var k int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &k)

	a := make([]int64, n)
	var aSum int64 = 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		aSum += a[i]
	}
	if aSum <= k {
		fmt.Println(0)
		return
	}

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

	result := aSum - k
	for i := 1; i < n; i++ {
		aSum -= a[n-i] - a[0]

		minCnt := int64(i + 1)
		decCnt := (aSum - k + minCnt - 1) / minCnt

		cost := decCnt + int64(i)
		if cost < result {
			result = cost
		}
	}
	fmt.Println(result)
}

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
func min(x, y int64)int64{
	if x<y{
		return x
	}
	return y
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n int64
		var k int64
		fmt.Fscan(in,&n,&k)
		a := make([]int64,n+5)
		var i int64
		var sum int64
		sum = 0
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
			sum+=a[i]
		}
		sort.Slice(a[1:n+1],func(i,j int)bool{
			return a[i+1]<a[j+1]
		})
		//fmt.Println(a)
		var l, r int64
		l = 0
		r = 2000000000000000
		var ans int64
		ans = 0
		for l<=r{
			mid := (l+r)>>1
			var cnt int64
			cnt=0
			tar := sum
			for i=n;i>=2;i--{
				if a[i]-a[1]+(cnt+2)*(mid-cnt-1)<((cnt+1)*(mid-cnt)){
					break
				}
				tar -= a[i]-a[1]
				cnt++
			}
			tar = tar -(cnt+1)*(mid-cnt)
			if tar<=k{
				ans = mid
				r=mid-1
			}else{
				l=mid+1
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
func min(x, y int64)int64{
	if x<y{
		return x
	}
	return y
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n int64
		var k int64
		fmt.Fscan(in,&n,&k)
		a := make([]int64,n+5)
		var i int64
		var sum int64
		sum = 0
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
			sum+=a[i]
		}
		sort.Slice(a[1:n+1],func(i,j int)bool{
			return a[i+1]<a[j+1]
		})
		//fmt.Println(a)
		var l, r int64
		l = 0
		r = 2000000000000000
		var ans int64
		ans = 0
		r = 14
		for l<=r{
			mid := (l+r)>>1
			var cnt int64
			cnt=0
			tar := sum
			for i=n;i>=2;i--{
				if a[i]-a[1]+(cnt+2)*(mid-cnt-1)<((cnt+1)*(mid-cnt)){
					break
				}
				tar -= a[i]-a[1]
				cnt++
			}
			tar = tar -(cnt+1)*(mid-cnt)
			if tar<=k{
				ans = mid
				r=mid-1
			}else{
				l=mid+1
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

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

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

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

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

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

func solve() {
	var (
		n int
		k int64
	)
	scan(&n, &k)

	var (
		a = make([]int64, n)
		S int64
	)
	for i := range a {
		scan(&a[i])
		S += a[i]
	}

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

	if n == 1 {
		dx := a[0] - k
		if dx < 0 {
			dx = 0
		}
		printf("%v\n", dx)
		return
	}

	var suffsum = make([]int64, n)
	suffsum[n-1] = a[n-1]
	for i := n - 2; i >= 0; i-- {
		suffsum[i] = suffsum[i+1] + a[i]
	}

	var ans int64 = 1 << 60
	if suffsum[0] <= k {
		ans = 0
	}
	for i := 1; i < len(a); i++ {
		var (
			cnt = int64(len(a) - i)
			s   = S - suffsum[i] + cnt*a[0]
			res = cnt
		)
		if s > k {
			ds := s - k
			dmin := (ds + cnt) / (cnt + 1)
			res += dmin
		}
		if ans > res {
			ans = res
		}
	}

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

package main

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

func solve(A []int, K int64) int64 {
	n := len(A)
	if n == 1 {
		return max(0, int64(A[0])-K)
	}
	sort.Ints(A)
	var sum int64

	for _, num := range A {
		sum += int64(num)
	}

	if sum <= K {
		return 0
	}

	var best int64 = math.MaxInt64

	sum -= int64(A[0])

	for i := n - 1; i > 0; i-- {
		// decrease first to some m
		// and set A[i...]  to A[0]
		// (n - i + 1) * x + sum <= K
		sum -= int64(A[i])
		x := (K - sum) / int64(n-i+1)
		if x*int64(n-i+1) > (K - sum) {
			x--
		}
		a := max(0, int64(A[0])-x)
		best = min(best, a+int64(n-i))
	}

	return best
}

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

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)

	for tc > 0 {
		tc--
		var n int
		var K uint64
		s, _ := reader.ReadBytes('\n')
		pos := readInt(s, 0, &n) + 1
		readUint64(s, pos, &K)
		A := readNNums(reader, n)
		res := solve(A, int64(K))
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

package main

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

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

	t := readInt(reader)

	for t > 0 {
		n, k := readTwoInt(reader)
		a := readArrayInt(reader)

		sort.Ints(a)

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

		ans := int(1e9)
		for t := 0; t < n; t++ {
			partSum := sum + a[0]*t
			cnt := t
			if partSum > k {
				cnt += (partSum - k + t) / (t + 1)
			}

			if ans > cnt {
				ans = cnt
			}

			sum -= a[n-t-1]
		}

		fmt.Fprintln(writer, ans)

		t--
	}

	writer.Flush()
}

func sum(a1 int64, n int64) int64 {
	return (2*a1 + (n-1)*4) * n / 2
}

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"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

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

func main() {
	defer out.Flush()
	//redirectInputToFile(in, "input.txt")

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

func solve() {
	xx := readArrInt()
	n := xx[0]
	target := xx[1]
	arr := readArrInt()
	sort.Ints(arr)
	prefixSum := make([]int, n+1)
	for i := 0; i < n; i++ {
		prefixSum[i+1] = prefixSum[i] + arr[i]
	}
	//println(prefixSum)
	ans := math.MaxInt
	for i := 0; i < n; i++ {
		if prefixSum[n-i]+arr[0]*i < target {
			ans = min(ans, i)
		} else {
			gap := (prefixSum[n-i] + arr[0]*i - target + i) / (i + 1)
			ans = min(gap+i, ans)
		}
	}
	println(ans)

}

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

func reverse(s string) string {
	r := []rune(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)
}

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

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

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

func readFloat(in *bufio.Reader) float64 {
	nStr := readStr()
	n, _ := strconv.ParseFloat(nStr, 64)
	return n
}

func readInt() int {
	nStr := readStr()
	n, _ := strconv.Atoi(nStr)
	return n
}

func readStr() string {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return nStr
}

func readLineNumbs() []string {
	line := readStr()
	numbs := strings.Split(line, " ")
	return numbs
}

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

func readArrFloat() {
	numbs := readLineNumbs()
	arr := make([]float64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseFloat(n, 64)
		arr[i] = val
	}
}

func readArrInt64() []int64 {
	numbs := readLineNumbs()
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

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

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

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

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


You are given two integers $$$l$$$ and $$$r$$$, where $$$l < r$$$. We will add $$$1$$$ to $$$l$$$ until the result is equal to $$$r$$$. Thus, there will be exactly $$$r-l$$$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.For example:   if $$$l=909$$$, then adding one will result in $$$910$$$ and $$$2$$$ digits will be changed;  if you add one to $$$l=9$$$, the result will be $$$10$$$ and $$$2$$$ digits will also be changed;  if you add one to $$$l=489999$$$, the result will be $$$490000$$$ and $$$5$$$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system.Output the total number of changed digits, if you want to get $$$r$$$ from $$$l$$$, adding $$$1$$$ each time.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case is characterized by two integers $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le 10^9$$$).

For each test case, calculate the total number of changed digits if you want to get $$$r$$$ from $$$l$$$, adding one each time.

package main

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

// Math

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

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

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

func interestingFunction(l, r int) int {
	out := 0
	for r > 0 {
		out += r - l
		l /= 10
		r /= 10
	}
	return out
}

package main

import "fmt"

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

	var l, r int
	for ; t > 0; t-- {
		fmt.Scanln(&l, &r)
		fmt.Println(interestingFunction(l, r))
	}
}

func interestingFunction(l, r int) int {
	out := 0
	for r > 0 {
		out += r - l
		l /= 10
		r /= 10
	}
	return out
}

package main

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

var in *bufio.Reader

func count(x int64) int64 {
	result := x
	for x > 0 {
		x /= 10
		result += x
	}
	return result
}

func solve() {
	var l, r int
	fmt.Fscan(in, &l, &r)

	fmt.Println(count(int64(r)) - count(int64(l)))
}

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

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

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

package main

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

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

	type pair struct {
		x, y int
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var l, r int64
		Fscan(in, &l, &r)

		right := r
		for i, j := int64(1), int64(10); r / j != 0; j *= 10 {
			right += i * (r / j) - (i-1) * (r / j)
			i++
		}
		left := l
		for i, j := int64(1), int64(10); l / j != 0; j *= 10 {
			left += i * (l / j) - (i-1) * (l / j)
			i++
		}
		Fprintln(out, right - left)
	}
}

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

func decomposition(a int) int {
	var ans int
	for p := 2; a >= p * p; {
		if a % p == 0 {
			a /= p
			ans++
		} else {
			p++
		}
	}
	if a != 1 {
		ans++
	}
	return ans
}

package main

import (
	"bufio"
	"fmt"
	"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()
	t := 0
	fmt.Fscan(in, &t)
	for i := 0; i < t; i ++ {
		solve := func() {
			l, r, ans := 0, 0, 0
			fmt.Fscan(in, &l, &r)
			for ; l > 0 || r > 0; l, r = l / 10, r / 10{
				ans += r - l
			}
			fmt.Fprintln(out, ans)
		}
		solve()
	}
}

package main

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

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

	var t int

	fmt.Fscan(read, &t)

	for i := 0; i  < t; i++ {

		var l, r int
		fmt.Fscan(read, &l, &r)

		fmt.Println(solve(l, r))
	}
}

func solve(l, r int) int64 {

	m := l

	var left int64

	cnt := 1
	for i := 1; i < 12 ; i++ {
		if m < cnt {
			break
		}

		left += int64(m)/int64(cnt)

		cnt *= 10
	}

	m = r

	var right int64

	cnt = 1
	for i := 1; i < 12 ; i++ {
		if m < cnt {
			break
		}

		right += int64(m)/int64(cnt)

		cnt *= 10
	}

	return right - left
}
//1111111110
//1111111102

package main

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

func calculate(n int) int64 {
	ans := int64(n)
	n /= 10
	for i := n; i > 0; i /= 10 {
		ans += int64(i)
	}
	return ans
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	solve := func(Case int) {
		var l, r int
		fmt.Fscan(in, &l, &r)
		fmt.Fprintln(out, calculate(r)-calculate(l))

	}

	T := 1
	fmt.Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}
}

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

func min(a []int) int {
	mn := int(1e9)
	for i := range a {
		if a[i] < mn {
			mn = a[i]
		}
	}
	return mn
}
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

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()

	f := func(n int64) (s int64) {
		t := int64(1)
		for n >= t {
			s += n / t
			t *= 10
		}
		return
	}

	solve := func(Case int) {
		var l, r int64
		Fscan(in, &l, &r)
		Fprintln(out, f(r)-f(l))
	}

	T := 1
	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) }