You are given two positive integers $$$a$$$ and $$$b$$$. In one move you can increase $$$a$$$ by $$$1$$$ (replace $$$a$$$ with $$$a+1$$$). Your task is to find the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$. It is possible, that you have to make $$$0$$$ moves, as $$$a$$$ is already divisible by $$$b$$$. You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).

For each test case print the answer — the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$.

package main;
import (
    "fmt"
)
func main() {
    var test_count int
    fmt.Scanf("%d\n", &test_count)
    for i := 0; i < test_count; i++ {
        solve_test();
    }
}

func solve_test() {
    var a, b int
    fmt.Scanf("%d%d\n", &a, &b);
    if a % b == 0 {
        fmt.Println(0)
    } else {
        fmt.Println(b - a%b);
    }
}

package main

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

func main() {
	var t, x, y int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &x, &y)
		reminder := x % y
		if reminder == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(y - x%y)
		}
	}
}

package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

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

// Sort
type RuneSlice []rune

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

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	for i := 0; i < N; i++ {
		a, b := sc.nextInt(), sc.nextInt()
		q := ceil(a, b)
		fmt.Fprintln(wtr, q*b-a)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, a, b int
	fmt.Scan(&t)
	answers := make([]int, t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a, &b)
		if a%b == 0 {
			answers[i] = 0
		} else {
			answers[i] = (a/b+1)*b - a
		}
	}
	for i := 0; i < t; i++ {
		fmt.Println(answers[i])
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var a, b uint32
	scanner.Scan() // ignore first input
	for scanner.Scan() {
		fmt.Sscanf(scanner.Text(), "%d %d", &a, &b)
		if a%b == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(b - a%b)
		}
	}
	if err := scanner.Err(); err != nil {
		log.Println(err)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Fscan(in, &a, &b)
		if a%b == 0 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, b-a%b)
		}
	}
	out.Flush()
}

package main

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

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

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var a, b int
	scanf("%d %d\n", &a, &b)

	switch {
	case a%b == 0:
		printf("%d\n", 0)
		return
	case a < b:
		printf("%d\n", b-a)
		return
	default:
		printf("%d\n", ((a/b+1)*b)-a)
		return
	}
}

package main

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

func main(){
    var(
        t,a,b   int
        sc      =bufio.NewScanner(os.Stdin)
    )
    sc.Scan()
    t,_=strconv.Atoi(sc.Text())
    for t>0{
        sc.Scan()
        s:=strings.Split(sc.Text()," ")
        a,_=strconv.Atoi(s[0])
        b,_=strconv.Atoi(s[1])
        if a%b==0{
            fmt.Println(0)
        }else{
            fmt.Println(b*((a/b)+1)-a)
        }
        t--
    }
}

package main

import "fmt"

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

func solve(a, b int) int {
	if a < b {
		return b - a
	}
	if a%b == 0 {
		return 0
	}
	return b - a%b
}

package main

import (
	"fmt"
)

func main () {
	var t, a, b, c int
	var mas []int
	fmt.Scan(&t)
	for i:=0; i<t; i++ {
		fmt.Scan(&a, &b)
		if a % b == 0 {
			mas = append(mas, 0)
		} else {
			c = b-a%b
			mas = append(mas, c)
		}
	}
	for i:=0; i<len(mas); i++ {
		fmt.Println(mas[i])
	}
}

// @problemURL url.com
package main

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

func next(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	// var inFile, _ = os.Open("in.txt")
	// var in = bufio.NewReader(inFile)
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	for T := atoi(next(s)); T > 0; T-- {
		a, b := atoi(next(s)), atoi(next(s))
		if a%b == 0 {
			fmt.Println(0)
			continue
		}
		t := a % b
		fmt.Println(b - t)
	}

	// Code
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()

	for t := 0; t < T; t++ {
		a, b := NextInt(), NextInt()

		t := a % b
		if t != 0 {
			t = b - t
		}
		fmt.Fprintln(out, t)
	}
}

package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		fmt.Println((b - (a % b)) % b)
	}
}

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for T := 0 ; T < t ; T ++ {
		var a, b int
		fmt.Fscanf(in, "%d %d\n", &a, &b)

		output := a % b
		if output > 0{
			output = b - output
		}
		fmt.Println(output)
	}

}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		if a % b == 0 {
			fmt.Println(0)
		}else{
			fmt.Println(b - (a % b))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a, b int64
		fmt.Scanf("%d %d\n", &a, &b)
		x := a / b
		y := a % b
		if y == 0 {
			fmt.Println(0)
			continue
		}
		x = (x + 1) * b - a
		fmt.Println(x)
	}
}

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"
	"io"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)
	n := 0
	fmt.Sscanf(readLine(reader), "%d", &n)

	for i := 0; i < n; i++ {
		line := readLine(reader)
		a,b := 0, 0
		fmt.Sscanf(line, "%d %d", &a, &b)
		if a % b == 0 {
			fmt.Println(0)
			continue
		}
		d := ((a / b) + 1)*b
		fmt.Println(d - a)
	}
}

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

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

package main

import(
	"fmt"
)

func main() {
	t := 0
	ans := []int{}
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		a := 0
		b := 0
		fmt.Scanf("%d %d\n", &a, &b)
		if a%b == 0 {
			ans = append(ans, 0)
		} else {
			ans = append(ans, (b-(a%b)))
		}
	}

	for _, x := range ans {
		fmt.Println(x)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		if a % b == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(b - a % b)
		}

	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

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

		if(a%b == 0) {
			printf("0\n")
		} else {
			printf("%d\n", b - (a%b))
		}
	}
}

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, a, b int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b)
		Fprintln(out, (b-a%b)%b)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint16
	var a, b uint32
	fmt.Fscanf(in, "%d\n", &n)
	for i := uint16(0); i < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		if a%b == 0 {
			fmt.Println(a % b)
		} else {
			fmt.Println(b - a%b)
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	buf := make([]int, 0, 10)
	for i := 1; i < t+1; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		if a%b == 0 {
			buf = append(buf, 0)
		} else {
			buf = append(buf, b-(a%b))
		}
	}
	for i := 0; i < t; i++ {
		fmt.Println(buf[i])
	}

}

package main

import (
	"fmt"
)

// 5
// 10 4
// 13 9
// 100 13
// 123 456
// 92 46

func main() {
	var t int

	fmt.Scan(&t)

	for t != 0 {
		var a, b int
		fmt.Scan(&a, &b)
		if a%b == 0 {
			fmt.Println(0)
		} else {
			fmt.Println((int(a/b)+1)*b - a)
		}
		t--
	}
}

package main

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

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

	var nt, a, b int
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk:=0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d %d\n", &a, &b)
		var ret = (b - a % b) % b
		fmt.Fprintf(writer, "%d\n", ret)
	}
}

package main

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

