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.util.*;
  public class check1  {
  
      public static void find2(List<Long> al,int n,char c[],int ind,char no1,char no2)
      {
          if(ind>=n){
  //            System.out.println(String.valueOf(c));
              long t1=0;
              long mul=n-1;
              for(int i=0;i<n;i++)
              {
                  long t2=c[i]-'0';
                  t1 = t1+ (long)Math.pow(10,mul)*t2;
                  mul--;
              }
              al.add(t1);
  //            al.add(Long.parseLong(String.valueOf(c)));
              return;
          }
          c[ind]=no1;
          find2(al,n,c,ind+1,no1,no2);
          c[ind]=no2;
          find2(al,n,c,ind+1,no1,no2);
      }
      public static void find1(List<Long> al,int n,char c[],int ind,char no1)
      {
          long t1=0;
          long mul=n-1;
          for(int i=0;i<n;i++)
          {
              long t2=c[i]-'0';
              t1 = t1+ (long)Math.pow(10,mul)*t2;
              mul--;
          }
          al.add(t1);
          if(ind<0) return;
  
          c[ind]=no1;
          find1(al,n,c,ind-1,no1);
      }
      public static void find0(List<Long> al1,List<Long> al2)
      {
          int n=10;
          char c[]=new char[n];
  
          for(char i='0';i<='9';i++){
              Arrays.fill(c,'0');
              al1.add((long)1111111111);
              find1(al1,n,c,n-1,i);
          }
          for(int n1=1;n1<=n;n1++){
              for(int i=0;i<9;i++){
                  for(int j=i+1;j<=9;j++){
  
                      Arrays.fill(c,'0');
                      char no1 = (char)(i+'0');
                      char no2 = (char)(j+'0');
  //                System.out.println(no1+" "+no2);
                      find2(al2,n1,c,0,no1,no2);
                  }
              }
          }
      }
      public static long bs(List<Long> al,long no)
      {
          int n = al.size();
          int s=0,e=n-1;
  
          while(s<e)
          {
              int mid = s+(e-s)/2;
              if(al.get(mid)<no) s=mid+1;
              else e=mid;
          }
          return al.get(s);
      }
      public static void main(String[] args) throws IOException{
  
          Reader sc=new Reader();
          PrintWriter out = new PrintWriter(System.out);
  
          List<Long> al1 = new ArrayList<>();
          List<Long> al2 = new ArrayList<>();
          find0(al1,al2);
          Collections.sort(al1);
          Collections.sort(al2);
  //        out.println(al1);
  //
  //        for(int i=0;i<500;i++){
  //            out.print(al2.get(i)+" ");
  //        }
  //        out.println();
          int t=sc.nextInt();
          while(t-->0)
          {
              long no = sc.nextLong();
              long k = sc.nextLong();
              long ans = -1;
  
              if(k==1)    ans = bs(al1,no);
              if(k==2)    ans = bs(al2,no);
              out.println(ans);
          }
          out.flush();
      }
  
      public static long power(long x,long power)
      {
          if(power==0) return 1;
  
          long ans1 = power(x,power/2);
          ans1=ans1*ans1;
  
          if(power%2==0) return ans1;
          return x*ans1;
      }
  
      //    (a*a_inverse) = 1(mod m)
  //    finding a_inverse
      public static long modInverse(long a,long m)
      {
  //        works only when m is prime
          long g=gcd(a,m);
          if(g==1) return power(a,m-2,m);
          else return -1;
      }
  
      //    (x^power)mod(m)
      public static long power(long x,long power,long m)
      {
          if(power==0) return 1;
  
          long p = power(x,power/2,m)%m;
          p = (p*p)%m;
  
          if(power%2==0) return p;
          return (x*p)%m;
      }
      public static long gcd(long small,long large)
      {
          if(small==0) return large;
          return gcd(large % small,small);
      }
  
      public static boolean isprime(long no)
      {
          if(no<=1) return false;
          if(no<=3) return true;
          if(no%2==0 || no%3==0) return false;
          // 6k+1 6k+5 can be prime
          for(long i=5;i*i<=no;i+=6)
          {
              if(no%(i)==0 || no%(i+2)==0)
                  return false;
          }
          return true;
      }
  
      //    prime no smaller than or equal to n
      public static boolean[] prime_nos_till_no(int no)
      {
          boolean prime[]=new boolean[no+1];
  //        prime[i]== true means prime
  //        prime[i]== false means not a prime
  //        initialize prime array as true
  
          Arrays.fill(prime,true);
          prime[0]=false;
          for(int i=2;i*i<=no;i++)
          {
              if(prime[i]==true)
              {
                  for(int j=i*i;j<=no;j+=i)
                  {
                      prime[j]=false;
                  }
              }
          }
          return prime;
  
      }
      public static void shufflearray(long arr[])
      {
  
  
          int n=arr.length;
          Random rand=new Random();
          for(int i=0;i<n;i++)
          {
              long temp=arr[i];
              int randomPos=i+rand.nextInt(n-i);
              arr[i]=arr[randomPos];
              arr[randomPos]=temp;
          }
      }
      //       Arrays.sort(arr, new Comparator<pair>() {
  //        //@Override
  //        public int compare(pair o1, pair o2) {
  //            long l1=o1.a-o2.a;
  //            if(l1<0L) return -1;
  //            if(l1==0) return 0;
  //            return 1;
  //        }
  //    });
      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 nextLine() throws IOException {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n')
                      break;
                  buf[cnt++] = (byte) c;
              }
              return new String(buf, 0, cnt);
          }
          public boolean isSpaceChar(int c) {
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          public String next() throws IOException{
              int c = read();
              while (isSpaceChar(c)) c = read();
              StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
  
          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();
          }
  
      }
  
  }