Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.  The park consists of 2n + 1 - 1 squares connected by roads so that the scheme of the park is a full binary tree of depth n. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2n, 2n + 1, ..., 2n + 1 - 1 and these exits lead straight to the Om Nom friends' houses. From each square i (2 ≤ i < 2n + 1) there is a road to the square . Thus, it is possible to go from the park entrance to each of the exits by walking along exactly n roads.    To light the path roads in the evening, the park keeper installed street lights along each road. The road that leads from square i to square  has ai lights.Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe. He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.

The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit. The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and . All numbers ai are positive integers, not exceeding 100.

Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.

NotePicture for the sample test. Green color denotes the additional street lights.

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

type Node struct {
  Id, Value, MinCost int
  Parent, Left, Right *Node
}

func buildTree(maxDepth, depth, id int, parent *Node) *Node {
  node := &Node{ Id: id, Parent: parent }
  if depth < maxDepth {
    node.Left = buildTree(maxDepth, depth+1, 2*id, node)
    node.Right = buildTree(maxDepth, depth+1, 2*id+1, node)
  }
  return node
}

var values []int
var maxValue int

func setValue(node *Node, value int) {
  node.Value = value
  if value > maxValue {
    maxValue = value
  }
  if node.Left != nil {
    setValue(node.Left, value + values[2*node.Id-2])
    setValue(node.Right, value + values[2*node.Id-1])
  }
}

func setMinCost(node *Node) int {
  if node.Left == nil {
    node.MinCost = maxValue - node.Value
  } else {
    left, right := setMinCost(node.Left), setMinCost(node.Right)
    if left < right {
      node.MinCost = left
    } else {
      node.MinCost = right
    }
  }
  //writer.WriteString(fmt.Sprintf("%d: %d\n", node.Id, node.MinCost))
  return node.MinCost
}

func getResult(node *Node, value int) int {
  cost := node.MinCost - value
  if node.Left == nil {
    return cost
  }
  left := getResult(node.Left, value + cost)
  right := getResult(node.Right, value + cost)
  return cost + left + right
}

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

  h := getI()
  children := 1
  for i := 0; i <= h; i++ {
    children *= 2
  }
  values = make([]int, children-2)
  for i := range values {
    values[i] = getI()
  }
  tree := buildTree(h, 0, 1, nil)
  setValue(tree, 0)
  setMinCost(tree)

  result := getResult(tree, 0)
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = (2 * node) + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	if M[l] > M[r] {
		M[node] = M[l]
	} else {
		M[node] = M[r]
	}

	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = (2 * node) + 1
	var sum = 0
	sum += solve(l, level-1, M[l]-A[l]) + (lit - M[l])
	sum += solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d\n", &n)
	p = (1 << uint(n+1)) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	if M[l] > M[r] {
		M[node] = M[l]
	} else {
		M[node] = M[r]
	}

	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	var sum = 0
	sum += solve(l, level-1, M[l]-A[l]) + (lit - M[l])
	sum += solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = 1<<uint(n+1) - 1
	for i := 0; i <= p; i++ {
		A[i] = 0
		M[i] = 0
	}

	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

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

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	M[node] = max(M[l], M[r])
	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	var sum = solve(l, level-1, M[l]-A[l]) + (lit - M[l]) +
		solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = 1<<uint(n+1) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	if M[l] > M[r] {
		M[node] = M[l]
	} else {
		M[node] = M[r]
	}

	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	var sum = 0
	sum += solve(l, level-1, M[l]-A[l]) + (lit - M[l])
	sum += solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = 1<<uint(n+1) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

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

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	M[node] = max(M[l], M[r])
	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	var sum = solve(l, level-1, M[l]-A[l]) + (lit - M[l]) +
		solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = 1<<uint(n+1) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}


Polycarp and his friends want to visit a new restaurant. The restaurant has $$$n$$$ tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from $$$1$$$ to $$$n$$$ in the order from left to right. The state of the restaurant is described by a string of length $$$n$$$ which contains characters "1" (the table is occupied) and "0" (the table is empty).Restaurant rules prohibit people to sit at a distance of $$$k$$$ or less from each other. That is, if a person sits at the table number $$$i$$$, then all tables with numbers from $$$i-k$$$ to $$$i+k$$$ (except for the $$$i$$$-th) should be free. In other words, the absolute difference of the numbers of any two occupied tables must be strictly greater than $$$k$$$.For example, if $$$n=8$$$ and $$$k=2$$$, then:  strings "10010001", "10000010", "00000000", "00100000" satisfy the rules of the restaurant;  strings "10100100", "10011001", "11111111" do not satisfy to the rules of the restaurant, since each of them has a pair of "1" with a distance less than or equal to $$$k=2$$$. In particular, if the state of the restaurant is described by a string without "1" or a string with one "1", then the requirement of the restaurant is satisfied.You are given a binary string $$$s$$$ that describes the current state of the restaurant. It is guaranteed that the rules of the restaurant are satisfied for the string $$$s$$$.Find the maximum number of free tables that you can occupy so as not to violate the rules of the restaurant. Formally, what is the maximum number of "0" that can be replaced by "1" such that the requirement will still be satisfied?For example, if $$$n=6$$$, $$$k=1$$$, $$$s=$$$ "100010", then the answer to the problem will be $$$1$$$, since only the table at position $$$3$$$ can be occupied such that the rules are still satisfied.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case starts with a line containing two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2\cdot 10^5$$$) — the number of tables in the restaurant and the minimum allowed distance between two people. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ consisting of "0" and "1" — a description of the free and occupied tables in the restaurant. The given string satisfy to the rules of the restaurant — the difference between indices of any two "1" is more than $$$k$$$. The sum of $$$n$$$ for all test cases in one test does not exceed $$$2\cdot 10^5$$$.

