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.nio.charset.StandardCharsets;
  import java.util.*;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  
  public class Solution {
      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;
          }
      }
  
      public static void main(String[] args) throws Exception {
  
          BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new
                  FileOutputStream(java.io.FileDescriptor.out), StandardCharsets.US_ASCII), 512);
          FastReader sc = new FastReader();
  
           int z = sc.nextInt();
           while(z-->0) {
           int n = sc.nextInt();
           int k = sc.nextInt();
           String a = String.valueOf(n);
           long ans = 0;
           int len = a.length();
           for(int i =9;i>=0;i--){
               long temp =0;
               for(int j=0;j<len;j++){
                   temp*=10;
                   temp+=i;
               }
               if(temp>=n)
                   ans=temp;
           }
           if(k==1){
               out.write(ans+"\n");
               continue;
           }
           out.write(solve(a,len,ans,n)+"\n");
  
           }
           out.flush();
      }
      static Long solve(String a, int len, long ans, int n){
          for(char i ='0';i<='9';i++){
              for(char j = (char) (i+1); j<='9'; j++){
                  //System.out.println("char"+" " + j);
                  boolean isPresent = true;
                  char [] arr = a.toCharArray();
                  for(int m = 0;m<len;m++){
                      if(arr[m]<j){
                          char [] t = a.toCharArray();
                          if(t[m]<i){
                              t[m]=i;
                          }
                          else
                              t[m]=j;
                          for(int o=m+1;o<len;o++)
                              t[o]=i;
                          long temp= Long.parseLong(String.valueOf(t));
                          if(ans>temp)
                              ans=temp;
                      }
                      
                      if(arr[m]!=i&&arr[m]!=j)
                      {
                          isPresent=false;
  
                          break;
                      }
  
                  }
                  if(isPresent)
                  {
                     // System.out.println(j+" char"+" " +i);
                      return (long)n;
                  }
              }
          }
          return ans;
      }
  }
  
  