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.DataInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.*;
  
  public class A{
      static void sort(int[] A){
  
          int n = A.length;
          Random rnd = new Random();
          for(int i=0; i<n; ++i){
              int tmp = A[i];
              int randomPos = i + rnd.nextInt(n-i);
              A[i] = A[randomPos];
              A[randomPos] = tmp;
          }
          Arrays.sort(A);
      }
      static class Reader {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Reader() {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Reader(String file_name) throws IOException {
              din = new DataInputStream(
                      new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      } else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte) c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextInt() throws IOException {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          public long nextLong() throws IOException {
              long ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg)
                  return -ret;
              return ret;
          }
  
          public double nextDouble() throws IOException {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
  
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          private void fillBuffer() throws IOException {
              bytesRead = din.read(buffer, bufferPointer = 0,
                      BUFFER_SIZE);
              if (bytesRead == -1)
                  buffer[0] = -1;
          }
  
          private byte read() throws IOException {
              if (bufferPointer == bytesRead)
                  fillBuffer();
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException {
              if (din == null)
                  return;
              din.close();
          }
      }
  
      static int editDistanceWith2Ops(String X, String Y) {
          // Find LCS
          int m = X.length(), n = Y.length();
          int L[][] = new int[m + 1][n + 1];
          for (int i = 0; i <= m; i++) {
              for (int j = 0; j <= n; j++) {
                  if (i == 0 || j == 0) {
                      L[i][j] = 0;
                  } else if (X.charAt(i - 1) == Y.charAt(j - 1)) {
                      L[i][j] = L[i - 1][j - 1] + 1;
                  } else {
                      L[i][j] = Math.max(L[i - 1][j], L[i][j - 1]);
                  }
              }
          }
          int lcs = L[m][n];
  
          // Edit distance is delete operations +
          // insert operations.
          return (m - lcs) + (n - lcs);
      }
  
      public static int lcs( char[] Y, char[] X, int n, int m )
      {
          int c=0;
          for(int j=0;j<n;j++)
          {
              if(X[c]==Y[j])
              {
                  c++;
              }
              if(c>=m)
              {
                  break;
              }
          }
          return c;
      }
  
      /* Utility function to get max of 2 integers */
      public static int max(int a, int b)
      {
          return (a > b)? a : b;
      }
  
      static TreeMap<Long,Integer> map=new TreeMap();
      static TreeMap<Long,Integer> map2=new TreeMap();
      public static void rec(long x,long y,long left,long num)
      {
          if(left==0)
          {
              //return -1;
          }
          else
          {
  
              {
              map.put(num*10+x,1);
              rec(x,y,left-1,num*10+x);}
  
  
              {
              map.put(num*10+y,1);
              rec(x,y,left-1,num*10+y);}
  
  
          }
      }
      public static void main(String args[]) throws IOException {
          Reader sc=new Reader();
          long mod=1000000007l;
          int cases=sc.nextInt();
          StringBuilder prin=new StringBuilder();
  
          ArrayList<Integer> arr=new ArrayList<>();
  
  
          for(long j=0;j<=9;j++)
          {
              for(long k=0;k<=9;k++)
              {
                  for(long f=1;f<=10;f++)
                  {
                      rec(j,k,f,0);
                  }
              }
          }
  
          for(int j=1;j<=9;j++)
          {
              long c=j;
              for(int k=0;k<10;k++)
              {
                  map2.put(c,1);
                  c=c*10+j;
              }
          }
  
          map.put(1000000000l,1);
  
          while(cases>0)
          {
              cases--;
              long x=sc.nextLong();
              long k=sc.nextLong();
              if(k==2)
              {
                  prin.append(map.ceilingKey(x)+"\n");
              }
              else
              {
                  prin.append(map2.ceilingKey(x)+"\n");
              }
          }
          System.out.println(prin);
  
      }
  }
  