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.math.*;
  import java.util.*;
  
  public class F {
  
      static final int MAX_N = 1000010;
      static final int INF = 0x3f3f3f3f;
  
      public static void main(String[] args) throws IOException {
  
          initReader(System.in);
  
          makeTB();
  
  
          int T = nextInt();
          for (int i = 1; i <= T; i++)
          solve();
  
  
          pw.flush();
      }
  
      /*******************************************************************************************************************************/
  
      static TreeSet<Long> set1 = new TreeSet<>();
      static TreeSet<Long> set2 = new TreeSet<>();
  
      public static void solve() throws IOException {
          long n = nextLong();
          int k = nextInt();
  
          if (k == 1) {
              pw.println(set1.ceiling(n));
          } else {
              pw.println(set2.ceiling(n));
          }
  
  
      }
  
      public static void makeTB() {
          for (int i = 0; i < 10; i++) {
              StringBuilder s = new StringBuilder();
              for (int j = 0; j < 10; j++) {
                  s.append((char) ('0' + i));
                  set1.add(getNum(s));
                  set2.add(getNum(s));
  
                  for (int k = 0; k < 10; k++) dp(s, (char) ('0' + k), 0);
              }
          }
      }
  
      public static void dp(StringBuilder s, char k, int step) {
          if (step == s.length()) return ;
  
          StringBuilder s1 = new StringBuilder(s);
          s1.replace(step, step + 1, String.valueOf(k));
          set2.add(getNum(s1));
          dp(s1, k, step + 1);
  
          StringBuilder s2 = new StringBuilder(s);
          dp(s2, k, step + 1);
      }
  
      public static long getNum(StringBuilder s) {
          return Long.parseLong(String.valueOf(s));
      }
  
  
      /*******************************************************************************************************************************/
  
  
  
      /*******************************************************************************************************************************/
  
      static BufferedReader reader;
      static StringTokenizer tokenizer;
      static PrintWriter pw;
  
      public static void initReader(InputStream input) throws IOException {
          reader = new BufferedReader(new InputStreamReader(input));
          tokenizer = new StringTokenizer("");
          pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  
  //        reader = new BufferedReader(new FileReader("test.in"));
  //        tokenizer = new StringTokenizer("");
  //        pw = new PrintWriter(new BufferedWriter(new FileWriter("test1.out")));
      }
  
      public static boolean hasNext() {
          try {
              while (!tokenizer.hasMoreTokens()) {
                  tokenizer = new StringTokenizer(reader.readLine());
              }
          } catch (Exception e) {
              return false;
          }
          return true;
      }
  
      public static String next() throws IOException {
          while (!tokenizer.hasMoreTokens()) {
              tokenizer = new StringTokenizer(reader.readLine());
          }
          return tokenizer.nextToken();
      }
  
      public static String nextLine() {
          try {
              return reader.readLine();
          } catch (Exception e) {
              return null;
          }
      }
  
      public static int nextInt() throws IOException {
          return Integer.parseInt(next());
      }
  
      public static long nextLong() throws IOException {
          return Long.parseLong(next());
      }
  
      public static double nextDouble() throws IOException {
          return Double.parseDouble(next());
      }
  
      public static char nextChar() throws IOException {
          return next().charAt(0);
      }
  
      public static short nextShort() throws IOException {
          return Short.parseShort(next());
      }
  
  }
  