For each test case output one integer — the number of tables that you can occupy so as not to violate the rules of the restaurant. If additional tables cannot be taken, then, obviously, you need to output $$$0$$$.

NoteThe first test case is explained in the statement.In the second test case, the answer is $$$2$$$, since you can choose the first and the sixth table.In the third test case, you cannot take any free table without violating the rules of the restaurant.

package main

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

var s string

func nextPoint(p int) int {
	for i := p; i < len(s); i++ {
		if s[i] == '1' {
			return i
		}
	}

	return len(s)
}

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

	var t, n, k int

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {

		fmt.Fscanf(reader, "%d %d\n%s\n", &n, &k, &s)
		sum := 0
		p := nextPoint(0)

		for i := 0; i < n; {
			if s[i] == '1' {
				i += (k + 1)
				continue
			}

			if i >= p {
				p = nextPoint(i + 1)
			}

			if p-i > k || p == n {
				i += (k + 1)
				sum++
			} else {
				i++
			}
		}

		fmt.Println(sum)
	}
}

package main

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

var s string

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

	var t, n, k int

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {

		fmt.Fscanf(reader, "%d %d\n%s\n", &n, &k, &s)
		d := make([]int, n+1)
		for i := 1; i < n; i++ {
			if s[i] == '1' || s[i-1] == '1' {
				d[i] = i
			} else {
				d[i] = d[i-1]
			}
		}

		if s[n-1] == '1' {
			d[n] = d[n-1] + 1
		} else {
			d[n] = d[n-1]
		}

		sum := 0
		var i, left, right int
		for i = 0; i <= k && i < n; {
			if s[i] == '1' {
				i += (k + 1)
				continue
			}

			if i+k >= n {
				right = d[n]
			} else {
				right = d[i+k]
			}

			if d[i] == right {
				sum++
				i += (k + 1)
			} else {
				i++
			}
		}

		for i < n {
			if s[i] == '1' {
				i += (k + 1)
				continue
			}

			left = d[i-k]

			if i+k >= n {
				right = d[n-1]
			} else {
				right = d[i+k]
			}

			if left == right {
				sum++
				i += (k + 1)
			} else {
				i++
			}
		}

		fmt.Println(sum)
	}
}

package main

import (
  "fmt"
)

var t int
func main() {
  fmt.Scan(&t)
  for i := 0; i < t; i++ {
    var n, k int
    fmt.Scan(&n, &k)
    var tables []byte
    fmt.Scan(&tables)
    last := -1
    var startFromZero bool
    if tables[0] == '0' {
      startFromZero = true
    } else {
      startFromZero = false
    }
    ans := 0
    for j := range tables {
      var available int
      if tables[j] == '1' {
        if startFromZero {
          available = (j-1)-last
          startFromZero = false
          if available > 0 {
          	ans += available / (k+1)
          }
        } else {
          available = ((j-1)-last-2*k)
          if available > 0 {
          	ans++
          	available--
          	ans += available / (k+1)
          }
        }
        last = j
      } else if j == n-1 {
        if startFromZero {
          available = n
        } else {
          available = j-last-k
        }
        if available > 0 {
          ans++
          available--
          ans += available / (k+1)
        }
      }
    }
    fmt.Println(ans)
  }

}

package main

import "fmt"

func main() {
    var CASE int
    fmt.Scanf("%d\r\n",&CASE)
    for K := 0;K < CASE;K++ {
        var n,k int
        fmt.Scan(&n,&k)
        var s string
        fmt.Scan(&s)
        res := 0
        //fmt.Print(s)
        last := -1
        cnt := 0

        for i := 0;i < n + 1;i++ {
            if i == n || s[i] == '1' {
                if last == -1 && i == n {
                    res += (cnt - 1) / (k + 1) + 1
                } else if last == -1 || i == n {
                    res += cnt / (k + 1)
                    if cnt % (k + 1) != 0 {
                        //res++
                    }
                } else {
                    res += (cnt - k) / (k + 1)
                }
                last = i
                cnt = 0
            } else {
                cnt++
            }
        }

        fmt.Printf("%d\n",res)
    }
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)

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

		fmt.Println(solve(n, k, s[:n]))
	}
}

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(n, k int, s string) int {
	var j int
	if s[0] == '1' {
		j++
	}

	var res int
	for i := 0; i < n; {
		j := i + 1

		for j < n && s[j] != '1' {
			j++
		}

		var left, right int
		if s[i] == '1' {
			left = k
		}
		if j < n && s[j] == '1' {
			right = k
		}

		d := j - i

		if left == k {
			d--
		}

		d -= left + right

		if d > 0 {
			res += (d + k) / (k + 1)
		}

		i = j
	}

	return res
}

