#include <bits/stdc++.h>
using namespace std;
const double pai = acos(-1.0);
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 5e3 + 10;
inline int read() {
  int k = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) k = (k << 1) + (k << 3) + c - 48, c = getchar();
  return k * f;
}
int t, n, k, cnt[1030];
int a[20];
long long dp[20][1030][12];
long long dfs(int pos, int pre, int state, bool lead, bool limit) {
  if (pos == -1 && cnt[state] <= k) return 1;
  if (!limit && !lead && dp[pos][state][k] != -1) return dp[pos][state][k];
  int up = limit ? a[pos] : 9;
  long long res = 0;
  for (int i = 0; i <= up; i++) {
    if (i == 0 && lead)
      res += dfs(pos - 1, i, state, lead && i == 0, limit && i == a[pos]);
    else {
      if (cnt[state | (1 << i)] > k) continue;
      res += dfs(pos - 1, i, (state | (1 << i)), lead && i == 0,
                 limit && i == a[pos]);
    }
  }
  if (!limit && !lead) dp[pos][state][k] = res;
  return res;
}
long long solve(int x) {
  int pos = 0;
  while (x) {
    a[pos++] = x % 10;
    x /= 10;
  }
  return dfs(pos - 1, -1, 0, 1, 1);
}
int main() {
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < 1 << 10; i++) cnt[i] = __builtin_popcount(i);
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    long long num = solve(n - 1);
    long long l = n, r = 2e9, ans = 0;
    while (l <= r) {
      int mid = l + r >> 1;
      if (solve(mid) - num >= 1) {
        r = mid - 1;
        ans = mid;
      } else
        l = mid + 1;
    }
    printf("%lld\n", ans);
  }
  return 0;
}

### Prompt

Generate a CPP solution to 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>
using namespace std;
const double pai = acos(-1.0);
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 5e3 + 10;
inline int read() {
  int k = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) k = (k << 1) + (k << 3) + c - 48, c = getchar();
  return k * f;
}
int t, n, k, cnt[1030];
int a[20];
long long dp[20][1030][12];
long long dfs(int pos, int pre, int state, bool lead, bool limit) {
  if (pos == -1 && cnt[state] <= k) return 1;
  if (!limit && !lead && dp[pos][state][k] != -1) return dp[pos][state][k];
  int up = limit ? a[pos] : 9;
  long long res = 0;
  for (int i = 0; i <= up; i++) {
    if (i == 0 && lead)
      res += dfs(pos - 1, i, state, lead && i == 0, limit && i == a[pos]);
    else {
      if (cnt[state | (1 << i)] > k) continue;
      res += dfs(pos - 1, i, (state | (1 << i)), lead && i == 0,
                 limit && i == a[pos]);
    }
  }
  if (!limit && !lead) dp[pos][state][k] = res;
  return res;
}
long long solve(int x) {
  int pos = 0;
  while (x) {
    a[pos++] = x % 10;
    x /= 10;
  }
  return dfs(pos - 1, -1, 0, 1, 1);
}
int main() {
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < 1 << 10; i++) cnt[i] = __builtin_popcount(i);
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    long long num = solve(n - 1);
    long long l = n, r = 2e9, ans = 0;
    while (l <= r) {
      int mid = l + r >> 1;
      if (solve(mid) - num >= 1) {
        r = mid - 1;
        ans = mid;
      } else
        l = mid + 1;
    }
    printf("%lld\n", ans);
  }
  return 0;
}

```