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.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.*;
  
  
  public class javacp{
  
  
      static FastReader fs=new FastReader();
      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;
          }
  
          int[] inputIntArray(int n){
              int[] arr = new int[n];
              for(int i=0;i<n;i++)
                  arr[i] = fs.nextInt();
  
              return arr;
          }
      }
  
      static void sort(int[] arr){
          ArrayList<Integer> al = new ArrayList<>();
          for(int val : arr){
              al.add(val);
          }
  
          Collections.sort(al);
          for(int i=0;i<arr.length;i++){
              arr[i] = al.get(i);
          }
      }
  
      static class Pair {
          String str;
          int[] list;
  
          Pair(String str){
              this.str = str;
              list = new int[5];
          }
      }
  
      static class PairComparator implements Comparator<Pair>{
  
          int idx ;
          PairComparator(int idx){
              this.idx = idx;
          }
  
          @Override
          public int compare(Pair o1, Pair o2) {
              return (2*o2.list[idx]-o2.str.length())  - (2*o1.list[idx]-o1.str.length());
          }
      }
  
      static int[] par1 , rank1;
      static int[] par2;
      static int[] rank2;
  
      static void union1(int vt1 , int vt2){
          int parent1 = findParent1(vt1) , parent2 = findParent1(vt2);
          int r1 = rank1[parent1] , r2 =  rank1[parent2];
  
          if(r1 < r2)
              par1[parent1] = parent2;
          else par1[parent2] = parent1;
  
          if(r1 == r2) rank1[parent1]++;
      }
  
      static void union2(int vt1 , int vt2){
          int parent1 = findParent2(vt1) , parent2 = findParent2(vt2);
          int r1 = rank2[parent1] , r2 =  rank2[parent2];
  
          if(r1 < r2)
              par2[parent1] = parent2;
          else par2[parent2] = parent1;
  
          if(r1 == r2) rank2[parent1]++;
      }
  
      static int findParent1(int vt){
          if(par1[vt] == vt) return vt;
          par1[vt] = findParent1(par1[vt]);
  
          return par1[vt];
      }
  
      static int findParent2(int vt){
          if(par2[vt] == vt) return vt;
          par2[vt] = findParent2(par2[vt]);
  
          return par2[vt];
      }
  
      static void initialise(int numOfVtces){
          par1 = new int[numOfVtces];
          par2 = new int[numOfVtces];
  
          rank1 = new int[numOfVtces];
          rank2 = new int[numOfVtces];
  
          for(int i=0;i<numOfVtces;i++){
              par1[i] = par2[i] = i;
              rank1[i] = rank2[i] = 0;
          }
      }
  
  
      public static void main(String[] args) throws IOException{
  
          int t = 1;
          t = fs.nextInt();
  
          ArrayList<Long> k1 = fillK1();
          Collections.sort(k1);
          ArrayList<Long> k2 = fillK2();
          Collections.sort(k2);
  
          while (t-- > 0) {
              int n = fs.nextInt() , k = fs.nextInt();
              if(k == 1){
                  int key = Collections.binarySearch(k1,(long)n);
                  if(key < 0){
                      key = Math.abs(key)-1;
                      System.out.println(k1.get(key));
                  }
                  else System.out.println(n);
  
              }else {
                  int key = Collections.binarySearch(k2,(long)n);
                  if(key < 0){
                      key = Math.abs(key)-1;
                      System.out.println(k2.get(key));
                  }
                  else System.out.println(n);
              }
          }
      }
  
      static ArrayList<Long> fillK1(){
          ArrayList<Long> al = new ArrayList<>();
          for(int i=1;i<=9;i++){
              fill(0,i,al);
          }
          return al;
      }
  
      static ArrayList<Long> fillK2(){
          ArrayList<Long> al = new ArrayList<>();
          for(int i=1;i<=9;i++){
              for(int j=i+1;j<=9;j++){
                  fill(0,i,j,al);
              }
          }
  
          for(int i=0,j=1;j<=9;j++){
              fill(j,i,j,al);
          }
          return al;
      }
  
      static void fill(long num,int a, int b,ArrayList<Long> al){
          if(num > 10000000000L) return;
          if(num != 0) al.add(num);
  
          fill(num*10+a,a,b,al);
          fill(num*10+b,a,b,al);
      }
  
      static void fill(long num,int a,ArrayList<Long> al){
          if(num > 10000000000L) return;
          if(num != 0) al.add(num);
  
          fill(num*10+a,a,al);
      }
  
  
  
      static void printArr(int[] arr){
          for(int i=0;i< arr.length;i++)
          {
              System.out.print(arr[i] + " ");
          }
          System.out.println();
      }
  
      private static int lcm(int a, int b) {
          int gcd = gcd(a,b);
          return (int)((long)a*(long)b)/gcd ;
      }
  
  
      private static int gcd(int a, int b) {
          if(b == 0) return a;
          else return gcd(b , a % b);
      }
  
  
      private static void swap(int[] arr, int start, int rand_pivot) {
          int temp = arr[start];
          arr[start] = arr[rand_pivot];
          arr[rand_pivot] = temp;
      }
  
  
  }