func main() {
	for t := ScanInt64(); t > 0; t-- {
		a, b := ScanInt64(), ScanInt64()
		if a % b == 0{
			P(0)
			continue
		}
		remainder := a/b
		P((b*(remainder + 1)) - a)
	}

	close(O)
	oWg.Wait()
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	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 S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(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 SArr64(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 MnMx(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 Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
)

func solve() {
	var a, b int
	fmt.Scan(&a, &b)
	if a%b == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(b - (a % b))
	}
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main
import (
	"fmt"
)

func main() {
    var t int
    fmt.Scan(&t)
    for i := 0; i < t; i++ {
        var a,b int
        fmt.Scan(&a)
        fmt.Scan(&b)
        c:= a%b
        if(c==0){
            fmt.Print(0)
        } else{
            fmt.Print(b-c)
        }
        fmt.Print("\n")
    }
}

package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
)

func read() int {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	return n
}
func wr(n int) {
	writer.WriteString(strconv.Itoa(n))
}
func wrs(st string) {
	writer.WriteString(st)
}
func main() {
	scanner.Split(bufio.ScanWords)
	var t = read()
	for ; t > 0; t-- {
		a, b := read(), read()
		wr(((a-1)/b+1)*b - a)
		wrs("\n")
	}
	writer.Flush()
}

package main

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

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

func main() {
	var t int
	Fscan(scanner, &t)
	for ; t > 0; t-- {
		var a, b int
		Fscan(scanner, &a, &b)
		Fprintln(writer, ((a-1)/b+1)*b-a)
	}
	writer.Flush()
}

package main

import "fmt"

func main() {
    var t, a, b int

    fmt.Scan(&t)
    for i := 0; i < t; i++ {
        fmt.Scan(&a)
        fmt.Scan(&b)
        fmt.Println((b - a % b) % b)
    }
}

package main

import "fmt"

func main() {
	var a, b int64
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a, &b)
		if a%b == 0 {
			fmt.Println(0)
		} else {
			var mul = a / b
			fmt.Println((mul+1)*b - a)
		}
	}
}

package main

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

//func Max(a, b int64) int64 {
//	if a > b {
//		return a
//	}
//	return b
//}
//
//func Min(a, b int64) int64 {
//	if a > b {
//		return b
//	}
//	return a
//}

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

func main() {
	var t int
	fmt.Fscan(scanner, &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Fscan(scanner, &a, &b)
		if a%b == 0 {
			fmt.Fprintln(writer, 0)
		} else {
			fmt.Fprintln(writer, (a/b+1)*b-a)
		}
	}
	writer.Flush()
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	// reader := fileReader("/Users/bmancini/code/go/src/github.com/bmancini55/go-playpen/codeforces/p1328a/input.txt")

	t, err := readInt(reader)
	if err != nil {
		log.Fatal(err)
	}

	tuples, err := readInts(reader, t)
	if err != nil {
		log.Fatal(err)
	}

	for _, tuple := range tuples {
		a := tuple[0]
		b := tuple[1]

		// fmt.Printf("a: %d, b %d, mod: %d, eq: %v\n", a, b, a%b, a%b == 0)
		if a%b == 0 {
			fmt.Printf("%d\n", 0)
		} else {
			r := b - (a % b)
			fmt.Printf("%d\n", r)
		}
	}

}

func fileReader(path string) *bufio.Reader {
	var (
		f   *os.File
		r   *bufio.Reader
		err error
	)

	f, err = os.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	r = bufio.NewReader(f)
	return r
}

func readInt(reader *bufio.Reader) (int, error) {
	var (
		result int
		err    error
	)

	line, err := reader.ReadString('\n')
	if err != nil {
		return 0, err
	}

	fields := strings.Fields(line)
	result, err = strconv.Atoi(fields[0])

	if err != nil {
		return 0, err
	}

	return result, nil
}

func readInts(reader *bufio.Reader, n int) ([][]int, error) {
	results := [][]int{}

	for i := 0; i < n; i++ {
		line, err := reader.ReadString('\n')
		if err != nil {
			return nil, err
		}

		nums, err := parseInts(line)
		if err != nil {
			return nil, err
		}

		results = append(results, nums)
	}
	return results, nil
}

func parseInts(s string) ([]int, error) {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
		err    error
	)
	for i, f := range fields {
		ints[i], err = strconv.Atoi(f)
		if err != nil {
			return nil, err
		}
	}
	return ints, nil
}

package main

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

// https://codeforces.com/problemset/problem/1328/A
// A. Divisibility Problem
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// You are given two positive integers a
// and b. In one move you can increase a by 1 (replace a with a+1). Your task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible, that you have to make 0 moves, as a is already divisible by b. You have to answer t

// independent test cases.
// Input

// The first line of the input contains one integer t
// (1≤t≤104) — the number of test cases. Then t

// test cases follow.

// The only line of the test case contains two integers a
// and b (1≤a,b≤109

// ).
// Output

// For each test case print the answer — the minimum number of moves you need to do in order to make a
// divisible by b.

func main() {
	bufStdin := bufio.NewReader(os.Stdin)
	bufStdout := bufio.NewWriter(os.Stdout)

	var t int
	_, _ = fmt.Fscan(bufStdin, &t)

	for i := 0; i < t; i++ {
		var a, b int
		_, _ = fmt.Fscan(bufStdin, &a, &b)

		if a <= b {
			fmt.Fprintln(bufStdout, b-a)
		} else {
			// if a is already divisible by b, we don't need take any steps
			if a%b == 0 {
				fmt.Fprintln(bufStdout, 0)
			} else {
				bsInA := a / b
				nextMultiple := (bsInA + 1) * b
				fmt.Fprintln(bufStdout, nextMultiple-a)
			}

		}
	}

	_ = bufStdout.Flush()
}

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

    var t int
    fmt.Fscan(r, &t)
    for i := 0; i < t; i++ {
        var a, b, c int
        fmt.Fscan(r, &a, &b)
        if a%b == 0 {
            c = 0
        } else {
            c = b - (a%b)
        }
        fmt.Fprintln(w, c)
    }
}

