Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day.Sadly, he's going on a vacation for a day, and he isn't able to continue his solving streak on his own. As Katie is a reliable person, Kuro kindly asked her to come to his house on this day to play the game for him.Initally, there is an empty array $$$a$$$. The game consists of $$$q$$$ tasks of two types. The first type asks Katie to add a number $$$u_i$$$ to $$$a$$$. The second type asks Katie to find a number $$$v$$$ existing in $$$a$$$ such that $$$k_i \mid GCD(x_i, v)$$$, $$$x_i + v \leq s_i$$$, and $$$x_i \oplus v$$$ is maximized, where $$$\oplus$$$ denotes the bitwise XOR operation, $$$GCD(c, d)$$$ denotes the greatest common divisor of integers $$$c$$$ and $$$d$$$, and $$$y \mid x$$$ means $$$x$$$ is divisible by $$$y$$$, or report -1 if no such numbers are found.Since you are a programmer, Katie needs you to automatically and accurately perform the tasks in the game to satisfy her dear friend Kuro. Let's help her!

The first line contains one integer $$$q$$$ ($$$2 \leq q \leq 10^{5}$$$) — the number of tasks the game wants you to perform. $$$q$$$ lines follow, each line begins with an integer $$$t_i$$$ — the type of the task:    If $$$t_i = 1$$$, an integer $$$u_i$$$ follow ($$$1 \leq u_i \leq 10^{5}$$$) — you have to add $$$u_i$$$ to the array $$$a$$$.  If $$$t_i = 2$$$, three integers $$$x_i$$$, $$$k_i$$$, and $$$s_i$$$ follow ($$$1 \leq x_i, k_i, s_i \leq 10^{5}$$$) — you must find a number $$$v$$$ existing in the array $$$a$$$ such that $$$k_i \mid GCD(x_i, v)$$$, $$$x_i + v \leq s_i$$$, and $$$x_i \oplus v$$$ is maximized, where $$$\oplus$$$ denotes the XOR operation, or report -1 if no such numbers are found.  It is guaranteed that the type of the first task is type $$$1$$$, and there exists at least one task of type $$$2$$$.

For each task of type $$$2$$$, output on one line the desired number $$$v$$$, or -1 if no such numbers are found.

NoteIn the first example, there are 5 tasks:   The first task requires you to add $$$1$$$ into $$$a$$$. $$$a$$$ is now $$$\left\{1\right\}$$$.  The second task requires you to add $$$2$$$ into $$$a$$$. $$$a$$$ is now $$$\left\{1, 2\right\}$$$.  The third task asks you a question with $$$x = 1$$$, $$$k = 1$$$ and $$$s = 3$$$. Taking both $$$1$$$ and $$$2$$$ as $$$v$$$ satisfies $$$1 \mid GCD(1, v)$$$ and $$$1 + v \leq 3$$$. Because $$$2 \oplus 1 = 3 > 1 \oplus 1 = 0$$$, $$$2$$$ is the answer to this task.  The fourth task asks you a question with $$$x = 1$$$, $$$k = 1$$$ and $$$s = 2$$$. Only $$$v = 1$$$ satisfies $$$1 \mid GCD(1, v)$$$ and $$$1 + v \leq 2$$$, so $$$1$$$ is the answer to this task.  The fifth task asks you a question with $$$x = 1$$$, $$$k = 1$$$ and $$$s = 1$$$. There are no elements in $$$a$$$ that satisfy the conditions, so we report -1 as the answer to this task.

package main

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

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

const N = int(1e5 + 10)

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

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

type Trie struct {
	v int
	nxt [2]*Trie
}

func (t *Trie) init() {
	t.v, t.nxt[0], t.nxt[1] = -1, nil, nil
}

var root Trie

func insert(x int) {
	cur := &root
	for i := 30; i >= 0; i-- {
		c := x & (1 << uint(i))
		if c > 0 {
			c = 1
		}
		if cur.v == -1 {
			cur.v = x
		} else {
			cur.v = min(cur.v, x)
		}
		//fmt.Println(i, c)
		if cur.nxt[c] == nil {
			cur.nxt[c] = &Trie{-1, [2]*Trie{nil, nil}}
		}
		cur = cur.nxt[c]
	}
	cur.v = x
}

func query(x, s int) int {
	cur := &root
	for i := 30; i >= 0; i-- {
		xx := x & (1 << uint(i))
		if xx > 0 {
			xx = 1
		}
		if cur.nxt[1-xx] != nil && cur.nxt[1-xx].v <= s {
			cur = cur.nxt[1-xx]
		} else if cur.nxt[xx] != nil && cur.nxt[xx].v <= s {
			cur = cur.nxt[xx]
		} else {
			return -1
		}
	}
	return cur.v
}

func main() {
	defer out.Flush()

	var q, t, x, k, s int
	mp := make([]bool, N)

	fmt.Fscan(in, &q)
	mx := 0
	root.init()
	for ; q > 0; q-- {
		//fmt.Println(q)
		fmt.Fscan(in, &t)
		if t == 1 {
			fmt.Fscan(in, &x)
			mp[x] = true
			mx = max(mx, x)
			insert(x)
			continue
		}
		fmt.Fscan(in, &x, &k, &s)
		if x%k != 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		s = min(mx, s-x)
		//fmt.Println(x, k, s)
		if k > 1 {
			mx := -1
			ret := -1
			for i := k; i <= s; i += k {
				if mp[i] {
					if (i^x) > mx {
						mx = i ^ x
						ret = i
					}
				}
			}
			fmt.Fprintln(out, ret)
			continue
		}
		fmt.Fprintln(out, query(x, s))
	}
}

package main

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

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

const N = int(1e5 + 10)

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

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

type Trie struct {
	v int
	nxt [2]*Trie
}

func (t *Trie) init() {
	t.v, t.nxt[0], t.nxt[1] = -1, nil, nil
}

var root Trie

func insert(x int) {
	cur := &root
	for i := 30; i >= 0; i-- {
		c := x & (1 << uint(i))
		if c > 0 {
			c = 1
		}
		//fmt.Println(i, c)
		if cur.nxt[c] == nil {
			cur.nxt[c] = &Trie{-1, [2]*Trie{nil, nil}}
		}
		cur = cur.nxt[c]
	}
	cur.v = x
}

func query(x, s int) int {
	cur := &root
	flag := false
	for i := 30; i >= 0; i-- {
		xx := x & (1 << uint(i))
		if xx > 0 {
			xx = 1
		}
		if flag {
			if cur.nxt[1-xx] != nil {
				cur = cur.nxt[1-xx]
			} else {
				cur = cur.nxt[xx]
			}
		} else {
			ss := s & (1 << uint(i))
			if ss > 0 {
				ss = 1
			}
			if ss == 0 {
				if cur.nxt[0] != nil {
					cur = cur.nxt[0]
				} else {
					return -1
				}
			} else {
				if cur.nxt[1-xx] != nil {
					cur = cur.nxt[1-xx]
					if xx == 1 {
						flag = true
					}
				} else if cur.nxt[xx] != nil {
					cur = cur.nxt[xx]
					if xx == 0 {
						flag = true
					}
				} else {
					return -1
				}
			}
		}
	}
	return cur.v
}

func main() {
	defer out.Flush()

	var q, t, x, k, s int
	mp := make([]bool, N)

	fmt.Fscan(in, &q)
	mx := 0
	root.init()
	for ; q > 0; q-- {
		//fmt.Println(q)
		fmt.Fscan(in, &t)
		if t == 1 {
			fmt.Fscan(in, &x)
			mp[x] = true
			mx = max(mx, x)
			insert(x)
			continue
		}
		fmt.Fscan(in, &x, &k, &s)
		if x%k != 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		s = min(mx, s-x)
		//fmt.Println(x, k, s)
		if k > 1 {
			mx := -1
			ret := -1
			for i := k; i <= s; i += k {
				if mp[i] {
					if (i^x) > mx {
						mx = i ^ x
						ret = i
					}
				}
			}
			fmt.Fprintln(out, ret)
			continue
		}
		fmt.Fprintln(out, query(x, s))
	}
}


Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?

The first line contains the only integer n (1 ≤ n ≤ 100) — the number of cookie bags Anna and Maria have. The second line contains n integers ai (1 ≤ ai ≤ 100) — the number of cookies in the i-th bag.

Print in the only line the only number — the sought number of ways. If there are no such ways print 0.

NoteIn the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.

package main

import (
	"fmt"
)

func main() {
	var n, s, ans, f int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		s += a[i]
	}

	for i := 0; i < n; i++ {
		if (s-a[i])%2 == 0 {
			ans++
		}
	}

	fmt.Println(ans)
	fmt.Scan(&f)
}

package main

import (
	"fmt"
)

func main() {
	var n, cnt, sum int
	fmt.Scan(&n)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		sum += a[i]
	}
	for i := 0; i < n; i++ {
		if (sum-a[i])%2 == 0 {
			cnt += 1
		}
	}
	fmt.Println(cnt)
}

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
)

