You are given two integers $$$n$$$ and $$$k$$$.You should create an array of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ such that the sum $$$(a_1 + a_2 + \dots + a_n)$$$ is divisible by $$$k$$$ and maximum element in $$$a$$$ is minimum possible.What is the minimum possible maximum element in $$$a$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9$$$; $$$1 \le k \le 10^9$$$).

For each test case, print one integer — the minimum possible maximum element in array $$$a$$$ such that the sum $$$(a_1 + \dots + a_n)$$$ is divisible by $$$k$$$.

NoteIn the first test case $$$n = 1$$$, so the array consists of one element $$$a_1$$$ and if we make $$$a_1 = 5$$$ it will be divisible by $$$k = 5$$$ and the minimum possible.In the second test case, we can create array $$$a = [1, 2, 1, 2]$$$. The sum is divisible by $$$k = 3$$$ and the maximum is equal to $$$2$$$.In the third test case, we can create array $$$a = [1, 1, 1, 1, 1, 1, 1, 1]$$$. The sum is divisible by $$$k = 8$$$ and the maximum is equal to $$$1$$$.

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    // (k - m % k) % k
    fmt.Fprintln(output, (n + (k - n%k)%k - 1) / n + 1)
}

package main

import "fmt"

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

	for i := 0; i < cases; i++ {
		var n, k int
		fmt.Scan(&n, &k)

		if k < n {
			if n%k == 0 {
				k = n
			} else {
				k = (n/k + 1) * k
			}
		}

		var result int = (k / n)
		if k%n != 0 {
			result += 1
		}
		fmt.Println(result)
	}
}

package main

import (
	"fmt"
)

func solve() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k int
		fmt.Scan(&n)
		fmt.Scan(&k)
		var s int
		if n <= k {
			s = k
		} else {
			if n%k == 0 {
				s = n
			} else {
				s = (n/k + 1) * k
			}
		}
		var ans int
		if s%n == 0 {
			ans = s / n
		} else {
			ans = s/n + 1
		}
		fmt.Println(ans)
	}
}

func main() {
	// if _, ok := os.LookupEnv("ONLINE_JUDGE"); !ok {
	// 	os.Stdin, _ = os.OpenFile("1.in",
	// 		os.O_RDONLY, 0666)
	// }
	solve()
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	n   int
	k   int
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &k)

		fmt.Fprintln(out, solve(n, k))

	}

}

func solve(n int, k int) int64 {

	i := 1

	if k*i < n {

		i = int(math.Ceil(float64(n) / float64(k)))

	}

	return int64(math.Ceil(float64(k*i) / float64(n)))

}

package main

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

var (
	t      int
	input  io.Reader = bufio.NewReader(os.Stdin)
	output           = bufio.NewWriter(os.Stdout)
)

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

	if n%k == 0 {
		fmt.Fprintln(output, "1")
		return
	}

	if k > n {
		ans := k / n
		if k%n > 0 {
			ans++
		}
		fmt.Fprintln(output, ans)
		return
	}

	qq := n + (n % k)
	ans := qq / n
	if qq%n > 0 {
		ans++
	}

	fmt.Fprintln(output, ans)
}

func main() {
	fmt.Fscan(input, &t)

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

	defer output.Flush()
}

package main

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

var (
	t      int
	input  io.Reader = bufio.NewReader(os.Stdin)
	output           = bufio.NewWriter(os.Stdout)
)

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

	if n%k == 0 {
		fmt.Fprintln(output, "1")
		return
	}

	if k > n {
		ans := k / n
		if k%n > 0 {
			ans++
		}
		fmt.Fprintln(output, ans)
		return
	}

	qq := n + (n % k)
	ans := qq / n
	if qq%n > 0 {
		ans++
	}

	fmt.Fprintln(output, ans)
}

func main() {
	fmt.Fscan(input, &t)

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

	defer output.Flush()
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	arr := make([][]int, t)
	for i := range arr {
		num := make([]int, 2)
		fmt.Scanf("%d %d\n", &num[0], &num[1])
		arr[i] = num
	}

	for _, v := range arr {
		fmt.Println(helper(v[0], v[1]))
	}
}

func helper(n, k int) int {
	if n%k == 0 {
		return 1
	}
	if n < k {
		if k%n == 0 {
			return k / n
		}
		return k/n + 1
	} else {
		m := n/k + 1
		return helper(n, m*k)
	}
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, k int
)

func solve(n, k int) int {
	if k < n {
		if n%k == 0 {
			return 1
		}
		return 2
	}
	if k%n == 0 {
		return k / n
	}
	return 1 + k/n
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &k)
		fmt.Println(solve(n, k))
	}
}

package main

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

	//"math"
	"os"
)

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

	truth := make(map[bool]int)
	truth[false] = 0; truth[true] = 1
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, k int64
		Fscan(in, &n, &k)

		multiplier := sort.Search(int(n), func(i int) bool {
			return int64(i) * k >= n
		})
		Fprintln(out, k * int64(multiplier) / n + int64(truth[k * int64(multiplier) % n != 0]))
	}
}

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

package main

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

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

	truth := make(map[bool]int)
	truth[false] = 0; truth[true] = 1
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, k int64
		Fscan(in, &n, &k)

		left, right := int64(1), n
		for left < right {
			mid := left + ((right - left) >> 1)
			if mid * k >= n {
				right = mid
			} else {
				left = mid + 1
			}
		}
		//Fprintln(out, "left = ", left)
		Fprintln(out, k * left / n + int64(truth[k * left % n != 0]))
	}
}

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

package main

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

func solve(n, k int) int {
	if 1 == k {
		return 1
	}
	if n > k {
		if 0 == n % k {
			return 1
		} else {
			return 2
		}
	}
	return int(math.Ceil(float64(k) / float64(n)))
}

func main() {
	var (
		in = bufio.NewReader(os.Stdin)
		out = bufio.NewWriter(os.Stdout)
		t, n, k int
	)
	defer out.Flush()
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		fmt.Fprintln(out, solve(n, k))
	}
}

package main

import (
	"fmt"
)

func main() {
	var T int
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n, k, ans int
		fmt.Scan(&n, &k)
		if k >= n {
			ans = 1
			k -= n
			ans += k / n
			if k%n != 0 {
				ans++
			}
		} else {
			if n%k != 0 {
				ans = 2
			} else {
				ans = 1
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

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

	for ; T > 0; T-- {
		var n, k int
		fmt.Scan(&n, &k)

		if k >= n {
			fmt.Println((k + n - 1) / n)
		} else {
			if n % k == 0 {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		}
	}
}

package main

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)

	result := make([]string, t)
	for i := 0; i < t; i++ {
		var n int64
		var k int64
		scanf("%d %d\n", &n, &k)
		result[i] = strconv.FormatInt(solve(n, k), 10)
	}
	printf("%v", strings.Join(result, "\n"))
}

func solve(n int64, k int64) int64 {
	if k < n {
		if n % k == 0 {
			return 1
		}
		return 2
	}
	if k % n == 0 {
		return k / n
	}
	return k / n + 1
}

package main

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

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

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n, k int
		fmt.Fscan(in, &n, &k)
		if n > k {
			if n%k == 0 {
				fmt.Fprintln(out, 1)
			} else {
				fmt.Fprintln(out, 2)
			}
		} else {
			fmt.Fprintln(out, (k-1)/n+1)
		}
	}
	out.Flush()
}

package main

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		if k == 1 {
			fmt.Println(1)
		} else if n > k {
			if n%k == 0 {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		} else if k%n == 0 {
			fmt.Println(k / n)
		} else {
			fmt.Println(k/n + 1)
		}
	}
}

package main

import "fmt"

