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 java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.PriorityQueue;
  import java.util.StringTokenizer;
  import java.util.TreeSet;
  import java.io.*;
   
  public class NearestBeautifulNumber {
  	
  	private static class MyScanner {
  	    BufferedReader br;
  	    StringTokenizer st;
  
  	    public MyScanner() {
  	       br = new BufferedReader(new InputStreamReader(System.in));
  	    }
  
  	    String next() {
  	        while (st == null || !st.hasMoreElements()) {
  	            try {
  	                st = new StringTokenizer(br.readLine());
  	            } catch (IOException e) {
  	                e.printStackTrace();
  	            }
  	        }
  	        return st.nextToken();
  	    }
  
  	    int nextInt() {
  	        return Integer.parseInt(next());
  	    }
  
  	    long nextLong() {
  	        return Long.parseLong(next());
  	    }
  
  	    double nextDouble() {
  	        return Double.parseDouble(next());
  	    }
  
  	    String nextLine(){
  	        String str = "";
  		  try {
  		     str = br.readLine();
  		  } catch (IOException e) {
  		     e.printStackTrace();
  		  }
  		  return str;
  	    }
  
  	 }
  	
  
  	
  	public static String solution(String n, int k)
  			
  	{
  		StringBuilder sb = new StringBuilder();
  		int l = n.length();
  		
  		char ca = n.charAt(0);
  		int a = Integer.parseInt(ca+"");
  		int i = 1;
  		
  		while(i<l && n.charAt(i)==ca)
  			i++;
  		
  		if(i==l)
  			return n;
  		
  		
  		char cb = n.charAt(i);
  		int b = Integer.parseInt(cb+"");
  		
  		if(k==1)
  		{
  			if (b<a) {
  				
  				sb.append(n.substring(0,i));
  				while(i<l)
  					{ sb.append(ca); i++; }
  				return sb.toString();
  			}
  			
  			if (b>a) {
  				
  				for(int j = 0; j<l; j++)
  				   sb.append((a+1)+"");
  				
  				return sb.toString();
  
  			}
  		}
  		
  	   int z = i;
  	   i++;
  	   
  	   while(i<l && (n.charAt(i)==cb || n.charAt(i)==ca))
  			i++;
  	   
  	   if(i==l)
  			return n;
  	   
  	   char cc = n.charAt(i);
  	   int c = Integer.parseInt(cc+""); 
  	   int min = Math.min(a, b);
  	   int max = Math.max(a,b);
  	   
  	   if (c<min) {
  			
  			sb.append(n.substring(0,i));
  			while(i<l)
  				{ sb.append(min); i++;}
  			return sb.toString();
  		}
  		
  		if (c>max) {
  						
  			int j = i;
  			while(Integer.parseInt(n.charAt(j)+"")>=max)
  				j--;
  			
  			if(j<z)
  			{
  				sb.append(n.substring(0,z));
  				sb.append(max+1);
  				z++;
  				while(z<l)
  					{sb.append(min); z++;}
  				return sb.toString();
  			}
  			
  			sb.append(n.substring(0,j));
  			sb.append(max);
  			j++;
  			while(j<l)
  				{sb.append(min); j++;}
  			return sb.toString();
  		}
  		
  		else {
  			
  			sb.append(n.substring(0,i));
  			sb.append(max);
  			i++;
  			while(i<l)
  				{sb.append(min); i++;}
  			return sb.toString();
  			
  		}
  	   
  	}
  	
  	public static void gen (HashMap<Integer, TreeSet<Integer>> map, int num, int n, int a, int b, int x, int y) {
  	
  		if(n!=9)
  		 (map.get(x+y)).add(num); 
  			
  		if(n>0) {
  			
  			if(!(a==0 && n==9))
  		       gen(map,num*10+a,n-1,a,b,1,y);
  			
  			if(!(b==0 && n==9))
  			  gen(map,num*10+b,n-1,a,b,x,1);
  			
  		}
  			   
  	}
  	
  	public static void solutionn(String[] arr, int[] count) {
  		
  		HashMap<Integer, TreeSet<Integer>> map = new HashMap<>();
  		
  		for(int i = 1; i<=2; i++)
  			map.put(i, new TreeSet<>());
  		
  		for(int i = 0; i<9; i++) {
  			
  			for(int j = i+1; j<10; j++)
  				gen(map,0,9,i,j,0,0);
  		}
  	
  		int t = arr.length;
  		
  		for(int i = 0; i<t; i++ )
  		{
  			int num = Integer.parseInt(arr[i]);
  			int k = count[i];
  			
  			if(num==1000000000)
  			{
  				if(k==1)
  					out.println(1111111111);
  				
  				if(k==2)
  					out.println(num);
  			}
  			
  			else if(num==999999999)
  			  out.println(num);
  			
  			else
  			  {
  				if(k==1)
  					out.println((map.get(1)).ceiling(num)+" ");
  				
  				if(k==2)
  			       out.println(Math.min((map.get(1)).ceiling(num), (map.get(2)).ceiling(num))+" ");
  				
  			  }
  			
  		}		
  			
  	}
          
  private static PrintWriter out = new PrintWriter(System.out);
  
  public static void main (String[] args)
  {
  	MyScanner s =  new MyScanner();
       
      int t = s.nextInt();
      String[] arr = new String[t];
      int[] count = new int[t];
      
      for(int j = 0; j<t ; j++)
      {
      	arr[j] = s.next();
      	count[j] = s.nextInt();
      }
      
      solutionn(arr,count);
      
      out.flush();
      out.close();
      
  }
  }
  