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.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.*;
  
  public class taskf1 {
  	public static void main(String[] args) {
  		FastScanner in = new FastScanner();
  		PrintWriter out = new PrintWriter(System.out);
  		Set<Long> s1 = new TreeSet<>();
  		Set<Long> s2 = new TreeSet<>();
  		StringBuilder sb1 = new StringBuilder("0000000000");
  		StringBuilder sb2 = new StringBuilder("0000000000");
  		for (int i = 1; i < 10; i++) {
  			gen1(sb1, 9, i, s1);
  		}
  		for (int i = 0; i < 10; i++) {
  			for (int j = 0; j < 10; j++) {
  				if (i != j) {
  					gen2(sb2, 9, i, j, s2);
  				}
  			}
  		}
  		ArrayList<Long> a1 = getArray(s1), a2 = getArray(s2);
  		int tt = in.nextInt();
  		for (int tc = 0; tc < tt; tc++) {
  			long n = in.nextLong();
  			int k = in.nextInt();
  			if (k == 1) {
  				out.println(lower_bound(a1, n));
  			} else {
  				out.println(lower_bound(a2, n));
  			}
  		}
  		out.flush();
  	}
  
  	static void gen1(StringBuilder s, int idx, int d1, Set<Long> ss) {
  		ss.add(Long.parseLong(s.toString()));
  		if (idx < 0) {
  			return;
  		}
  		StringBuilder new_s = new StringBuilder(s);
  		new_s.setCharAt(idx, (char) (d1 + '0'));
  		gen1(new_s, idx - 1, d1, ss);
  	}
  
  	static void gen2(StringBuilder s, int idx, int d1, int d2, Set<Long> ss) {
  		ss.add(Long.parseLong(s.toString()));
  		if (idx < 0) {
  			return;
  		}
  		StringBuilder new_s1 = new StringBuilder(s);
  		StringBuilder new_s2 = new StringBuilder(s);
  		new_s1.setCharAt(idx, (char) (d1 + '0'));
  		new_s2.setCharAt(idx, (char) (d2 + '0'));
  		gen2(new_s1, idx - 1, d1, d2, ss);
  		gen2(new_s2, idx - 1, d1, d2, ss);
  	}
  
  	static ArrayList<Long> getArray(Set<Long> s) {
  		ArrayList<Long> a = new ArrayList<>();
  		Iterator<Long> i = s.iterator();
  		while (i.hasNext()) {
  			a.add(i.next());
  		}
  		Collections.sort(a);
  		return a;
  	}
  
  	static long lower_bound(ArrayList<Long> a, long k) {
  		int low = 0, high = a.size() - 1;
  		int ans = a.size();
  		while (low <= high) {
  			int mid = (low + high) / 2;
  			if (a.get(mid) >= k) {
  				ans = mid;
  				high = mid - 1;
  			} else {
  				low = mid + 1;
  			}
  		}
  		return a.get(ans);
  	}
  
  	static class FastScanner {
  		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer tok = new StringTokenizer("");
  		String next() {
  			while(!tok.hasMoreTokens()) {
  				try {
  					tok = new StringTokenizer(br.readLine());
  				} catch (Exception e) {
  					e.printStackTrace();
  				}
  			}
  			return tok.nextToken();
  		}
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  		float nextFloat() {
  			return Float.parseFloat(next());
  		}
  		double nextDouble() {
  			return Double.parseDouble(next());
  		}
  	}
  }
  