func main() {
	var n int
	x:=make([]int,105)
	k,l:=0,0
	fmt.Scan(&n)
	for i:=0;i<n;i++ {
		fmt.Scan(&x[i])
		k+=x[i]
	}
	for i:=0;i<n;i++ {
			if (k-x[i])%2==0 {
				l++
			}
	}
	fmt.Println(l)
}

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 := getI()
  even := 0
  for i := 0; i < n; i++ {
    if getI()%2 == 0 {
      even++
    }
  }
  odd := n - even
  result := even
  if odd%2 == 1 {
    result = odd
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

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

	var eo [2]int

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

	if eo[1]%2 == 0 {
		fmt.Println(eo[0])
	} else {
		fmt.Println(eo[1])
	}
}

package main

import "fmt"

func main() {
    var n int
    var a [105]int
    ans, total := 0, 0
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
        total += a[i]
    }
    for i := 0; i < n; i++ {
        if (total-a[i]) % 2 == 0 { ans++ }
    }
    fmt.Println(ans)
}

//http://codeforces.com/contest/129/problem/A
package main

import (
	"fmt"
	"log"
)

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		log.Fatal(err)
	} else {
		cookiesInBags := make([]int, n)
		totalCookies := 0
		for i := 0; i < n; i++ {
			_, err := fmt.Scan(&cookiesInBags[i])
			if err == nil {
				totalCookies += cookiesInBags[i]
			}
		}
		fmt.Println(countWays(cookiesInBags, totalCookies))
	}
}

func countWays(cookiesInBags []int, totalCookies int) int {
	isEven := false
	if totalCookies%2 == 0 {
		isEven = true
	}
	res := 0

	if isEven {
		evenCount := 0
		for i := 0; i < len(cookiesInBags); i++ {
			currentNumber := cookiesInBags[i]
			if currentNumber%2 == 0 {
				evenCount++
			}
		}
		res = evenCount
	} else {
		oddCount := 0
		for i := 0; i < len(cookiesInBags); i++ {
			currentNumber := cookiesInBags[i]
			if currentNumber%2 != 0 {
				oddCount++
			}
		}
		res = oddCount
	}

	return res
}

// 129A
package main

import (
	"fmt"
)

func main() {
	var n, a int
	o, e := 0, 0
	fmt.Scan(&n)
	for i := o; i < n; i++ {
		fmt.Scan(&a)
		if a%2 == 0 {
			e++
		} else {
			o++
		}
	}
	if o%2 == 0 {
		fmt.Println(e)
	} else {
		fmt.Println(o)
	}

}

// 129A-mic
package main

import (
    "fmt"
)

func main() {
    var n, s, o, e int
    fmt.Scan(&n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
        s += a[i]
        if a[i]%2 == 0 {
            e++
        } else {
            o++
        }
    }
    if s%2 == 0 {
        fmt.Println(e)
    } else {
        fmt.Println(o)
    }

}


Berland year consists of $$$m$$$ months with $$$d$$$ days each. Months are numbered from $$$1$$$ to $$$m$$$. Berland week consists of $$$w$$$ days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than $$$w$$$ days.A pair $$$(x, y)$$$ such that $$$x < y$$$ is ambiguous if day $$$x$$$ of month $$$y$$$ is the same day of the week as day $$$y$$$ of month $$$x$$$.Count the number of ambiguous pairs.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$m$$$, $$$d$$$ and $$$w$$$ ($$$1 \le m, d, w \le 10^9$$$) — the number of months in a year, the number of days in a month and the number of days in a week.

Print $$$t$$$ integers — for each testcase output the number of pairs $$$(x, y)$$$ such that $$$x < y$$$ and day $$$x$$$ of month $$$y$$$ is the same day of the week as day $$$y$$$ of month $$$x$$$.

NoteHere are the pairs for the first test case:

package main

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

func gcd(a,b int64) int64{
	if(a==0 || b==0){
		return a+b
	}
	return gcd(b,a%b)
}

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var m,d,w,ans int64
		Fscan(in, &m,&d,&w);
		if m>d{
			m=d
		}
		d--
		if d%w==0{
			Fprintln(out,m*(m-1)/2)
			continue
		}
		d=w/gcd(d,w)
		ans+=m*(m/d)
		m/=d
		ans-=(m*(m+1)/2)*d
		Fprintln(out,ans)
	}
}

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

package main

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

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

	var gcd func(i, j int) int
	gcd = func(i, j int) int {
		if j == 0 {
			return i
		}
		return gcd(j, i%j)
	}

	for t := io.nextInt(); t > 0; t-- {
		m, d, w := io.nextInt(), io.nextInt(), io.nextInt()
		g := gcd(d-1, w)
		w /= g
		n := d
		if n > m {
			n = m
		}
		q, r := int64(n/w), int64(n%w)
		ans := q*(q-1)/2*(int64(w)-r) + q*(q+1)/2*r
		io.println(ans)
	}
}

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

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	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) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

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

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, 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()
}


Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.

The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

package main

import (
	"fmt"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	var firstDiv int64
	if a == 0 || a % k == 0 {
		firstDiv = a
	} else {
		if a < 0 {
			firstDiv = a - a % k
		} else {
			firstDiv = a + (k - a % k)
		}
	}

	var lastDiv int64
	if b == 0 || b % k == 0 {
		lastDiv = b
	} else {
		if b < 0 {
			lastDiv = b - (k + b % k)
		} else {
			lastDiv = b - b % k
		}
	}

	//fmt.Println("firstDiv", firstDiv)
	//fmt.Println("lastDiv", lastDiv)
	countDivs := (lastDiv - firstDiv) / k + 1
	fmt.Println(countDivs)
}

package main

import (
	"fmt"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	countDivs := ((b - a) / k) + 1
	fmt.Println(countDivs)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	var firstDiv int64
	if a % k == 0 {
		firstDiv = a
	} else {
		firstDiv = a + (k - abs(a % k))
	}

	var lastDiv int64
	if b % k == 0 {
		lastDiv = b
	} else {
		lastDiv = b - abs(b % k)
	}

	//fmt.Println("firstDiv", firstDiv)
	//fmt.Println("lastDiv", lastDiv)
	countDivs := (lastDiv - firstDiv) / k + 1
	fmt.Println(countDivs)
}

func abs(from int64) int64 {
	return int64(math.Abs(float64(from)))
}

package main

import (
	"fmt"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	var countDivs int64
	if a > k*-1 && b < k {
		countDivs = 1
	} else if k == 1 {
		countDivs = b - a + 1
	} else {
		countDivs = (b - a) / k
		if (b <= 0 && a >= 0) || a % k == 0 || b % k == 0 {
			countDivs += 1
		}
	}
	fmt.Println(countDivs)
}

package main

import (
	"fmt"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	var countDivs int64
	if a < k && b < k {
		countDivs = 1
	} else {
		countDivs = ((b - a) / k) + 1
	}
	fmt.Println(countDivs)
}

package main

import (
	"fmt"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	var countDivs int64
	if a > k*-1 && b < k {
		countDivs = 1
	} else {
		countDivs = ((b - a) / k) + 1
	}
	fmt.Println(countDivs)
}

package main

import (
	"fmt"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	firstDiv := findFirstDiv(a, k)
	lastDiv := findLastDiv(b, k)

	fmt.Println("firstDiv", firstDiv)
	fmt.Println("lastDiv", lastDiv)
	countDivs := (lastDiv-firstDiv)/k + 1
	fmt.Println(countDivs)
}

func findFirstDiv(x, k int64) int64 {
	var firstDiv int64
	if x >= 0 {
		if x%k == 0 {
			firstDiv = x
		} else {
			firstDiv = x + (k - x%k)
		}
	} else {
		firstDiv = x
		for true {
			if firstDiv%k == 0 {
				break
			}
			firstDiv++
		}
	}
	return firstDiv
}

func findLastDiv(x, k int64) int64 {
	var lastDiv int64
	if x >= 0 {
		if x%k == 0 {
			lastDiv = x
		} else {
			lastDiv = x - x%k
		}
	} else {
		lastDiv = x
		for true {
			if lastDiv%k == 0 {
				break
			}
			lastDiv--
		}
	}
	return lastDiv
}

package main

import (
	"fmt"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	var firstDiv int64
	if a % k == 0 {
		firstDiv = a
	} else {
		firstDiv = a + (k - a % k)
	}

	var lastDiv int64
	if b % k == 0 {
		lastDiv = b
	} else {
		lastDiv = b - b % k
	}

	countDivs := (lastDiv - firstDiv) / k + 1
	fmt.Println(countDivs)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var k int64
	var a int64
	var b int64

	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	//fmt.Println(k, a, b)
	var firstDiv int64
	if a % k == 0 {
		firstDiv = a
	} else {
		firstDiv = a + (k - abs(a % k))
	}

	var lastDiv int64
	if b % k == 0 {
		lastDiv = b
	} else {
		lastDiv = b - b % k
	}

	//fmt.Println("firstDiv", firstDiv)
	//fmt.Println("lastDiv", lastDiv)
	countDivs := (lastDiv - firstDiv) / k + 1
	fmt.Println(countDivs)
}