package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var (
		n, k int
		s string
	)
	fmt.Fscanln(input, &n, &k)
	fmt.Fscanln(input, &s)

	segs := make([]int, 0)
	l := 0
	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			segs = append(segs, l)
			l = 0
		} else {
			l++
		}
	}
	segs = append(segs, l)
	//fmt.Println("segs:", segs)
	ans := 0
	for i := 0; i < len(segs); i++ {
		if segs[i] == 0 {continue}
		if i == 0 && i == len(segs) - 1 {
			ans += segs[i] / (k + 1)
			if segs[i] % (k + 1) > 0 {ans++}
		} else if i == 0 || i == len(segs) - 1 {
			segs[i] -= k
			if segs[i] > 0 {
				ans += segs[i] / (k + 1)
				if segs[i]  % (k + 1) > 0 {ans++}
			}
		} else {
			segs[i] -= 2*k
			if segs[i] > 0 {
				ans += segs[i] / (k + 1)
				if segs[i] % (k + 1) > 0 {ans++}
			}
		}
	}

	fmt.Println(ans)
}

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

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 n, k int
		fmt.Fscan(in, &n, &k)
		var x string
		tables := 0
		kCount := 0
		fmt.Fscan(in, &x)
		for j := 0; j < n; j++ {
			if x[j] == '0' && kCount == 0 {
				tables++
				kCount = k
			} else if x[j] == '0' && kCount > 0 {
				kCount--
			}
			if x[j] == '1' && kCount > 0 {
				tables--
				kCount = k
			} else if x[j] == '1' && kCount == 0 {
				kCount = k
			}
		}
		fmt.Println(tables)
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		nks := strings.Split(string(line), " ")
		n, _ := strconv.ParseInt(nks[0], 10, 64)
		k, _ := strconv.ParseInt(nks[1], 10, 64)
		line = readLine(reader)
		for j := int64(0); j < n; j++ {
			if line[j] == '1' {
				m := int64(0)
				for m = j - 1; m >= j-k && m >= 0; m-- {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				for m = j + 1; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m - 1
			}
		}
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			if line[j] == '0' {
				sum++
				m := j + 1
				for ; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m - 1
			}
		}
		fmt.Println(sum)
	}
}

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

package main

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

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var str string
		var n, k int
		fmt.Fscan(in, &n, &k, &str)
		ans, dis := 0, k
		for _, s := range str {
			if s == '0' {
				dis++
			} else {
				dis = 0
			}
			if dis == 2*k+1 {
				ans++
				dis = k
			}
		}
		if dis >= k+1 {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1367/C
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, k int
	S    []rune
)

func main() {
	t = ReadInt()

	for i := 0; i < t; i++ {
		n, k = ReadInt2()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	memo := make([]bool, n)
	for i := 0; i < n; i++ {
		// if S[i] == '1' {
		// 	if i-1 >= 0 {
		// 		memo[i-1] = true
		// 	}
		// 	memo[i] = true
		// 	if i+1 < n {
		// 		memo[i+1] = true
		// 	}
		// }
		if S[i] == '1' {
			for j := i - k; j <= i+k; j++ {
				if 0 <= j && j < n {
					memo[j] = true
				}
			}
		}
	}

	comp, cnts := RunLengthEncoding(memo)

	ans := 0
	for i := 0; i < len(comp); i++ {
		if !comp[i] {
			ans += Kiriage(cnts[i], k+1)
		}
	}
	fmt.Println(ans)
}

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

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []bool) ([]bool, []int) {
	runes := []bool{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []bool, L []int) []bool {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []bool{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

var n, k, nTest int
var s string

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n, &k)
		fmt.Fscan(in, &s)
		res := 0

		dis := k
		for i := 0; i < n+k; i++ {
			if i >= n || s[i] == '0' {
				dis++
			} else {
				dis = 0
			}

			if dis == 2*k+1 {
				res++
				dis = k
			}
		}
		fmt.Fprintln(out, res)
	}

	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, n, k int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k, &s)
		c, p := 0, -1
		for i, b := range s {
			if b == '0' && (p == -1 || i-p > k) {
				c++
				p = i
			} else if b == '1' {
				if p >= 0 && s[p] == '0' && i-p <= k {
					c--
				}
				p = i
			}
		}
		Fprintln(out, c)
	}
}

package main

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

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

	var t, n, k int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k, &s)
		c, p := 0, -1
		for i, b := range s {
			if b == '0' && (p == -1 || i-p > k) {
				c++
				p = i
			} else if b == '1' {
				if p >= 0 && s[p] == '0' && i-p <= k {
					c--
				}
				p = i
			}
		}
		Fprintln(out, c)
	}
}

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

package main

import (
	"fmt"
	"math"
	"strings"
)

var (
	tests = 0
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	if n - count * k <= 0 {
		return 0
	}

	return int(math.Ceil(float64(n - count * k)/float64(k)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k+1,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k + 1, s[start:i+1]))
			total += cal(i-start+1, k + 1, s[start:i+1])
			start = i
		}
	}

	if s[n-1] == '0' {
		//fmt.Println("xxx", n-start, s[start:], cal(n-start, k + 1, s[start:]))
		total += cal(n-start, k + 1, s[start:])
	}

	fmt.Println(total)
}

func input() {
	fmt.Scanf("%d\n", &tests)

	for ; tests > 0; tests-- {
		var n int
		var k int
		var s string

		fmt.Scan(&n)
		fmt.Scan(&k)
		fmt.Scan(&s)
		//fmt.Println("xxx", n, k, s)
		process(n, k, s)
	}
}

package main

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

