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.util.*;
  import java.io.*;
  public class Sol{
   
  /*   
  ->check n=1, int overflow , array bounds , all possibilites(dont stuck on 1 approach)
  ->Problem = Observation(constraints(m<=n/3 or k<=min(100,n)) 
             + Thinking + Technique (seg_tree,binary lift,rmq,bipart,dp,connected comp etc)
  ->solve or leave it (- tutorial improves you in minimal way -)
  */
   
  public static void main (String []args) {
  //precomp();
  
  int times=ni();while(times-->0){solve();}out.close();}
  
  static long delta;
  static long ans;
  
  static void solve() {
   int n=ni();int k=ni();
  
   delta=(long)Math.pow(10,10);
   ans=0l;int cn=n;
   while(cn>=10)cn/=10;
   int fd=cn;int size=length(n);
  
   if(k==1){//out.println("yes");
      for(int i=0;i<10;i++){
          int cans=i;int cs=1;
          while(cs<size){cans=10*cans+i;cs++;}
          //out.println(cans+" "+n);
          if(cans>=n){out.println(cans);break;}
      }
   }
  
   else{
     for(int i=0;i<10;i++){
     dfs(fd,fd,i,1,size,n);
     }
     out.println(ans);
   }
  return;}
  
  static void dfs(int cans,int fd,int i,int csize,int size,int n){
      if(csize==size){
         int cdel=cans-n;
         if(cdel>=0 && cdel<=delta){ans=cans;delta=cdel;}
      }
      else{
         dfs(10*cans+fd,fd,i,csize+1,size,n);
         dfs(10*cans+i,fd,i,csize+1,size,n);
      }
   }
  
  static int length(int n){
     int c=0;
     while(n>0){n/=10;c++;}return c;
   }
  //-----------------Utility--------------------------------------------
  
  static long gcd(long a,long b){if(b==0)return a; return gcd(b,a%b);}
   
  static int Max=Integer.MAX_VALUE; static long mod=1000000007;
   
  static int v(char c){return (int)(c-'a');}
   
  public static long power(long x, long y )
      {
          //0^0 = 1
          long res = 1L;
          x = x%mod;
          while(y > 0)
          {
              if((y&1)==1)
                  res = (res*x)%mod;
              y >>= 1;
              x = (x*x)%mod;
          }
          return res;
      }
   
  /*static class Pair implements Comparable<Pair>{
          int id;int value;Pair next;
          public Pair(int id,int value) {
           
            this.id=id;this.value=value;next=null;
          }
          @Override
          public int compareTo(Pair p){return Long.compare(value,p.value);}
      }
  */
  
  //----------------------I/O---------------------------------------------
  
  static InputStream inputStream = System.in;
  static OutputStream outputStream = System.out;
  static FastReader in=new FastReader(inputStream);
  static PrintWriter out=new PrintWriter(outputStream);
   
  static class FastReader 
  { 
    BufferedReader br; 
    StringTokenizer st; 
   
          FastReader(InputStream is) {
              br = new BufferedReader(new InputStreamReader(is));
          }
   
    public String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
   
    public int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
   
    public long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
   
   public  double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
   
   
    String nextLine() 
    { 
        String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
  }
  static int ni() {
          try {
              boolean in = false;
              int res = 0;
              for (;;) {
                  int b = System.in.read() - '0';
                  if (b >= 0) {
                      in = true;
                      res = 10 * res + b;
                  }
                  else if (in)
                      return res;
              }
          } catch (IOException e) {
              throw new Error(e);
          }
      }
  static long nl(){return in.nextLong();}
  static double nd(){return in.nextDouble();}
  static String ns(){return in.nextLine();}
  }