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.*;
  import java.math.*;
  
  public class Coder {
    // static int find(int parent[], int i){
    //   if(parent[i]!=i)
    //     parent[i]=find(parent, parent[i]);
    //   return parent[i];
    // }
    // static void union(int parent[], int rank[], int x, int y){
    //   int xr=find(parent, x);
    //   int yr=find(parent, y);
    //   if(rank[xr]<rank[yr]){
    //     parent[xr]=yr;
    //   }else if(rank[yr]<rank[xr]){
    //     parent[yr]=xr;
    //   }else{
    //     parent[xr]=yr;
    //     rank[yr]++;
    //   }
    // }
  
    // static long pow(long a, long b){
    //   long res=1;
    //   while(b>0){
    //     if(b%2==1){
    //       res = (res * a)%m;
    //       b--;
    //     }else{
    //       a = (a*a)%m;
    //       b=b>>1;
    //     }
    //   }
    //   return res;
    // }
    // static void extendedGcd(long a, long b, long ar[]){
    //   if(b==0){
    //     ar[0]=1;
    //     ar[1]=0;
    //     ar[2]=a;
    //     return;
    //   }
    //   extendedGcd(b, a%b, ar);
    //   long temp=ar[1];
    //   ar[1]=(ar[0]- ar[1]*(a/b));
    //   ar[0]=temp;
    //   return;
    // }
    // // non prime b;
    // static long invmod(long a, long b){
    //   long ar[]=new long[3];
    //   extendedGcd(a, b, ar);
    //   return ar[0];
    // }
    // static long combination(int a, int b){
    //   long val1=fact[a];
    //   long val2=ifact[a-b];
    //   long val3=ifact[b];
    //   return (((val1 * val2)%m) * val3)%m;
    // }
    static char c[];
    static int k;
    static String st;
    static StringBuffer str=new StringBuffer();
  
    static String solve1(){
      int n=st.length();
      for(int i=0;i<=9;i++){
          StringBuffer s=new StringBuffer("");
          for(int j=0;j<n;j++){
              s.append(i);
          }
          String t=s.toString();
          if(t.compareTo(st)>=0) return t;
      }
      return "";
    }
    static String solve2(){
      String res=solve1(); 
      int n=st.length();
      // a=0 b=1
      for(int i=0;i<=9;i++){
          for(int j=i+1;j<=9;j++){
              boolean flag=true;
              char a=(char)(i+48), b=(char)(j+48);
              for(int k=0;k<n;k++){
                  if(st.charAt(k)<b){
                      StringBuffer t=new StringBuffer(st);
                      if(t.charAt(k)<a) t.setCharAt(k, a);
                      else t.setCharAt(k, b);
                      for(int p=k+1;p<n;p++) t.setCharAt(p, a);
                      String temp=t.toString();
                      if(res.compareTo(temp)>0) res=new String(temp);
                  }
                  if(st.charAt(k)!=a && st.charAt(k)!=b){
                      flag=false;
                      break;
                  }
              }
              if(flag) return st;
          }
      }
      return res;
    }
    static void solve(){
      if(k==1){
          str.append(solve1()).append("\n");
          return;
      }
      str.append(solve2()).append("\n");
    }
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader bf;
        PrintWriter pw;
        boolean lenv=false;
        if(lenv){
          bf = new BufferedReader(
                              new FileReader("input.txt"));
          pw=new PrintWriter(new
                BufferedWriter(new FileWriter("output.txt")));
        }else{
          bf = new BufferedReader(new InputStreamReader(System.in));
          pw = new PrintWriter(new OutputStreamWriter(System.out));
        }
    
      int q = Integer.parseInt(bf.readLine().trim());
      while (q-- > 0) {
        String s[]=bf.readLine().trim().split("\\s+");
        st=s[0];
        k=Integer.parseInt(s[1]);
        solve();
      }
      pw.print(str);
      pw.flush();
      // System.out.print(str);
    }
  }