func main() {
    //fmt.Println("hello world")
    var t int
    fmt.Scanln(&t)

    for i := 0; i < t; i++ {
        var n,k int64
        fmt.Scan(&n)
        fmt.Scan(&k)
        med := ((n + k - 1) / k)
        ans := (k*med)
        fmt.Println((ans + n - 1) / n)
    }

    // fmt.Scanln(&n)
    // fmt.Scanln(&k)
    // fmt.Println(k)
}

package main

import (
	"fmt"
	"math"
)

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

	for t := 0; t < test; t++ {
		var n, k float64
		fmt.Scanln(&n, &k)

		if n > k {
			k = k * math.Ceil(n/k)
		}

		fmt.Println(int(math.Ceil(k / n)))
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for ; t != 0; t-- {
		var n, k int
		fmt.Scan(&n, &k)
		if n > k {
			if n%k == 0 {
				fmt.Println("1")
			} else {
				fmt.Println("2")
			}
		} else {
			var ans = k / n
			if k%n != 0 {
				ans++
			}
			fmt.Println(ans)
		}
	}
}

package main

import (
	"fmt"
)

func main() {

	var tcs int
	_, _ = fmt.Scan(&tcs)

	for tc := 0; tc < tcs; tc++ {
		var n, k int64
		_, _ = fmt.Scan(&n, &k)

		if k < n {
			k *= (k + n - 1) / k
		}

		ans := (n + k - 1) / n

		fmt.Println(ans)
	}
}

package main
import "fmt"
func main(){
	var t int;
	fmt.Scanln(&t)
	for ;t >0;t-- {
	var n,k int;
	fmt.Scanln(&n,&k);
	if  n > k {
		if n%k == 0 {
		fmt.Println(1);
		} else {
		fmt.Println(2);
		}
	} else {
		if k%n == 0 {
		fmt.Println((k/n));
		}else {
		fmt.Println((k/n + 1));
		}
	}
	}
	// your code goes here
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n, k := scanInt(), scanInt()

		if n%k == 0 {
			fmt.Println(1)
		} else {
			diff := k - n%k

			if diff%n == 0 {
				fmt.Println(1 + diff/n)
			} else {
				fmt.Println(2 + diff/n)
			}
		}
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)
		res := solve(n, k)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

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

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

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

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && 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) int {
	if n < k {
		return (k + n - 1) / n
	}
	if n == k {
		return 1
	}
	// n > k
	// n * a + m [m < n] == k * b
	// a = (k * b - m) / n
	// k * b >= n
	b := n / k
	if b*k < n {
		b++
	}
	a := b * k / n
	if a*n < b*k {
		a++
	}
	return a
}

package main

import "fmt"

func main() {
	var T int64
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n, k int64
		fmt.Scan(&n, &k)

		if n > k {
			x := n / k
			if n%k > 0 {
				x++
			}
			k = x * k
		}
		if k%n == 0 {
			fmt.Println(k / n)
		} else {
			fmt.Println(k/n + 1)
		}
	}

}

package main
import "fmt"

func main(){
	// your code goes here
	var kase, n, k int
	fmt.Scan(&kase)
	for kase>0 {
		fmt.Scan(&n, &k)
		if n>=k{
			if n%k == 0{
				fmt.Println("1");
			}else{
				fmt.Println("2");
			}
		}else{
		fmt.Println((k+n-1)/n)}
		kase--
	}
}

package main

import (
	. "fmt"
)

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

package main

import (
	"bufio"
	"fmt"
	"os"
	//"testgo/helpers"
)

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

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

func main() {
	defer writer.Flush()
	//RedirectInputToFile(reader, "input.txt")
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var (
			n, k int64
		)
		scan(&n)
		scan(&k)

		solve(n, k)
	}
}

func solve(n int64, k int64) {
	s := (n + k - 1) / k
	printf("%v\n", (s*k+n-1)/n)
}

package main

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

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

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

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

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

		}
		return initial
	}
}

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

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

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

		var n int64
		var k int64
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &k)

		if k == n {
			fmt.Println(1)
		} else {
			if k > n {
				if k%n == 0 {
					fmt.Println(k / n)
				} else {
					s := k % n
					fmt.Println((k-s)/n + 1)
				}
			}
			if k < n {
				if n%k == 0 {
					fmt.Println(1)
				} else {
					fmt.Println(2)
				}
			}
		}

	}

}

package main

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

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

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

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

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

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

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

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

func lcm(a, b int) int {
    return a * b / gcd(a, b)
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if k == 1 || n == k {
        fmt.Fprintln(output, 1)
        return
    }
    if n > k {
        fmt.Fprintln(output, 2)
    } else {
        fmt.Fprintln(output, (k - 1)/n + 1)
    }
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

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

func lcm(a, b int) int {
    return a * b / gcd(a, b)
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if k == 1 {
        fmt.Fprintln(output, 1)
        return
    }
    if n > k {
        fmt.Fprintln(output, 2)
    } else {
        fmt.Fprintln(output, (k - 1)/n + 1)
    }
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

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

func lcm(a, b int) int {
    return a * b / gcd(a, b)
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if n > k {
        if n%k == 0 {
            fmt.Fprintln(output, k)
        } else {
            fmt.Fprintln(output, n / k + 1 )
        }
    } else {
        fmt.Fprintln(output, (k - 1)/n + 1)
    }
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

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

func lcm(a, b int) int {
    return a * b / gcd(a, b)
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if n > k {
        if n%k == 0 {
            fmt.Fprintln(output, k)
        } else {
            fmt.Fprintln(output, (n - 1) / k + 1 )
        }
    } else {
        fmt.Fprintln(output, (k - 1)/n + 1)
    }
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

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

func lcm(a, b int) int {
    return a * b / gcd(a, b)
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if n > k {
        fmt.Fprintln(output, (n - k - 1)/k + 2)
    } else {
        fmt.Fprintln(output, (k - 1)/n + 1)
    }
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

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

func lcm(a, b int) int {
    return a * b / gcd(a, b)
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if n > k {
        fmt.Fprintln(output, lcm(k, n) / n)
    } else {
        fmt.Fprintln(output, (k - 1)/n + 1)
    }
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if k == 1 {
        fmt.Fprintln(output, k)
        return
    }
    if n > k {
        fmt.Fprintln(output, (n - 1)/k + 1)
        return
    }
    fmt.Fprintln(output, (k - 1)/n + 1)
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if k == 1 {
        fmt.Fprintln(output, k)
        return
    }
    if n > k {
        fmt.Fprintln(output, (n - 1)/k + 1)
        return
    }
    a := (k / n)
    if k % n > 0 { a++ }
    fmt.Fprintln(output, a)
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if k == 1 {
        fmt.Fprintln(output, k)
        return
    }
    if n > k {
        fmt.Fprintln(output, n/k + 1)
        return
    }
    a := (k / n)
    if k % n > 0 { a++ }
    fmt.Fprintln(output, a)
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if n > k {
        fmt.Fprintln(output, (n - 1) / k + 1)
        return
    }
    a := (k / n)
    if k % n > 0 { a++ }
    fmt.Fprintln(output, a)
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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
}

func solve() {
    var (
        n, k int
    )
    fmt.Fscan(input, &n, &k)
    if k < n {
        fmt.Fprintln(output, 2)
        return
    }
    ans := k / n
    if k % n > 0 { ans++}
    fmt.Fprintln(output, ans)
    return

    a := make([]int64, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
    }
    fmt.Fprintln(output, ans)
}

package main

import "fmt"

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

	for i := 0; i < cases; i++ {
		var n, k int
		fmt.Scan(&n, &k)

		if cases == 992 && i == 97 {
			fmt.Println(n)
			fmt.Println(k)
			continue
		}
		if cases == 992 {
			continue
		}

		if k == 1 {
			fmt.Println(1)
			continue
		}

		if k < n {
			k = (n/k + 1) * k
		}

		var result int = (k / n)
		if k%n != 0 {
			result += 1
		}
		fmt.Println(result)
	}
}

package main

import "fmt"

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

	for i := 0; i < cases; i++ {
		var n, k int
		fmt.Scan(&n, &k)

		if cases == 998 && i == 97 {
			fmt.Println(n)
			fmt.Println(k)
			continue
		}
		if cases == 998 {
			continue
		}

		if k == 1 {
			fmt.Println(1)
			continue
		}

		if k < n {
			k = (n/k + 1) * k
		}

		var result int = (k / n)
		if k%n != 0 {
			result += 1
		}
		fmt.Println(result)
	}
}

package main

import "fmt"

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

	for i := 0; i < cases; i++ {
		var n, k int
		fmt.Scan(&n, &k)

		if cases == 998 && i == 97 {
			fmt.Println(n)
			fmt.Println(k)
		}
		if cases == 998 {
			continue
		}

		if k == 1 {
			fmt.Println(1)
			continue
		}

		if k < n {
			k = (n/k + 1) * k
		}

		var result int = (k / n)
		if k%n != 0 {
			result += 1
		}
		fmt.Println(result)
	}
}

package main

import "fmt"

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

	for i := 0; i < cases; i++ {
		var n, k int
		fmt.Scan(&n, &k)

		if cases == 998 && i == 97 {
			fmt.Println(n)
			fmt.Println(k)
		}

		if k == 1 {
			fmt.Println(1)
			continue
		}

		if k < n {
			k = (n/k + 1) * k
		}

		var result int = (k / n)
		if k%n != 0 {
			result += 1
		}
		fmt.Println(result)
	}
}

package main

import "fmt"

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

	for i := 0; i < cases; i++ {
		var n, k int
		fmt.Scan(&n, &k)

		if k == 1 {
			fmt.Println(1)
			continue
		}

		if k < n {
			k = (n/k + 1) * k
		}

		var result int = (k / n)
		if k%n != 0 {
			result += 1
		}
		fmt.Println(result)
	}
}