var (
	debug = false
	tests = 0
	reader io.Reader
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	if n - count * k <= 0 {
		return 0
	}

	return int(math.Ceil(float64(n - count * k)/float64(k)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k+1,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k + 1, s[start:i+1]))
			total += cal(i-start+1, k + 1, s[start:i+1])
			start = i
		}
	}

	if s[n-1] == '0' {
		//fmt.Println("xxx", n-start, s[start:], cal(n-start, k + 1, s[start:]))
		total += cal(n-start, k + 1, s[start:])
	}

	fmt.Println(total)
}

func input() {
	if debug {
		var e error
		reader, e = os.Open("input.txt")
		if e != nil {
			fmt.Println("error", e.Error())
			return
		}
	} else {
		reader = os.Stdin
	}

	fmt.Scanf("%d", &tests)

	for ; tests > 0; tests-- {
		var n int
		var k int
		var s string

		fmt.Scanf("%d %d", &n, &k)
		fmt.Scan(&s)
		process(n, k, s)
	}
}

package main

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

var s string

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

	var t, n, k int

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {

		fmt.Fscanf(reader, "%d %d\n%s\n", &n, &k, &s)
		d := make([]int, n)
		for i := 1; i < n; i++ {
			if s[i] == '1' || s[i-1] == '1' {
				d[i] = i
			} else {
				d[i] = d[i-1]
			}
		}

		sum := 0
		var i, left, right int
		for i = 0; i <= k; {

			if i+k >= n {
				right = d[n-1]
			} else {
				right = d[i+k]
			}

			if d[i] == right {
				sum++
				i += (k + 1)
			} else {
				i++
			}
		}

		for i < n {
			left = d[i-k]

			if i+k >= n {
				right = d[n-1]
			} else {
				right = d[i+k]
			}

			if left == right {
				sum++
				i += (k + 1)
			} else {
				i++
			}
		}

		fmt.Println(sum)
	}
}

package main

import (
  "fmt"
)

var t int
func main() {
  fmt.Scan(&t)
  for i := 0; i < t; i++ {
    var n, k int
    fmt.Scan(&n, &k)
    var tables []byte
    fmt.Scan(&tables)
    last := -1
    var startFromZero bool
    if tables[0] == '0' {
      startFromZero = true
    } else {
      startFromZero = false
    }
    ans := 0
    for j := range tables {
      var available int
      if tables[j] == '1' {
        if startFromZero {
          available = (j-1)-last
          startFromZero = false
        } else {
          available = ((j-1)-last-2*k)
        }
        if available > 0 {
          ans++
          available--
          ans += available / (k+1)
        }
        last = j
      } else if j == n-1 {
        if startFromZero {
          available = n
        } else {
          available = j-last-k
        }
        if available > 0 {
          ans++
          available--
          ans += available / (k+1)
        }
      }
    }
    fmt.Println(ans)
  }

}

package main

import "fmt"

func main() {
    var CASE int
    fmt.Scanf("%d\r\n",&CASE)
    for K := 0;K < CASE;K++ {
        var n,k int
        fmt.Scan(&n,&k)
        var s string
        fmt.Scan(&s)
        last := -k - 1
        res := 0
        //fmt.Print(s)
        for i := 0;i < n;i++ {
            if s[i] == '1' {
                dist := i - last - k
                if dist > k {
                    res += dist / (k + 1)
                }

                last = i
            }
        }
        now := n + k - 1
        dist := now - last - k
        if dist > k {
            res += dist / (k + 1)
        }
        fmt.Printf("%d\n",res)
    }
}

package main

import "fmt"

