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.util.*;
  import static java.lang.System.in;
  import static java.lang.System.out;
  
  public class F1 {    
      
      static TreeSet<Long> tree;
      
      static void generate(int idx, String number, int a[], int n) {
          if(idx==n) {
              tree.add(Long.valueOf(number));
              return;
          }
          for(int i : a) {
              generate(idx+1, number+i, a, n);
          }
      }
  
      public static void main(String args[]) throws Exception {   
          Foster sc = new Foster();
          PrintWriter p = new PrintWriter(out);
          tree = new TreeSet<>();
          for(int i = 0; i < 10; i++) {
              for(int j = i+1; j < 10; j++) {
                  int a[] = new int[2];
                  a[0] = i;
                  a[1] = j;
                  for(int n = 1; n <= 10; n++) {
                      generate(0, "", a, n);
                  }
              }
          }
          TreeSet<Long> one = new TreeSet<>();
          TreeSet<Long> two = new TreeSet<>();
          for(long i : tree) {
              long num = i;
              TreeSet<Long> set = new TreeSet<>();
              while(num > 0) {
                  long r = num % 10;
                  num /= 10;
                  set.add(r);
              }
              if(set.size()==1) one.add(i);
              else    two.add(i);
          }
          int t = sc.nextInt();
          while(t--!=0){
              long n = sc.nextLong();
              int k = sc.nextInt();
              if(k==1) {
                  p.println(one.ceiling(n));
              } else {
                  p.println(tree.ceiling(n));
              }
          }
          p.close();
      }
      
      static long[] sort(long a[]){
          ArrayList<Long> arr = new ArrayList<>();
          for(long i : a){
              arr.add(i);
          }
          Collections.sort(arr);
          for(int i = 0; i < arr.size(); i++){
              a[i] = arr.get(i);
          }
          return a;
      }
  
      static int[] sort(int a[]){
          ArrayList<Integer> arr = new ArrayList<>();
          for(int i : a){
              arr.add(i);
          }
          Collections.sort(arr);
          // Collections.reverse(arr);
          for(int i = 0; i < arr.size(); i++){
              a[i] = arr.get(i);
          }
          return a;
      }
      
  /*
   * Is that extra condition needed
   * Check overflow in pow function or in general
   * Check indices of read array functions
   * Think of an easier solution because the problems you solve are always easy
   * Check the iterator of loop
   */      
  
      static class Foster {
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          StringTokenizer st = new StringTokenizer("");
          String next() {
              while (!st.hasMoreTokens())
                  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());
          }
          int[] intArray(int n) {
              int arr[] = new int[n];
              for(int i = 0; i < n; i++) {
                  arr[i] = nextInt();
              }
              return arr;
          }
          long[] longArray(int n) {
              long arr[] = new long[n];
              for(int i = 0; i < n; i++) {
                  arr[i] = nextLong();
              }
              return arr;
          }
          static long pow(long... a) {
              long mod = Long.MAX_VALUE;
              if(a.length == 3)   mod = a[2];
              long res = 1;
              while(a[1] > 0) {
                  if((a[1] & 1) == 1)
                      res = (res * a[0]) % mod;
                  a[1] /= 2;
                  a[0] = (a[0] * a[0]) % mod;
              }
              return res;
          }
      }
  }