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
  from bisect import *
  
  zz=1
   
  sys.setrecursionlimit(10**5)
  if zz:
  	input=sys.stdin.readline
  else:	
  	sys.stdin=open('input.txt', 'r')
  	sys.stdout=open('all.txt','w')
  di=[[-1,0],[1,0],[0,1],[0,-1]]
  
  def fori(n):
  	return [fi() for i in range(n)]	
  def inc(d,c,x=1):
  	d[c]=d[c]+x if c in d else x
  def ii():
  	return input().rstrip()	
  def li():
  	return [int(xx) for xx in input().split()]
  def fli():
  	return [float(x) for x in input().split()]	
  def dadd(d,p,val):
  	if p in d:
  		d[p].append(val)
  	else:
  		d[p]=[val]		
  def gi():	
  	return [xx for xx in input().split()]
  def gtc(tc,*ans):
  	print("Case #"+str(tc)+":",*ans)	
  def cil(n,m):
  	return n//m+int(n%m>0)	
  def fi():
  	return int(input())
  def pro(a): 
  	return reduce(lambda a,b:a*b,a)		
  def swap(a,i,j): 
  	a[i],a[j]=a[j],a[i]	
  def bits(i,n):
  	p=bin(i)[2:]
  	return (n-len(p))*"0"+p	
  def prec(a,pre):
  	for i in a:
  		pre.append(pre[-1]+i)
  	pre.pop(0)	
  def YN(flag):
  	print("YES" if flag else "NO")	
  def si():
  	return list(input().rstrip())	
  def mi():
  	return 	map(int,input().split())			
  def gh():
  	sys.stdout.flush()
  def isvalid(i,j,n,m):
  	return 0<=i<n and 0<=j<m 
  def bo(i):
  	return ord(i)-ord('a')	
  def graph(n,m):
  	for i in range(m):
  		x,y=mi()
  		a[x].append(y)
  		a[y].append(x)
  
  
  
  t=fi()
  INF=10**18
  uu=t
  mod=10**9+7
  
  a=set()
  b=set()
  for i in range(1,10):
  	for j in range(1,11):
  		b.add(int(str(i)*j))
  def rec(i,j,k,l,p=""):
  	if k+l==0:
  		a.add(p)
  		return
  	if k:
  		rec(i,j,k-1,l,p+i)
  	if l:
  		rec(i,j,k,l-1,p+j)					
  for i in range(10):
  	for j in range(i+1,10):
  		for k in range(2,11):
  			for l in range(1,k):
  				rec(str(i),str(j),l,k-l)
  a=list(a)	
  b=list(b)
  b.sort()			
  for i in range(len(a)):
  	a[i]=int(a[i])
  a.sort()	
  while t>0:
  	t-=1
  	n,k=mi()
  	if k==2:
  		p=bisect_left(a,n)
  		print(a[p])	
  	else:	
  		p=bisect_left(b,n)
  		print(b[p])	
  