func main() {
    var CASE int
    fmt.Scanf("%d\r\n",&CASE)
    for K := 0;K < CASE;K++ {
        var n,k int
        fmt.Scan(&n,&k)
        var ss string
        fmt.Scan(&ss)
        s := []rune(ss)
        s = append(s,'1')
        last := -k - 1
        res := 0
        //fmt.Print(s)
        for i := 0;i < n + 1;i++ {
            if s[i] == '1' {
                dist := i - last - k
                if dist > k {
                    res += dist / (k + 1)
                }

                last = i
            }
        }
        fmt.Printf("%d\n",res)
    }
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)

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

		fmt.Println(solve(n, k, s[:n]))
	}
}

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(n, k int, s string) int {
	var j int
	if s[0] == '1' {
		j++
	}

	var res int
	for i := j + 1; i <= n; i++ {
		if i < n && s[i] == '0' {
			continue
		}
		// i == n or s[i] == '1'
		d := i - j

		if j == 0 && i == n {
			//x12x12x12..x
			res = (d + k) / (k + 1)
			break
		}
		//12k12k12k12
		//k12k1
		var x = d / (k + 1)
		r := d % (k + 1)

		if x > 0 {
			if j == 0 {
				// i < n
				if r != 0 {
					x--
				}
			} else {
				// j > 0
				if i < n && r != k {
					x--
				}
			}
		}
		res += x
		j = i + 1
	}

	return res
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)

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

		fmt.Println(solve(n, k, s[:n]))
	}
}

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(n, k int, s string) int {
	var j int
	if s[0] == '1' {
		j++
	}

	var res int
	for i := j + 1; i <= n; i++ {
		if i < n && s[i] == '0' {
			continue
		}
		// i == n or s[i] == '1'
		d := i - j

		if j == 0 && i == n {
			//x12x12x12..x
			res = (d + k) / (k + 1)
			break
		}
		//12k12k12k12
		//k12k1
		var x = d / (k + 1)
		r := d % (k + 1)

		if j == 0 {
			// i < n
			if r != 0 {
				x--
			}
		} else {
			// j > 0
			if i < n && r != k {
				x--
			}
		}

		res += x
		j = i + 1
	}

	return res
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		nks := strings.Split(string(line), " ")
		n, _ := strconv.ParseInt(nks[0], 10, 64)
		k, _ := strconv.ParseInt(nks[1], 10, 64)
		line = readLine(reader)
		for j := int64(0); j < n; j++ {
			if line[j] == '1' {
				m := int64(0)
				for m = j - 1; m >= j-k && m >= 0; m-- {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				for m = j + 1; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						m--
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			if line[j] == '0' {
				sum++
				m := j + 1
				for ;m<=j+k&&m<n;m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		fmt.Println(sum)
	}
}

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		nks := strings.Split(string(line), " ")
		n, _ := strconv.Atoi(nks[0])
		k, _ := strconv.Atoi(nks[1])
		line = readLine(reader)
		for j := 0; j < n; j++ {
			if line[j] == '1' {
				for m := j - 1; m >= j-k && m >= 0; m-- {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				for m := j + 1; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
			}
		}
		sum := 0
		for j := 0; j < n; j++ {
			if line[j] == '0' {
				sum++
				for m:=j+1;m<=j+k&&m<n;m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
			}
		}
		fmt.Println(sum)
	}
}

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		nks := strings.Split(string(line), " ")
		n, _ := strconv.ParseInt(nks[0], 10, 64)
		k, _ := strconv.ParseInt(nks[1], 10, 64)
		line = readLine(reader)
		for j := int64(0); j < n; j++ {
			if line[j] == '1' {
				m := int64(0)
				for m = j - 1; m >= j-k && m >= 0; m-- {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				for m = j + 1; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		sum := 0
		for j := int64(0); j < n; j++ {
			if line[j] == '0' {
				sum++
				m := j + 1
				for ;m<=j+k&&m<n;m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		fmt.Println(sum)
	}
}

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		nks := strings.Split(string(line), " ")
		n, _ := strconv.ParseInt(nks[0], 10, 64)
		k, _ := strconv.ParseInt(nks[1], 10, 64)
		line = readLine(reader)
		for j := int64(0); j < n; j++ {
			if line[j] == '1' {
				m := int64(0)
				for m = j - 1; m >= j-k && m >= 0; m-- {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				for m = j + 1; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m - 1
			}
		}
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			if line[j] == '0' {
				sum++
				m := j + 1
				for ;m<=j+k&&m<n;m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		fmt.Println(sum)
	}
}

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		nks := strings.Split(string(line), " ")
		n, _ := strconv.Atoi(nks[0])
		k, _ := strconv.Atoi(nks[1])
		line = readLine(reader)
		for j := 0; j < n; j++ {
			if line[j] == '1' {
				m := 0
				for m = j - 1; m >= j-k && m >= 0; m-- {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				for m = j + 1; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		sum := 0
		for j := 0; j < n; j++ {
			if line[j] == '0' {
				sum++
				for m:=j+1;m<=j+k&&m<n;m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
			}
		}
		fmt.Println(sum)
	}
}

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		nks := strings.Split(string(line), " ")
		n, _ := strconv.Atoi(nks[0])
		k, _ := strconv.Atoi(nks[1])
		line = readLine(reader)
		for j := 0; j < n; j++ {
			if line[j] == '1' {
				m := 0
				for m = j - 1; m >= j-k && m >= 0; m-- {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				for m = j + 1; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		sum := 0
		for j := 0; j < n; j++ {
			if line[j] == '0' {
				sum++
				m := j + 1
				for ;m<=j+k&&m<n;m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		fmt.Println(sum)
	}
}

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		nks := strings.Split(string(line), " ")
		n, _ := strconv.ParseInt(nks[0], 10, 64)
		k, _ := strconv.ParseInt(nks[1], 10, 64)
		line = readLine(reader)
		for j := int64(0); j < n; j++ {
			if line[j] == '1' {
				m := int64(0)
				for m = j - 1; m >= j-k && m >= 0; m-- {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				for m = j + 1; m <= j+k && m < n; m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			if line[j] == '0' {
				sum++
				m := j + 1
				for ;m<=j+k&&m<n;m++ {
					if line[m] == '1' {
						break
					}
					line[m] = '1'
				}
				j = m
			}
		}
		fmt.Println(sum)
	}
}

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

package main

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

var n, k, nTest int
var s string

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n, &k)
		fmt.Fscan(in, &s)
		res := 0

		dis := k
		for i := 0; i < n+k; i++ {
			if i >= n || s[i] == '0' {
				dis++
			}

			if (i < n && s[i] == '1') || (i == n+k-1) {
				res += dis / (2*k + 1)
				dis = 0
			}

		}
		fmt.Fprintln(out, res)
	}

	out.Flush()
}

package main

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

var (
	debug = false
	tests = 0
	reader io.Reader
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	return int(math.Ceil(float64(n - count * (k + 1))/float64(k+1)))
	//
	//if !strings.Contains(s, "1") {
	//	return int(math.Ceil(float64(n)/float64(k+1)))
	//}
	//
	//
	//if s[0] == '1' && s[n-1] == '1' {
	//	return int(math.Ceil(float64(n-2*k)/float64(k+1)))
	//}
	//
	//return int(math.Ceil(float64(n-k)/float64(k+1)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k, s[start:i+1]))
			total += cal(i-start+1, k, s[start:i+1])
			start = i
		}
	}

	if s[n-1] == '0' {
		total += cal(n-start, k, s[start:])
	}

	fmt.Println(total)
}

func input() {
	if debug {
		var e error
		reader, e = os.Open("input.txt")
		if e != nil {
			fmt.Println("error", e.Error())
			return
		}
	} else {
		reader = os.Stdin
	}

	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		scanner.Scan()
		n := parseInt(scanner.Text())
		scanner.Scan()
		k := parseInt(scanner.Text())
		scanner.Scan()
		s := scanner.Text()

		process(n, k, s)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

import (
	"fmt"
	"math"
	"strings"
)

var (
	tests = 0
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	if n - count * k <= 0 {
		return 0
	}

	return int(math.Ceil(float64(n - count * k)/float64(k)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k+1,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k + 1, s[start:i+1]))
			total += cal(i-start+1, k + 1, s[start:i+1])
			start = i
		}
	}

	if s[n-1] == '0' {
		//fmt.Println("xxx", n-start, s[start:], cal(n-start, k + 1, s[start:]))
		total += cal(n-start, k + 1, s[start:])
	}

	fmt.Println(total)
}

func input() {
	fmt.Scanf("%d\n", &tests)

	for ; tests > 0; tests-- {
		var n int
		var k int
		var s string

		fmt.Scanf("%d %d\n", &n, &k)
		fmt.Scanf("%s", &s)
		process(n, k, s)
	}
}

package main

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

var (
	debug = false
	tests = 0
	reader io.Reader
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	if n - count * k <= 0 {
		return 0
	}

	return int(math.Ceil(float64(n - count * k)/float64(k)))
	//
	//if !strings.Contains(s, "1") {
	//	return int(math.Ceil(float64(n)/float64(k+1)))
	//}
	//
	//
	//if s[0] == '1' && s[n-1] == '1' {
	//	return int(math.Ceil(float64(n-2*k)/float64(k+1)))
	//}
	//
	//return int(math.Ceil(float64(n-k)/float64(k+1)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k+1,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k + 1, s[start:i+1]))
			total += cal(i-start+1, k + 1, s[start:i+1])
			start = i
		}
	}

	if s[n-1] == '0' {
		//fmt.Println("xxx", n-start, s[start:], cal(n-start, k + 1, s[start:]))
		total += cal(n-start, k + 1, s[start:])
	}

	fmt.Println(total)
}

func input() {
	if debug {
		var e error
		reader, e = os.Open("input.txt")
		if e != nil {
			fmt.Println("error", e.Error())
			return
		}
	} else {
		reader = os.Stdin
	}

	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		scanner.Scan()
		n := parseInt(scanner.Text())
		scanner.Scan()
		k := parseInt(scanner.Text())
		scanner.Scan()
		s := scanner.Text()

		process(n, k, s)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

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

var (
	debug = false
	tests = 0
	reader io.Reader
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	if n - count * k <= 0 {
		return 0
	}

	return int(math.Ceil(float64(n - count * k)/float64(k)))
	//
	//if !strings.Contains(s, "1") {
	//	return int(math.Ceil(float64(n)/float64(k+1)))
	//}
	//
	//
	//if s[0] == '1' && s[n-1] == '1' {
	//	return int(math.Ceil(float64(n-2*k)/float64(k+1)))
	//}
	//
	//return int(math.Ceil(float64(n-k)/float64(k+1)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k + 1, s[start:i+1]))
			total += cal(i-start+1, k + 1, s[start:i+1])
			start = i
		}
	}

	if s[n-1] == '0' {
		//fmt.Println("xxx", n-start, s[start:], cal(n-start, k + 1, s[start:]))
		total += cal(n-start, k + 1, s[start:])
	}

	fmt.Println(total)
}