package main

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

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

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

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func main() {
	t := scanInt()
	for i := 0; i < t; i++ {
		a, b := scanInt(), scanInt()
		if a%b == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(b - a%b)
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

type numpair struct {
	a int
	b int
}

// https://codeforces.com/problemset/problem/1328/A
// комментарий к решению
// Т.к. требуется арифметика с числами, то используем fmt.Scan для считывания массива.
// Для вывода воспользуемся fmt.Sprint переведя массив необходимых операций в строку.
// Т.к. fmt.Sprint выводит данные через пробел, то задействуем strings.Replace .
// Компилятор видит, что заменяется 1 однобайтовый символ unicode на 1 однобайтовый символ unicode,
// плюс мы указываем кол-во замен, поэтому будет сгенерирован оптимальный код, как если бы мы
// производили свою арифметику с []byte
func taskSolution(a []numpair) string {
	ans := []int{}
	for _, p := range a {
		ans = append(ans, (p.b-(p.a%p.b))%p.b)
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

func main() {
	var t int
	if _, err := fmt.Scan(&t); err != nil {
		panic(err)
	}

	in := []numpair{}
	for i := 0; i < t; i += 1 {
		var a, b int
		if _, err := fmt.Scan(&a, &b); err != nil {
			panic(err)
		}
		in = append(in, numpair{a: a, b: b})
	}

	fmt.Println(taskSolution(in))
}

// Author: sighduck
// URL: https://codeforces.com/contest/1328/problem/A

package main

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

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

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

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

package main

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

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	return &wordScannerImpl{Scanner: s}
}

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

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

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	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()
}

func main() {
	reader := NewWordScanner(os.Stdin)
	writer := NewWriter(os.Stdout)
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		a := reader.NextInt64()
		b := reader.NextInt64()
		mod := a % b
		if mod != 0 {
			writer.Printf("%d\n", b-mod)
		} else {
			writer.Printf("0\n")
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	_, _ = fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var a,b int
		_, _ = fmt.Scanf("%d %d\n", &a,&b)
		if a%b == 0{
			fmt.Println(0)
		}else{
			fmt.Println(b - (a%b))
		}
	}

}

package main

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

func main() {
	var t, x, y int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &x, &y)
		fmt.Println(y - x%y)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, a, b int
	fmt.Scan(&t)
	answers := make([]int, t)
	for i := 0; i > t; i++ {
		fmt.Scan(&a, &b)
		if a%b == 0 {
			answers[i] = 0
		} else {
			answers[i] = (a/b+1)*b - a
		}
	}
	for i := 0; i < t; i++ {
		fmt.Println(answers[i])
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"math/rand"
	"os"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var 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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < casesNumb; i++ {
		exec()
	}

}

func exec() {
	var a, b int
	scanf("%d %d\n", &a, &b)

	if a < b {
		printf("%d\n", b-a)
		return
	}

	if isPrimeByFerma(b) {
		printf("%d\n", a-b)
		return
	}

	i := 0
	for {
		if a%b == 0 {
			break
		}
		a += 1
		i += 1
	}
	printf("%d\n", i)
}

func isPrimeByFerma(x int) bool {
	if x <= 1 || x == 4 {
		return false
	}
	if x <= 3 {
		return true
	}

	for i := 0; i < 100; i++ {
		a := 2 + rand.Int()%(x-4)

		if gcd(x, a) != 1 {
			return false
		}

		if int(math.Pow(float64(a), float64(x-1)))%x != 1 {
			return false
		}
	}

	return true
}

func gcd(a, b int) int {
	switch {
	case a < b:
		return gcd(b, a)
	case a%b == 0:
		return b
	default:
		return gcd(b, a%b)
	}
}

/**
 * Copyright shopee
 * @Author : Yuxiang.Lei
 * @MailBox: Yuxiang.Lei@shopee.com
 * @Date : 2020-03-26
 * @Version: v2.4
 **/

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a, b int64
		fmt.Scanf("%d %d\n", &a, &b)
		x := a / b
		y := a % b
		if y == 0 {
			fmt.Println(0)
			break
		}
		x = (x + 1) * b - a

		fmt.Println(x)
	}
}

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"
	"io"
	"os"
)

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	return &wordScannerImpl{Scanner: s}
}

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

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

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	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()
}

func main() {
	reader := NewWordScanner(os.Stdin)
	writer := NewWriter(os.Stdout)
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		a := reader.NextInt64()
		b := reader.NextInt64()
		mod := a % b
		if mod != 0 {
			writer.Printf("%d\n", b-mod)
		} else {
			writer.Printf("0")
		}
	}
}


Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help.Artem wants to paint an $$$n \times m$$$ board. Each cell of the board should be colored in white or black. Lets $$$B$$$ be the number of black cells that have at least one white neighbor adjacent by the side. Let $$$W$$$ be the number of white cells that have at least one black neighbor adjacent by the side. A coloring is called good if $$$B = W + 1$$$. The first coloring shown below has $$$B=5$$$ and $$$W=4$$$ (all cells have at least one neighbor with the opposite color). However, the second coloring is not good as it has $$$B=4$$$, $$$W=4$$$ (only the bottom right cell doesn't have a neighbor with the opposite color).  Please, help Medina to find any good coloring. It's guaranteed that under given constraints the solution always exists. If there are several solutions, output any of them.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 20$$$). Each of the next $$$t$$$ lines contains two integers $$$n, m$$$ ($$$2 \le n,m \le 100$$$) — the number of rows and the number of columns in the grid.

For each test case print $$$n$$$ lines, each of length $$$m$$$, where $$$i$$$-th line is the $$$i$$$-th row of your colored matrix (cell labeled with 'B' means that the cell is black, and 'W' means white). Do not use quotes. It's guaranteed that under given constraints the solution always exists.

NoteIn the first testcase, $$$B=3$$$, $$$W=2$$$.In the second testcase, $$$B=5$$$, $$$W=4$$$. You can see the coloring in the statement.

package main

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

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

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

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

const N = 105

var a [N][N]byte

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, m int
		scanf("%d %d\n", &n, &m)
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if (i+j)%2 == 0 {
					a[i][j] = 'B'
				} else {
					a[i][j] = 'W'
				}
			}
		}
		if (n*m)%2 == 0 {
		    var flag bool = true
			for i := 1; i <= n; i++ {
			    for j := 1; j <= m; j++ {
			        if a[i][j]=='W' && flag {
			            flag = false
			            a[i][j] = 'B'
			        }
			    }
			}
		}
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				printf("%c", a[i][j])
			}
			printf("\n")
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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 scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

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

func exec() {
	var n, m int
	scanf("%d %d\n", &n, &m)

	field := make([][]byte, n)
	for i := 0; i < n; i++ {
		field[i] = make([]byte, m)
		for j := 0; j < m-2; j++ {
			if j%2 == 0 {
				field[i][j] = 1
			}
		}
	}
	if m%2 == 0 {
		field[0][m-2] = 1
		for i := 0; i < n; i++ {
			field[i][m-1] = 1
		}
	} else {
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				field[i][m-1] = 1
			}
		}
		if n%2 == 0 {
			field[n-1][1] = 1
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if field[i][j] == 1 {
				printf("B")
				continue
			}
			printf("W")
		}
		printf("\n")
	}
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()

	for t := 0; t < T; t++ {
		n, m := NextInt(), NextInt()

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if i == 0 && j == 0 {
					fmt.Fprint(out, string('W'))
				} else {
					fmt.Fprint(out, string('B'))
				}
			}
			fmt.Fprintln(out)
		}
	}

}

package main

import "fmt"

func main() {
	n := 0
	fmt.Scan(&n)
	for cas := 0; cas < n; cas++ {
		n, m := 0, 0
		fmt.Scan(&n, &m)
		work(n, m)
	}
}

func work(n, m int) {
	//输出第一行
	for r := 0; r < m; r++ {
		if r == 0 {
			fmt.Printf("W")
		} else {
			fmt.Printf("B")
		}
	}
	fmt.Printf("\n")

	//输出剩下的n-1行
	for c := 1; c < n; c++ {
		for r := 0; r < m; r++ {
			fmt.Printf("B")
		}
		fmt.Printf("\n")
	}
}

package main