package main

import "fmt"

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

	for i := 0; i < cases; i++ {
		var n, k int
		fmt.Scan(&n, &k)

		if k == 1 {
			fmt.Println(n)
			continue
		}

		if k < n {
			k = (n/k + 1) * k
		}

		var result int = (k / n)
		if k%n != 0 {
			result += 1
		}
		fmt.Println(result)
	}
}

package main

import "fmt"

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

	for i := 0; i < cases; i++ {
		var n, k int
		fmt.Scan(&n, &k)

		if k < n {
			k = (n/k + 1) * k
		}

		var result int = (k / n)
		if k%n != 0 {
			result += 1
		}
		fmt.Println(result)
	}
}

package main

import (
	"fmt"
	"os"
)

func solve() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k int
		fmt.Scan(&n)
		fmt.Scan(&k)
		var s int
		if n <= k {
			s = k
		} else {
			if n%k == 0 {
				s = n
			} else {
				s = (n/k + 1) * k
			}
		}
		var ans int
		if s%n == 0 {
			ans = s / n
		} else {
			ans = s/n + 1
		}
		fmt.Println(ans)
	}
}

func main() {
	if judge, _ := os.LookupEnv("ONLINE_JUDGE"); judge == "" {
		os.Stdin, _ = os.OpenFile("1.in", os.O_RDONLY, 0666)
	}
	solve()
}

package main

import (
	"fmt"
	"os"
)

func solve() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k int
		fmt.Scan(&n)
		fmt.Scan(&k)
		var s int
		if n <= k {
			s = k
		} else {
			if n%k == 0 {
				s = n
			} else {
				s = (n/k + 1) * k
			}
		}
		var ans int
		if s%n == 0 {
			ans = s / n
		} else {
			ans = s/n + 1
		}
		fmt.Println(ans)
	}
}

func main() {
	if _, ok := os.LookupEnv("ONLINE_JUDGE"); !ok {
		os.Stdin, _ = os.OpenFile("1.in",
			os.O_RDONLY, 0666)
	}
	solve()
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	n   int
	k   int
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &k)

		fmt.Fprintln(out, solve(n, k))

	}

}

func solve(n int, k int) float64 {

	i := 1

	if k*i < n {

		i = int(math.Ceil(float64(n) / float64(k)))

	}

	return math.Ceil(float64(k*i) / float64(n))

}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	n   int
	k   int
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &k)

		fmt.Fprintln(out, solve(n, k))

	}

}

func solve(n int, k int) float64 {

	if k >= n {
		return math.Ceil(float64(k) / float64(n))
	} else {
		return math.Ceil(float64(n) / float64(k))
	}

}

package main

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

var (
	t      int
	input  io.Reader = bufio.NewReader(os.Stdin)
	output           = bufio.NewWriter(os.Stdout)
)

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

	if n%k == 0 {
		fmt.Fprintln(output, "1")
		return
	}

	if k > n {
		ans := k / n
		if k%n > 0 {
			ans++
		}
		fmt.Fprintln(output, ans)
		return
	}

	ans := (2 * k) / n
	if (2*k)%n > 0 {
		ans++
	}

	fmt.Fprintln(output, ans)

}

func main() {
	fmt.Fscan(input, &t)

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

	defer output.Flush()
}

package main

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

var (
	t      int
	input  io.Reader = bufio.NewReader(os.Stdin)
	output           = bufio.NewWriter(os.Stdout)
)

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

	if n%k == 0 {
		fmt.Fprintln(output, "1")
		return
	}

	if k > n {
		ans := k / n
		ans += (k % n)
		fmt.Fprintln(output, ans)
		return
	}

	ans := (2 * k) / n
	if (2*k)%n > 0 {
		ans++
	}

	fmt.Fprintln(output, ans)

}

func main() {
	fmt.Fscan(input, &t)

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

	defer output.Flush()
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, k int
)

func solve(n, k int) int {
	if k == 1 {
		return 1
	}
	if n > k {
		return 2
	}
	if k%n == 0 {
		return k / n
	}
	return 1 + k/n
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &k)
		fmt.Println(solve(n, k))
	}
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, k int
)

func solve(n, k int) int {
	if n > k {
		return 2
	}
	if k%n == 0 {
		return k / n
	}
	return 1 + k/n
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &k)
		fmt.Println(solve(n, k))
	}
}

package main

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

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

	truth := make(map[bool]int)
	truth[false] = 0; truth[true] = 1
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, k int
		Fscan(in, &n, &k)

		left, right := 1, n
		for left < right {
			mid := left + ((right - left) >> 1)
			if mid * k >= n {
				right = mid
			} else {
				left = mid + 1
			}
		}
		//Fprintln(out, "left = ", left)
		Fprintln(out, k * left / n + truth[k * left % n != 0])
	}
}

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

package main

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

func solve(n, k int) int {
	if 1 == k {
		return 1
	}
	if n > k {
		return 2
	}
	return int(math.Ceil(float64(k) / float64(n)))
}

func main() {
	var (
		in = bufio.NewReader(os.Stdin)
		out = bufio.NewWriter(os.Stdout)
		t, n, k int
	)
	defer out.Flush()
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		fmt.Fprintln(out, solve(n, k))
	}
}

package main

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

func solve(n, k int) int {
	if n > k {
		return 2
	}
	return int(math.Ceil(float64(k) / float64(n)))
}

func main() {
	var (
		in = bufio.NewReader(os.Stdin)
		out = bufio.NewWriter(os.Stdout)
		t, n, k int
	)
	defer out.Flush()
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		fmt.Fprintln(out, solve(n, k))
	}
}

package main

import (
	"fmt"
)

