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: //Author: net12k44
  import java.io.*;
  import java.util.*;
  //public
  class Main{//}
  
  private int get(char[] s, int[] d, int numDiff, int maxDiff, int min, int pre, int z) {
  	//out.println("----");
  	//out.println(z + " " + numDiff + " " + maxDiff);
  	for(int i = pre+1; i < s.length; ++i) {
  		if (i == pre+1) {
  			int k = s[i] - '0' + 1;
  			for(; k < 10; k++) {
  				if (numDiff < maxDiff) break;
  				if (numDiff == maxDiff && d[k] > 0) break;								
  			}
  			if (k >= 10) {
  				return -1;
  			}
  			if (d[k] == 0) numDiff++;
  
  			z = z*10 + k;
  			if (min > k) min = k;
  		} else {
  			//out.println(z + " " + numDiff + " " + maxDiff);
  			int k = min;
  			if (numDiff < maxDiff) k = 0;
  			z = z * 10 + k;			
  		}
  	}
  	
  	return z;
  	
  }
  
  private int solveSingleTest() {
  	String tt = in.next();
  	char[] s = tt.toCharArray();
  	int n = Integer.parseInt(tt);
  	int k = in.nextInt();
  	
  	int[] d = new int[10];
  	int numDiff = 0;
  	int min = 10;
  	for(int i = 0; i < s.length; ++i) {
  		int digit = s[i] - '0';
  		if (d[digit] == 0) {
  			numDiff++;
  		}
  		d[digit]++;		
  		if (min > digit) min = digit;
  	}
  	
  	int z = n;
  	for(int pre = s.length-1; pre >= -1; pre--) {				
  		if (numDiff <= k) {
  			int res = get(s, d, numDiff, k, min, pre, z);
  			if (res >= 0) return res;
  		}
  		
  		if (pre < 0) continue;
  		
  		int digit = s[pre]-'0';		
  		d[digit]--;
  		if (d[digit] == 0) {			
  			numDiff--;
  			while(min<10 && d[min] == 0) min++;
  		}
  		z = z/10;
  	}
  	
  	int res = 1;
  	for(int i = 0; i < s.length; ++i) {
  		res = res * 10;
  		if (k == 1) res++; 
  	}
  	return res;
  }
  
  private void solve() {
      int test = in.nextInt();
  	while (test-- > 0) out.println(solveSingleTest());
  }
      
  public static void main (String[] args) throws java.lang.Exception {        
      long startTime = System.currentTimeMillis();
  
      out = new PrintWriter(System.out);
      new Main().solve();    
      //out.println((String.format("%.2f",(double)(System.currentTimeMillis()-startTime)/1000)));
      out.close();
  }
  static PrintWriter out;
  static void println(int[] a){
      for(int i = 0; i < a.length; ++i){
          if (i != 0) out.print(' ');
          out.print(a[i]);
      }
      out.println();
  }
  static class in {
      static BufferedReader reader = new BufferedReader( new InputStreamReader(System.in) ) ;
      static StringTokenizer tokenizer = new StringTokenizer("");                
      static String next() {        
          while ( !tokenizer.hasMoreTokens() )
              try { tokenizer = new StringTokenizer( reader.readLine() ); }
              catch (IOException e){
                  throw new RuntimeException(e);            
              }        
          return tokenizer.nextToken();
      }
      static int nextInt() { return Integer.parseInt( next() ); }            
  }
  //////////////////////////////////////////////////
  }//