func abs(from int64) int64 {
	return int64(math.Abs(float64(from)))
}


Mishka wants to buy some food in the nearby shop. Initially, he has $$$s$$$ burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $$$1 \le x \le s$$$, buy food that costs exactly $$$x$$$ burles and obtain $$$\lfloor\frac{x}{10}\rfloor$$$ burles as a cashback (in other words, Mishka spends $$$x$$$ burles and obtains $$$\lfloor\frac{x}{10}\rfloor$$$ back). The operation $$$\lfloor\frac{a}{b}\rfloor$$$ means $$$a$$$ divided by $$$b$$$ rounded down.It is guaranteed that you can always buy some food that costs $$$x$$$ for any possible value of $$$x$$$.Your task is to say the maximum number of burles Mishka can spend if he buys food optimally.For example, if Mishka has $$$s=19$$$ burles then the maximum number of burles he can spend is $$$21$$$. Firstly, he can spend $$$x=10$$$ burles, obtain $$$1$$$ burle as a cashback. Now he has $$$s=10$$$ burles, so can spend $$$x=10$$$ burles, obtain $$$1$$$ burle as a cashback and spend it too.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given on a separate line and consists of one integer $$$s$$$ ($$$1 \le s \le 10^9$$$) — the number of burles Mishka initially has.

For each test case print the answer on it — the maximum number of burles Mishka can spend if he buys food optimally.

package main

import "fmt"

func FoodBuying(s int) int {
	rs := s
	for ; s >= 10; {
		d := s % 10
		n := s / 10
		rs += n
		s = n +d
	}
	return rs
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var s int
		fmt.Scanf("%d\n", &s)
		fmt.Println(FoodBuying(s))
	}
}

package main

import "fmt"

var (
	t int
)

func main() {
	fmt.Scan(&t)
	for cnt := 1; cnt <= t; cnt++ {
		var s, ans, tmp int
		fmt.Scan(&s)
		tmp = s
		for {
			var refound, yu = tmp / 10, tmp % 10
			ans += refound * 10
			if tmp < 10 {
				ans += tmp
				break
			}
			tmp = refound + yu
		}
		fmt.Println(ans)
	}
}

package main

import "fmt"

func buyFood(t int) int {
	for t > 0 {
		var s int
		fmt.Scan(&s)
		ans := 0
		pw := 1000 * 1000 * 1000
		for s > 0{
			for s < pw {
				pw /= 10
			}
			ans += pw
			s -= pw - pw / 10
		}
		fmt.Println(ans)
		t--
	}
	return 0
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
// 9876 = 9870 + 987 + 6 = 9870 + 990 + 3 = 9870 + 990 + 99 + 3 = 9870 + 990 + 100 + 10 + 3 =
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	cases := getIntFromInput(scanner)
	for i:=int64(0);i<cases;i++ {
		num := getIntFromInput(scanner)
		result := int64(0)
		for num / 10 > 0 {
			left := num % 10
			i := num / 10
			result += i * 10
			num = left + i
		}
		result += num
		fmt.Println(result)
	}

}

func getIntFromInput(s *bufio.Scanner) int64 {
	s.Scan()
	numStr := s.Text()
	num,_ := strconv.ParseInt(numStr, 10, 64)
	return num
}

package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

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 scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(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()
}

//•*¨*•.¸¸♪func(int)•*¨*•.¸¸♪
func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

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

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

	in := scanInt()

	for t := 0; t < in; t++ {
		s := scanInt64()
		ans := s

		for s != 0 {
			x := int64(1)
			for s/x/10 != 0 {
				x *= 10
			}

			ans += (s/x)*(x/10)
			s = s%x + (s/x)*(x/10)
		}

		fmt.Println(ans)
	}
}

package main

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

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var s int64
		fmt.Fscanf(reader, "%d\n", &s)

		ans := s
		for s > 0 {
			ans += s / 10
			if s >= 10 {
				s = (s % 10) + (s / 10)
			} else {
				s = 0
			}
		}

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

package main

import (
	"fmt"
)

func main() {
	t := 0
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		s := int64(0)
		fmt.Scanln(&s)
		s1 := s
		for s >= 10 {
			cb := s / 10
			s  = s % 10 + cb
			s1 += cb
		}
		fmt.Println(s1)
	}
}

// https://serhatgiydiren.github.io

package main

import "fmt"
import "os"
import "bufio"

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

func solve(test_id int) {
 var n int
 res := 0
 fmt.Fscanf(reader, "%d\n", &n)
 for ; n > 9 ; {
  val := n - n % 10
  res += val
  n = val / 10 + n % 10
 }
 fmt.Fprintf(writer,"%d\n", n + res)
}

func solve_cases() {
 defer writer.Flush()
 t := 1
 fmt.Fscanf(reader, "%d\n", &t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

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

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

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

func solve() {
	var n int64
	scanf("%d\n", &n)
	var ans int64
	for n > 9 {
		ans += n - n % 10
		n = n / 10 + n % 10
	}
	ans += n
	printf("%d\n", ans)
}

func main() {
	t := 1
	scanf("%d\n", &t)
	for t > 0 {
		 solve()
		 t--
	}
	writer.Flush()
}

package main

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

func main() {
	for testCase := scanInt(); testCase > 0; testCase--{
		n := scanInt()
		answer := 0

		for n >= 10{
			answer += n - n % 10
			n = n % 10 + n / 10
		}
		answer += n
		printFmt(answer)
	}
	close(channelType)
	oWg.Wait()
}

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

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

func init() {
	printFmt = fmt.Println

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

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

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

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

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if (a == 0) {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}
func min(args ...int) int { mn, _ := minMaxFinder(args...); return mn }
func max(args ...int) int { _, mx := minMaxFinder(args...); return mx }
func minMaxFinder(args ...int) (int, int) { minVal, maxVal := int(math.MaxInt32), int(math.MinInt32); for _, v := range args { if v < minVal { minVal = v }; if v > maxVal { maxVal = v } }; return minVal, maxVal }

package main

import "fmt"

func sum(a int,b int) int {

	b+=a/10

	if a/10<1 {
		return b
	}
	return sum(a/10+a%10,b)
}

func main(){
	var x int
	var y int
	var s []int
	fmt.Scanf("%d",&y)
	s = make([]int, y,y)

	for i:=0;i<y;i++{
	    fmt.Scanln()
		fmt.Scanf("%d",&x)
		s[i]=x
	}
	for i:=0;i<y;i++{
		fmt.Println(sum(s[i],0)+s[i])
	}
}

package main

import "fmt"

func sum(a int,b int) int {

	b+=a/10

	if a/10<1 {
		return b
	}
	return sum(a/10+a%10,b)
}

func main(){
	var x int
	var y int
	fmt.Scanln(&y)
	for i:=0;i<y;i++{
	    fmt.Scanln(&x)
	    fmt.Println(sum(x,0)+x)
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin);
	out := bufio.NewWriter(os.Stdout);
	var t int;
	fmt.Fscan(in, &t);
	for i := 0; i < t; i++ {
		s, ans := 0, 0;
		fmt.Fscan(in, &s);
		for ; s / 10 > 0; s -= (s / 10)*10 - s / 10 {
			ans += (s/10)*10;
		}
		ans += s;
		fmt.Fprintln(out, ans);
	}
	out.Flush();
}

package main

import "fmt"

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

	for t > 0 {
		var a uint
		fmt.Scan(&a)
		sum := a
		for a >= 10 {
			sum += a / 10
			a = (a / 10) + (a % 10)
		}
		fmt.Println(sum)
		t--
	}
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Buffer(make([]byte, 1<<12), 1<<20)

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

	s.Scan()
	t, _ := strconv.Atoi(s.Text())

	for i := 0; i < t; i++ {
		s.Scan()
		n, _ := strconv.Atoi(s.Text())
		k := 0
		for n >= 10 {
			k += (n / 10) * 10
			n = n/10 + n%10
		}
		k += n
		fmt.Fprintln(w, k)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int

	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		var s, max uint64
		fmt.Scanln(&s)

		max = s
		for {
			remain := s % 10
			s = s / 10
			max += s
			if s == 0 {
				break
			}

			s += remain
		}

		fmt.Println(max)
	}
}

package main

import "fmt"

var (
	t int
)

func main() {
	fmt.Scan(&t)
	for cnt := 1; cnt <= t; cnt++ {
		var ans, tmp int
		fmt.Scan(&ans)
		tmp = ans
		for tmp != 0 {
			var refound, yu = tmp / 10, tmp % 10
			if yu >= 5 && refound != 0 {
				ans++
			}
			ans += refound
			tmp = refound
		}
		fmt.Println(ans)
	}
}

package main

import "fmt"

func sum(a int,b int) int {

	b+=a/10

	if a/10<1 {
		return b
	}
	return sum(a/10+a%10,b)
}

func main(){
	var x int
	var y int
	var s []int
	fmt.Scanf("%d",&y)
	s = make([]int, y)

	for i:=0;i<y;i++{
		fmt.Scanf("%d",&x)

		s[i]=x
	}
	for i:=0;i<y;i++{
		fmt.Println(sum(s[i],0)+s[i])
	}
}

package main

import "fmt"

func sum(a int,b int) int {

	b+=a/10

	if a/10<1 {
		return b
	}
	return sum(a/10+a%10,b)
}

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

	for i:=0;i<y;i++{
		fmt.Println(sum(x,0)+x)
	}
}

package main

import "fmt"

func sum(a int,b int) int {

	b+=a/10

	if a/10<1 {
		return b
	}
	return sum(a/10+a%10,b)
}

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

	for i:=0;i<y;i++{
		fmt.Scanf("%d",&x)
		fmt.Println(sum(x,0)+x)
	}
}