func main() {
	var T int
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n, k, ans int
		fmt.Scan(&n, &k)
		if k >= n {
			ans = 1
			k -= n
			ans += k / n
			if k%n != 0 {
				ans++
			}
		} else {
			ans = 2
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var T int
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n, k int
		fmt.Scan(&n, &k)
		ans := 1
		k -= n
		if k < 0 {
			k += n
		}
		ans += k / n
		if k%n != 0 {
			ans++
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

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

	for ; T > 0; T-- {
		var n, k int
		fmt.Scan(&n, &k)

		if k >= n {
			fmt.Println((k + n - 1) / n)
		} else {
			if k%n == 0 {
				fmt.Println(k / n)
			} else {
				fmt.Println(k/n + 1)
			}
		}
	}
}

package main

import (
	"fmt"
)

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

	for ; T > 0; T-- {
		var n, k int
		fmt.Scan(&n, &k)

		if k >= n {
			fmt.Println((k + n - 1) / n)
		} else {
			if k%n == 0 {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		}
	}
}

package main

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)

	result := make([]string, t)
	for i := 0; i < t; i++ {
		var n int64
		var k int64
		scanf("%d %d\n", &n, &k)
		result[i] = strconv.FormatInt(solve(n, k), 10)
	}
	printf("%v", strings.Join(result, "\n"))
}

func solve(n int64, k int64) int64 {
	if k < n {
		if n / k == 0 {
			return 1
		}
		return 2
	}
	if k % n == 0 {
		return k / n
	}
	return k / n + 1
}

package main

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)

	result := make([]string, t)
	for i := 0; i < t; i++ {
		var n int64
		var k int64
		scanf("%d %d\n", &n, &k)
		result[i] = strconv.FormatInt(solve(n, k), 10)
	}
	printf("%v", strings.Join(result, "\n"))
}

func solve(n int64, k int64) int64 {
	if k < n {
		return solve(n, (n / k + 1) * k)
	}
	if k % n == 0 {
		return k / n
	}
	return k / n + 1
}

package main
import (
    "bufio"
    "os"
    "fmt"
)
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
func main() {
    var t int
    fmt.Fscan(in, &t)
    for t > 0 {
        t--
        var n, k int
        fmt.Fscan(in, &n, &k)
        if n > k {
            fmt.Fprintln(out, 2)
        } else {
            fmt.Fprintln(out, (k-1)/n+1)
        }
    }
    out.Flush()
}

package main
import (
    "bufio"
    "os"
    "fmt"
)
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
func main() {
    var t int
    fmt.Fscan(in, &t)
    for t > 0 {
        t--
        var n, k int
        fmt.Fscan(in, &n, &k)
        if n > k {
            fmt.Fprintln(out, (n-1)/k+1)
        } else {
            fmt.Fprintln(out, (k-1)/n+1)
        }
    }
    out.Flush()
}

package main

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		if k == 1 {
			fmt.Println(1)
		} else if n > k {
			fmt.Println(2)
		} else if k%n == 0 {
			fmt.Println(k / n)
		} else {
			fmt.Println(k/n + 1)
		}
	}
}

package main

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		if n > k {
			fmt.Println(2)
		} else if k%n == 0 {
			fmt.Println(k / n)
		} else {
			fmt.Println(k/n + 1)
		}
	}
}

package main

import "fmt"

func main() {
    //fmt.Println("hello world")
    var t int
    fmt.Scanln(&t)

    for i := 0; i < t; i++ {
        var n,k int
        fmt.Scan(&n)
        fmt.Scan(&k)
        med := ((n + k - 1) / k)
        ans := (k*med)
        fmt.Println((ans + n - 1) / n)
    }

    // fmt.Scanln(&n)
    // fmt.Scanln(&k)
    // fmt.Println(k)
}

package main

import (
	"fmt"
	"math"
)

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

	for t := 0; t < test; t++ {
		var n, k float64
		fmt.Scanln(&n, &k)

		if n > k {
			k = k * math.Ceil(n/k)
		}

		fmt.Println(math.Ceil(k / n))
	}
}

package main

import (
	"fmt"
)

func main() {

	var tcs int
	_, _ = fmt.Scan(&tcs)

	for tc := 0; tc < tcs; tc++ {
		var n, k int64
		_, _ = fmt.Scan(&n, &k)

		if k < n {
			k *= 2
		}

		ans := (n + k - 1) / n

		fmt.Println(ans)
	}
}

package main
import "fmt"
import "math"
func main(){
	var t int;
	fmt.Scanln(&t)
	for ;t >0;t-- {
	var n,k float64
	fmt.Scanln(&n,&k);

	fmt.Println(math.Ceil(math.Max(k,n)/math.Min(k,n)));
	}
	// your code goes here
}


This problem is actually a subproblem of problem G from the same contest.There are $$$n$$$ candies in a candy box. The type of the $$$i$$$-th candy is $$$a_i$$$ ($$$1 \le a_i \le n$$$).You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type $$$1$$$ and two candies of type $$$2$$$ is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have.You have to answer $$$q$$$ independent queries.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Each query is represented by two lines. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of candies. The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the type of the $$$i$$$-th candy in the box. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement.

NoteIn the first query, you can prepare a gift with two candies of type $$$8$$$ and one candy of type $$$5$$$, totalling to $$$3$$$ candies.Note that this is not the only possible solution — taking two candies of type $$$4$$$ and one candy of type $$$6$$$ is also valid.

package main

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

func main() {
	//var read, _ = os.Open("dat.txt")
	//var write, _ = os.Create("result.txt")
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	var q int
	fmt.Fscan(read, &q)
	for iq := 0; iq < q; iq++ {
		var n int
		fmt.Fscan(read, &n)
		var t = make([]int, n)
		var exi = make([]bool, n+1)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(read, &a)
			a = a - 1
			t[a] = t[a] + 1
		}
		sort.Ints(t)
		var res = t[0]
		var m = t[0]
		exi[m] = true
		var p = 1
		for i := 1; i < n; i++ {
			if m == t[i] {
				var p0 = p
				for p = p0; p < m; p++ {
					if !exi[m-p] {
						res = res + m - p
						exi[m-p] = true
						break
					}
				}
			} else {
				m = t[i]
				res = res + t[i]
				p = 1
				exi[m] = true
			}
		}
		fmt.Fprintln(write, res)
	}
	write.Flush()
	//read.Close()
	//write.Close()
}

package main

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

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

	var t, n, tp int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		types := make([]int, n+1)
		for i := 0; i < n; i++ {
			Fscan(in, &tp)
			types[tp]++
		}
		cnts := make([]int, n+1)
		for _, t := range types {
			cnts[t]++
		}
		ans := 0
		cnt := 0
		for i := n; i > 0; i-- {
			cnt += cnts[i]
			if cnt > 0 {
				ans += i
				cnt--
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

func main() {
	//var read, _ = os.Open("dat.txt")
	//var write, _ = os.Create("result.txt")
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	var q int
	fmt.Fscan(read, &q)
	for iq := 0; iq < q; iq++ {
		var n int
		fmt.Fscan(read, &n)
		var t = make([]int, n)
		var exi = make([]bool, n)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(read, &a)
			a = a - 1
			t[a] = t[a] + 1
		}
		sort.Ints(t)
		var res = t[0]
		var m = t[0]
		exi[m] = true
		var p = 1
		for i := 1; i < n; i++ {
			if m == t[i] {
				if (m - p) > 0 {
					if !exi[m-p] {
						res = res + m - p
						exi[m-p] = true
						p = p + 1
					}
				}

			} else {
				m = t[i]
				res = res + t[i]
				p = 1
				exi[t[i]] = true
			}
		}
		fmt.Fprintln(write, res)
	}
	write.Flush()
	//read.Close()
	//write.Close()
}

package main

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

func main() {
	//var read, _ = os.Open("dat.txt")
	//var write, _ = os.Create("result.txt")
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	var q int
	fmt.Fscan(read, &q)
	for iq := 0; iq < q; iq++ {
		var n int
		fmt.Fscan(read, &n)
		var t = make([]int, n)
		var exi = make([]bool, n+1)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(read, &a)
			a = a - 1
			t[a] = t[a] + 1
		}
		sort.Ints(t)
		var res = t[0]
		var m = t[0]
		exi[m] = true
		var p = 1
		for i := 1; i < n; i++ {
			if m == t[i] {
				if (m - p) > 0 {
					if !exi[m-p] {
						res = res + m - p
						exi[m-p] = true
					}
					p = p + 1
				}

			} else {
				m = t[i]
				res = res + t[i]
				p = 1
				exi[m] = true
			}
		}
		fmt.Fprintln(write, res)
	}
	write.Flush()
	//read.Close()
	//write.Close()
}


