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.io.*;
  import java.math.*;
  
  public class cf {
  	static PrintWriter pw = new PrintWriter(System.out);
  
  	public static void main(String[] args) throws IOException, InterruptedException {
  		Scanner sc = new Scanner(System.in);
  		int t = sc.nextInt();
  		arrl = new ArrayList<>();
  		gen(new HashSet<>(), "");
  		TreeSet<Integer> ts = new TreeSet<>();
  		for (String s : arrl) {
  			if (s.length() != 0)
  				ts.add(Integer.parseInt(s));
  		}
  		ts.pollFirst();
  		ts.add((int) 1e9);
  //		pw.println(ts);
  //		pw.println(ts.size());
  		while (t-- > 0) {
  			int n = sc.nextInt(), k = sc.nextInt();
  			if (k == 1) {
  				String x = n + "";
  				int y = x.charAt(0) - '0';
  				int c = 0;
  				for (int i = 0; i < x.length(); i++) {
  					if (x.charAt(i) > x.charAt(0)) {
  						c = 1;
  						break;
  					}
  					if (x.charAt(i) < x.charAt(0)) {
  						break;
  					}
  				}
  				if (c == 1) {
  					for (int i = 0; i < x.length(); i++) {
  						pw.print(y + 1);
  					}
  				} else {
  					for (int i = 0; i < x.length(); i++) {
  						pw.print(y);
  					}
  				}
  				pw.println();
  			} else {
  				pw.println(ts.ceiling(n));
  			}
  		}
  		pw.close();
  	}
  
  	static boolean chk(int x) {
  		String s = x + "";
  		HashSet<Integer> hs = new HashSet<>();
  		for (int i = 0; i < s.length(); i++) {
  			hs.add(s.charAt(i) - '0');
  		}
  		return hs.size() <= 2;
  	}
  
  	static ArrayList<String> arrl;
  
  	static void gen(HashSet<Integer> hs, String cur) {
  		arrl.add(cur);
  		if (cur.length() == 9) {
  			return;
  		}
  		for (int j = 0; j < 10; j++) {
  			String x = cur;
  			HashSet<Integer> h = (HashSet<Integer>) hs.clone();
  			if (h.contains(j)) {
  				gen(h, x + j);
  			} else {
  				h.add(j);
  				if (h.size() <= 2)
  					gen(h, x + j);
  			}
  		}
  	}
  
  	public static class tuble implements Comparable<tuble> {
  		int x;
  		int y;
  		int z;
  
  		public tuble(int x, int y, int z) {
  			this.x = x;
  			this.y = y;
  			this.z = z;
  		}
  
  		public String toString() {
  			return x + " " + y + " " + z;
  		}
  
  		public int compareTo(tuble other) {
  			if (this.x == other.x) {
  				if (this.y == other.y)
  					return this.z - other.z;
  				return this.y - other.y;
  			} else {
  				return this.x - other.x;
  			}
  		}
  	}
  
  	public static class pair implements Comparable<pair> {
  		int x;
  		int y;
  
  		public pair(int x, int y) {
  			this.x = x;
  			this.y = y;
  		}
  
  		public String toString() {
  			return x + " " + y;
  		}
  
  		public boolean equals(Object o) {
  			if (o instanceof pair) {
  				pair p = (pair) o;
  				return p.x == x && p.y == y;
  			}
  			return false;
  		}
  
  		public int hashCode() {
  			return new Integer(x).hashCode() * 31 + new Integer(y).hashCode();
  		}
  
  		public int compareTo(pair other) {
  			if (this.x == other.x) {
  				return Long.compare(this.y, other.y);
  			}
  			return Long.compare(this.x, other.x);
  		}
  	}
  
  	static class Scanner {
  		StringTokenizer st;
  		BufferedReader br;
  
  		public Scanner(InputStream s) {
  			br = new BufferedReader(new InputStreamReader(s));
  		}
  
  		public Scanner(FileReader r) {
  			br = new BufferedReader(r);
  		}
  
  		public String next() throws IOException {
  			while (st == null || !st.hasMoreTokens())
  				st = new StringTokenizer(br.readLine());
  			return st.nextToken();
  		}
  
  		public int nextInt() throws IOException {
  			return Integer.parseInt(next());
  		}
  
  		public long nextLong() throws IOException {
  			return Long.parseLong(next());
  		}
  
  		public String nextLine() throws IOException {
  			return br.readLine();
  		}
  
  		public double nextDouble() throws IOException {
  			return Double.parseDouble(next());
  		}
  
  		public boolean ready() throws IOException {
  			return br.ready();
  		}
  
  	}
  
  }