package main

import "fmt"

func sum(a int,b int) int {

	b+=a/10

	if a/10<1 {
		return b
	}
	return sum(a/10+a%10,b)
}

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

	for i:=0;i<6;i++{
		fmt.Println(sum(x,0)+x)
	}
}

package main

import "fmt"

func sum(a []int) string {
	var sum int

	for index:=0;index<len(a);index++{
		sum+=a[index]
	}
	if sum%2==1 {
		return "YES"
	}

	if sum%2==0{
		for m:=0;m<len(a);m++{
			for n:=m+1; n<len(a);n++{
				if (a[m]+a[n])%2==1 {
					return "YES"
				}
			}
		}
	}

	return "NO"
}

func main(){
	var x int
	var n int

	fmt.Scan(&n)
	for i:=0;i<n;i++{
		fmt.Scan(&x)
		var list = make([]int,x,x)
		for i:=0;i<x;i++ {
			fmt.Scan(&list[i])
		}
		fmt.Println(sum(list))
	}
}

package main

import "fmt"

func sum(a int,b int) int {

	b+=a/10

	if a/10<1 {
		return b
	}
	return sum(a/10+a%10,b)
}

func main(){
	var x int
	fmt.Scanf("%d",&x)
	fmt.Println(sum(x,0)+x)

}


A string $$$a=a_1a_2\dots a_n$$$ is called even if it consists of a concatenation (joining) of strings of length $$$2$$$ consisting of the same characters. In other words, a string $$$a$$$ is even if two conditions are satisfied at the same time:  its length $$$n$$$ is even;  for all odd $$$i$$$ ($$$1 \le i \le n - 1$$$), $$$a_i = a_{i+1}$$$ is satisfied. For example, the following strings are even: "" (empty string), "tt", "aabb", "oooo", and "ttrrrroouuuuuuuukk". The following strings are not even: "aaa", "abab" and "abba".Given a string $$$s$$$ consisting of lowercase Latin letters. Find the minimum number of characters to remove from the string $$$s$$$ to make it even. The deleted characters do not have to be consecutive.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. The descriptions of the test cases follow. Each test case consists of one string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$), where $$$|s|$$$ — the length of the string $$$s$$$. The string consists of lowercase Latin letters. It is guaranteed that the sum of $$$|s|$$$ on all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single number — the minimum number of characters that must be removed to make $$$s$$$ even.

6

aabbdabdccc

zyx

aaababbb

aabbcc

oaoaaaoo

bmefbmuyw

NoteIn the first test case you can remove the characters with indices $$$6$$$, $$$7$$$, and $$$9$$$ to get an even string "aabbddcc".In the second test case, each character occurs exactly once, so in order to get an even string, you must remove all characters from the string.In the third test case, you can get an even string "aaaabb" by removing, for example, $$$4$$$-th and $$$6$$$-th characters, or a string "aabbbb" by removing the $$$5$$$-th character and any of the first three.

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for t := t; t > 0; t-- {
		var s string
		fmt.Fscanf(in, "%s\n", &s)
		s = "#" + s
		n := len(s)
		d := make([]int, n)
		m := make(map[uint8]int)
		for i := 1; i < n; i++ {
			j := m[s[i]]
			d[i] = d[i-1] + 1
			if j > 0 {
				k := i - j - 1 + d[j-1]
				if k < d[i] {
					d[i] = k
				}
			}
			m[s[i]] = i
		}
		fmt.Fprintln(out, d[n-1])
	}
}

package main

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

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

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

	cases := 0
	Fscan(in, &cases)

	var str string
	var n int

	for ; cases > 0; cases-- {
		Fscan(in, &str)
		n = len(str)
		str = "!" + str
		dp := make([]int, n+1) //dp[i]表示 第i个元素需要满足even string最少需要remove的个数
		dp[0] = 0              //初始化dp，表示移除0个元素最少需要0次
		vis := make(map[byte]int)
		for i := 1; i <= n; i++ {
			if pos, ok := vis[str[i]]; !ok {
				dp[i] = dp[i-1] + 1
			} else {
				dp[i] = min(dp[i-1]+1, dp[pos-1]+(i-pos-1))
			}
			vis[str[i]] = i
		}
		Fprintf(out, "%d\n", dp[n])
	}
}

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

package main

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

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

var in = bufio.NewReader(os.Stdin)

func solve(){
	var s string
	fmt.Fscan(in,&s)
	n:=len(s)
	s=" " + s
	dp:=make([]int,n+1)
	pos:=make([]int,26)

	// fmt.Print(s,n," ")
	for i:=1;i<=n;i++{
		dp[i]=dp[i-1] + 1
		l:=pos[s[i]-'a']
		if l>0 {
			dp[i]=min(dp[i],dp[l-1] + i - l - 1)
		}
		pos[s[i]-'a']=i;
	}

	fmt.Println(dp[n])
}
func main() {
	var tc int
    fmt.Scan(&tc)
	// fmt.Print(tc)
	for i:=0;i<tc;i++{
		solve()
	}
}

package main

import (
	"fmt"
	"strings"
)

// abcbd

// a != b
// a = 1
// b = 1
// c = 1
// b = 2

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

func cost(s string, from int, memo map[int]int) int {
	if from == (len(s) - 1) {
		return 1
	}
	if from >= len(s) {
		return 0
	}
	v, ok := memo[from]
	if ok {
		return v
	}
	if s[from] == s[from+1] {
		return cost(s, from+2, memo)
	}
	next := strings.Index(s[from+1:], string(s[from]))
	if next == -1 {
		return 1 + cost(s, from+1, memo)
	}

	dist := (next + from) - from
	resp := min(1+cost(s, from+1, memo), dist+cost(s, (next+from+2), memo))
	memo[from] = resp
	return resp
}
func main() {
	var testCases int
	fmt.Scanf("%d\n", &testCases)

	for i := 0; i < int(testCases); i++ {
		var s string
		fmt.Scanf("%s\n", &s)
		if len(s)%2 == 1 {

		}
		fmt.Println(cost(s, 0, make(map[int]int)))
	}
}

package main

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

/*
7
asdasd
abbbab
aabbccd
eaabbccd
abccba
aabbxxx
abbcca
---
4
2
1
2
4
1
2
--
*/

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

	prev := make([]bool, 26)

	cnt := 0

	for _, r := range s {
		ord := int(r - 'a')

		if prev[ord] {
			for i := range prev {
				prev[i] = false
			}
			cnt += 2
		} else {
			prev[ord] = true
		}
	}

	fmt.Fprintln(writer, len(s)-cnt)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func 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))
}

// https://codeforces.com/problemset/problem/1660/C

// 1660C - Get an Even String

// A string a=a1a2…an is called even if it consists of a concatenation (joining) of strings of length 2 consisting of the same characters. In other words, a string a is even if two conditions are satisfied at the same time:
//  • its length n is even;
//  • for all odd i (1≤i≤n−1), ai=ai+1 is satisfied.
// For example, the following strings are even: "" (empty string), "tt", "aabb", "oooo", and "ttrrrroouuuuuuuukk". The following strings are not even: "aaa", "abab" and "abba".
// Given a string s consisting of lowercase Latin letters. Find the minimum number of characters to remove from the string s to make it even. The deleted characters do not have to be consecutive.

// Input
// The first line of input data contains an integer t (1≤t≤10^4) —the number of test cases in the test.
// The descriptions of the test cases follow.
// Each test case consists of one string s (1≤|s|≤2⋅10^5), where |s| — the length of the string s. The string consists of lowercase Latin letters.
// It is guaranteed that the sum of |s| on all test cases does not exceed 2⋅10^5.

// Output
// For each test case, print a single number — the minimum number of characters that must be removed to make s even.

// Examples
// input
// 6
// aabbdabdccc
// zyx
// aaababbb
// aabbcc
// oaoaaaoo
// bmefbmuyw
// output
// 3
// 3
// 2
// 0
// 2
// 7

// Note

// In the first test case you can remove the characters with indices 6, 7, and 9 to get an even string "aabbddcc".
// In the second test case, each character occurs exactly once, so in order to get an even string, you must remove all characters from the string.
// In the third test case, you can get an even string "aaaabb" by removing, for example, 4-th and 6-th characters, or a string "aabbbb" by removing the 5-th character and any of the first three.

// Tutorial