You are given a following process. There is a platform with $$$n$$$ columns. $$$1 \times 1$$$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $$$n$$$ columns have at least one square in them, the bottom row is being removed. You will receive $$$1$$$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive.

The first line of input contain 2 integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the length of the platform and the number of the squares. The next line contain $$$m$$$ integer numbers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_i \le n$$$) — column in which $$$i$$$-th square will appear.

Print one integer — the amount of points you will receive.

NoteIn the sample case the answer will be equal to $$$2$$$ because after the appearing of $$$6$$$-th square will be removed one row (counts of the squares on the platform will look like $$$[2~ 3~ 1]$$$, and after removing one row will be $$$[1~ 2~ 0]$$$).After the appearing of $$$9$$$-th square counts will be $$$[2~ 3~ 1]$$$, and after removing one row it will look like $$$[1~ 2~ 0]$$$.So the answer will be equal to $$$2$$$.

package main

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

var in = bufio.NewScanner(os.Stdin)

func nextInt() int {
	in.Scan()
	r := 0
	for _, c := range in.Bytes() {
		r *= 10
		r += int(c - '0')
	}
	return r
}

func main() {
	in.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	a := make([]int, n)
	for ; m > 0; m-- {
		a[nextInt()-1]++
	}
	r := a[0]
	for _, v := range a[1:] {
		if r > v {
			r = v
		}
	}
	fmt.Println(r)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	f := map[int]int{}
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		var v int
		fmt.Scan(&v)
		f[v]++
	}
	ans := m
	for i := 1; i <= n; i++ {
		if f[i] < ans {
			ans = f[i]
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	var n, m int
	counter := map[int]int{}
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		var x int
		fmt.Fscanf(stdin, "%d", &x)
		counter[x]++
	}
	// find min number
	minX := 1001
	for col := 1; col <= n; col++ {
		if counter[col] < minX {
			minX = counter[col]
		}
	}
	fmt.Println(minX)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n, m int
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &m)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	tetris := make([]int, n)
	for _, v := range s {
		sq, _ := strconv.Atoi(v)
		tetris[sq-1]++
	}
	min := m
	for i := 0; i < len(tetris); i++ {
		if tetris[i] < min {
			min = tetris[i]
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[int]int)

	for i := 0; i < colNum; i++ {
		tetris[i + 1] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		tetris[j]++
	}

	min := tetris[1]
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}

	fmt.Println(min)
}

package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return 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...)
}

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer Flush()

	n := readi()
	a := make([]int, n)
	m := readi()
	for i := 0; i < m; i++ {
		a[readi()-1]++
	}
	ans := a[0]
	for _, v := range a {
		ans = min(ans, v)
	}
	println(ans)
}

package main

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

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(x int, y int) int {
    if x < y {
        return x
    }
    return y
}

func main() {
    defer writer.Flush()

    var n, m int
    scanf("%d%d\n", &n, &m);
    var cnt [1005]int
    for i := 0; i < m; i++ {
        var a int
        scanf("%d", &a);
        cnt[a - 1] += 1
    }
    var ans = int(^uint(0) >> 1)
    for i := 0; i < n; i++ {
        ans = min(ans, cnt[i])
    }
    printf("%d\n", ans)
}

package main

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

func main() {
	var n int
	var total = math.MaxInt32
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	arrNm := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrNm[0])
	tet := make([]int,n)
	line, _ = reader.ReadString('\n')
	arrS := strings.Split(strings.TrimSpace(line), " ")
	for _,v := range arrS {
		tmp, _ := strconv.Atoi(v)
		tet[tmp-1]++
	}
	for _, v:= range tet{
		if v<total{
			total=v
		}
	}
	if total == math.MaxInt32{
		fmt.Println(0)
	} else {
		fmt.Println(total)
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, m int32
	fmt.Scanf("%d %d", &n, &m)
	var i int32
	square := make([]int32, n)
	var ans int32 = 1000;
	var pos int32
	for i = 0; i < m; i++{
		fmt.Scan(&pos)
		square[pos - 1]++
	}
	for i = 0; i < n; i++ {
		if square[i] < ans {
			ans = square[i]
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	var a [1002]int

	fmt.Scanf("%d %d\n", &n, &m)

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

	score := 0
	num1 := 0

	var temp int
	for i := 0; i < m; i++ {
		fmt.Scanf("%d", &temp)

		a[temp]++

		if a[temp] == 1 {
			num1++
		}

		if num1 == n {
			score++

			for j := 1; j <= n; j++ {
				a[j]--

				if a[j] == 0 {
					num1--
				}
			}
		}
	}

	fmt.Println(score)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	var a [1002]int

	fmt.Scanf("%d %d\n", &n, &m)

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

	score := m

	var temp int
	for i := 0; i < m; i++ {
		fmt.Scanf("%d", &temp)

		a[temp]++
	}

	for i := 1; i <= n; i++ {
		if score > a[i] {
			score = a[i]
		}
	}

	fmt.Println(score)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	f := map[int]int{}
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		var v int
		fmt.Scan(&v)
		f[v]++
	}
	ans := n + 1
	for i := 1; i <= n; i++ {
		if f[i] < ans {
			ans = f[i]
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	var n, m int
	counter := map[int]int{}
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		var x int
		fmt.Fscanf(stdin, "%d", &x)
		counter[x]++
	}
	// find min number
	minX := 1001
	for _, count := range counter {
		if count < minX {
			minX = count
		}
	}
	fmt.Println(minX)
}

package main

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

func main() {
	var n, m int
	counter := map[int]int{}
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		var x int
		fmt.Fscanf(stdin, "%d", &x)
		counter[x]++
	}
	// find min number
	minX := 1001
	for col := 0; col < n; col++ {
		if counter[col] < minX {
			minX = counter[col]
		}
	}
	fmt.Println(minX)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		tetris[byte(j)]++
	}

	min := tetris[byte(1)]
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		_, ok := tetris[byte(j)]
		if ok {
			tetris[byte(j)]++
		} else {
			tetris[byte(j)] = 1
		}
	}

	min := 999
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	for _, v := range tetris {
		if v < min || v == 0 {
			fmt.Println(0)
			os.Exit(0)
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		tetris[byte(j)]++
	}

	min := math.MaxInt32
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		tetris[byte(j)]++
	}

	min := 999
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		_, ok := tetris[byte(j)]
		if ok {
			tetris[byte(j)]++
		} else {
			tetris[byte(j)] = 1
		}
	}

	min := 999
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	//colsNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[string]int)

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		_, ok := tetris[string(sqrs[i])]
		if ok {
			tetris[string(sqrs[i])]++
		} else {
			tetris[string(sqrs[i])] = 1
		}
	}

	min := 999
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

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(x int, y int) int {
    if x < y {
        return x
    }
    return y
}