import (
	"fmt"
)

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

	for test := 0; test < testCount; test++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			for k := 0; k < m; k++ {
				if i == 0 && k == 0 {
					fmt.Printf("%c", 'W')
				} else {
					fmt.Printf("%c", 'B')
				}
			}
			fmt.Printf("%c", '\n')
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Scanf("%d %d\n", &n, &m)
		bo := (n%2 == 0) || (m%2 == 0)
		for x := 0; x < n; x++ {
			for y := 0; y < m; y++ {
				if (x+y)%2 == 0 {
					fmt.Printf("B")
				} else {
					if bo {
						fmt.Printf("B")
						bo = false
					} else {
						fmt.Printf("W")
					}
				}
			}
			fmt.Println()
		}
	}
}

package main

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

func main() {
	// var err error
	// os.Stdin, err = os.Open("")
	// noError(err)

	r := bufio.NewReaderSize(os.Stdin, 50*1024*1024)
	T := readInt(r)
	for t := 1; t <= T; t++ {
		N, M := readTwoInts(r)
		var black [2]int
		if (N * M) % 2 == 0 {
			if M == 1 {
				black = [2]int{0, M-1}
			} else if N == 1 {
				black = [2]int{N-1, 0}
			} else {
				black = [2]int{M % 2, M-1}
			}
		}
		for r := 0; r < N; r++ {
			off := 0
			if r % 2 == 1 {
				off = 1
			}
			for c := 0; c < M; c++ {
				if (off + c) % 2 == 0 || (r == black[0] && c == black[1]) {
					fmt.Print("B")
				} else {
					fmt.Print("W")
				}
			}
			if r != N-1 {
				fmt.Println()
			}
		}
		if t != T {
			fmt.Println()
		}
	}
}
/**
* Utils
*/
func readInt(r *bufio.Reader) int {
	return strToInt(readLine(r))
}

func readTwoInts(r *bufio.Reader) (int, int) {
	ints := readInts(r, 2)
	return ints[0], ints[1]
}

func readInts(r *bufio.Reader, n int) []int {
	result := make([]int, n)
	strs := strings.Split(readLine(r), " ")
	for i := 0; i < n; i++ {
		result[i] = strToInt(strs[i])
	}
	return result
}

func readLine(r *bufio.Reader) string {
	str, _, err := r.ReadLine()
	noError(err)
	return string(str)
}

func strToInt(s string) int {
	num, err := strconv.Atoi(s)
	noError(err)
	return num
}

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

// 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,m int
 fmt.Fscanf(reader, "%d %d\n", &n, &m)
 for i := 0 ; i < n ; i++ {
  for j := 0 ; j < m ; j++ {
   if ( i + j ) % 2 == 0 || ( ( n * m ) % 2 == 0 && i == 0 && j == 1 ) {
    fmt.Fprintf(writer,"B")
   } else {
    fmt.Fprintf(writer,"W")
   }
  }
  fmt.Fprintf(writer,"\n")
 }
}

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

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

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

func max(arr []int) (max int) {
	max = arr[0]
	for _, val := range arr {
		if val > max {
			max = val
		}
	}
	return max
}

func main() {
	var t int
	fmt.Scan(&t)
	for qt := 0; qt < t; qt++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if i == 0 && j == 0 {
					fmt.Print("W")
				} else {
					fmt.Print("B")
				}
			}
			fmt.Println()
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n, m int
		fmt.Scan(&n)
		fmt.Scan(&m)
		var s2 = "B"
		var s1 = "W"
		for i := 1; i < m; i++ {
			s1 += "B"
			s2 += "B"
		}
		fmt.Println(s1)
		for i := 1; i < n; i++ {
			fmt.Println(s2)
		}
		t -= 1
	}
}

package main

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

func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, m int
		fmt.Scan(&n, &m)
		if n*m%2 == 0 {
			for i := 0; i < n; i++ {
				if i == 0 {
					for j := 0; j < m; j++ {
						if j == 0 {
							fmt.Fprint(w, "B")
						} else if j%2 == 0 {
							fmt.Fprint(w, "W")
						} else {
							fmt.Fprint(w, "B")
						}
					}
				} else if i%2 == 0 {
					for j := 0; j < m; j++ {
						if j%2 == 0 {
							fmt.Fprint(w, "W")
						} else {
							fmt.Fprint(w, "B")
						}
					}
				} else {
					for j := 0; j < m; j++ {
						if j%2 == 0 {
							fmt.Fprint(w, "B")
						} else {
							fmt.Fprint(w, "W")
						}
					}
				}
				fmt.Fprintln(w)
			}
		} else {
			for i := 0; i < n; i++ {
				if i%2 == 0 {
					for j := 0; j < m; j++ {
						if j%2 == 0 {
							fmt.Fprint(w, "B")
						} else {
							fmt.Fprint(w, "W")
						}
					}
				} else {
					for j := 0; j < m; j++ {
						if j%2 == 0 {
							fmt.Fprint(w, "W")
						} else {
							fmt.Fprint(w, "B")
						}
					}
				}
				fmt.Fprintln(w)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"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 {
	NextInt() int
	NextInt64() int64
	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) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

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) NextString() string {
	impl.Scan()
	return impl.Text()
}

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

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        n, m := reader.NextInt64(), reader.NextInt64()
        isB := true
        colorBlackOnce := (n*m)&1==0
        for i := int64(0); i < n; i++ {
            for j := int64(0); j < m; j++ {
                if isB {
                    writer.Printf("B")
                } else if colorBlackOnce {
                    writer.Printf("B")
                    colorBlackOnce = false
                } else {
                    writer.Printf("W")
                }
                isB = !isB
                if j == m-1 {
                    writer.Printf("\n")
                }
            }
        }
    }
}

package main

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

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

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

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

const N = 105

var a [N][N]byte

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, m int
		scanf("%d %d\n", &n, &m)
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if (i+j)%2 == 0 {
					a[i][j] = 'B'
				} else {
					a[i][j] = 'W'
				}
			}
		}
		if (n*m)%2 == 0 {
			a[n][m] = 'B'
		}
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				printf("%c", a[i][j])
			}
			printf("\n")
		}
	}
}

package main

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

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

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

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

const N = 105

var a [N][N]byte

func main() {
	defer writer.Flush()

	var t int
	scanf("%d", &t)
	for ; t > 0; t-- {
		var n, m int
		scanf("%d %d\n", &n, &m)
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if i+j%2 == 0 {
					a[i][j] = 'B'
				} else {
					a[i][j] = 'W'
				}
			}
		}
		if (n*m)%2 == 0 {
			a[n][m] = 'B'
		}
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				printf("%c", a[i][j])
			}
			printf("\n")
		}
	}
}

package main

import "fmt"

func main() {
	n := 0
	fmt.Scanf("%d", &n)
	for cas := 0; cas < n; cas++ {
		n, m := 0, 0
		fmt.Scanf("%d %d", &n, &m)
		work(n, m)
	}
}

func work(n, m int) {
	//输出第一行
	for r := 0; r < m; r++ {
		if r == 0 {
			fmt.Printf("W")
		} else {
			fmt.Printf("B")
		}
	}
	fmt.Printf("\n")

	//输出剩下的n-1行
	for c := 1; c < n; c++ {
		for r := 0; r < m; r++ {
			fmt.Printf("B")
		}
		fmt.Printf("\n")
	}
}

