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.lang.*;
  import java.io.*;
  import java.math.BigInteger;
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.DataInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.math.BigInteger;
  import java.util.List;
  import java.util.Map;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  public class third
  {	
  	 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();
  	        }
  	 }
  	 public static long gcd(long x, long p)
  	    {
  	        if (x == 0)
  	            return p;
  	         
  	        return gcd(p%x, x);
  	    }
  	 static int sieve =  1000000 ;
  
  
  	 static boolean[] prime =  new boolean[sieve + 1] ;
  
  	 public static void sieveOfEratosthenes() 
  	     { 
  	         // FALSE == prime and 1 // TRUE ==  COMPOSITE
  	         
  	         // time complexity = 0(NlogLogN)== o(N)
  	         
  	         // gives prime nos bw 1 to N // size - 1e7(at max)
  	         
  	         for(int i = 4; i<= sieve ; i++)
  	         {
  	             prime[i] = true  ; i++ ;
  	            
  	         }
  	         
  	         for(int p = 3; p*p <= sieve; p++) 
  	         { 
  	            if(prime[p] == false) 
  	             { 
  	                     for(int i = p*p; i <= sieve; i += p) 
  	                     prime[i] = true; 
  	             } 
  	             
  	             p++ ;
  	         } 
  	           
  	     } 
  	 public static void arrInpInt(int [] arr, int n) throws IOException
  	 {
  		 Reader reader = new Reader();
  		 for(int i=0;i<n;i++)
  	   		{
  	   			arr[i]=reader.nextInt();	
  	   		}
  	 }
  	 public static void arrInpLong(long [] arr, int n) throws IOException
  	 {
  		 Reader reader = new Reader();
  		 for(int i=0;i<n;i++)
  	   		{
  	   			arr[i]=reader.nextLong();	
  	   		}
  	 }
  	 public static void printArr(int[] arr)
  	 {
  		 for(int i=0;i<arr.length;i++)
  		 {
  			 System.out.print(arr[i]+" ");
  		 }
  		 System.out.println();
  	 }
  	 public static int[] decSort(int[] arr)
  	 {
  		  int[] arr1 = Arrays.stream(arr).boxed().sorted(Collections.reverseOrder()).mapToInt(Integer::intValue).toArray();	
  		  return arr1;
  	 }
  	 
  //	public static int binarySearch(int l, int r, int x)
  //	    {
  //	        if (r >= l) {
  //	            int mid = l + (r - l) / 2;
  //	            if (arr[mid] == x)
  //	                return mid;
  //	            if (arr[mid] > x)
  //	                return binarySearch(arr, l, mid - 1, x);
  //	            return binarySearch(arr, mid + 1, r, x);
  //	        }
  //	        return -1;
  //	    }
  	public static long binarySearch2(long l, long r, long sum,int N)
      {
  		if(r<l)return l;
          if (r >= l) {
              long mid = l + (r - l) / 2;
              if (mid*(N-1) == sum)
                  return mid;
              if(mid*(N-1)>sum &&(mid-1)*(N-1)<sum)return mid;
              if (mid*(N-1)> sum)
                  return binarySearch2(l, mid-1, sum,N);
              return binarySearch2( mid + 1,r,sum,N );
          }
          return -1;
      }
  	//if present - return the first occurrence of the no
  	//not present- return the index of next greater value 
  	//if greater than all the values return N(taking high=N-1)
  	//if smaller than all the values return 0(taking low =0)
  	static int lower_bound(int arr[], int low,
  	             int high, int X)
  	{
  
  	 if (low > high) {
  	     return low;
  	 }
  	 int mid = low + (high - low) / 2;
  	 if (arr[mid] >= X) {
  	     return lower_bound(arr, low,
  	                        mid - 1, X);
  	 }
  
  	 return lower_bound(arr, mid + 1,
  	                    high, X);
  	}
  	//if present - return the index of next greater value
  	//not present- return the index of next greater value 
  	//if greater than all the values return N(taking high=N-1)
  	//if smaller than all the values return 0(taking low =0)
  	
  	
  	 public static class Pair  {// comparator with class
  		    int x;
  		    int y;
  		 public Pair(int x, int y)
  		    {
  		        this.x = x;
  		        this.y = y;
  		    }
  		}
  
  	 private static HashMap sortValues(HashMap<Integer,ArrayList<Integer>> map)   
  	 {   
  	 List list = new LinkedList(map.entrySet());    
  	 Collections.sort(list, new Comparator()   
  	 {  
  	 public int compare(Object o1, Object o2)   
  	 {  
  	 return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());  
  	 }  
  	 });  
  	 //copying the sorted list in HashMap to preserve the iteration order  
  	 HashMap sortedHashMap = new LinkedHashMap();  
  	 for (Iterator it = list.iterator(); it.hasNext();)   
  	 {  
  	  Map.Entry entry = (Map.Entry) it.next();  
  	 sortedHashMap.put(entry.getKey(), entry.getValue());  
  	 }   
  	 return sortedHashMap;  
  	 }  
  	 //public static HashMap<String,Integer> DP=new HashMap<String,Integer>();
  	//public static HashMap<Long,Integer> factor= new HashMap<Long,Integer>();
  	 public static TreeSet<Long> set=new TreeSet<Long>();
  	 
  	 public static void  rec(int f, int l, int n,long fin,long mul)
  	{
  		if(n==0) {set.add(fin);return; }
  		rec(f,l,n-1,fin+f*mul,mul*10);
  		rec(f,l,n-1,fin+l*mul,mul*10); 
  	}
  
  	
  	
  	public static void main(String args[]) throws NumberFormatException, IOException ,java.lang.Exception
  	{
  		
  		Reader reader = new Reader();
  		//HashSet<Long> set=new HashSet<Long>();
  		for(int i=1;i<11;i++)
  		{
  			for(int j=0;j<10;j++)
  			{
  				int first=j;
  				for(int k=0;k<10;k++)
  				{
  					int second=k;
  					if(first!=second)rec(first,second,i,0,1);
  				}
  			}
  		}
  		//System.out.println(set);
  		
  		//System.out.println(strings[62]);
  		//System.out.println(strings);
  		//rec();
  		//sieveOfEratosthenes();
  		//System.out.println(prime[0]+" "+prime[1]+" "+prime[2]+" "+prime[3]+" "+prime[4]);
  		//Scanner reader=new Scanner(System.in);
  		//BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
  		//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		//int cases=Integer.parseInt(br.readLine());
  		//int cases=0;
  		int cases=reader.nextInt();
  	//	System.out.println(Integer.toBinaryString(1024));
     	while (cases-->0){
     		//maxheap x=new maxheap();
     		int N=reader.nextInt();
     		int K=reader.nextInt();
     		//System.out.println(N+" "+K);
     	 //PriorityQueue<Long> Q = new PriorityQueue<Long>();
     		//int S=reader.nextInt();
     		
     		//int circum=reader.nextInt();
     		//int K=reader.nextInt();
     		//int N=Integer.parseInt(br.readLine());
     		//String[] first=br.readLine().split(" ");
     		//int X=Integer.parseInt(first[0]);
     		//int Y=Integer.parseInt(first[1]);
     		//int X=reader.nextInt();
     		//int Y=reader.nextInt();
     		//String str=br.readLine();
     		//int max=Integer.MIN_VALUE;
     		//int min=Integer.MAX_VALUE;
     		//HashMap<String,Integer> map=new HashMap<String,Integer>();
     		//HashSet<Integer> map=new HashSet<Integer>();
     		//int[] arr=new int[N];
     		//int [] arr1=new int[N];
     		//long[]arr=new long[N];
     		//arrInpInt(arr,N);
     		//arrInpLong(arr,N);
     		//int[] arr1=decSort(arr);
     		//printArr(arr1);
     		//System.out.println(arr[N]);
     		//String fin=strip()
     		//long row=(long) Math.sqrt(N);
     		//System.out.println(row);
     		String str=N+"";
     		//HashSet<Character> set=new HashSet<Character>();
     		if(K==1)
  			{HashSet<Character> set=new HashSet<Character>();
  	   		for(int i=0;i<str.length();i++)set.add(str.charAt(i));
  	   		//System.out.println(set);
  	   		if(set.size()<=K)System.out.println(N);
  	   		else
  	   		{
  				int ind=0;
  				while(str.charAt(ind)==str.charAt(ind+1))ind++;
  				int left=Character.getNumericValue(str.charAt(ind));
  				int right=Character.getNumericValue(str.charAt(ind+1));
  				if(right>left)
  				{
  					
  					for(int i=0;i<str.length();i++)System.out.print(left+1);
  						
  				}
  				else
  				{
  					for(int i=0;i<str.length();i++)System.out.print(left);
  				}
  				System.out.println();
  	   		}	
  			}
     		else
     		{
     			System.out.println(set.ceiling((long)N));
     		}
     		
     		
     	 //System.out.println(fin);
  //System.out.println(arr[N]);
  //System.out.println(possible(p,arr,k-1,circum));
     		
     		}
     		
     	
     		}
  
  	}
  
  