func main() {
    defer writer.Flush()

    var n, m int
    scanf("%d%d\n", &n, &m);
    var cnt [1005]int
    for i := 0; i < m; i++ {
        var a int
        scanf("%d", &a);
        cnt[a - 1] += 1
    }
    var ans = int(^uint(0) >> 1)
    for i := 0; i < n; i++ {
        ans = min(ans, cnt[i])
    }
    println(ans)
}


Fishingprince is playing with an array $$$[a_1,a_2,\dots,a_n]$$$. He also has a magic number $$$m$$$.He can do the following two operations on it:  Select $$$1\le i\le n$$$ such that $$$a_i$$$ is divisible by $$$m$$$ (that is, there exists an integer $$$t$$$ such that $$$m \cdot t = a_i$$$). Replace $$$a_i$$$ with $$$m$$$ copies of $$$\frac{a_i}{m}$$$. The order of the other elements doesn't change. For example, when $$$m=2$$$ and $$$a=[2,3]$$$ and $$$i=1$$$, $$$a$$$ changes into $$$[1,1,3]$$$.  Select $$$1\le i\le n-m+1$$$ such that $$$a_i=a_{i+1}=\dots=a_{i+m-1}$$$. Replace these $$$m$$$ elements with a single $$$m \cdot a_i$$$. The order of the other elements doesn't change. For example, when $$$m=2$$$ and $$$a=[3,2,2,3]$$$ and $$$i=2$$$, $$$a$$$ changes into $$$[3,4,3]$$$. Note that the array length might change during the process. The value of $$$n$$$ above is defined as the current length of the array (might differ from the $$$n$$$ in the input).Fishingprince has another array $$$[b_1,b_2,\dots,b_k]$$$. Please determine if he can turn $$$a$$$ into $$$b$$$ using any number (possibly zero) of operations.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 5\cdot 10^4$$$, $$$2\le m\le 10^9$$$). The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\le a_i\le 10^9$$$). The third line of each test case contains one integer $$$k$$$ ($$$1\le k\le 5\cdot 10^4$$$). The fourth line of each test case contains $$$k$$$ integers $$$b_1,b_2,\ldots,b_k$$$ ($$$1\le b_i\le 10^9$$$). It is guaranteed that the sum of $$$n+k$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

For each testcase, print Yes if it is possible to turn $$$a$$$ into $$$b$$$, and No otherwise. You can print each letter in any case (upper or lower).

NoteIn the first test case of the sample, we can do the second operation with $$$i=2$$$: $$$[1,\color{red}{2,2},4,2]\to [1,\color{red}{4},4,2]$$$.In the second testcase of the sample, we can:  do the second operation with $$$i=2$$$: $$$[1,\color{red}{2,2},8,2,2]\to [1,\color{red}{4},8,2,2]$$$.  do the second operation with $$$i=4$$$: $$$[1,4,8,\color{red}{2,2}]\to [1,4,8,\color{red}{4}]$$$.  do the first operation with $$$i=3$$$: $$$[1,4,\color{red}{8},4]\to [1,4,\color{red}{4,4},4]$$$.  do the second operation with $$$i=2$$$: $$$[1,\color{red}{4,4},4,4]\to [1,\color{red}{8},4,4]$$$.  do the second operation with $$$i=3$$$: $$$[1,8,\color{red}{4,4}]\to [1,8,\color{red}{8}]$$$.  do the second operation with $$$i=2$$$: $$$[1,\color{red}{8,8}]\to [1,\color{red}{16}]$$$.

package main

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

type Stat struct {
	x int
	c int64
}

type Task struct {
	n, m, l int
	a, b []Stat
}

func ReadArray(reader io.Reader, n int, m int) []Stat {
	a := make([]Stat, 0, n)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		c := int64(1)
		for ak % m == 0 {
			ak /= m
			c *= int64(m)
		}
		if (len(a) > 0 && a[len(a) - 1].x == ak) {
			a[len(a) - 1].c += c
		} else {
			a = append(a, Stat{x: ak, c: c})
		}
	}
	return a
}

func Solve(task Task) string {
	a := task.a
	b := task.b

	ok := true
	for len(b) > 0 && len(a) > 0 && ok {
		lastA := &a[len(a) - 1]
		lastB := &b[len(b) - 1]
		ok = lastA.x == lastB.x && lastA.c >= lastB.c
		lastA.c -= lastB.c
		b = b[:len(b) - 1]
		if (lastA.c == 0) {
			a = a[:len(a) - 1]
		}
	}

	if ok && len(a) == 0 && len(b) == 0 {
		return "Yes"
	} else {
		return "No"
	}
}

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

	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	tasks := make(chan Task)
	go func(out chan<- Task){
		for t := 0; t < testCaseCount; t++ {
			var task Task
			fmt.Fscan(reader, &task.n, &task.m)
			task.a = ReadArray(reader, task.n, task.m)
			fmt.Fscan(reader, &task.l)
			task.b = ReadArray(reader, task.l, task.m)
			out <- task
		}
	}(tasks)

	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	for t := 0; t < testCaseCount; t++ {
		task := <-tasks
		ans := Solve(task)
		fmt.Fprintln(writer, ans)
	}
}

package main

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

type Stat struct {
	x int
	c int64
}

func ReadArray(reader io.Reader, n int, m int) []Stat {
	a := make([]Stat, 0, n)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		c := int64(1)
		for ak % m == 0 {
			ak /= m
			c *= int64(m)
		}
		if (len(a) > 0 && a[len(a) - 1].x == ak) {
			a[len(a) - 1].c += c
		} else {
			a = append(a, Stat{x: ak, c: c})
		}
	}
	return a
}

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var (
		n int
		m int
		l int
	)
	fmt.Fscan(reader, &n, &m)
	a := ReadArray(reader, n, m)
	fmt.Fscan(reader, &l)
	b := ReadArray(reader, l, m)

	ok := true
	for len(b) > 0 && len(a) > 0 && ok {
		lastA := &a[len(a) - 1]
		lastB := &b[len(b) - 1]
		ok = lastA.x == lastB.x && lastA.c >= lastB.c
		lastA.c -= lastB.c
		b = b[:len(b) - 1]
		if (lastA.c == 0) {
			a = a[:len(a) - 1]
		}
	}

	if ok && len(a) == 0 && len(b) == 0 {
		fmt.Fprintln(writer, "Yes")
	} else {
		fmt.Fprintln(writer, "No")
	}
}

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

	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var m int64
		fmt.Fscan(in, &n, &m)

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

		g := func(n int64) int64 {
			for n%m == 0 {
				n /= m
			}
			return n
		}
		f := true
		var i, j int
		var t1, t2 int64
		for i < n && j < k {
			t1, t2 = 0, 0
			z := g(aa[i])
			for i < n && z == g(aa[i]) {
				t1 += aa[i] / z
				i++
			}
			for j < k && z == g(bb[j]) {
				t2 += bb[j] / z
				j++
			}

			if t1 != t2 {
				f = false
				break
			}
		}

		if f && i == n && j == k {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}
}

package main

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

type pair struct {
	v int
	c int64
}

func getS(a []int, m int) []pair {
	ans := make([]pair, 0, len(a))

	for _, v := range a {
		c := int64(1)
		for v%m == 0 {
			v /= m
			c *= int64(m)
		}

		if len(ans) != 0 && ans[len(ans)-1].v == v {
			ans[len(ans)-1].c += c
		} else {
			ans = append(ans, pair{v, c})
		}
	}
	return ans
}

