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:    RonWonWon
  *   	CREATED:   18.08.2021 22:58:58        
  /*==========================================================================*/
  import java.io.*;
  import java.util.*;
  
  public class F1 {
  	
  	public static void main(String[] args) throws IOException {
  		/*
      in.ini();
      PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
      */
      long startTime = System.nanoTime();
      int t = in.nextInt(), T = 1;  
      List<Long> list = new ArrayList<>();
      List<Long> list2 = new ArrayList<>();
      for(int i=0;i<=9;i++){
  			for(int j=0;j<=9;j++){
  				for(int ii=0;ii<(1<<10);ii++){
  					for(int len=1;len<=10;len++){
  						long cur = 0;
    					for(int jj=0;jj<len;jj++){
    						if((ii&(1<<jj))!=0) cur = cur*10 + i;
    						else cur = cur*10 + j;
    					}
    					if(i==j) list2.add(cur);
    					list.add(cur);
  					}
  				}
  			}
      }
      Collections.sort(list2);
      Collections.sort(list);
      while(t-->0) { 
        int n = in.nextInt(), k = in.nextInt();
        if(k==1) out.println(bs(list2,n));
        else out.println(bs(list,n));
     		//out.println("Case #"+T+": "+ans); T++;
      }
      /*
      startTime = System.nanoTime() - startTime;
      System.err.println("Time: "+(startTime/1000000));
      */
      out.flush();
  	}
  	
  	static long bs(List<Long> list, int n){
  		int low = 0, high = list.size()-1, mid;
  		while(low<=high){
  			mid = (low+high)>>1;
  			if(list.get(mid)==n) return list.get(mid);
  			if(list.get(mid)>n) high = mid-1;
  			else low = mid+1;
  		}
  		return list.get(low);
  	}
  	
  	static FastScanner in = new FastScanner();
    static PrintWriter out = new PrintWriter(System.out);
  	static int oo = Integer.MAX_VALUE;
  	static long ooo = Long.MAX_VALUE;
  	
  	static String print(int a[]){
  		String str = Arrays.toString(a).replaceAll(",","");
      return str.substring(1,str.length()-1);
  	}
  	
  	static String print(long a[]){
  		String str = Arrays.toString(a).replaceAll(",","");
      return str.substring(1,str.length()-1);
  	}
  	
  	static String print(ArrayList<Integer> a){
  		String str = Arrays.toString(a.toArray()).replaceAll(",","");
      return str.substring(1,str.length()-1);
  	}
  	
  	static String printL(ArrayList<Long> a){
  		String str = Arrays.toString(a.toArray()).replaceAll(",","");
      return str.substring(1,str.length()-1);
  	}
  	
  	static class FastScanner {
  		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st = new StringTokenizer("");
  		
  		void ini() throws FileNotFoundException {
  			br = new BufferedReader(new FileReader("input.txt"));
  		}
  		
  		String next() {
  			while(!st.hasMoreTokens())
  				try { st = new StringTokenizer(br.readLine()); }
  				catch(IOException e) {}
  			return st.nextToken();
  		}
  		
  		String nextLine(){
  			try{ return br.readLine(); } 
  			catch(IOException e) { } return "";
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		
  		int[] readArray(int n) {
  			int a[] = new int[n];
  			for(int i=0;i<n;i++) a[i] = nextInt();
  			return a;
  		}
  		
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  		
  		long[] readArrayL(int n) {
  			long a[] = new long[n];
  			for(int i=0;i<n;i++) a[i] = nextLong();
  			return a;
  		}
  		
  		double nextDouble() {
  			return Double.parseDouble(next());
  		}
  		
  		double[] readArrayD(int n) {
  			double a[] = new double[n];
  			for(int i=0;i<n;i++) a[i] = nextDouble();
  			return a;
  		}
  	}
  
  	static final Random random = new Random();
  
  	static void ruffleSort(int[] a){
  		int n = a.length;
  		for(int i=0;i<n;i++){
  			int j = random.nextInt(n), temp = a[j];
  			a[j] = a[i]; a[i] = temp;
  		}
  		Arrays.sort(a); 	
  	}
  	
  	static void ruffleSortL(long[] a){
  		int n = a.length;
  		for(int i=0;i<n;i++){
  			int j = random.nextInt(n);
  			long temp = a[j];
  			a[j] = a[i]; a[i] = temp;
  		}
  		Arrays.sort(a); 	
  	}
  }
  