// We will act greedily: we will make an array prev consisting of 26 elements, in which we will mark prev[i]=true if the letter is already encountered in the string, and prev[i]=false otherwise. In the variable m we will store the length of the even string that can be obtained from s. We will go through the string by executing the following algorithm:
//  • if prev[i]=false, mark prev[i]=true.
//  • if prev[i]=true, then we already have a pair of repeating characters to add to an even string — add 2 to the number m and clear the array used.
// Clearing prev is necessary because both characters that will make up the next pair must be in the s string after the current character. In other words, if the last character in the current pair was st, then the first character in the new pair can be sk, where t<k<n.
// Then we calculate the answer as n−m.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, m, n, i uint
	var s string
	var prev [26]bool
	var char rune

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &s)
			m = 0
			n = uint(len(s))

			for i = 0; i < 26; i++ {
				prev[i] = false
			}

			for _, char = range s {
				if prev[char-'a'] {
					m += 2
					for i = 0; i < 26; i++ {
						prev[i] = false
					}
				} else {
					prev[char-'a'] = true
				}
			}

			fmt.Fprintln(writer, n-m)
		}
	}

	writer.Flush()
}

package main

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

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

	var n int
	Fscan(in, &n)
	for ; n > 0; n-- {
		var s string
		Fscan(in, &s)
		maps := map[byte]int{}
		ans := 0
		for i := 0; i < len(s); i++ {
			indx := s[i]
			if maps[indx] != 0 {
				ans += len(maps) - 1
				maps = map[byte]int{}
			} else {
				maps[indx]++
			}
		}
		ans += len(maps)
		Fprintln(out, ans)
	}
}

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

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
}

package main

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

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

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

	defer out.Flush()

	var T int
	var s string
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &s)
		tmpList := []byte(s)
		tmpMap := map[byte]bool{}
		tmpCount := 0
		for _, v := range tmpList {
			if tmpMap[v] {
				tmpCount--
				tmpMap = map[byte]bool{}
			} else {
				tmpMap[v] = true
				tmpCount++
			}
		}
		fmt.Fprintln(out, tmpCount)
	}
}

package main

// Problem description URL https://atcoder.jp/contests/abc236/tasks/abc240_a

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

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

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

type pair struct {
	Color int
	Size  int
}

var (
	n   = 0
	t   = 0
	a []int
	res []int
	s   *list.List
	cur = 0
)

func solve() {
	scan(&t)
	for t != 0 {
		t--
		str := ""
		scan(&str)
		n = len(str)
		prev := make([]bool, 26)
		m := 0
		for _, c := range str {
			if prev[c - 'a'] {
				m += 2
				for i := 0; i < 26; i++ {
					prev[i] = false
				}
			} else {
				prev[c - 'a'] = true
			}
		}
		printf("%d\n", n - m)
	}
}

func main() {
	defer out.Flush()
	solve()
}

package main

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

const mod = 998244353
const mx = 3000

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var str string
	fmt.Fscan(in,&str)
	m := map[int32]int{}
	cnt := 0
	for _,v := range str{
		if m[v] == 1{
			cnt += 2
			m = map[int32]int{}
		}else{
			m[v] = 1
		}
	}
	fmt.Fprintln(out,len(str) - cnt)
}

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

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

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

package main

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

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

	var T int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		ans := len(s)
		v := 0
		for _, b := range s {
			b := 1 << (b & 31)
			if v&b > 0 {
				ans -= 2
				v = 0
			} else {
				v |= b
			}
		}
		Fprintln(out, ans)
	}
}

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

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

func main() {
  defer writer.Flush()
  var t int
  for scanf("%d\n", &t) ; t > 0 ; t-- {
    var s string
    scanf("%s\n", &s)
    a := []byte(s)
    lastoff := make([]int, 256)
    for i := 0 ; i < 256 ; i++ {
      lastoff[i] = -1
    }
    sameoff := make([]int, len(a))
    x := -1
    for i := len(a) - 1 ; i >= 0 ; i-- {
      if lastoff[a[i]] == -1 {
        sameoff[i] = min(-1, x)
      } else {
        sameoff[i] = min(lastoff[a[i]] - i, x)
      }
      x = sameoff[i]
      if x != -1 {
        x++
      }
      lastoff[a[i]] = i
    }

    ans := 0
    for len(sameoff) > 0 {
      if sameoff[0] == -1 {
        ans++
        sameoff = sameoff[1:]
      } else {
        rem := sameoff[0] + 1
        ans += rem - 2
        sameoff = sameoff[rem:]
      }
    }
    printf("%d\n", ans)
  }
}

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 s string
		fmt.Fscan(in, &s)

		m := make([]bool, 26)
		var tot int64
		var pos int
		for i, ch := range s {
			if !m[ch-'a'] {
				m[ch-'a'] = true
			} else {
				tot += int64((i - pos) - 1)
				pos = i + 1
				m = make([]bool, 26)
			}
		}

		for _, v := range m {
			if v {
				tot++
			}
		}

		fmt.Fprintln(out, tot)
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var s string
		fmt.Fscan(in, &s)
		dp := make([]int, len(s)+1)
		dic := [26]int{}
		for i := 0; i < 26; i++ {
			dic[i] = -1
		}
		for i := 0; i < len(s); i++ {
			dp[i+1] = dp[i] + 1
			if last := dic[s[i]-'a']; last != -1 {
				dp[i+1] = min(dp[i+1], dp[last]+i-last-1)
			}
			dic[s[i]-'a'] = i
		}
		fmt.Fprintln(out, dp[len(s)])

	}
}

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
}

package main

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

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([]int, n)
		m := make(map[uint8][]int)
		for i := 1; i < n; i++ {
			j := m[s[i]]
			d[i] = d[i-1] + 1
			if i > 1 {
				if d[i-2]+2 < d[i] {
					d[i] = d[i-2] + 2
				}
			}
			x := len(j)
			if x > 0 {
				k := i - j[x-1] - 1 + d[j[x-1]-1]
				if x > 1 {
					q := i - j[x-2] - 1 + d[j[x-2]-1]
					if q < k {
						k = q
					}
				}
				if k < d[i] {
					d[i] = k
				}
			}
			if _, ok := m[s[i]]; ok {
				m[s[i]] = append(m[s[i]], i)
			} else {
				m[s[i]] = []int{i}
			}

		}
		fmt.Fprintln(out, d[n-1])
	}
}

package main

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

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

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([]int, n)
		m := make(map[uint8]int)
		for i := 1; i < n; i++ {
			d[i] = d[i-1] + 1
			if i > 1 {
				d[i] = min(d[i], d[i-2]+2)
			}
			j := m[s[i]]
			if j > 0 {
				d[i] = min(d[i], i-j-1+d[j-1])
			}
			m[s[i]] = i
		}
		fmt.Fprintln(out, d[n-1])
	}
}

package main

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

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

const inf = 1e8

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([][]int, n)
		for i := 0; i < n; i++ {
			d[i] = make([]int, 2)
		}
		m := make(map[uint8]int)
		for i := 1; i < n; i++ {
			d[i][0] = min(i, 1+min(d[i-1][0], d[i-1][1]))
			j := m[s[i]]
			if j > 0 {
				d[i][1] = i - j - 1 + min(d[j-1][0], d[j-1][1])
			} else {
				d[i][1] = i
			}
			m[s[i]] = i
		}
		fmt.Fprintln(out, min(d[n-1][0], d[n-1][1]))
	}
}

package main

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

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

const inf = 1e8

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([][]int, n)
		for i := 0; i < n; i++ {
			d[i] = make([]int, 2)
		}
		m := make(map[uint8]int)
		for i := 1; i < n; i++ {
			d[i][0] = 1 + min(d[i-1][0], d[i-1][1])
			j := m[s[i]]
			if j > 0 {
				d[i][1] = i - j - 1 + min(d[j-1][0], d[j-1][1])
			} else {
				d[i][1] = i
			}
			m[s[i]] = i
		}
		fmt.Fprintln(out, min(d[n-1][0], d[n-1][1]))
	}
}

package main

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

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

const inf = 1e8

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([][]int, n)
		for i := 0; i < n; i++ {
			d[i] = make([]int, 2)
		}
		m := make(map[uint8]int)
		for i := 1; i < n; i++ {
			d[i][0] = 1 + min(d[i-1][0], d[i-1][1])
			j := m[s[i]]
			if j > 0 {
				d[i][1] = i - j - 1 + min(d[j-1][0], d[j-1][1])
			} else {
				d[i][1] = inf
			}
			m[s[i]] = i
		}
		fmt.Fprintln(out, min(d[n-1][0], d[n-1][1]))
	}
}