func input() {
	if debug {
		var e error
		reader, e = os.Open("input.txt")
		if e != nil {
			fmt.Println("error", e.Error())
			return
		}
	} else {
		reader = os.Stdin
	}

	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		scanner.Scan()
		n := parseInt(scanner.Text())
		scanner.Scan()
		k := parseInt(scanner.Text())
		scanner.Scan()
		s := scanner.Text()

		process(n, k, s)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

import (
	"fmt"
	"math"
	"strings"
)

var (
	tests = 0
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	if n - count * k <= 0 {
		return 0
	}

	return int(math.Ceil(float64(n - count * k)/float64(k)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k+1,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k + 1, s[start:i+1]))
			total += cal(i-start+1, k + 1, s[start:i+1])
			start = i
		}
	}

	if s[n-1] == '0' {
		//fmt.Println("xxx", n-start, s[start:], cal(n-start, k + 1, s[start:]))
		total += cal(n-start, k + 1, s[start:])
	}

	fmt.Println(total)
}

func input() {
	fmt.Scanf("%d", &tests)

	for ; tests > 0; tests-- {
		var n int
		var k int
		var s string

		fmt.Scanf("%d %d", &n, &k)
		fmt.Scan(&s)
		process(n, k, s)
	}
}

package main

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

var (
	debug = false
	tests = 0
	reader io.Reader
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	return int(math.Ceil(float64(n - count * (k + 1))/float64(k+1)))
	//
	//if !strings.Contains(s, "1") {
	//	return int(math.Ceil(float64(n)/float64(k+1)))
	//}
	//
	//
	//if s[0] == '1' && s[n-1] == '1' {
	//	return int(math.Ceil(float64(n-2*k)/float64(k+1)))
	//}
	//
	//return int(math.Ceil(float64(n-k)/float64(k+1)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k, s[start:i+1]))
			total += cal(i-start+1, k, s[start:i+1])
			start = i
		}
	}

	fmt.Println(total)
}

