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.*;
  import java.math.BigInteger;
  import java.util.InputMismatchException;
  
  public class Main {
  	static PrintWriter out;
  	static Reader in;
  	public static void main(String[] args) throws IOException {
  		input_output();
  		Main solver = new Main();
  		solver.solve();
  		out.close();
  
  		out.flush();
  	} 
  
  	static long INF = (long)1e18;
  	static int MAXN = (int)1e5 + 5;
  	static int MOD = (int)1e9 + 7;
  	static int q, t, n, m, k;
  	static double pi = Math.PI;
  
  	void solve() throws IOException {
  		t = in.nextInt();
  		
  
  		while (t --> 0) {
  			n = in.nextInt();
  			k = in.nextInt();
  
  			if (k == 1) out.println(solve1(n));
  			else out.println(solve2(n));
  		}	
  	}
  
  	static int solve1(int n) {
  		String s = n+"";
  		for (int i = 1; i <= 9; i++) {
  			int m = 0, ten = 1;
  			for (int j = 1; j <= s.length(); j++) {
  				m += ten*i;
  				ten *= 10;
  			}
  
  			if (n <= m) return m;
  		}
  
  		return 0;
  	}
  
  	static int solve2(int n) {
  		int m = solve1(n);
  		String s = n+"";
  
  		for (int a = 0; a <= 9; a++) {
  			for (int b = a+1; b <= 9; b++) {
  				StringBuilder next = new StringBuilder("");
  
  				for (int i = 0; i < s.length(); i++) {
  					int dig = s.charAt(i)-'0';
  
  					if (dig < b) {
  						StringBuilder tmpNext = new StringBuilder(next);
  						if (a <= dig) tmpNext.append(b);
  						else tmpNext.append(a);
  
  						for (int j = s.length()-i-1; j >= 1; j--) {
  							tmpNext.append(a);
  						}
  
  						int tmpNextInt = Integer.parseInt(tmpNext.toString());
  						if (tmpNextInt < m) m = tmpNextInt;
  					}
  
  					if (dig == a || dig == b) {
  						next.append(dig);
  					} else {
  						break;
  					}
  				}
  
  				if (next.length() == s.length()) return Integer.parseInt(next.toString());
  			}
  		}
  
  		return m;
  	}
  
  	static class Reader {
  		private InputStream mIs;
  		private byte[] buf = new byte[1024];
  		private int curChar;
  		private int numChars;
  
  		public Reader() {
  			this(System.in);
  		}
  
  		public Reader(InputStream is) {
  			mIs = is;
  		}
  
  		public int read() {
  			if (numChars == -1) {
  				throw new InputMismatchException();
  
  			}
  			if (curChar >= numChars) {
  				curChar = 0;
  				try {
  					numChars = mIs.read(buf);
  				} catch (IOException e) {
  					throw new InputMismatchException();
  				}
  				if (numChars <= 0) {
  					return -1;
  				}
  			}
  			return buf[curChar++];
  		}
  
  		public String nextLine() {
  			int c = read();
  			while (isSpaceChar(c)) {
  				c = read();
  			}
  			StringBuilder res = new StringBuilder();
  			do {
  				res.appendCodePoint(c);
  				c = read();
  			} while (!isEndOfLine(c));
  			return res.toString();
  		}
  
  		public String next() {
  			int c = read();
  			while (isSpaceChar(c)) {
  				c = read();
  			}
  			StringBuilder res = new StringBuilder();
  			do {
  				res.appendCodePoint(c);
  				c = read();
  			} while (!isSpaceChar(c));
  			return res.toString();
  		}
  
  		double nextDouble() {
  			return Double.parseDouble(next());
  		}
  
  		public long nextLong() {
  			int c = read();
  			while (isSpaceChar(c)) {
  				c = read();
  			}
  			int sgn = 1;
  			if (c == '-') {
  				sgn = -1;
  				c = read();
  			}
  			long res = 0;
  			do {
  				if (c < '0' || c > '9') {
  					throw new InputMismatchException();
  				}
  				res *= 10;
  				res += c - '0';
  				c = read();
  			} while (!isSpaceChar(c));
  			return res * sgn;
  		}
  
  		public int nextInt() {
  			int c = read();
  			while (isSpaceChar(c)) {
  				c = read();
  			}
  			int sgn = 1;
  			if (c == '-') {
  				sgn = -1;
  				c = read();
  			}
  			int res = 0;
  			do {
  				if (c < '0' || c > '9') {
  					throw new InputMismatchException();
  				}
  				res *= 10;
  				res += c - '0';
  				c = read();
  			} while (!isSpaceChar(c));
  			return res * sgn;
  		}
  
  		public boolean isSpaceChar(int c) {
  			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  		}
  
  		public boolean isEndOfLine(int c) {
  			return c == '\n' || c == '\r' || c == -1;
  		}
  
  	}
  	static void input_output() throws IOException {
  		File f = new File("in.txt");
  		if (f.exists() && !f.isDirectory()) {
  			in = new Reader(new FileInputStream("in.txt"));
  		} else in = new Reader();
  		f = new File("out.txt");
  		if (f.exists() && !f.isDirectory()) {
  			out = new PrintWriter(new File("out.txt"));
  		} else out = new PrintWriter(System.out);
  	}
  }