It is a simplified version of problem F2. The difference between them is the constraints (F1: $$$k \le 2$$$, F2: $$$k \le 10$$$).You are given an integer $$$n$$$. Find the minimum integer $$$x$$$ such that $$$x \ge n$$$ and the number $$$x$$$ is $$$k$$$-beautiful.A number is called $$$k$$$-beautiful if its decimal representation having no leading zeroes contains no more than $$$k$$$ different digits. E.g. if $$$k = 2$$$, the numbers $$$3434443$$$, $$$55550$$$, $$$777$$$ and $$$21$$$ are $$$k$$$-beautiful whereas the numbers $$$120$$$, $$$445435$$$ and $$$998244353$$$ are not.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le k \le 2$$$).

For each test case output on a separate line $$$x$$$ — the minimum $$$k$$$-beautiful integer such that $$$x \ge n$$$.

package main

import (
	"bufio"
	//	"container/heap" for heap.Init()
	"fmt"
	"os"
	"runtime"
)

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

type IntHeap []int

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

const (
	INIT = -1
)

var (
	k   int
	n   []int
	ans []int
)

// a >= b
func ge(a, b []int) bool {
	check(len(a) == len(b))
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return a[i] > b[i]
		}
	}
	return true
}

func ok(a []int) bool {
	cnt := make([]int, 10)
	uniq := 0
	for i := 0; i < len(a); i++ {
		if cnt[a[i]] == 0 {
			uniq++
			if uniq > k {
				return false
			}
		}
		cnt[a[i]]++
	}
	return true
}

func toi(a []int) int {
	rv := 0
	for _, x := range a {
		rv *= 10
		rv += x
	}
	return rv
}

func gen(d int) []int {
	rv := make([]int, len(n))
	for i := 0; i < len(n); i++ {
		rv[i] = d
	}
	return rv
}

func can(a, b int) {
	for i := 0; i < len(n); i++ {
		if n[i] < b { // change after prefix of length i
			t := make([]int, len(n))
			copy(t, n)

			if n[i] < a {
				t[i] = a
			} else {
				t[i] = b
			}

			for j := i + 1; j < len(n); j++ {
				t[j] = a
			}

			//			fmt.Printf("a %d b %d ans %v t %v ge %t\n", a, b, ans, t, ge(ans, t))
			if ge(ans, t) {
				copy(ans, t)
			}
		}

		if n[i] != a && n[i] != b { // prefix no longer valid
			return
		}

	}
}

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

	var tc int
	fmt.Fscan(r, &tc)

	for ; tc > 0; tc-- {

		var s string
		fmt.Fscan(r, &s, &k)
		n = make([]int, len(s))
		for i := 0; i < len(s); i++ {
			n[i] = int(s[i] - '0')
		}

		if ok(n) {
			fmt.Println(toi(n))
			continue
		}

		ans = gen(9)
		for i := 8; i > 0; i-- {
			t := gen(i)
			if ge(t, n) {
				ans = t
			}
		}

		if k > 1 {
			for a := 0; a < 10; a++ {
				for b := a + 1; b < 10; b++ {
					can(a, b)
				}
			}
		}

		fmt.Println(toi(ans))

	}
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	var s string
	var k int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &s, &k)
		w1 := do(s, k)
		fmt.Fprint(w, w1)
		fmt.Fprintln(w)
	}
}

func do(t string, k int) string {
	s := make([]byte, len(t))
	for i := range t {
		s[i] = t[i] - '0'
	}
	v := make([]byte, 10)
	w := make([]byte, len(t))
	dfs(s, w, v, k, true)
	for i := range w {
		w[i] += '0'
	}
	return string(w)
}

func dfs(t []byte, w []byte, v []byte, k int, strict bool) bool {
	if k < 0 {
		return false
	}
	if len(t) == 0 {
		return true
	}
	var b byte
	if strict {
		b = t[0]
	}
	for i := b; i <= 9; i++ {
		w[0] = i
		o := 0
		if v[i] == 0 {
			o = 1
		}
		v[i]++
		if dfs(t[1:], w[1:], v, k-o, strict && i == t[0]) {
			return true
		}
		v[i]--
	}
	return false
}

package main

import (
	"bufio"
	//	"container/heap" for heap.Init()
	"fmt"
	"os"
	"runtime"
)

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

type IntHeap []int

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

const (
	INIT = -1
)

var (
	k   int
	n   []int
	ans []int
)

// a >= b
func ge(a, b []int) bool {
	check(len(a) == len(b))
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return a[i] > b[i]
		}
	}
	return true
}

func ok(a []int) bool {
	cnt := make([]int, 10)
	uniq := 0
	for i := 0; i < len(a); i++ {
		if cnt[a[i]] == 0 {
			uniq++
			if uniq > k {
				return false
			}
		}
		cnt[a[i]]++
	}
	return true
}

func toi(a []int) int {
	rv := 0
	for _, x := range a {
		rv *= 10
		rv += x
	}
	return rv
}

func gen(d int) []int {
	rv := make([]int, len(n))
	for i := 0; i < len(n); i++ {
		rv[i] = d
	}
	return rv
}

func can(a, b int) {
	for i := 0; i < len(n); i++ {
		if n[i] < b { // change after prefix of length i
			t := make([]int, len(n))
			copy(t, n)

			if n[i] < a {
				t[i] = a
			} else {
				t[i] = b
			}

			for j := i + 1; j < len(n); j++ {
				t[j] = a
			}

			// fmt.Printf("ans %v t %v ge %t\n", ans, t, ge(ans, t))
			if ge(ans, t) {
				copy(ans, t)
			}
		}

		if n[i] != a && n[i] != b { // prefix no longer valid
			return
		}

	}
}

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

	var tc int
	fmt.Fscan(r, &tc)

	for ; tc > 0; tc-- {

		var s string
		fmt.Fscan(r, &s, &k)
		n = make([]int, len(s))
		for i := 0; i < len(s); i++ {
			n[i] = int(s[i] - '0')
		}

		if ok(n) {
			fmt.Println(toi(n))
			continue
		}

		ans = gen(9)
		for i := 8; i > 0; i-- {
			t := gen(i)
			if ge(t, n) {
				ans = t
			}
		}

		if k > 1 {
			for a := 0; a < 9; a++ {
				for b := a + 1; b < 9; b++ {
					can(a, b)
				}
			}
		}

		fmt.Println(toi(ans))

	}
}