description: It is a simplified version of problem F2. The difference between them is the constraints (F1: k ≤ 2, F2: k ≤ 10).
  
  You are given an integer n. Find the minimum integer x such that x ≥ 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.
  
  Input
  
  The first line contains one integer t (1 ≤ t ≤ 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 ≤ n ≤ 10^9, 1 ≤ k ≤ 2).
  
  Output
  
  For each test case output on a separate line x — the minimum k-beautiful integer such that x ≥ n.
  
  Example
  
  Input
  
  
  4
  1 1
  221 2
  177890 2
  998244353 1
  
  
  Output
  
  
  1
  221
  181111
  999999999
solution: import sys
  #import random
  from bisect import bisect_right as lb
  from collections import deque
  #sys.setrecursionlimit(10**8)
  from queue import PriorityQueue as pq
  #from math import *
  input_ = lambda: sys.stdin.readline().strip("\r\n")
  ii = lambda : int(input_())
  il = lambda : list(map(int, input_().split()))
  ilf = lambda : list(map(float, input_().split()))
  ip = lambda : input_()
  fi = lambda : float(input_())
  ap = lambda ab,bc,cd : ab[bc].append(cd)
  li = lambda : list(input_())
  pr = lambda x : print(x)
  prinT = lambda x : print(x)
  f = lambda : sys.stdout.flush()
  inv =lambda x:pow(x,mod-2,mod)
  mod = 10**9 + 7
  
  dig = {}
  ans = 0
  s = ""
  k = 0
  
  def dp (i,t) :
      global dig,s,k,ans
  
      if (i == len(s)) :
          return ans
  
      tot = 0
  
      for j in range (10) :
          if (t and j < int(s[i])) :
              continue
          if (tot >= 2) :
              continue
          if (len(dig) == k and (not dig.get(j))) :
              continue
  
          ans *= 10
          ans += j
  
          flag = dig.get(j,0)
  
          if (not flag) :
              dig[j] = 1
  
          temp = dp(i+1,t and (j == int(s[i])))
  
          if (temp!= -1) :
              return temp
  
          if (not flag) :
              del dig[j]
  
          ans //= 10
  
      return -1
  
  for _ in range (ii()) :
      n,k = il()
  
      s = str(n)
      ans = 0
      dig = {}
  
      print(dp(0,1))
  