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: t = int(input())
  
  
  results = []
  
  for i in range(t):
      n, k = input().split()
      k = int(k)
      if k == 1:
          digits = len(n)
          important_num = int(digits * "1")
          n = int(n)
          for j in range(1, 10):
              if important_num * j >= n:
                  results.append(important_num * j)
                  break
          else:
              results.append((digits+1) * "1")
      elif k == 2:
          digits_num = len(n)
          digits = [int(c) for c in n]
  
          num_results = []
          
          a = digits[0]
          char_a = n[0]
          for b in range(0, 10):
              char_b = str(b)
              current_num = ""
              for digit in digits:
                  if digit > a:
                      if digit > b:
                          break
                      elif digit < b:
                          current_num += char_b + char_a * (digits_num - len(current_num) - 1)
                          num_results.append(current_num)
                          break
                      else:
                          current_num += char_b
                  elif digit < a:
                      if digit > b:
                          current_num += char_a + char_b * (digits_num - len(current_num) - 1)
                          num_results.append(current_num)
                          break
                      elif digit < b:
                          if a < b:
                              current_num += char_a * (digits_num - len(current_num))
                              num_results.append(current_num)
                              break
                          else:
                              current_num += char_b * (digits_num - len(current_num))
                              num_results.append(current_num)
                              break
                      else:
                          num_results.append(current_num + char_a + char_b * (digits_num - len(current_num) - 1))
                          current_num += char_b
                  else:
                      if digit > b:
                          current_num += char_a
                      elif digit < b:
                          num_results.append(current_num + char_b + char_a * (digits_num - len(current_num) - 1))
                          current_num += char_a
                      else:
                          current_num += char_a
              else:
                  num_results.append(current_num)
  
          if n[0] == 9:
              num_results.append("1" + digits_num * "0")
          else:
              num_results.append(str(digits[0]+1) + (digits_num-1) * "0")
  
          results.append(min([int(item) for item in num_results]))
  
  
  
  for i in range(t):
      print(results[i])