package main

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

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([]int, n)
		m := make(map[uint8][]int)
		for i := 1; i < n; i++ {
			d[i] = d[i-1] + 1
			x := m[s[i]]
			if len(x) > 0 {
				for _, j := range x {
					k := i - j - 1 + d[j-1]
					if k < d[i] {
						d[i] = k
					}
				}
			}
			if _, ok := m[s[i]]; ok {
				m[s[i]] = append(m[s[i]], i)
			} else {
				m[s[i]] = []int{i}
			}

		}
		res := d[1] + n - 2
		for i := 2; i < n; i++ {
			k := d[i] + n - i - 1
			if k < res {
				res = k
			}
		}
		fmt.Fprintln(out, res)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([]int, n)
		m := make(map[uint8][]int)
		for i := 1; i < n; i++ {
			d[i] = d[i-1] + 1
			x := m[s[i]]
			if len(x) > 0 {
				for _, j := range x {
					k := i - j - 1 + d[j-1]
					if k < d[i] {
						d[i] = k
					}
				}
			}
			if _, ok := m[s[i]]; ok {
				m[s[i]] = append(m[s[i]], i)
			} else {
				m[s[i]] = []int{i}
			}

		}
		fmt.Fprintln(out, d[n-1])
	}
}

package main

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

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([]int, n)
		m := make(map[uint8][]int)
		for i := 1; i < n; i++ {
			j := m[s[i]]
			d[i] = d[i-1] + 1
			x := len(j)
			if x > 0 {
				k := i - j[x-1] - 1 + d[j[x-1]-1]
				if x > 1 {
					q := i - j[x-2] - 1 + d[j[x-2]-1]
					if q < k {
						k = q
					}
				}
				if k < d[i] {
					d[i] = k
				}
			}
			if _, ok := m[s[i]]; ok {
				m[s[i]] = append(m[s[i]], i)
			} else {
				m[s[i]] = []int{i}
			}

		}
		fmt.Fprintln(out, d[n-1])
	}
}

package main

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

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

func main() {
	defer out.Flush()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for {
		if !scanner.Scan() {
			break
		}
		s := "#" + scanner.Text()
		n := len(s)
		d := make([]int, n)
		m := make(map[uint8]int)
		for i := 1; i < n; i++ {
			j := m[s[i]]
			d[i] = d[i-1] + 1
			if j > 0 {
				k := i - j - 1 + d[j-1]
				if k < d[i] {
					d[i] = k
				}
			}
			m[s[i]] = i
		}
		fmt.Fprintln(out, d[n-1])
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for t := t; t > 0; t-- {
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		s := "#" + scanner.Text()
		n := len(s)
		d := make([]int, n)
		m := make(map[uint8]int)
		for i := 1; i < n; i++ {
			j := m[s[i]]
			d[i] = d[i-1] + 1
			if j > 0 {
				k := i - j - 1 + d[j-1]
				if k < d[i] {
					d[i] = k
				}
			}
			m[s[i]] = i
		}
		fmt.Fprintln(out, d[n-1])
	}
}

package main

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

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

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

	cases := 0
	Fscan(in, &cases)

	var str string
	var n int

	for ; cases > 0; cases-- {
		Fscan(in, &str)
		n = len(str)
		str = "!" + str
		dp := make([]int, n+1) //dp[i]表示 第i个元素需要满足even string最少需要remove的个数
		dp[0] = 0              //初始化dp，表示移除0个元素最少需要0次
		vis := make(map[byte]int)
		cnt := make(map[byte]int)
		for i := 1; i <= n; i++ {
			if pos, ok := vis[str[i]]; !ok || cnt[str[i]]%2 == 0 {
				dp[i] = dp[i-1] + 1
			} else {
				dp[i] = min(dp[i-1]+1, dp[pos-1]+(i-pos-1))
			}
			vis[str[i]] = i
			cnt[str[i]]++
		}
		Fprintf(out, "%d\n", dp[n])
	}
}

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

package main

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

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

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

	cases := 0
	Fscan(in, &cases)

	var str string
	var n int

	for ; cases > 0; cases-- {
		Fscan(in, &str)
		n = len(str)
		str = "!" + str
		dp := make([]int, n+1) //dp[i]表示 第i个元素需要满足even string最少需要remove的个数
		dp[0] = 0              //初始化dp，表示移除0个元素最少需要0次
		vis := make(map[byte]int)
		cnt := make(map[byte]int)
		for i := 1; i <= n; i++ {
			if pos, ok := vis[str[i]]; !ok || cnt[str[i]]%2 == 0 {
				dp[i] = dp[i-1] + 1
			} else {
				dp[i] = min(dp[i-1]+1, dp[pos-1] + (i - pos - 1))
			}
			vis[str[i]] = i
			cnt[str[i]]++
		}
		Println(dp)
		Fprintf(out, "%d\n", dp[n])
	}
}

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

package main

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

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

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

	cases := 0
	Fscan(in, &cases)

	var str string
	var n int

	for ; cases > 0; cases-- {
		Fscan(in, &str)
		n = len(str)
		str = "!" + str
		dp := make([]int, n+1) //dp[i]表示 第i个元素需要满足even string最少需要remove的个数
		dp[0] = 0              //初始化dp，表示移除0个元素最少需要0次
		vis := make(map[byte]int)
		for i := 1; i <= n; i++ {
			if pos, ok := vis[str[i]]; !ok {
				dp[i] = dp[i-1] + 1
			} else {
				dp[i] = dp[pos-1] + (i - pos - 1)
			}
			vis[str[i]] = i
		}
		Fprintf(out, "%d\n", dp[n])
	}
}

package main

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

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

var in = bufio.NewReader(os.Stdin)

func solve(){
	var s string
	fmt.Fscan(in,&s)
	n:=len(s)
	s=" " + s
	dp:=make([]int,n+1)
	pos:=make([]int,26)

	// fmt.Print(s,n," ")
	for i:=1;i<=n;i++{
		dp[i]=dp[i-1] + 1
		l:=pos[s[i]-'a']
		if l>0 {
			dp[i]=min(dp[i],dp[l-1] + i - l - 1)
		}
		pos[s[i]-'a']=l;
	}

	fmt.Println(dp[n])
}
func main() {
	var tc int
    fmt.Scan(&tc)
	// fmt.Print(tc)
	for i:=0;i<tc;i++{
		solve()
	}
}

package main

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

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

var in = bufio.NewReader(os.Stdin)

func solve(){
	var s string
	fmt.Fscan(in,s)
	n:=len(s)
	s=" " + s
	dp:=make([]int,n+1)
	pos:=make([]int,26)

	for i:=1;i<=n;i++{
		dp[i]=dp[i-1]
		l:=pos[s[i]-'a']
		if l>0 {
			dp[i]=min(dp[i],dp[l-1] + i - l - 1)
		}
		pos[s[i]-'a']=l;
	}

	fmt.Println(dp[n])
}
func main() {
	var tc int
    fmt.Scan(&tc)
	// fmt.Print(tc)
	for i:=0;i<tc;i++{
		solve()
	}
}


Consider the following process. You have a binary string (a string where each character is either 0 or 1) $$$w$$$ of length $$$n$$$ and an integer $$$x$$$. You build a new binary string $$$s$$$ consisting of $$$n$$$ characters. The $$$i$$$-th character of $$$s$$$ is chosen as follows:  if the character $$$w_{i-x}$$$ exists and is equal to 1, then $$$s_i$$$ is 1 (formally, if $$$i > x$$$ and $$$w_{i-x} = $$$ 1, then $$$s_i = $$$ 1);  if the character $$$w_{i+x}$$$ exists and is equal to 1, then $$$s_i$$$ is 1 (formally, if $$$i + x \le n$$$ and $$$w_{i+x} = $$$ 1, then $$$s_i = $$$ 1);  if both of the aforementioned conditions are false, then $$$s_i$$$ is 0. You are given the integer $$$x$$$ and the resulting string $$$s$$$. Reconstruct the original string $$$w$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line contains the resulting string $$$s$$$ ($$$2 \le |s| \le 10^5$$$, each character of $$$s$$$ is either 0 or 1). The second line contains one integer $$$x$$$ ($$$1 \le x \le |s| - 1$$$). The total length of all strings $$$s$$$ in the input does not exceed $$$10^5$$$.

For each test case, print the answer on a separate line as follows:   if no string $$$w$$$ can produce the string $$$s$$$ at the end of the process, print $$$-1$$$;  otherwise, print the binary string $$$w$$$ consisting of $$$|s|$$$ characters. If there are multiple answers, print any of them.

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

		s, _ := reader.ReadString('\n')
		x := readNum(reader)

		ok, w := solve(s, x)

		if !ok {
			buf.WriteString("-1")
		} else {
			buf.WriteString(w)
		}
		buf.WriteByte('\n')
	}
	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') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

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

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

	return i
}