func input() {
	if debug {
		var e error
		reader, e = os.Open("input.txt")
		if e != nil {
			fmt.Println("error", e.Error())
			return
		}
	} else {
		reader = os.Stdin
	}

	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		scanner.Scan()
		n := parseInt(scanner.Text())
		scanner.Scan()
		k := parseInt(scanner.Text())
		scanner.Scan()
		s := scanner.Text()

		process(n, k, s)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

import (
	"fmt"
	"math"
	"strings"
)

var (
	tests = 0
)

func main() {
	input()
}

func cal(n int, k int, s string) int {
	if n < 1 || s == "1" {
		return 0
	}

	if s == "0" {
		return 1
	}

	count := strings.Count(s, "1")
	if n - count * k <= 0 {
		return 0
	}

	return int(math.Ceil(float64(n - count * k)/float64(k)))
}

func process(n int, k int, s string) {
	if !strings.Contains(s, "1") {
		fmt.Println(cal(n,k+1,s))
		return
	}

	start := 0
	total := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			//fmt.Println("xxx", i-start+1, s[start:i+1], cal(i-start+1, k + 1, s[start:i+1]))
			total += cal(i-start+1, k + 1, s[start:i+1])
			start = i
		}
	}

	if s[n-1] == '0' {
		//fmt.Println("xxx", n-start, s[start:], cal(n-start, k + 1, s[start:]))
		total += cal(n-start, k + 1, s[start:])
	}

	fmt.Println(total)
}

func input() {
	fmt.Scanf("%d\n", &tests)

	for ; tests > 1; tests-- {
		var n int
		var k int
		var s string

		fmt.Scanf("%d %d\n", &n, &k)
		fmt.Scanf("%s\n", &s)
		process(n, k, s)
	}
}


You are given two positive integers $$$n$$$ and $$$k$$$. Print the $$$k$$$-th positive integer that is not divisible by $$$n$$$.For example, if $$$n=3$$$, and $$$k=7$$$, then all numbers that are not divisible by $$$3$$$ are: $$$1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$$$. The $$$7$$$-th number among them is $$$10$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are given, one per line. Each test case is two positive integers $$$n$$$ ($$$2 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$).

For each test case print the $$$k$$$-th positive integer that is not divisible by $$$n$$$.

package main

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

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

func Assert(b bool) {
  if !b {
    panic("Assertion error")
  }
}

func main() {
  input := os.Stdin
  /*
  input := strings.NewReader(`6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1
`)
  */
  scanner := bufio.NewScanner(input)

  getLine := func() string {
    if !scanner.Scan() {
      panic("expected line")
    }
    return scanner.Text()
  }

  parseNumber := func(s string) int {
    t, err := strconv.ParseInt(s, 10, 64)
    CheckError(err)
    return int(t)
  }

  getNumber := func() int {
    return parseNumber(getLine())
  }

  t := getNumber()
  for i := 0; i < t; i++ {
    lst := strings.Split(getLine(), " ")
    n := parseNumber(lst[0])
    k := parseNumber(lst[1])

    //fmt.Println(n, k)
    processPair(n, k)
  }

}

func processPair(n, k int) {
  p := k / (n - 1)
  q := k % (n - 1)

  var x int
  if q == 0 {
    x = n*p - 1
  } else {
    x = n*p + q
  }

  fmt.Println(x)
}

package main

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

