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.*;
  public class A739F1treeset {
      public static void main(String[] args) {
          JS scan = new JS();
          PrintWriter out = new PrintWriter(System.out);
          int t = scan.nextInt();
          TreeSet<Long> setk2 = new TreeSet<>();
          for(int i = 0;i<10;i++){
              for(int j = 0;j<10;j++){
                  int min = Math.min(i,j);
                  int max = Math.max(i,j);
                  if(max==0)continue;
                  for(int length = 1;length<11;length++) {
                      for (int k = 0; k < 1 << length; k++) {
                          StringBuilder s = new StringBuilder(Integer.toBinaryString(k));
                          while (s.length() != length) {
                              s.insert(0, "0");
                          }
                          StringBuilder sb = new StringBuilder();
                          for (int l = 0; l < s.length(); l++) {
                              if (s.charAt(l) == '1' || (min == 0 && l == 0)) {
                                  sb.append(max);
                              } else {
                                  sb.append(min);
                              }
                          }
                          long val = Long.parseLong(sb.toString());
  //                        if (min == 3 && max == 8) {
  //                            System.out.println(s + " " + val);
  //                        }
                          setk2.add(val);
                      }
                  }
              }
          }
          TreeSet<Long> setk1 = new TreeSet<>();
          for(int i = 1;i<=9;i++) {
              for(int j = 1;j<=11;j++){
                  StringBuilder sb = new StringBuilder();
                  for(int k = 0;k<j;k++){
                      sb.append(i);
                  }
                  long val = Long.parseLong(sb.toString());
                  setk1.add(val);
              }
          }
  //        for(Long curr:setk1){
  //            System.out.println(curr);
  //        }
          while(t-->0) {
              int n = scan.nextInt();
              int k = scan.nextInt();
              int length = (int) Math.log10(n)+1;
              long best = Long.MAX_VALUE;
              if(k==2){
                  best = setk2.higher((long) (n-1));
              }
              best = Math.min(best,setk1.higher((long)(n-1)));
              out.println(best);
          }
          out.flush();
          out.close();
      }
      static class JS {
          public int BS = 1 << 16;
          public char NC = (char) 0;
          byte[] buf = new byte[BS];
          int bId = 0, size = 0;
          char c = NC;
          double num = 1;
          BufferedInputStream in;
  
          public JS() {
              in = new BufferedInputStream(System.in, BS);
          }
  
          public JS(String s) throws FileNotFoundException {
              in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
          }
  
          public char nextChar() {
              while (bId == size) {
                  try {
                      size = in.read(buf);
                  } catch (Exception e) {
                      return NC;
                  }
                  if (size == -1) return NC;
                  bId = 0;
              }
              return (char) buf[bId++];
          }
  
          public int nextInt() {
              return (int) nextLong();
          }
  
          public long nextLong() {
              num = 1;
              boolean neg = false;
              if (c == NC) c = nextChar();
              for (; (c < '0' || c > '9'); c = nextChar()) {
                  if (c == '-') neg = true;
              }
              long res = 0;
              for (; c >= '0' && c <= '9'; c = nextChar()) {
                  res = (res << 3) + (res << 1) + c - '0';
                  num *= 10;
              }
              return neg ? -res : res;
          }
  
          public double nextDouble() {
              double cur = nextLong();
              return c != '.' ? cur : cur + nextLong() / num;
          }
  
          public String next() {
              StringBuilder res = new StringBuilder();
              while (c <= 32) c = nextChar();
              while (c > 32) {
                  res.append(c);
                  c = nextChar();
              }
              return res.toString();
          }
  
          public String nextLine() {
              StringBuilder res = new StringBuilder();
              while (c <= 32) c = nextChar();
              while (c != '\n') {
                  res.append(c);
                  c = nextChar();
              }
              return res.toString();
          }
  
          public boolean hasNext() {
              if (c > 32) return true;
              while (true) {
                  c = nextChar();
                  if (c == NC) return false;
                  else if (c > 32) return true;
              }
          }
      }
  }
  