package main

import (
	"fmt"
)

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

	for test := 0; test < testCount; test++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			for k := 0; k < m; k++ {
				if i == 0 && k == 0 {
					fmt.Printf("%c", 'B')
				} else {
					fmt.Printf("%c", 'A')
				}
			}
			fmt.Printf("%c", '\n')
		}
	}
}

package main

import (
	"fmt"
)

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

	for test := 0; test < testCount; test++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			for k := 0; k < m; k++ {
				if i == 0 && k == 0 {
					fmt.Printf("%c", 'B')
				} else {
					fmt.Printf("%c", 'W')
				}
			}
			fmt.Printf("%c", '\n')
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Scanf("%d %d\n", &n, &m)
		if n > 2 {
			for j := 0; j < n; j++ {
				for k := 0; k < m; k++ {
					if k == m-1 {
						if j == n-2 {
							fmt.Printf("B")
						} else {
							fmt.Printf("W")
						}
					} else {
						fmt.Printf("B")
					}
				}
				fmt.Println()
			}
		} else if m > 2 {
			for j := 0; j < n; j++ {
				for k := 0; k < m; k++ {
					if j == n-1 {
						if k == m-2 {
							fmt.Printf("B")
						} else {
							fmt.Printf("W")
						}
					} else {
						fmt.Printf("B")
					}
				}
				fmt.Println()
			}
		} else {
			fmt.Println("no solution")
		}
	}
}

package main

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

func main() {
	// var err error
	// os.Stdin, err = os.Open("")
	// noError(err)

	r := bufio.NewReaderSize(os.Stdin, 50*1024*1024)
	T := readInt(r)
	for t := 1; t <= T; t++ {
		N, M := readTwoInts(r)
		var black [2]int
		if (N * M) % 2 == 0 {
			if N == 1 {
				black = [2]int{0, M-1}
			} else if M == 1 {
				black = [2]int{N-1, 0}
			} else {
				black = [2]int{N-1, M-1}
			}
		}
		for r := 0; r < N; r++ {
			off := 0
			if r % 2 == 1 {
				off = 1
			}
			for c := 0; c < M; c++ {
				if (off + c) % 2 == 0 || (r == black[0] && c == black[1]) {
					fmt.Print("B")
				} else {
					fmt.Print("W")
				}
			}
			if r != N-1 {
				fmt.Println()
			}
		}
		if t != T {
			fmt.Println()
		}
	}
}
/**
* Utils
*/
func readInt(r *bufio.Reader) int {
	return strToInt(readLine(r))
}

func readTwoInts(r *bufio.Reader) (int, int) {
	ints := readInts(r, 2)
	return ints[0], ints[1]
}

func readInts(r *bufio.Reader, n int) []int {
	result := make([]int, n)
	strs := strings.Split(readLine(r), " ")
	for i := 0; i < n; i++ {
		result[i] = strToInt(strs[i])
	}
	return result
}

func readLine(r *bufio.Reader) string {
	str, _, err := r.ReadLine()
	noError(err)
	return string(str)
}

func strToInt(s string) int {
	num, err := strconv.Atoi(s)
	noError(err)
	return num
}

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

// 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,m int
 fmt.Fscanf(reader, "%d %d\n", &n, &m)
 for i := 0 ; i < n ; i++ {
  for j := 0 ; j < m ; j++ {
   if ( i + j ) % 2 == 0 || ( i == n - 1 && j == m - 1 ) {
    fmt.Fprintf(writer,"B")
   } else {
    fmt.Fprintf(writer,"W")
   }
  }
  fmt.Fprintf(writer,"\n")
 }
}

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


Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $$$d, m$$$, find the number of arrays $$$a$$$, satisfying the following constraints:  The length of $$$a$$$ is $$$n$$$, $$$n \ge 1$$$  $$$1 \le a_1 < a_2 < \dots < a_n \le d$$$  Define an array $$$b$$$ of length $$$n$$$ as follows: $$$b_1 = a_1$$$, $$$\forall i > 1, b_i = b_{i - 1} \oplus a_i$$$, where $$$\oplus$$$ is the bitwise exclusive-or (xor). After constructing an array $$$b$$$, the constraint $$$b_1 < b_2 < \dots < b_{n - 1} < b_n$$$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $$$m$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) denoting the number of test cases in the input. Each of the next $$$t$$$ lines contains two integers $$$d, m$$$ ($$$1 \leq d, m \leq 10^9$$$). Note that $$$m$$$ is not necessary the prime!

For each test case, print the number of arrays $$$a$$$, satisfying all given constrains, modulo $$$m$$$.

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()

	a := make([]int, 32)
	f := make([]int64, 32)
	for t := 0; t < T; t++ {
		d, m := NextInt(), NextInt64()

		for i, x := 0, d; i < 31; i++ {
			a[i] = x & 1
			x >>= 1
			f[i] = 0
		}

		eq := true
		for i := 30; i >= 0; i-- {
			if eq && a[i] == 1 {
				f[i] = int64(d - (1 << uint32(i)) + 1)
				eq = false
			} else if eq && a[i] == 0 {
				f[i] = 0
			} else if !eq {
				f[i] = int64(1 << uint32(i))
			}
		}
		var total int64
		for i := 0; i < 31; i++ {
			res := f[i] % m
			for j := 0; j < i; j++ {
				res += ((f[i] % m) * (f[j] % m)) % m
				if res >= m {
					res -= m
				}
			}
			f[i] = res
			total += f[i]
			if total >= m {
				total %= m
			}
		}
		fmt.Fprintln(out, total)
	}

}

/*
URL:
https://codeforces.com/problemset/problem/1329/B
*/

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
	d, m int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		d, m = ReadInt64_2()

		solve()
	}
}

func solve() {
	PrintfDebug("d: %d\n", d)
	if m == 1 {
		fmt.Println(0)
		return
	}

	i := 0
	ans := int64(1)
	for 1<<uint(i+1) <= d {
		p := int64(1 << uint(i))
		ans *= (p + 1)
		PrintfDebug("kake: %d\n", p+1)
		ans %= m

		i++
	}
	mb := int64(1 << uint(i))
	ans *= (d - mb + 2)
	PrintfDebug("kake: %d\n", d-mb+2)
	PrintfDebug("\n")
	ans %= m
	fmt.Println(NegativeMod(ans-1, m))
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	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"
)

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

	var tc int
	fmt.Fscanf(r, "%d\n", &tc)

	for t := 1; t <= tc; t++ {
		var d, m uint64
		fmt.Fscanf(r, "%d %d\n", &d, &m)

		dp := make([]uint64, 33)
		for i := 32; i >= 0; i-- {
			p := uint64(1) << uint64(i)
			if p > d {
				dp[i] = 0
			} else if p*2 > d {
				dp[i] = (d - p + 1) % m
			} else {
				dp[i] = (p*dp[i+1])%m + dp[i+1] + p
				dp[i] %= m
			}
		}

		fmt.Println(dp[0])
	}
}