func solve(s string, x int) (bool, string) {
	w := make([]byte, len(s))
	var n int
	for i := 0; i < len(s); i++ {
		if s[i] != '0' && s[i] != '1' {
			break
		}
		w[i] = '1'
		n++
	}
	w = w[:n]
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			if i-x >= 0 {
				w[i-x] = '0'
			}
			if i+x < n {
				w[i+x] = '0'
			}
		}
	}

	for i := 0; i < n; i++ {
		if s[i] == '1' {
			if i-x >= 0 && w[i-x] == '1' {
				continue
			}
			if i+x < n && w[i+x] == '1' {
				continue
			}
			return false, ""
		} else {
			// s[i] == '0'
			if i-x >= 0 && w[i-x] == '1' {
				return false, ""
			}
			if i+x < n && w[i+x] == '1' {
				return false, ""
			}
		}
	}
	return true, string(w)
}

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		ss, x := io.Next(), io.NextInt()
		n := len(ss)

		s := make([]byte, n*3)
		copy(s[n:], ss)
		off := n

		ok := true
		ans := make([]byte, 3*n)
		for i := off; i < off+x; i++ {
			if i+x < off+n || s[i] == '0' {
				ans[i+x] = s[i]
			} else {
				ok = false
			}
		}
		for i := off + n - x; i < off+n; i++ {
			if (i-x < off && s[i] == '0') || (i-x >= off && (ans[i-x] == s[i] || ans[i-x] == 0)) {
				ans[i-x] = s[i]
			} else {
				ok = false
			}
		}
		for i := off + x; i < off+n-x; i++ {
			if s[i] == '0' {
				if (ans[i-x] == 0 || ans[i-x] == '0') && (ans[i+x] == 0 || ans[i+x] == '0') {
					ans[i-x] = '0'
					ans[i+x] = '0'
				} else {
					ok = false
				}
			} else if (i-x >= off && ans[i-x] == 0) || ans[i-x] == '1' {
				ans[i-x] = '1'
			} else if (i+x < off+n && ans[i+x] == 0) || ans[i+x] == '1' {
				ans[i+x] = '1'
			} else {
				ok = false
			}
		}
		ans = ans[off : off+n]
		for i := range ans {
			if ans[i] == 0 {
				ans[i] = '0'
			}
		}

		if ok {
			io.Println(string(ans))
		} else {
			io.Println(-1)
		}
	}
}

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) 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) 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) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

func convsw(x int, s string) string {
	n := len(s)
	w := make([]byte, n)

	for i := range s {
		if s[i] == '0' {
			if i - x >= 0 {
				w[i-x] = '0'
			}
			if i + x < n {
				w[i+x] = '0'
			}
		}
	}

	for i := range w {
		if w[i] != '0' {
			w[i] = '1'
		}
	}

	return string(w)
}

func convws(x int, w string) string {
	n := len(w)
	s := make([]byte, n)

	for i := range w {
		if w[i] == '1' {
			if i - x >= 0{
				s[i-x] = '1'
			}

			if i + x < n {
				s[i+x] = '1'
			}
		}
	}

	for i := range s {
		if s[i] != '1' {
			s[i] = '0'
		}
	}

	return string(s)
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	ini := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func() string {
		sc.Scan()
		return sc.Text()
	}

	for t := ini(); t > 0; t-- {
		s := ins()
		x := ini()

		w := convsw(x, s)
		//fmt.Println(w)
		s1 := convws(x, w)
		//fmt.Println(s1)

		if s == s1 {
			fmt.Println(w)
		} else {
			fmt.Println(-1)
			//fmt.Println(s1)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var x int
		var w string
		fmt.Fscan(in, &w)
		fmt.Fscan(in, &x)
		s := make([]byte, len(w))
		for j := 0; j < len(w); j++ {
			if w[j] == '0' {
				if j-x >= 0 {
					s[j-x] = '0'
				}
				if j+x < len(w) {
					s[j+x] = '0'
				}
			}
		}
		for j := 0; j < len(w); j++ {
			if s[j] != '0' {
				s[j] = '1'
			}
		}
		possible := true
		for j := 0; j < len(w); j++ {
			if w[j] == '1' {
				if j-x >= 0 && s[j-x] == '1' {
					continue
				}
				if j+x < len(w) && s[j+x] == '1' {
					continue
				}
				possible = false
			}
		}
		if possible {
			fmt.Println(string(s))
		} else {
			fmt.Println(-1)
		}
	}
}

/*
URL:
https://codeforces.com/contest/1400/problem/C
*/

package main

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

var (
	t int

	S []rune
	x int
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		S = ReadRuneSlice()
		x = readi()

		solve()
	}
}

func solve() {
	n := len(S)
	T := make([]rune, n)
	for i := 0; i < n; i++ {
		T[i] = '!'
	}

	// 両方ともfalseのケース
	for i := 0; i < n; i++ {
		left, right := false, false
		if i-x >= 0 {
			left = true
		}
		if i+x < n {
			right = true
		}

		if !left && !right && S[i] == '1' {
			fmt.Println(-1)
			return
		}
	}

	// 結果が0のところから確定させる
	for i := 0; i < n; i++ {
		if S[i] == '0' {
			if i-x >= 0 {
				T[i-x] = '0'
			}
			if i+x < n {
				T[i+x] = '0'
			}
		}
	}

	// 単方向の1から確定させる、矛盾があたら-1
	for i := 0; i < n; i++ {
		if S[i] == '1' {
			left, right := false, false
			if i-x >= 0 {
				left = true
			}
			if i+x < n {
				right = true
			}

			if left && right {
				continue
			}

			if left {
				if T[i-x] == '0' {
					fmt.Println(-1)
					return
				} else {
					T[i-x] = '1'
				}
			}

			if right {
				if T[i+x] == '0' {
					fmt.Println(-1)
					return
				} else {
					T[i+x] = '1'
				}
			}
		}
	}

	// PrintfDebug("%v\n", string(T))

	// 双方向の1をみる、両方0なら矛盾
	for i := 0; i < n; i++ {
		if S[i] == '1' {
			left, right := false, false
			if i-x >= 0 {
				left = true
			}
			if i+x < n {
				right = true
			}

			if left && right {
				if T[i-x] == '0' && T[i+x] == '0' {
					fmt.Println(-1)
					return
				}
			}
		}
	}

	// 残った部分は1
	for i := 0; i < n; i++ {
		if T[i] != '0' && T[i] != '1' {
			T[i] = '1'
		}
	}

	fmt.Println(string(T))
}

func output(S []rune) {
	n := len(S)
	T := make([]rune, n)
	for i := 0; i < n; i++ {
		T[i] = '!'
	}

	// 結果が0のところから確定させる
	for i := 0; i < n; i++ {
		if S[i] == '0' {
			if i-x >= 0 {
				T[i-x] = '0'
			}
			if i+x < n {
				T[i+x] = '0'
			}
		}
	}

	// 単方向の1から確定させる、矛盾があたら-1
	for i := 0; i < n; i++ {
		if S[i] == '1' {
			left, right := false, false
			if i-x >= 0 {
				left = true
			}
			if i+x < n {
				right = true
			}

			if left && right {
				continue
			}

			if left {
				if T[i-x] == '0' {
					fmt.Println(-1)
					return
				} else {
					T[i-x] = '1'
				}
			}

			if right {
				if T[i+x] == '0' {
					fmt.Println(-1)
					return
				} else {
					T[i+x] = '1'
				}
			}
		}
	}

	// PrintfDebug("%v\n", string(T))

	// 双方向の1をみる、両方0なら矛盾
	for i := 0; i < n; i++ {
		if S[i] == '1' {
			left, right := false, false
			if i-x >= 0 {
				left = true
			}
			if i+x < n {
				right = true
			}

			if left && right {
				if T[i-x] == '0' && T[i+x] == '0' {
					fmt.Println(-1)
					return
				}
			}
		}
	}

	// 残った部分は1
	for i := 0; i < n; i++ {
		if T[i] != '0' && T[i] != '1' {
			T[i] = '1'
		}
	}

	fmt.Println(string(T))
}

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

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

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

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

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

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

