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: # F1
  from collections import defaultdict, Counter
  
  def func(s, k, i, ns):
      global vis, res
      if len(vis) > k:
          return False
      if s[0:i] > ns[0:i]:
          return False
      if i >= len(s):
          res = min(res, int("".join(ns)))
          return True
      
      for j in range(0, 10):
          if i == 0 and j == 0:
              continue
          vis[j] += 1
          if func(s, k, i+1, ns + [str(j)]):
              return True
          vis[j] -= 1
          if vis[j] <= 0:
              del vis[j]
  
      return False
  
  
  test = int(input())
  for t in range(test):
      n, k = map(int, input().split())
      s = list(str(n))
      f = Counter(s)
      res = float("inf")
      
      if (k == 1 and len(f) == 1) or (k == 2 and f == 2):
          print(n)
          continue
      if k == 1:
          m = len(s)
          number = "".join("1"*m)
          number = int(number)
          for i in range(1, 10):
              if i*number >= n:
                  res = i*number
                  break
      else:
          vis = defaultdict(int)
          _ = func(s, k, 0, [])
  
      print(res)