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 Main{
  	static Boolean[][][]memo;
  	static char[]in;
  	static int k;
  	static boolean dp(int bigger,int i,int msk) {
  		if(Integer.bitCount(msk)>k)return false;
  		if(i==in.length)return true;
  		if(memo[bigger][i][msk]!=null)return memo[bigger][i][msk];
  		if(bigger==1) {
  			boolean ans=false;
  			for(int c=0;c<10 && !ans;c++) {
  				ans|=dp(bigger, i+1, msk|(1<<c));
  			}
  			return memo[bigger][i][msk]=ans;
  		}
  		boolean ans=dp(0, i+1, msk|(1<<(in[i]-'0')));
  		for(int c=(in[i]-'0')+1;c<10 && !ans;c++) {
  			ans|=dp(1, i+1, msk|(1<<c));
  		}
  		return memo[bigger][i][msk]=ans;
  	}
  	static void trace(int bigger,int i,int msk) {
  		if(i==in.length)return;
  		if(bigger==1) {
  			for(int c=0;c<10;c++) {
  				if(dp(bigger, i+1, msk|(1<<c))) {
  					pw.print(c);
  					trace(bigger, i+1, msk|(1<<c));
  					return;
  				}
  			}
  			return;
  		}
  		if(dp(0, i+1, msk|(1<<(in[i]-'0')))) {
  			pw.print(in[i]);
  			trace(0, i+1, msk|(1<<(in[i]-'0')));
  			return;
  		}
  		for(int c=(in[i]-'0')+1;c<10;c++) {
  			if(dp(1, i+1, msk|(1<<c))) {
  				pw.print(c);
  				trace(1, i+1, msk|(1<<c));
  				return;
  			}
  		}
  	}
  	static void main() throws Exception{
  		in=sc.next().toCharArray();
  		k=sc.nextInt();
  		memo=new Boolean[2][in.length][1<<10];
  		if(!dp(0, 0, 0)) {
  			if(k==1) {
  				for(int i=0;i<=in.length;i++)pw.print(1);
  				pw.println();
  				return;
  			}
  			pw.print(1);
  			for(int i=0;i<in.length;i++)pw.print(0);
  			pw.println();
  			return;
  		}
  		trace(0, 0, 0);
  		pw.println();
  	}
  	public static void main(String[] args) throws Exception{
  		sc=new MScanner(System.in);
  		pw = new PrintWriter(System.out);
  		int tc=1;
          tc=sc.nextInt();
  		for(int i=1;i<=tc;i++) {
  //			pw.printf("Case #%d: ", i);
  			main();
  		}
  		pw.flush();
  	}
  	static PrintWriter pw;
  	static MScanner sc;
  	static class MScanner {
  		StringTokenizer st;
  		BufferedReader br;
  		public MScanner(InputStream system) {
  			br = new BufferedReader(new InputStreamReader(system));
  		}
  	 
  		public MScanner(String file) throws Exception {
  			br = new BufferedReader(new FileReader(file));
  		}
  	 
  		public String next() throws IOException {
  			while (st == null || !st.hasMoreTokens())
  				st = new StringTokenizer(br.readLine());
  			return st.nextToken();
  		}
  		public int[] intArr(int n) throws IOException {
  	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
  	        return in;
  		}
  		public long[] longArr(int n) throws IOException {
  	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
  	        return in;
  		}
  		public int[] intSortedArr(int n) throws IOException {
  	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
  	        shuffle(in);
  	        Arrays.sort(in);
  	        return in;
  		}
  		public long[] longSortedArr(int n) throws IOException {
  	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
  	        shuffle(in);
  	        Arrays.sort(in);
  	        return in;
  		}
  		public Integer[] IntegerArr(int n) throws IOException {
  	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
  	        return in;
  		}
  		public Long[] LongArr(int n) throws IOException {
  	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
  	        return in;
  		}
  		public String nextLine() throws IOException {
  			return br.readLine();
  		}
  	 
  		public int nextInt() throws IOException {
  			return Integer.parseInt(next());
  		}
  	 
  		public double nextDouble() throws IOException {
  			return Double.parseDouble(next());
  		}
  	 
  		public char nextChar() throws IOException {
  			return next().charAt(0);
  		}
  	 
  		public long nextLong() throws IOException {
  			return Long.parseLong(next());
  		}
  	 
  		public boolean ready() throws IOException {
  			return br.ready();
  		}
  	 
  		public void waitForInput() throws InterruptedException {
  			Thread.sleep(3000);
  		}
  		
  	}
  	static void dbg(int[]in) {
  		System.out.println(Arrays.toString(in));
  	}
  	static void dbg(long[]in) {
  		System.out.println(Arrays.toString(in));
  	}
  	static void sort(int[]in) {
  		shuffle(in);
  		Arrays.sort(in);
  	}
  	static void sort(long[]in) {
  		shuffle(in);
  		Arrays.sort(in);
  	}
  	static void shuffle(int[]in) {
  		for(int i=0;i<in.length;i++) {
  			int idx=(int)(Math.random()*in.length);
  			int tmp=in[i];
  			in[i]=in[idx];
  			in[idx]=tmp;
  		}
  	}
  	static void shuffle(long[]in) {
  		for(int i=0;i<in.length;i++) {
  			int idx=(int)(Math.random()*in.length);
  			long tmp=in[i];
  			in[i]=in[idx];
  			in[idx]=tmp;
  		}
  	}
  }