/********** 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...)

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

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

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

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

// 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(ReadString(), 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
}

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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"
	"io"
	"os"
)

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

	var T, x int
	var t []byte
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &t, &x)
		n := len(t)
		s := make([]byte, n)
		for i, b := range t {
			if b == '0' {
				if i >= x {
					s[i-x] = '0'
				}
				if i+x < n {
					s[i+x] = '0'
				}
			}
		}
		for i, b := range s {
			if b == 0 {
				s[i] = '1'
			}
		}
		for i, b := range t {
			if b == '1' && !(i >= x && s[i-x] == '1' || i+x < n && s[i+x] == '1') {
				Fprintln(out, -1)
				continue o
			}
		}
		Fprintln(out, string(s))
	}
}

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

package main

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

var reader = bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		var s string
		fmt.Fscan(reader, &s)

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

		w := make([]string, len(s))
		for j := 0; j < len(s); j++ {
			w[j] = "1"
		}

		for j := 0; j < len(s); j++ {
			if s[j] == '0' {
				if j-x >= 0 {
					w[j-x] = "0"
				}

				if j+x < len(s) {
					w[j+x] = "0"
				}
			}
		}

		for j := 0; j < len(s); j++ {
			if s[j] == '1' {
				at_least_one := false

				if (j-x) >= 0 && w[j-x] == "1" {
					at_least_one = true
				}

				if (j+x < len(s)) && w[j+x] == "1" {
					at_least_one = true
				}

				if !at_least_one {
					w = nil
					break
				}
			}
		}

		if w == nil {
			fmt.Println("-1")
		} else {
			fmt.Println(strings.Join(w, ""))
		}
	}
}

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		ss, x := io.Next(), io.NextInt()
		n := len(ss)

		s := make([]byte, n*3)
		copy(s[n:], ss)
		off := n

		ok := true
		ans := make([]byte, 3*n)
		copy(ans[off+x:off+2*x], s[off:off+x])
		for i := off + n - x; i < off+n; i++ {
			if ans[i-x] == 0 || ans[i-x] == s[i] {
				ans[i-x] = s[i]
			} else {
				ok = false
			}
		}
		for i := off + x; i < off+n-x; i++ {
			if s[i] == '0' {
				if (ans[i-x] == 0 || ans[i-x] == '0') && (ans[i+x] == 0 || ans[i+x] == '0') {
					ans[i-x] = '0'
					ans[i+x] = '0'
				} else {
					ok = false
				}
			} else if ans[i-x] == 0 || ans[i-x] == '1' {
				ans[i-x] = '1'
			} else if ans[i+x] == 0 || ans[i+x] == '1' {
				ans[i+x] = '1'
			} else {
				ok = false
			}
		}
		ans = ans[off : off+n]
		for i := range ans {
			if ans[i] == 0 {
				ans[i] = '0'
			}
		}

		if ok {
			io.Println(string(ans))
		} else {
			io.Println(-1)
		}
	}
}

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) 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) 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) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		ss, x := io.Next(), io.NextInt()
		n := len(ss)

		s := make([]byte, n*3)
		copy(s[n:], ss)
		off := n

		ok := true
		ans := make([]byte, 3*n)
		copy(ans[off+x:off+2*x], s[off:off+x])
		for i := off + n - x; i < off+n; i++ {
			if ans[i-x] == 0 || ans[i-x] == s[i] {
				ans[i-x] = s[i]
			} else {
				ok = false
			}
		}
		for i := off + x; i < off+n-x; i++ {
			if s[i] == '0' {
				if (ans[i-x] == 0 || ans[i-x] == '0') && (ans[i+x] == 0 || ans[i+x] == '0') {
					ans[i-x] = '0'
					ans[i+x] = '0'
				} else {
					ok = false
				}
			} else if (i-x >= off && ans[i-x] == 0) || ans[i-x] == '1' {
				ans[i-x] = '1'
			} else if (i+x < off+n && ans[i+x] == 0) || ans[i+x] == '1' {
				ans[i+x] = '1'
			} else {
				ok = false
			}
		}
		ans = ans[off : off+n]
		for i := range ans {
			if ans[i] == 0 {
				ans[i] = '0'
			}
		}

		if ok {
			io.Println(string(ans))
		} else {
			io.Println(-1)
		}
	}
}

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) 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) 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) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		ss, x := io.Next(), io.NextInt()
		n := len(ss)

		s := make([]byte, n*3)
		copy(s[n:], ss)
		off := n

		ok := true
		ans := make([]byte, 3*n)
		copy(ans[off+x:off+2*x], s[off:off+x])
		for i := off + n - x; i < off+n; i++ {
			if (i-x >= off && ans[i-x] == 0) || ans[i-x] == s[i] {
				ans[i-x] = s[i]
			} else {
				ok = false
			}
		}
		for i := off + x; i < off+n-x; i++ {
			if s[i] == '0' {
				if (ans[i-x] == 0 || ans[i-x] == '0') && (ans[i+x] == 0 || ans[i+x] == '0') {
					ans[i-x] = '0'
					ans[i+x] = '0'
				} else {
					ok = false
				}
			} else if (i-x >= off && ans[i-x] == 0) || ans[i-x] == '1' {
				ans[i-x] = '1'
			} else if (i+x < off+n && ans[i+x] == 0) || ans[i+x] == '1' {
				ans[i+x] = '1'
			} else {
				ok = false
			}
		}
		ans = ans[off : off+n]
		for i := range ans {
			if ans[i] == 0 {
				ans[i] = '0'
			}
		}

		if ok {
			io.Println(string(ans))
		} else {
			io.Println(-1)
		}
	}
}

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) 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) 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) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

func convsw(x int, s string) string {
	n := len(s)
	w := make([]byte, n)

	for i := range s {
		if s[i] == '0' {
			if i - x >= 0 {
				w[i-x] = '0'
			}
			if i + x < n {
				w[i+x] = '0'
			}
		}
	}

	for i := range w {
		if w[i] != '0' {
			w[i] = '1'
		}
	}

	return string(w)
}

func convws(x int, w string) string {
	n := len(w)
	s := make([]byte, n)

	for i := range w {
		if w[i] == '1' {
			if i - x >= 0{
				s[i-x] = '1'
			}

			if i + x < n {
				s[i+x] = '1'
			}
		}
	}

	for i := range s {
		if s[i] != '1' {
			s[i] = '0'
		}
	}

	return string(s)
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanLines)

	ini := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func() string {
		sc.Scan()
		return sc.Text()
	}

	for t := ini(); t > 0; t-- {
		s := ins()
		x := ini()

		w := convws(x, s)
		s1 := convsw(x, w)

		if s == s1 {
			fmt.Println(w)
		} else {
			fmt.Println(-1)
		}
	}
}

/*
URL:
https://codeforces.com/contest/1400/problem/C
*/

package main

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

var (
	t int

	S []rune
	x int
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		S = ReadRuneSlice()
		x = readi()

		solve()
	}
}

func solve() {
	n := len(S)
	T := make([]rune, n)
	for i := 0; i < n; i++ {
		T[i] = '!'
	}

	for i := 0; i < n; i++ {
		if S[i] == '0' {
			if i-x >= 0 {
				T[i-x] = '0'
			}
			if i+x < n {
				T[i+x] = '0'
			}
		}
	}

	for i := 0; i < n; i++ {
		if S[i] == '1' {
			left, right := false, false
			if i-x >= 0 {
				left = true
			}
			if i+x < n {
				right = true
			}

			if left && right {
				continue
			}

			if left {
				if T[i-x] == '0' {
					fmt.Println(-1)
					return
				} else {
					T[i-x] = '1'
				}
			}

			if right {
				if T[i+x] == '0' {
					fmt.Println(-1)
					return
				} else {
					T[i+x] = '1'
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		if T[i] != '0' && T[i] != '1' {
			T[i] = '1'
		}
	}

	fmt.Println(string(T))
}

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

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

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

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

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

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

/********** 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...)

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

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

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

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

// 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(ReadString(), 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
}

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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
}

/*
URL:
https://codeforces.com/contest/1400/problem/C
*/

package main

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

var (
	t int

	S []rune
	x int
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		S = ReadRuneSlice()
		x = readi()

		solve()
	}
}

func solve() {
	n := len(S)
	T := make([]rune, n)
	for i := 0; i < n; i++ {
		T[i] = '!'
	}

	// 結果が0のところから確定させる
	for i := 0; i < n; i++ {
		if S[i] == '0' {
			if i-x >= 0 {
				T[i-x] = '0'
			}
			if i+x < n {
				T[i+x] = '0'
			}
		}
	}

	// 単方向の1から確定させる、矛盾があたら-1
	for i := 0; i < n; i++ {
		if S[i] == '1' {
			left, right := false, false
			if i-x >= 0 {
				left = true
			}
			if i+x < n {
				right = true
			}

			if left && right {
				continue
			}

			if left {
				if T[i-x] == '0' {
					fmt.Println(-1)
					return
				} else {
					T[i-x] = '1'
				}
			}

			if right {
				if T[i+x] == '0' {
					fmt.Println(-1)
					return
				} else {
					T[i+x] = '1'
				}
			}
		}
	}

	// PrintfDebug("%v\n", string(T))

	// 双方向の1をみる、両方0なら矛盾
	for i := 0; i < n; i++ {
		if S[i] == '1' {
			left, right := false, false
			if i-x >= 0 {
				left = true
			}
			if i+x < n {
				right = true
			}

			if left && right {
				if T[i-x] == '0' && T[i+x] == '0' {
					fmt.Println(-1)
					return
				}
			}
		}
	}

	// 残った部分は1
	for i := 0; i < n; i++ {
		if T[i] != '0' && T[i] != '1' {
			T[i] = '1'
		}
	}

	fmt.Println(string(T))
}

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

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

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

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

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

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

/********** 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...)

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

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

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

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

// 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(ReadString(), 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
}

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		var s string
		fmt.Fscan(reader, &s)

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

		check := make([]string, len(s))
		for j := 0; j < len(s); j++ {
			check[j] = "1"
		}

		for j := 0; j < len(s); j++ {
			if s[j] == '0' {
				if j-x >= 0 {
					check[j-x] = "0"
				}

				if j+x < len(s) {
					check[j+x] = "0"
				}
			}
		}

		for j := 0; j < len(s); j++ {
			if s[j] == '1' {
				if (j < x) && (j+x < len(s)) && check[j+x] == "0" {
					check = nil
					break
				}

				if (j >= len(s)-x) && (j-x >= 0) && check[j-x] == "0" {
					check = nil
					break
				}

				if (j-x >= 0) && (j+x < len(s)) && check[j-x] == "0" && check[j+x] == "0" {
					check = nil
					break
				}
			}
		}

		if check == nil {
			fmt.Println("-1")
		} else {
			fmt.Println(strings.Join(check, ""))
		}
	}
}