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.*;
  import java.io.*;
  import java.math.*;
  
  
   
  public class Main {
       public static String number(char t,int g){
            String s="";
            for(int p=0;p<g;p++)
            s=s+t;
            return s;
            
       } 
       public static String one(String a){
            char i;
            int k= a.length();
            
            for(i='1';i<='9';i++)
            if((number(i,k).compareTo(a))>=0)
            break;
            
            return(number(i,k));
            
       }
       public static String two(String a){
            String res= one(a);
            
            for(char q='0';q<='9';q++){
                 for (char b=(char)((int)q+1);b<='9';b++){
                      boolean n_ok = true;
                      for(int i=0;i<a.length();i++){
                           if (a.charAt(i)<b){
                                String t=a;
                                char arr[]=t.toCharArray();
                                if(a.charAt(i)<q)
                                arr[i]=q;
                                else 
                                arr[i]=b;
                                for (int j = i + 1; j < a.length(); j++)
  						arr[j] = q;
  						
                                String ok = new String(arr);
                                if(res.compareTo(ok)>0)
                                res=ok;
                           }
                           if(a.charAt(i) != q && a.charAt(i) != b)
  				{
  					n_ok = false;
  					break;
  				}
                      }
                 if (n_ok) return a;
                      
                 }
            }
            return res;
            
       }
      	public static void main(String[] args)throws IOException, InterruptedException{
      	      Scanner sc = new Scanner(System.in);
   	        int t= sc.nextInt();
   	         
   	        for(int h=0;h<t;h++)
   	         {String p;
   	              String s= sc.next();
   	              int k=sc.nextInt();
   	              if(k==1)
   	               p=one(s);
   	               else 
   	               p=two(s);
   	               System.out.println(p);
   	              
   	              
   	              
      	}
      	}
   	                   
   	                   
   	                   
   	                   
   	        
   	              
   	         
   	             
  	static class Scanner {
  		StringTokenizer st;
  		BufferedReader br;
   
  		public Scanner(InputStream s) {
  			br = new BufferedReader(new InputStreamReader(s));
  		}
   
  		public Scanner(FileReader r) {
  			br = new BufferedReader(r);
  		}
   
  		public String next() throws IOException {
  			while (st == null || !st.hasMoreTokens())
  				st = new StringTokenizer(br.readLine());
  			return st.nextToken();
  		}
   
  		public int nextInt() throws IOException {
  			return Integer.parseInt(next());
  		}
   
  		public long nextLong() throws IOException {
  			return Long.parseLong(next());
  		}
   
  		public String nextLine() throws IOException {
  			return br.readLine();
  		}
   
  		public double nextDouble() throws IOException {
  			return Double.parseDouble(next());
  		}
   
  		public boolean ready() throws IOException {
  			return br.ready();
  		}
   
  	}
   
  }