#include <bits/stdc++.h>
bool isp(int x) {
  if (x < 2) return 0;
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
int FPW(int x, int y, int mod) {
  int res = 1;
  for (; y; y >>= 1) {
    if (y % 2) res = res * x % mod;
    x = x * x % mod;
  }
  return res;
}
using namespace std;
int cnts(int x) {
  int ret = 0;
  while (x) {
    ret |= (1 << (x % 10));
    x /= 10;
  }
  return __builtin_popcount(ret);
}
int main() {
  int T = read();
  while (T--) {
    int N = read(), K = read();
    int ans = N;
    while (cnts(ans) > K) {
      int l = 1, r = ans;
      while (cnts(r) > K) {
        l *= 10, r /= 10;
      }
      l /= 10;
      ans /= l;
      ans++;
      ans *= l;
    }
    cout << ans << endl;
  }
  return 0;
}

### Prompt

Create a solution in cpp for the following problem:

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

### Response

```cpp
#include <bits/stdc++.h>
bool isp(int x) {
  if (x < 2) return 0;
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
int FPW(int x, int y, int mod) {
  int res = 1;
  for (; y; y >>= 1) {
    if (y % 2) res = res * x % mod;
    x = x * x % mod;
  }
  return res;
}
using namespace std;
int cnts(int x) {
  int ret = 0;
  while (x) {
    ret |= (1 << (x % 10));
    x /= 10;
  }
  return __builtin_popcount(ret);
}
int main() {
  int T = read();
  while (T--) {
    int N = read(), K = read();
    int ans = N;
    while (cnts(ans) > K) {
      int l = 1, r = ans;
      while (cnts(r) > K) {
        l *= 10, r /= 10;
      }
      l /= 10;
      ans /= l;
      ans++;
      ans *= l;
    }
    cout << ans << endl;
  }
  return 0;
}

```