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())
  for _ in range(t):
      n,k=map(int,input().split())
      l=[]
      while n>0:
          l.insert(0,n%10)
          n=n//10
      digit=set()
      ans=[]
      idx=0
      while len(digit)<k-1:
          digit.add(l[idx])
          ans.append(l[idx])
          idx+=1
      while idx<len(l) and l[idx] in digit:
          ans.append(l[idx])
          idx+=1
      
      if len(ans)<len(l):
          tmp=idx
          digit.add(l[idx])
          Ma=max(digit)
          fix=idx
          while tmp<len(l) and l[tmp] in digit:
              if l[tmp]<Ma:
                  fix=tmp
              tmp+=1
          if tmp<len(l) and max(digit)>l[tmp]:
              for i in range(idx,tmp):
                  ans.append(l[i])
              M=Ma
              for item in digit:
                  if item>l[tmp]:
                      M=min(M,item)
              ans.append(M)
              m=min(digit)
              for _ in range(tmp+1,len(l)):
                  ans.append(m)
          elif tmp<len(l) and max(digit)<l[tmp]:
              if fix != idx:
                  M=Ma
                  for item in digit:
                      if item>l[fix]:
                          M=min(M,item)
                  for i in range(idx,fix):
                      ans.append(l[i])
                  ans.append(M)
                  m=min(digit)
                  for i in range(fix+1,len(l)):
                      ans.append(m)
              elif fix == idx:
                  digit.remove(l[idx])
                  ans.append(l[idx]+1)
                  if l[idx]+1 in digit:
                      for i in range(idx+1,len(l)):
                          ans.append(0)
                  else:
                      digit.add(l[idx]+1)
                      m=min(digit)
                      for i in range(idx+1,len(l)):
                          ans.append(m)
          else:
              for i in range(idx,tmp):
                  ans.append(l[i])
  
      tot=ans[0]
      for i in range(1,len(ans)):
          tot*=10
          tot+=ans[i]
      print(tot)
  