#include <bits/stdc++.h>
using namespace std;
long long n, k;
int bi[20];
int ok(long long p) {
  int f[10] = {0}, op = 0;
  for (long long o = p; o; o /= 10) f[(int)(o % 10)] = 1;
  for (int i = 0; i < 10; i++) op += f[i];
  return op;
}
int f[20];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    int r = 0;
    if (ok(n) <= k) {
      cout << n << endl;
      continue;
    }
    for (int i = n; i; i /= 10) bi[r++] = i % 10;
    int sp = 0;
    for (long long i = n; i; i /= 10, sp++) {
      long long rr = i % 10, p = i / 10;
      int ss = -1;
      for (int j = rr + 1; j < 10; j++)
        if (ok(p * 10 + j) <= k) {
          ss = j;
          break;
        }
      if (ss > -1) {
        long long io = p * 10 + ss;
        memset(f, 0, sizeof(f));
        int sq;
        for (long long j = io; j; j /= 10) f[j % 10] = 1;
        for (int j = 0; j < 10; j++)
          if (f[j]) {
            sq = j;
            break;
          }
        if (ok(io) < k) sq = 0;
        for (int j = 0; j < sp; j++) io = io * 10 + sq;
        cout << io << endl;
        break;
      }
    }
  }
}

### 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>
using namespace std;
long long n, k;
int bi[20];
int ok(long long p) {
  int f[10] = {0}, op = 0;
  for (long long o = p; o; o /= 10) f[(int)(o % 10)] = 1;
  for (int i = 0; i < 10; i++) op += f[i];
  return op;
}
int f[20];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    int r = 0;
    if (ok(n) <= k) {
      cout << n << endl;
      continue;
    }
    for (int i = n; i; i /= 10) bi[r++] = i % 10;
    int sp = 0;
    for (long long i = n; i; i /= 10, sp++) {
      long long rr = i % 10, p = i / 10;
      int ss = -1;
      for (int j = rr + 1; j < 10; j++)
        if (ok(p * 10 + j) <= k) {
          ss = j;
          break;
        }
      if (ss > -1) {
        long long io = p * 10 + ss;
        memset(f, 0, sizeof(f));
        int sq;
        for (long long j = io; j; j /= 10) f[j % 10] = 1;
        for (int j = 0; j < 10; j++)
          if (f[j]) {
            sq = j;
            break;
          }
        if (ok(io) < k) sq = 0;
        for (int j = 0; j < sp; j++) io = io * 10 + sq;
        cout << io << endl;
        break;
      }
    }
  }
}

```