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.lang.*;
  
  
  
  
  public class cc {
  	
  	private class Pair{
  		ArrayList<String> a = new ArrayList<>();
  		
  	}
  	
  	static class FastReader {
          BufferedReader br;
          StringTokenizer st;
   
          public FastReader()
          {
              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;
          }
      }
  	
  	private static FastReader sc =new FastReader();
  	
  	public static void main(String[] args) {
  		int t = sc.nextInt();
  		while(t-->0) {
  			solve();
  		}
  
  	}
  
  	private static void solve() {
  		int n = sc.nextInt();
  		int k = sc.nextInt();
  		if(n/10==0) {
  			System.out.println(n);
  			return;
  		}
  		if(k==1) {
  			String s = String.valueOf(n);
  			char c = s.charAt(0);
  			for(int i=1; i<s.length(); i++) {
  				if(s.charAt(i)<c) {
  					break;
  				}
  				if(s.charAt(i)>c) {
  					c++;
  					break;
  				}
  			}
  			int m = 0;
  			for(int i=0; i<s.length(); i++) {
  				m*=10;
  				m+=(c-'0');
  			}
  			System.out.println(m);
  		}else {
  			if(n/100==0) {
  				System.out.println(n);
  				return;
  			}
  			String s = String.valueOf(n);
  			char ch[] = s.toCharArray();
  			ch[0] = s.charAt(0);
  			int i=0;
  			for(i=1; i<s.length(); i++) {
  				if(s.charAt(i)!=s.charAt(0)) {
  					ch[i] = s.charAt(i);
  					break;
  				}else {
  					ch[i] = s.charAt(i);
  				}
  			}
  			int sec = i;
  			i++;
  			char c2 = ch[0];
  			if(i<=s.length())
  				c2 = s.charAt(i-1);
  			for(; i<s.length(); i++) {
  				if(s.charAt(i)<Math.min(ch[0], c2)) {
  					while(i!=s.length()) {
  						ch[i] = (char)Math.min(ch[0], c2);
  						i++;
  					}
  					System.out.println(new String(ch));
  					return;
  				}else if(s.charAt(i)==Math.min(ch[0], c2)) {
  					ch[i] = (char)Math.min(ch[0], c2);
  				}else if(s.charAt(i)>Math.min(ch[0], c2) && s.charAt(i)<Math.max(ch[0], c2)){
  					ch[i] = (char)Math.max(ch[0], c2);
  					i++;
  					while(i!=s.length()) {
  						ch[i] = (char)Math.min(ch[0], c2);
  						i++;
  					}
  					System.out.println(new String(ch));
  					return;
  				}else if(s.charAt(i)==Math.max(ch[0], c2)){
  					ch[i] = (char)Math.max(ch[0], c2);
  				}else {
  					i--;
  					while(i!=sec) {
  						if(ch[i]!=(char)Math.max(ch[0], c2)) {
  							ch[i] = (char)Math.max(ch[0], c2);
  							i++;
  							while(i!=s.length()) {
  								ch[i] = (char)Math.min(ch[0], c2);
  								i++;
  							}
  							System.out.println(new String(ch));
  							return;
  						}
  						i--;
  					}
  					if(c2 == '9')	i--;
  					ch[i]++;
  					c2 = ch[i];
  					if(ch[0]==c2) {
  						c2 = '0';
  					}
  					i++;
  					while(i!=s.length()) {
  						ch[i] = (char)Math.min(ch[0], c2);
  						i++;
  					}
  					System.out.println(new String(ch));
  					return;
  				}
  			}
  			System.out.println(new String(ch));
  		}
  	}
  }
  