func solve(a, b []int, m int) bool {
	sa := getS(a, m)
	sb := getS(b, m)
	if len(sa) != len(sb) {
		return false
	}
	for i := 0; i < len(sa); i++ {
		v1, v2 := sa[i], sb[i]
		if v1 != v2 {
			return false
		}
	}
	return true
}

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

	var t int
	var n int
	var k int
	var m int
	a := make([]int, 1e5)
	b := make([]int, 1e5)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		Fscan(in, &k)
		for i := 0; i < k; i++ {
			Fscan(in, &b[i])
		}

		ans := solve(a[:n], b[:k], m)
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	run(os.Stdin, os.Stdout)
	// a := []int{1, 2, 2, 4, 2}
	// a = []int{1, 2, 2, 8, 2, 2}
	// a = []int{1, 16}
	// a = []int{3, 9, 6, 3, 12, 12, 36, 12}
	// a = []int{9, 3, 2, 2, 2, 3, 4, 12, 4, 12, 4, 12, 4, 12, 4, 4}
	// a = []int{1, 4, 4, 2}
	// a = []int{1, 1000000000, 1000000000, 1000000000}
	// ans := getS(a, 1000000000)
	// fmt.Println(ans)
}

package main

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

type occ struct {
	num   int
	count int64
}

func minimize(num, m int) (int, int64) {
	count := int64(1)
	for num > 1 && num%m == 0 {
		num = num / m
		count *= int64(m)
	}
	return num, count
}

func readOcc(n, m int, r *bufio.Reader) []occ {
	ret := make([]occ, 0, n)
	for ; n > 0; n-- {
		var x int
		_, _ = fmt.Fscan(r, &x)
		num, count := minimize(x, m)
		if len(ret) > 0 && ret[len(ret)-1].num == num {
			ret[len(ret)-1].count += count
		} else {
			ret = append(ret, occ{num, count})
		}
	}
	return ret
}

