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: for _ in range(int(input())):
      n, k = input().split()
      k = int(k)
      if len(n) == 1:
          print(n)
          continue
      if k == 1:
          f = True
          ff = True
          for u in n:
              if n[0] < u and ff:
                  f = False
              elif u < n[0]:
                  ff = False
          if f:
              print(n[0] * len(n))
          else:
              print(str(int(n[0]) + 1) * len(n))
      else:
          f = True
          ans = [""] * len(n)
          i1 = -1
          ib = 1
          a, b = n[0], n[1]
          bp1 = str(int(b) + 1)
          ans[0], ans[1] = a, b
          sf = False
          for i in range(1, len(n)):
              if sf:
                  sf = False
                  continue
              if f and b == a and i < len(n) - 1:
                  ans[i] = a
                  b = n[i + 1]
                  bp1 = str(int(b) + 1)
                  ib = i + 1
                  if b != a:
                      f = False
                      ans[i + 1] = b
                      sf = True
                  continue
              if n[i] < min(a, b):
                  ans[i] = min(a, b)
                  ans = ans[:i + 1] + [min(a, b)] * (len(n) - i - 1)
                  break
              elif n[i] == min(a, b):
                  ans[i] = min(a, b)
                  i1 = i
              elif n[i] < max(a, b):
                  ans[i] = max(a, b)
                  ans = ans[:i + 1] + [min(a, b)] * (len(n) - i - 1)
                  break
              elif n[i] == min(a, b):
                  ans[i] = min(a, b)
                  i1 = i
              elif n[i] == max(a, b):
                  ans[i] = max(a, b)
              else:
                  ta = tuple()
                  if i1 != -1:
                      ans[i1] = max(a, b)
                      ans = ans[:i1 + 1] + [min(a, b)] * (len(n) - i1 - 1)
                      ta = tuple(ans)
  
                  ans[ib] = bp1
                  ans = ans[:ib + 1] + [min(a, bp1) if a != bp1 else "0"] * (len(n) - ib - 1)
                  if not ta or tuple(ans) < ta:
                      ta = tuple(ans)
                  ans = list(ta)
                  break
          print(*ans, sep="")
  