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.io.*;
  import java.lang.*;
  import java.util.*;
  
  public class F1_1560 {
      static long works = Long.MAX_VALUE;
      static ArrayList<Long> arrl = new ArrayList<>();
      public static void main(String[] args) throws IOException{
          StringBuffer ans = new StringBuffer();
          StringTokenizer st;
          BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
          st = new StringTokenizer(f.readLine());
          int t = Integer.parseInt(st.nextToken());
          for(int i = 0; i < 10; i++){
              for(int x = i; x < 10; x++){
                  if(x == 0) continue;
                  tryAll(new StringBuffer(), i, x);
              }
          }
          Collections.sort(arrl);
          for(; t > 0; t--){
              st = new StringTokenizer(f.readLine());
              long n = Integer.parseInt(st.nextToken());
              int k = Integer.parseInt(st.nextToken());
              int rl = Collections.binarySearch(arrl, n);
              if(rl < 0) rl = -rl-1;
  
              if(k == 1){
                  String works = "";
                  for(int i = 1; i < 10; i++){
                      String r = "";
                      for(int x = 0; x < Long.toString(n).length();x++){
                          r+=i;
                      }
                      if(Long.parseLong(r) >= n){
                          works = r;
                          break;
                      }
                  }
                  ans.append(works).append("\n");
                  continue;
              }
  
              ans.append(arrl.get(rl)).append("\n");
          }
  
          f.close();
  
          System.out.println(ans);
      }
      public static void tryAll(StringBuffer curr, int val1, int val2){
  
          if(curr.length() != 0 || val1 != 0) {
              StringBuffer ft = new StringBuffer();
              ft.append(curr);
              ft.append(val1);
              long r = Long.parseLong(ft.toString());
              arrl.add(r);
              if(r < Math.pow(10,9))
                  tryAll(ft, val1, val2);
          }
          StringBuffer ft = new StringBuffer();
          ft.append(curr);
          ft.append(val2);
          long r = Long.parseLong(ft.toString());
          arrl.add(r);
          if(r < Math.pow(10,9))
              tryAll(ft, val1, val2);
      }
      public static class point{
          int x;
          int y;
          public point(int x,int y){
              this.x = x;
              this.y = y;
          }
          public String toString(){
              return(x + " " + y);
          }
          public boolean equals(Object x){
              point y = ((point)(x));
              if (this.x == y.x && this.y == y.y){
                  return true;
              }
              return false;
          }
          public int hashCode(){
              return Objects.hash(x,y);
          }
      }
  }