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: # cook your dish here
  import sys
  import bisect
  from bisect import bisect_left as lb
  from bisect import bisect_right as rb
  input_=lambda: sys.stdin.readline().strip("\r\n")
  from math import log
  from math import gcd
  from math import atan2,acos
  from random import randint
  sa=lambda :input_()
  sb=lambda:int(input_())
  sc=lambda:input_().split()
  sd=lambda:list(map(int,input_().split()))
  sflo=lambda:list(map(float,input_().split()))
  se=lambda:float(input_())
  sf=lambda:list(input_())
  flsh=lambda: sys.stdout.flush()
  #sys.setrecursionlimit(10**7)
  mod=10**9+7
  mod1=998244353
  gp=[]
  cost=[]
  dp=[]
  mx=[]
  ans1=[]
  ans2=[]
  special=[]
  specnode=[]
  a=0
  kthpar=[]
  def dfs2(root,par):
      if par!=-1:
          dp[root]=dp[par]+1
      for i in range(1,20):
          if kthpar[root][i-1]!=-1:
              kthpar[root][i]=kthpar[kthpar[root][i-1]][i-1]
      for child in gp[root]:
          if child==par:continue
          kthpar[child][0]=root
          dfs(child,root)
          
  ans=0
  b=[]
  vis=[]
  tot=0
  time=[]
  time1=[]
  adj=[]
  mx=-1
  eps=0.0000001
  def dfs(a,b,p,c):
      if a==b:
          return c
      for i,j in adj[a]:
          if i==p:continue
          temp=dfs(i,b,a,c+j)
          if dfs(i,b,a):
              mx=max(i,mx)
              return 1
      return tot
  ans=0
  dig={}
  s=0
  k=0
  def recur_dp(i,tight):
      global s,ans,k,dig
      if i==len(s):
          return ans
      t=0
      for j in range(10):
          if tight and j<int(s[i]):continue
          if t>=2:continue
          if len(dig)==k and dig.get(j) is None:continue
          ans*=10
          ans+=j
          abe=0
          if dig.get(j) is None:
              abe=1
          dig[j]=1
          fl=recur_dp(i+1,tight&(j==int(s[i])))
          if fl!=-1:
              return fl
          if abe:
              del dig[j]
          ans//=10
      return -1
          
  def hnbhai(tc):
      global s,n,k,ans,dig
      n,k=sd()
      s=str(n)
      ans=0
      dig={}
      print(recur_dp(0,1))
  for _ in range(sb()):
      hnbhai(_+1)
  