Try guessing the statement from this picture:   You are given a non-negative integer $$$d$$$. You have to find two non-negative real numbers $$$a$$$ and $$$b$$$ such that $$$a + b = d$$$ and $$$a \cdot b = d$$$.

The first line contains $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Each test case contains one integer $$$d$$$ $$$(0 \le d \le 10^3)$$$.

For each test print one line. If there is an answer for the $$$i$$$-th test, print "Y", and then the numbers $$$a$$$ and $$$b$$$. If there is no answer for the $$$i$$$-th test, print "N". Your answer will be considered correct if $$$|(a + b) - a \cdot b| \le 10^{-6}$$$ and $$$|(a + b) - d| \le 10^{-6}$$$.

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

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

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if a < b {
			a, b = b, a
		}
		if ok {
			fmt.Printf("Y %.10f %.10f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

package main

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

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

	var T, D int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &D)
		if 0 < D && D < 4 {
			Fprintln(out, "N")
			continue
		}
		d := float64(D)
		dt := math.Sqrt(d * (d - 4))
		Fprintf(out, "Y %.9f %.9f\n", (d+dt)/2, (d-dt)/2)
	}
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t, d := 0, 0
	fmt.Fscanf(in, "%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &d)
		x1 := float64(d*d - 4*d)
		x2 := math.Sqrt(float64(x1))
		x3 := (-1.0*float64(d) + x2) / -2.0
		if x3 >= 0 {
			x4 := float64(d) - x3
			if x4 >= 0 {
				fmt.Fprintf(out, "Y %.9f %0.9f\n", math.Abs(x4), math.Abs(x3))
				continue
			}
		}
		x5 := (-1.0*float64(d) - x2) / -2.0
		if x5 >= 0 {
			x6 := float64(d) - x5
			if x6 >= 0 {
				fmt.Fprintf(out, "Y %.9f %0.9f\n", math.Abs(x6), math.Abs(x5))
				continue
			}
		}
		fmt.Fprintf(out, "N\n")

	}
	fmt.Fprintf(out, "\n")
	return
}

// Codeforces 1076 C Meme Problem train
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
	"math"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	delim := byte(' ')
	for i:=0; i<n; i++ {
		if i==(n-1) {
			delim = byte('\n')
		}
		s, err := in.ReadString(delim)
		s = strings.Trim(s, " \n\r")
		if err != nil {
			fmt.Println("read failure", err)
			panic(err)
		}
		aa,err := strconv.Atoi(s)
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[i] = aa
	}
	return a
}

var n int
var d []int
var a []float64
var b []float64

func readData() {
	in = bufio.NewReader(os.Stdin)
	n, _, _, _, _ = readFive()
	d = make([]int, n)
	for i:=0; i<n; i++ {
		d[i],_,_,_,_ = readFive()
	}
}

func solve() {
	for i:=0; i<n; i++ {
		dd := float64(d[i])
		if dd <= 0.1 {
			fmt.Println("Y 0.0 0.0")
			continue
		}
		di := (dd*dd)/4.0 - dd
		if di < -0.000001 {
			fmt.Println("N")
			continue
		}
		di = math.Sqrt(di)
		a := dd/2.0 + di
		b := dd/2.0 - di
		fmt.Println("Y ", a, b)
	}
}