func main() {
	t := scanInt()
	for ; t > 0; t-- {
		n , k := scanInt(), scanInt()
		x := k / (n - 1)
		if k % (n - 1) == 0 {
			_, _ = printFmt(n*x - 1)
		} else {
			_, _ = printFmt(n*x + k % (n-1))
		}
	}
}
/*********************** 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, _ := MnMx(args...); return mn }
func max(args ...int) int { _, mx := MnMx(args...); return mx }
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n, k int64
		fmt.Scanf("%d %d\n", &n, &k)
		q := k / (n - 1)
		r := k % (n - 1)
		if r == 0 {
			fmt.Println(q*n - 1)
		} else {
			fmt.Println(q*n + r)
		}
	}
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		n, k := s.NextInt(), s.NextInt()
		if n > k {
			fmt.Println(k)
		} else {
			v := n*(k/(n-1)) + k%(n-1)
			if v%n == 0 {
				v--
			}
			fmt.Println(v)
		}
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1352/problem/C
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n, k int
	fmt.Fscan(input, &n, &k)
	if k < n {
		fmt.Println(k)
	} else {
		r := k % (n - 1)
		g := k / (n - 1)
		kn := g * n
		ans := kn + r
		if r == 0 {
			ans--
		}

		fmt.Println(ans)
	}

}

package main

import (
	"fmt"
)

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

	for i := 0; i < t; i++ {
		var n, k int
		fmt.Scan(&n, &k)
		// find the k-th positive integer not divisible by n
		m := k + (k-1)/(n-1)
		fmt.Println(m)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"

)
func max(a,b int) int{
	if(a>b){
		return a
	}
	return b;
}
func main(){
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int;
	fmt.Fscanln(reader, &T)
	for t:=0;t<T;t++ {
		var n,k int;
		fmt.Fscanln(reader,&n,&k)
		countsEveryItteration := n-1
		multiples := k/countsEveryItteration
		if(k%countsEveryItteration==0){
			fmt.Fprintln(writer,n*multiples-1)
			continue
		}
		startValue := n*multiples
		startItterations := countsEveryItteration*multiples
		diff:= k -startItterations
		fmt.Fprintln(writer,startValue+diff)
	}
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()

		nk := scanner.Text()

		parts := strings.Fields(nk)

		nn := parts[0]
		kk := parts[1]

		n, _  := strconv.Atoi(nn)

		k, _  := strconv.Atoi(kk)

		res := solve2(n, k)

		fmt.Println(res)
	}
}

func solve2(n , k int) int {
	q := k / (n - 1)

	a := q * n

	b := a - q

	s := k - b

	if s == 0 {
		return  a - 1
	}

	return s + a
}

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, k int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, k = ReadInt2()
		solve(int64(n), int64(k))
	}
}

func solve(n, k int64) {
	var ans int64

	c := k / (n - 1)
	nokori := k - (n-1)*c

	if nokori == 0 {
		ans = n*c - 1
	} else {
		ans = n*c + nokori
	}

	fmt.Println(ans)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		k := readInt()
		a := int64(k / (n - 1))

		a2 := int64(k % (n - 1))
		start := (int64(n) * a) + a2
		if a2 == 0 {
			start--
		}
		fmt.Println(start)
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

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

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

	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		ans := sort.Search(2.1e9, func(x int) bool { return x-x/n >= k })
		Fprintln(out, ans)
	}
}

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

package main

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

var DEBUG = true

func main() {
	defer Flush()

	T := readi()
	for t := 0; t < T; t++ {
		n := readi()
		k := readi()
		println(solve(n, k))
	}

}

func solve(n, k int) int {
	x := (k - 1) / (n - 1)
	return x*n + (k-1)%(n-1) + 1
}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

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

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	t := nextInt()
	for i := 0; i < t; i++ {
		n, k := nextInt(), nextInt()
		if k < n-1 {
			fmt.Println(k)
			continue
		}
		if k%(n-1) == 0 {
			fmt.Println(k/(n-1)*n - 1)
			continue
		} else if k%(n-1) > 0 {
			fmt.Println(int(k/(n-1))*n + k%(n-1))
			continue
		}
	}

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}

// 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, k int
 fmt.Fscanf(reader, "%d %d\n", &n, &k)
 fmt.Fprintf(writer,"%d\n", (k-1) / (n-1) + k)
}

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, k, ans int64
	scanf("%d %d\n", &n, &k)
	ans = k
	cnt := ans - ans / n
	for cnt != k {
		if cnt < k {
			ans +=  k - cnt
			cnt =  ans - ans / n
		} else {
			ans -= cnt - k
			cnt = ans - ans / n
		}
	}
	printf("%d\n", ans)
}

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

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	for ; t > 0; t-- {
		var n int
		var k int
		fmt.Scanln(&n, &k)
		x := k / (n - 1)
		if k%(n-1) == 0 {
			fmt.Println(n*x - 1)
		} else {
			fmt.Println(n*x + k%(n-1))
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t, n, k int64
	fmt.Fscan(reader, &t)
	for i := int64(0); i < t; i++ {
		fmt.Fscan(reader, &n, &k)
		fmt.Fprintln(writer, k + (k - 1) / (n - 1))
	}
}//2020-07-31 15:11:56.58

package main

import "fmt"

func main() {

	var t,i int
	fmt.Scan(&t)
	// fmt.Printf(" %d" ,t/10)
	i = 0
	for i<t {
		i+=1
		var n,k int
		fmt.Scan(&n ,&k)
		x:=0
		x = ((k)/(n-1))*(n)
		y:=(k%(n-1))
		if y==0{
			fmt.Println(x-1)
		}
		if y!=0{
			fmt.Println(x+y)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, k := 0, 0
		fmt.Fscan(in, &n, &k)
		// ans = k + # of skips till k
		// skip = an integer div by n
		fmt.Fprintln(out, k+(k-1)/(n-1))
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, k := 0, 0
		fmt.Fscan(in, &n, &k)
		// ans = k + # of skips till k
		// skip = an integer div by n
		skips := (k - 1) / (n - 1)
		fmt.Fprintln(out, k+skips)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, k := 0, 0
		fmt.Fscan(in, &n, &k)
		// ans = k + # of skips till k
		// skip = an integer div by n
		skip := (k - 1) / (n - 1)
		fmt.Fprintln(out, k+skip)
	}
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextUInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

func gcd(x, y int64) int64 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

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

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

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

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n, k := reader.NextInt64(), reader.NextInt64()
		writer.Printf("%d\n", sol(n, k))
	}
}

func sol(n, k int64) int64 {
	space := n-1
	spaces := k / space
	spacesExtra := k % space
	if spacesExtra == 0 {
		return n * spaces - 1
	}
	return n * spaces + spacesExtra
}

// 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, k int64
 fmt.Fscanf(reader, "%d %d\n", &n, &k)
 lo := int64(1)
 hi := int64(2*1e9)
 for ; lo < hi ; {
  mid := (lo + hi) >> 1
  val := mid - mid / n
  if val > k {
   hi = mid - 1
  } else if val < k {
   lo = mid + 1
  } else {
   lo = mid
   hi = mid
  }
 }
 fmt.Fprintf(writer,"%d\n", lo)
}

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