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
  inpu = sys.stdin.readline
  prin = sys.stdout.write
  for _ in range(int(inpu())) :
      n, k = map(int, inpu().split())
      lis = list(map(int, str(n)))
      ans = 0
      if k == 1 :
          for i in range(len(lis), 11):
              mi = min(lis)
              while mi <= 9:
                  if int(str(mi)*i) >= n :
                      prin(str(mi)*i + '\n')
                      ans = 1
                      break
                  mi+=1
              if ans == 1: break
  
      if k == 2 :
          l = len(set(lis))
          if l <= 2 :
              prin(str(n) + '\n')
              continue
  
          else:
              lastb = -1
              lasta = -1
              a = lis[0]
              b = 11
              for i in range(1, len(lis)) :
                  if lis[i] == b:
                      lastb = i
                  elif lis[i] == a:
                      lasta = i
                  if lis[i] != a and b == 11 :
                      b = lis[i]
                      unique = i
                  elif lis[i] !=a and lis[i] != b :
                      unique2 = i
                      c = lis[i]
                      break
              
              h = lis[unique2 - 1]
              e = a^b^h
              if c<h:
                  if min(a, b) > c:
                      prin(''.join(map(str, lis[0:unique2])) + str(min(a, b))*(len(lis) - unique2) + '\n')
                  else:
                      prin(''.join(map(str, lis[0:unique2])) + str(h) + str(e)*(len(lis) - unique2 - 1) + '\n')
  
  
              elif c>a and c>b :
                  if h == a and a<b:
                      prin(''.join(map(str, lis[0:unique2-1])) + str(b) + str(a)*(len(lis) - unique2) + '\n')
                  elif h == a and a>b:
                      if lastb != -1:
                          prin(''.join(map(str, lis[0:lastb])) + str(a) + str(b)*(len(lis) - lastb - 1) + '\n')
                      else:
                          if b + 1 == a :
                              prin(''.join(map(str, lis[0:unique])) + str(a) + '0'*(len(lis) - unique - 1) + '\n')
                          else:
                              prin(''.join(map(str, lis[0:unique])) + str(b + 1)*(len(lis) - unique) + '\n')
                  elif h == b:
                      if b + 1 != a:
                          if a < b :
                              if lasta > unique:
                                  prin(''.join(map(str, lis[0:lasta])) + str(b) + str(a)*(len(lis) - lasta - 1) + '\n')
                              else:
                                  prin(str(a)*unique + str(b+1) + str(min(b + 1, a))*(len(lis) - unique - 1) + '\n')
                          else:
                              if lastb == -1 :
                                  prin(str(a)*unique + str(b+1) + str(min(b + 1, a))*(len(lis) - unique - 1) + '\n')
                              else:
                                  prin(''.join(map(str, lis[0:unique2-1])) + str(a) + str(b)*(len(lis) - unique2) + '\n')
                      elif b + 1 == a and lastb == -1:
                          prin(str(a)*(unique+1) + '0'*(len(lis) - unique - 1) + '\n')
                      
                      elif b + 1 == a and lastb != -1:
                          prin(''.join(map(str, lis[0:unique2-1])) + str(a) + str(min(a, b))*(len(lis) - unique2) + '\n')
              
              elif c>h and c<e :
                  prin(''.join(map(str, lis[0:unique2])) + str(e) + str(h)*(len(lis) - unique2 - 1) + '\n')