func printRes() {
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	for i := 0; i < n; i++ {
		d := scanNum()
		if d == 0 {
			fmt.Println("Y 0.000000000 0.000000000")
			continue
		}
		if d == 1 {
			fmt.Println("N")
			continue
		}
		l, r, mid := 1.0, float64(d)/2, 1.0
		for c := 0; c < 50000; c++ {
			mid = (l + r) / 2
			if mid*(float64(d)-mid) < float64(d) {
				l = mid
			} else {
				r = mid
			}
		}
		diff := (float64(d)-mid)*mid - float64(d)
		if diff*diff > 1e-12 {
			fmt.Println("N")
			continue
		}
		fmt.Println("Y", float64(d)-mid, mid)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var test int
	var d float64
	var a, b, det float64
	fmt.Scan(&test)
	for i := 0; i < test; i++ {
		fmt.Scan(&d)
		det = math.Pow(d, 2) - (4 * d)
		if det >= 0 {
			a = (d + math.Pow(det, 0.5)) * 0.5
			if a == 0 {
				fmt.Println("Y 0.000000000 0.000000000")
			} else {
				b = d / a
				fmt.Printf("Y %.9f %.9f\n", a, b)
			}
		} else {
			fmt.Println("N")
		}
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

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

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if ok {
			fmt.Printf("Y %f %f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

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

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if a < b {
			a, b = b, a
		}
		if ok {
			fmt.Printf("Y %f %f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

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

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if ok {
			fmt.Printf("Y %.7f %.7f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

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

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if a < b {
			a, b = b, a
		}
		if ok {
			fmt.Printf("Y %.7f %.7f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

// Codeforces 1076 C Meme Problem train
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
	"math"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	delim := byte(' ')
	for i:=0; i<n; i++ {
		if i==(n-1) {
			delim = byte('\n')
		}
		s, err := in.ReadString(delim)
		s = strings.Trim(s, " \n\r")
		if err != nil {
			fmt.Println("read failure", err)
			panic(err)
		}
		aa,err := strconv.Atoi(s)
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[i] = aa
	}
	return a
}

var n int
var d []int
var a []float64
var b []float64

func readData() {
	in = bufio.NewReader(os.Stdin)
	n, _, _, _, _ = readFive()
	d = make([]int, n)
	for i:=0; i<n; i++ {
		d[i],_,_,_,_ = readFive()
	}
}

func solve() {
	for i:=0; i<n; i++ {
		dd := float64(d[i])
		if dd <= 0.1 {
			fmt.Println("Y 0.0 0.0")
			continue
		} else if dd <= 2.1 {
			fmt.Println("N")
			continue
		}
		di := math.Sqrt((dd*dd)/4.0 - dd)
		a := dd/2.0 + di
		b := dd/2.0 - di
		fmt.Println("Y ", a, b)
	}
}

func printRes() {
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	for i := 0; i < n; i++ {
		d := scanNum()
		if d == 0 {
			fmt.Println("Y 0.000000000 0.000000000")
			continue
		}
		if d == 1 {
			fmt.Println("N")
			continue
		}
		l, r, mid := 1.0, float64(d)/2, 1.0
		for c := 0; c < 50000; c++ {
			mid = (l + r) / 2
			if mid*(float64(d)-mid) < float64(d) {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Println("Y", float64(d)-mid, mid)
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	for i := 0; i < n; i++ {
		d := scanNum()
		if d == 0 {
			fmt.Println("Y 0.000000000 0.000000000")
			continue
		}
		if d == 1 {
			fmt.Println("N")
			continue
		}
		l, r, mid := 1.0, float64(d)/2, 1.0
		for c := 0; c < 1000; c++ {
			mid = (l + r) / 2
			if mid*(float64(d)-mid) < float64(d) {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Println("Y", float64(d)-mid, mid)
	}
}


A tree of size n is an undirected connected graph consisting of n vertices without cycles.Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the condition holds: "vertices u and v are connected by an edge if and only if vertices pu and pv are connected by an edge".You are given permutation p of size n. Find some tree size n, invariant relative to the given permutation.

The first line contains number n (1 ≤ n ≤ 105) — the size of the permutation (also equal to the size of the sought tree). The second line contains permutation pi (1 ≤ pi ≤ n).

If the sought tree does not exist, print "NO" (without the quotes). Otherwise, print "YES", and then print n - 1 lines, each of which contains two integers — the numbers of vertices connected by an edge of the tree you found. The vertices are numbered from 1, the order of the edges and the order of the vertices within the edges does not matter. If there are multiple solutions, output any of them.

NoteIn the first sample test a permutation transforms edge (4, 1) into edge (1, 4), edge (4, 2) into edge (1, 3) and edge (1, 3) into edge (4, 2). These edges all appear in the resulting tree.It can be shown that in the second sample test no tree satisfies the given condition.

package main

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

const (
	maxn int = 100000 + 5
)

var (
	n, m int
	a    [maxn]int
)

func main() {
	// file, _ := os.Open("input.txt")
	file := os.Stdin
	f := bufio.NewReader(file)
	fmt.Fscanf(f, "%d\n", &n)
	var center1, center2 = -1, -1
	for i := 1; i <= n; i++ {
		fmt.Fscanf(f, "%d", &a[i])
		if i == a[i] {
			center1 = i
		}
		if i == a[a[i]] {
			center2 = i
		}
	}

	if center1 != -1 {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			if i != center1 {
				fmt.Printf("%d %d\n", i, center1)
			}
		}
	} else if center2 != -1 {
		marked := make([]bool, n+1)
		for i := 0; i < n+1; i++ {
			marked[i] = false
		}
		var a1, a2 []int
		res := true
		for i := 1; i <= n; i++ {
			if i != center2 && i != a[center2] {
				idx := 1
				s := i
				for !marked[s] {
					marked[s] = true
					if idx%2 == 1 {
						a1 = append(a1, s)
					} else {
						a2 = append(a2, s)
					}
					s = a[s]
					idx++
				}
				if idx%2 == 0 {
					res = false
				}
			}
		}
		if res {
			fmt.Println("YES")
			fmt.Printf("%d %d\n", center2, a[center2])
			for i := 0; i < len(a1); i++ {
				fmt.Printf("%d %d\n", center2, a1[i])
			}
			for i := 0; i < len(a2); i++ {
				fmt.Printf("%d %d\n", a[center2], a2[i])
			}
		} else {
			fmt.Println("NO")
		}
	} else {
		fmt.Println("NO")
	}
}


After being discouraged by 13 time-limit-exceeded verdicts on an ugly geometry problem, you decided to take a relaxing break for arts and crafts.There is a piece of paper in the shape of a simple polygon with $$$n$$$ vertices. The polygon may be non-convex, but we all know that proper origami paper has the property that any horizontal line intersects the boundary of the polygon in at most two points.If you fold the paper along the vertical line $$$x=f$$$, what will be the area of the resulting shape? When you fold, the part of the paper to the left of the line is symmetrically reflected on the right side.  Your task is to answer $$$q$$$ independent queries for values $$$f_1,\ldots,f_q$$$.

The first line contains two integers $$$n$$$, $$$q$$$ ($$$3\le n\le 10^5, 1\le q\le 10^5$$$)  — the number of polygon vertices and queries, respectively. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$|x_i|, |y_i|\le 10^5$$$)  — the coordinates of the $$$i$$$-th point of the polygon. The polygon has an edge connecting each pair of adjacent points in the input, and also an edge between $$$(x_1,y_1)$$$ and $$$(x_n,y_n)$$$. It is guaranteed that the polygon is non-degenerate and that any horizontal line intersects the boundary of the polygon in at most two points. In particular, no boundary edge is strictly horizontal. Two adjacent sides may be collinear. Each of the next $$$q$$$ lines contains a single integer $$$f_i$$$ ($$$\min\limits_{j=1}^n(x_j)< f_i< \max\limits_{j=1}^n(x_j)$$$)  — the $$$x$$$-coordinate of the $$$i$$$-th fold query. It is guaranteed that all $$$f_i$$$ are distinct.

For each query, output the area $$$A_i$$$ of the paper if you fold it along the line $$$x=f_i$$$. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}$$$.

NoteThe first test, with the fold $$$f=-5$$$:  The second test, with the fold $$$f=1$$$:  The third test, with the fold $$$f=-1$$$:

package main

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

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

	type Point struct {
		x, y float64
	}
	type Event struct {
		x       float64
		a, b, c float64
	}
	type Query struct {
		x   float64
		idx int
	}

	n, q := io.NextInt(), io.NextInt()
	p := make([]Point, n)
	for i := range p {
		p[i] = Point{float64(io.NextInt()), float64(io.NextInt())}
	}
	qry := make([]Query, q)
	for i := range qry {
		x := float64(io.NextInt())
		qry[i] = Query{x, i}
	}

	var e []Event
	add := func(a, b Point, mul float64) {
		if math.Abs(a.y-b.y) < 1e-8 || math.Abs(a.x-b.x) < 1e-8 {
			return
		}
		if a.x > b.x {
			a, b, mul = b, a, -mul
		}
		m := (b.y - a.y) / (b.x - a.x)
		c := a.y - m*a.x
		e = append(e,
			Event{a.x, mul * m, mul * c, -mul * (m*a.x*a.x/2 + c*a.x)},
			Event{b.x, -mul * m, -mul * c, mul * (m*b.x*b.x/2 + c*b.x)})
	}

	var area float64
	lowest := 0
	for i, a := range p {
		j := (i + 1) % n
		b := p[j]
		if a.y < p[lowest].y {
			lowest = i
		}
		area += a.x*b.y - b.x*a.y
		if a.y < b.y {
			a, b = b, a
		}
		add(a, b, 1)
	}
	area = math.Abs(area / 2)

	getMid := func(a, b, p Point) Point {
		return Point{((p.y-a.y)*(b.x-a.x)/(b.y-a.y) + a.x + p.x) / 2, p.y}
	}

	l, r := (lowest+1)%n, (lowest+n-1)%n
	last := p[lowest]
	for l != r {
		var m Point
		if p[l].y < p[r].y {
			m = getMid(p[(r+1)%n], p[r], p[l])
			l = (l + 1) % n
		} else {
			m = getMid(p[(l+n-1)%n], p[l], p[r])
			r = (r + n - 1) % n
		}
		add(last, m, 2)
		last = m
	}
	add(last, p[l], 2)

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

	i := 0
	var a, b, c float64
	ans := make([]float64, q)
	for _, q := range qry {
		for ; i < len(e) && e[i].x < q.x; i++ {
			a += e[i].a
			b += e[i].b
			c += e[i].c
		}
		ans[q.idx] = area + (a*q.x*q.x/2 + b*q.x + c)
	}

	for _, x := range ans {
		fmt.Fprintf(io, "%.9f\n", x)
	}
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

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

func (f *FastIO) readC() byte {
	_, _ = f.Read(f.c[:])
	return f.c[0]
}

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


One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the height of the i-th castle is equal to hi. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition hi ≤ hi + 1 holds for all i from 1 to n - 1.Squidward suggested the following process of sorting castles:   Castles are split into blocks — groups of consecutive castles. Therefore the block from i to j will include castles i, i + 1, ..., j. A block may consist of a single castle.  The partitioning is chosen in such a way that every castle is a part of exactly one block.  Each block is sorted independently from other blocks, that is the sequence hi, hi + 1, ..., hj becomes sorted.  The partitioning should satisfy the condition that after each block is sorted, the sequence hi becomes sorted too. This may always be achieved by saying that the whole sequence is a single block. Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day. The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.

Print the maximum possible number of blocks in a valid partitioning.

NoteIn the first sample the partitioning looks like that: [1][2][3].  In the second sample the partitioning is: [2, 1][3, 2]

package main

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

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

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

var nums [100050]int
var maxx [100050]int

func main() {
	var n, ans, curH int
	fmt.Scanln(&n)
	in := bufio.NewReader(os.Stdin)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &nums[i])
		if i == 0 {
			maxx[i] = nums[i]
		} else {
			maxx[i] = Max(&maxx[i - 1], &nums[i])
		}
	}
	ans = 0
	curH = nums[n - 1]
	for i := n - 1; i >= 1; i-- {
		if curH >= maxx[i - 1] {
			curH = nums[i - 1]
			ans++
		} else {
			curH = Min(&curH, &nums[i])
		}
	}
	fmt.Println(ans + 1)
}


You have two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$. You would like to make all the elements of both strings equal to $$$0$$$. Unfortunately, you can modify the contents of these strings using only the following operation:  You choose two indices $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$);  For every $$$i$$$ that respects $$$l \le i \le r$$$, change $$$a_i$$$ to the opposite. That is, $$$a_i := 1 - a_i$$$;  For every $$$i$$$ that respects either $$$1 \le i < l$$$ or $$$r < i \le n$$$, change $$$b_i$$$ to the opposite. That is, $$$b_i := 1 - b_i$$$. Your task is to determine if this is possible, and if it is, to find such an appropriate chain of operations. The number of operations should not exceed $$$n + 5$$$. It can be proven that if such chain of operations exists, one exists with at most $$$n + 5$$$ operations.

Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the strings. The second line of each test case contains a binary string $$$a$$$, consisting only of characters 0 and 1, of length $$$n$$$. The third line of each test case contains a binary string $$$b$$$, consisting only of characters 0 and 1, of length $$$n$$$. It is guaranteed that sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print first "YES" if it's possible to make all the elements of both strings equal to $$$0$$$. Otherwise, print "NO". If the answer is "YES", on the next line print a single integer $$$k$$$ ($$$0 \le k \le n + 5$$$) — the number of operations. Then $$$k$$$ lines follows, each contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$) — the description of the operation. If there are several correct answers, print any of them.

YES
1
2 2
NO
NO
YES
2
1 2
2 2
YES
2
1 1
2 3

NoteIn the first test case, we can perform one operation with $$$l = 2$$$ and $$$r = 2$$$. So $$$a_2 := 1 - 1 = 0$$$ and string $$$a$$$ became equal to 000. $$$b_1 := 1 - 1 = 0$$$, $$$b_3 := 1 - 1 = 0$$$ and string $$$b$$$ became equal to 000.In the second and in the third test cases, it can be proven that it's impossible to make all elements of both strings equal to $$$0$$$.In the fourth test case, we can perform an operation with $$$l = 1$$$ and $$$r = 2$$$, then string $$$a$$$ became equal to 01, and string $$$b$$$ doesn't change. Then we perform an operation with $$$l = 2$$$ and $$$r = 2$$$, then $$$a_2 := 1 - 1 = 0$$$ and $$$b_1 = 1 - 1 = 0$$$. So both of string $$$a$$$ and $$$b$$$ became equal to 00.In the fifth test case, we can perform an operation with $$$l = 1$$$ and $$$r = 1$$$. Then string $$$a$$$ became equal to 011 and string $$$b$$$ became equal to 100. Then we can perform an operation with $$$l = 2$$$ and $$$r = 3$$$, so both of string $$$a$$$ and $$$b$$$ became equal to 000.

package main

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

const cf = true

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

	var s1, s2 string
	fmt.Fscan(in, &s1, &s2)

	sum := make([]int, n)

	ans := 0
	cur := 0
	for i := 0; i < n; i++ {
		sum[i] += cur
		if s1[i] == '1' {
			cur++
			ans++
		}
	}
	cur = 0
	for i := n - 1; i >= 0; i-- {
		sum[i] += cur
		if s1[i] == '1' {
			cur++
		}
	}
	cnt1, cnt0 := 0, 0
	for i := range s2 {
		chr := s2[i]
		if sum[i]%2 == 1 {
			if chr == '1' {
				chr = '0'
			} else {
				chr = '1'
			}
		}
		if chr == '0' {
			cnt0++
		} else {
			cnt1++
		}
	}
	if cnt1 > 0 && cnt0 > 0 {
		fmt.Fprintln(out, "NO")
		return
	}
	fmt.Fprintln(out, "YES")

	if cnt0 > 0 {
		fmt.Fprintln(out, ans)
	} else {
		fmt.Fprintln(out, ans+3)
	}

	for i := n - 1; i >= 0; i-- {
		if s1[i] == '1' {
			fmt.Fprintln(out, i+1, i+1)
		}
	}
	if cnt1 > 0 {
		fmt.Fprintln(out, 1, 1)
		fmt.Fprintln(out, 2, n)
		fmt.Fprintln(out, 1, n)
	}
}

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

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

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

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

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

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

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

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

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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

package main

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

const cf = true

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

	var s1, s2 string
	fmt.Fscan(in, &s1, &s2)

	sum := make([]int, n)

	ans := 0
	cur := 0
	for i := 0; i < n; i++ {
		sum[i] += cur
		if s1[i] == '1' {
			cur++
			ans++
		}
	}
	cur = 0
	for i := n - 1; i >= 0; i-- {
		sum[i] += cur
		if s1[i] == '1' {
			cur++
		}
	}
	cnt1, cnt0 := 0, 0
	for i := range s2 {
		chr := s2[i]
		if sum[i]%2 == 1 {
			if chr == '1' {
				chr = '0'
			} else {
				chr = '1'
			}
		}
		if chr == '0' {
			cnt0++
		} else {
			cnt1++
		}
	}
	if cnt1 > 0 && cnt0 > 0 {
		fmt.Fprintln(out, "NO")
		return
	}

	if cnt0 > 0 {
		fmt.Fprintln(out, ans)
	} else {
		fmt.Fprintln(out, ans+3)
	}

	for i := n - 1; i >= 0; i-- {
		if s1[i] == '1' {
			fmt.Fprintln(out, i+1, i+1)
		}
	}
	if cnt1 > 0 {
		fmt.Fprintln(out, 1, 1)
		fmt.Fprintln(out, 2, n)
		fmt.Fprintln(out, 1, n)
	}
}

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

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

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

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

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

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

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

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

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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