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
  
  for _ in range (ii()) :
      n,k = il()
  
      if (k == 1) :
          x = list(str(n))
  
          for i in range (1,10) :
              y = str(i)*(len(x))
              if (int(y) >= n) :
                  print(y)
                  break
  
      else :
          fl = 0
          x = list(str(n))
  
          
          ans1 = []
          for i in range (1,10) :
              for j in range (10) :
                  ans = []
                  t = 1
                  if (i == j) :
                      continue
                  x1 = min(i,j)
                  x2 = max(i,j)
                  temp = 1
                  y1 = 0
                  y2 = 0
  
                  #print(i,j)
                  
                  for k in range (len(x)) :
                      if (temp == 0) :
                          ans.append(str(x1))
                          y1 = 1
                          continue
                      if (x1>=int(x[k])) :
                          ans.append(str(x1))
                          y1 = 1
                          if (x1 > int(x[k])) :
                              temp = 0
                      elif (x2 >= int(x[k])) :
                          ans.append(str(x2))
                          y2 = 1
                          
                          if (x2 > int(x[k])) :
                   #           print('a')
                              temp = 0
                      else :
                          k2 = -1
                          for k1 in range (k-1,-1,-1) :
                              if (ans[k1] == str(x1)) :
                                  ans[k1] = str(x2)
                                  k2 = k1
                                  break
                          if (k2 == -1) :
                              t = 0
                              break
  
                          for k1 in range (k2+1,k) :
                              ans[k1] = str(x1)
                          ans.append(str(x1))
                          temp = 0
  
                    
                  if (t and y1 and y2) :
                      ans1.append(int("".join(ans)))
  
          for i in range (1,10) :
              y = str(i)*(len(x))
              if (int(y) >= n) :
                  ans1.append(int(y))
  
          if (len(ans1)) :
              prinT(min(ans1))
          else :
              print('1' + '0'*(len(x)))
                  
                  
  
  
      
  