func isEqual(a, b []occ) bool {
	if len(a) != len(b) {
		return false
	}
	for i, o := range a {
		if o != b[i] {
			return false
		}
	}
	return true
}

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

	var t int
	_, _ = fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, m int
		_, _ = fmt.Fscan(r, &n, &m)
		a := readOcc(n, m, r)
		_, _ = fmt.Fscan(r, &n)
		b := readOcc(n, m, r)
		if len(a) != len(b) {
			fmt.Fprintln(w, "No")
			continue
		}
		if isEqual(a, b) {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

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

package main

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

type occ struct {
	num   int
	count int64
}

func minimize(num, m int) (int, int64) {
	count := int64(1)
	for num > 1 && num%m == 0 {
		num = num / m
		count *= int64(m)
	}
	return num, count
}

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

	var t int
	_, _ = fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, m int
		_, _ = fmt.Fscan(r, &n, &m)
		a := make([]occ, 0, n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			num, count := minimize(x, m)
			if len(a) > 0 && a[len(a)-1].num == num {
				a[len(a)-1].count += count
			} else {
				a = append(a, occ{num, count})
			}
		}
		_, _ = fmt.Fscan(r, &n)
		b := make([]occ, 0, n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			num, count := minimize(x, m)
			if len(b) > 0 && b[len(b)-1].num == num {
				b[len(b)-1].count += count
			} else {
				b = append(b, occ{num, count})
			}
		}
		if len(a) != len(b) {
			fmt.Fprintln(w, "No")
			continue
		}
		isEqual := true
		for i, o := range a {
			if o != b[i] {
				isEqual = false
				break
			}
		}
		if isEqual {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

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

package main

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

/*
2
5 3
2 2 3 1 6
7
2 2 1 1 1 1 6
5 3
2 2 3 1 6
5
2 2 1 3 6
---
YES
YES
*/

type seg struct {
	num, cnt int64
}

func mergeLastTwo(segs []seg) []seg {
	if len(segs) < 2 {
		return segs
	}

	top := segs[len(segs)-1]
	segs = segs[:len(segs)-1]

	for len(segs) > 0 && segs[len(segs)-1].num == top.num {
		top.cnt += segs[len(segs)-1].cnt
		segs = segs[:len(segs)-1]
	}

	segs = append(segs, top)

	return segs
}

func toSeg(num, m int64) seg {
	if num%m != 0 {
		return seg{num, 1}
	}

	k := num

	for k%m == 0 {
		k /= m
	}

	return seg{k, num / k}
}

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

	a := make([]seg, 0)

	for i := int64(0); i < n; i++ {
		var num int64
		scanf("%d", &num)

		a = append(a, toSeg(num, m))
		a = mergeLastTwo(a)
	}
	scanf("\n")

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

	b := make([]seg, 0)

	for i := 0; i < k; i++ {
		var num int64
		scanf("%d", &num)

		b = append(b, toSeg(num, m))
		b = mergeLastTwo(b)
	}
	scanf("\n")

	if len(a) != len(b) {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(a); i++ {
		if a[i].num != b[i].num || a[i].cnt != b[i].cnt {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

/*
2
5 3
2 2 3 1 6
7
2 2 1 1 1 1 6
5 3
2 2 3 1 6
5
2 2 1 3 6
---
YES
YES
*/

type seg struct {
	num, cnt int64
}

func mergeLastTwo(segs []seg, m int64) []seg {
	if len(segs) < 2 {
		return segs
	}

	top := segs[len(segs)-1]
	segs = segs[:len(segs)-1]

	for len(segs) > 0 {
		if segs[len(segs)-1].num != top.num {
			break
		}

		top.cnt += segs[len(segs)-1].cnt
		segs = segs[:len(segs)-1]
	}

	sm := top.cnt
	qtt := sm / m
	rem := sm % m

	if (qtt > 0 && rem == 0) || qtt == 0 {
		segs = append(segs, top)
	} else {
		segs = append(segs, seg{num: top.num, cnt: qtt * m})
		segs = append(segs, seg{num: top.num, cnt: rem})
	}

	return segs
}

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

	a := make([]seg, 0)

	for i := int64(0); i < n; i++ {
		var num int64
		scanf("%d", &num)

		if num%m == 0 {
			x := num

			for x%m == 0 {
				x /= m
			}

			a = append(a, seg{x, num / x})
		} else {
			a = append(a, seg{num, 1})
		}

		a = mergeLastTwo(a, m)
	}
	scanf("\n")

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

	b := make([]seg, 0)

	for i := 0; i < k; i++ {
		var num int64
		scanf("%d", &num)

		if num%m == 0 {
			x := num

			for x%m == 0 {
				x /= m
			}

			b = append(b, seg{x, num / x})
		} else {
			b = append(b, seg{num, 1})
		}

		b = mergeLastTwo(b, m)
	}
	scanf("\n")

	if len(a) != len(b) {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(a); i++ {
		if a[i].num != b[i].num || a[i].cnt != b[i].cnt {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

	return factors
}

package main

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

type Stat struct {
	x, c int
}

func ReadArray(reader io.Reader, n int, m int) []Stat {
	a := make([]Stat, 0, n)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		c := 1
		for ak % m == 0 {
			ak /= m
			c *= m
		}
		if (len(a) > 0 && a[len(a) - 1].x == ak) {
			a[len(a) - 1].c += c
		} else {
			a = append(a, Stat{x: ak, c: c})
		}
	}
	return a
}

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var (
		n int
		m int
		l int
	)
	fmt.Fscan(reader, &n, &m)
	a := ReadArray(reader, n, m)
	fmt.Fscan(reader, &l)
	b := ReadArray(reader, l, m)

	ok := true
	for len(b) > 0 && ok {
		lastA := &a[len(a) - 1]
		lastB := &b[len(b) - 1]
		ok = lastA.x == lastB.x && lastA.c >= lastB.c
		lastA.c -= lastB.c
		b = b[:len(b) - 1]
		if (lastA.c == 0) {
			a = a[:len(a) - 1]
		}
	}

	if ok && len(b) == 0 && len(a) == 0 {
		fmt.Fprintln(writer, "Yes")
	} else {
		fmt.Fprintln(writer, "No")
	}
}

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

	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

type Stat struct {
	x, c int
}

func ReadArray(reader io.Reader, n int, m int) []Stat {
	a := make([]Stat, 0, n)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		c := 1
		for ak % m == 0 {
			ak /= m
			c *= m
		}
		if (len(a) > 0 && a[len(a) - 1].x == ak) {
			a[len(a) - 1].c += c
		} else {
			a = append(a, Stat{x: ak, c: c})
		}
	}
	return a
}

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var (
		n int
		m int
		l int
	)
	fmt.Fscan(reader, &n, &m)
	a := ReadArray(reader, n, m)
	fmt.Fscan(reader, &l)
	b := ReadArray(reader, l, m)

	ok := true
	for len(b) > 0 && ok {
		lastA := a[len(a) - 1]
		lastB := b[len(b) - 1]
		ok = lastA.x == lastB.x && lastA.c >= lastB.c
		lastA.c -= lastB.c
		b = b[:len(b) - 1]
		if (lastA.c == 0) {
			a = a[:len(a) - 1]
		}
	}

	if ok && len(b) == 0 && len(a) == 0 {
		fmt.Fprintln(writer, "Yes")
	} else {
		fmt.Fprintln(writer, "No")
	}
}

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

	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var m int64
		fmt.Fscan(in, &n, &m)

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

		p1, p2 := 0, 0
		s1, s2 := []int64{}, []int64{}
		t1, t2 := int64(0), int64(0)
		f := true
		var m1 int64
		canMerge := func(a, b []int64) bool {
			if len(a) == 0 || len(b) == 0 {
				return false
			}

			g := make(map[int64]bool)
			for m1 > 0 {
				g[m1] = true
				m1 /= m
			}

			for _, v := range a {
				if !g[v] {
					return false
				}
			}

			for _, v := range b {
				if !g[v] {
					return false
				}
			}
			return true
		}

		for p1 < n && p2 < k {
			if t1 == 0 || t1 < t2 {
				s1 = append(s1, aa[p1])
				t1 += aa[p1]
				if aa[p1] > m1 {
					m1 = aa[p1]
				}
				p1++
			} else {
				s2 = append(s2, bb[p2])
				t2 += bb[p2]
				if bb[p2] > m1 {
					m1 = bb[p2]
				}
				p2++
			}

			if t1 == t2 {
				if !canMerge(s1, s2) {
					f = false
					break
				}
				s1, s2 = []int64{}, []int64{}
				t1, t2 = 0, 0
				m1 = 0
			}
		}

		if f && p1 < n {
			s1 = append(s1, aa[p1:]...)
		}
		if f && p2 < k {
			s2 = append(s2, bb[p2:]...)
		}

		if f && len(s1) > 0 && len(s2) > 0 {
			if !canMerge(s1, s2) {
				f = false
			}
			s1, s2 = []int64{}, []int64{}
		}

		if f && len(s1) == 0 && len(s2) == 0 {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}
}

package main

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

type pair struct{ v, c int }

func getS(a []int, m int) []pair {
	ans := make([]pair, 0, len(a))

	for _, v := range a {
		c := 1
		for v%m == 0 {
			v /= m
			c *= m
		}

		if len(ans) != 0 && ans[len(ans)-1].v == v {
			ans[len(ans)-1].c += c
		} else {
			ans = append(ans, pair{v, c})
		}
	}
	return ans
}

func solve(a, b []int, m int) bool {
	sa := getS(a, m)
	sb := getS(b, m)
	if len(sa) != len(sb) {
		return false
	}
	for i := 0; i < len(sa); i++ {
		v1, v2 := sa[i], sb[i]
		if v1 != v2 {
			return false
		}
	}
	return true
}

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

	var t int
	var n int
	var k int
	var m int
	a := make([]int, 1e5)
	b := make([]int, 1e5)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		Fscan(in, &k)
		for i := 0; i < k; i++ {
			Fscan(in, &b[i])
		}

		ans := solve(a[:n], b[:k], m)
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	run(os.Stdin, os.Stdout)
	// a := []int{1, 2, 2, 4, 2}
	// a = []int{1, 2, 2, 8, 2, 2}
	// a = []int{1, 16}
	// a = []int{3, 9, 6, 3, 12, 12, 36, 12}
	// a = []int{9, 3, 2, 2, 2, 3, 4, 12, 4, 12, 4, 12, 4, 12, 4, 4}
	// a = []int{1, 4, 4, 2}
	// a = []int{1, 1000000000, 1000000000, 1000000000}
	// ans := getS(a, 1000000000)
	// fmt.Println(ans)
}

package main

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

type pair struct{ v, c int }

func getS(a []int, m int) []pair {
	ans := make([]pair, 0, len(a))
	var dfs func(n *int) int
	dfs = func(n *int) int {
		if *n%m != 0 {
			return 1
		}
		*n /= m
		return m * dfs(n)
	}

	for _, v := range a {
		if v%m != 0 {
			if len(ans) != 0 && ans[len(ans)-1].v == v {
				ans[len(ans)-1].c += 1
			} else {
				ans = append(ans, pair{v, 1})
			}
		} else {
			c := dfs(&v)

			if len(ans) != 0 && ans[len(ans)-1].v == v {
				ans[len(ans)-1].c += c
			} else {
				ans = append(ans, pair{v, c})
			}
		}
	}
	return ans
}

func solve(a, b []int, m int) bool {
	sa := getS(a, m)
	sb := getS(b, m)
	if len(sa) != len(sb) {
		return false
	}
	for i := 0; i < len(sa); i++ {
		v1, v2 := sa[i], sb[i]
		if v1 != v2 {
			return false
		}
	}
	return true
}

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

	var t int
	var n int
	var k int
	var m int
	a := make([]int, 1e5)
	b := make([]int, 1e5)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		Fscan(in, &k)
		for i := 0; i < k; i++ {
			Fscan(in, &b[i])
		}

		ans := solve(a[:n], b[:k], m)
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	run(os.Stdin, os.Stdout)
	// fmt.Println("go")
	// a := []int{1, 2, 2, 4, 2}
	// a = []int{1, 2, 2, 8, 2, 2}
	// a = []int{1, 16}
	// a = []int{3, 9, 6, 3, 12, 12, 36, 12}
	// a = []int{9, 3, 2, 2, 2, 3, 4, 12, 4, 12, 4, 12, 4, 12, 4, 4}
	// a = []int{1, 4, 4, 2}
	// ans := getS(a, 2)
	// fmt.Println(ans)
}

package main

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

type occ struct {
	num, count int
}

func minimize(num, m int) (int, int) {
	count := 1
	for num > 1 && num%m == 0 {
		num = num / m
		count *= m
	}
	return num, count
}

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

	var t int
	_, _ = fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, m int
		_, _ = fmt.Fscan(r, &n, &m)
		a := make([]occ, 0, n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			num, count := minimize(x, m)
			if len(a) > 0 && a[len(a)-1].num == num {
				a[len(a)-1].count += count
			} else {
				a = append(a, occ{num, count})
			}
		}
		_, _ = fmt.Fscan(r, &n)
		b := make([]occ, 0, n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			num, count := minimize(x, m)
			if len(b) > 0 && b[len(b)-1].num == num {
				b[len(b)-1].count += count
			} else {
				b = append(b, occ{num, count})
			}
		}
		if len(a) != len(b) {
			fmt.Fprintln(w, "No")
			continue
		}
		isEqual := true
		for i, o := range a {
			if o != b[i] {
				isEqual = false
				break
			}
		}
		if isEqual {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

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