#include <bits/stdc++.h>
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
const int mo = 998244353;
const int maxn = 2e5 + 10;
int t = 1, n, m, k;
long long num1[maxn], num2[maxn];
int cnt1 = 0, cnt2 = 0;
void dfs(int step, long long num, int x, int y) {
  num2[cnt2++] = num;
  if (step == 10) return;
  dfs(step + 1, num * 10 + x, x, y);
  dfs(step + 1, num * 10 + y, x, y);
}
int main() {
  scanf("%d", &t);
  for (int i = 1; i <= 9; i++) {
    long long num = 0;
    for (int j = 1; j <= 10; j++) {
      num *= 10;
      num += i;
      num1[cnt1++] = num;
    }
  }
  sort(num1, num1 + cnt1);
  cnt2 = cnt1;
  memcpy(num2, num1, sizeof(num1));
  for (int i = 0; i <= 8; i++)
    for (int j = i + 1; j <= 9; j++) {
      dfs(0, 0, i, j);
    }
  sort(num2, num2 + cnt2);
  while (t--) {
    scanf("%d%d", &n, &k);
    if (k == 1) {
      printf("%d\n", num1[lower_bound(num1, num1 + cnt1, n) - num1]);
    } else {
      printf("%d\n", num2[lower_bound(num2, num2 + cnt2, n) - num2]);
    }
  }
}

### Prompt

In Cpp, your task is to solve 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>
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
const int mo = 998244353;
const int maxn = 2e5 + 10;
int t = 1, n, m, k;
long long num1[maxn], num2[maxn];
int cnt1 = 0, cnt2 = 0;
void dfs(int step, long long num, int x, int y) {
  num2[cnt2++] = num;
  if (step == 10) return;
  dfs(step + 1, num * 10 + x, x, y);
  dfs(step + 1, num * 10 + y, x, y);
}
int main() {
  scanf("%d", &t);
  for (int i = 1; i <= 9; i++) {
    long long num = 0;
    for (int j = 1; j <= 10; j++) {
      num *= 10;
      num += i;
      num1[cnt1++] = num;
    }
  }
  sort(num1, num1 + cnt1);
  cnt2 = cnt1;
  memcpy(num2, num1, sizeof(num1));
  for (int i = 0; i <= 8; i++)
    for (int j = i + 1; j <= 9; j++) {
      dfs(0, 0, i, j);
    }
  sort(num2, num2 + cnt2);
  while (t--) {
    scanf("%d%d", &n, &k);
    if (k == 1) {
      printf("%d\n", num1[lower_bound(num1, num1 + cnt1, n) - num1]);
    } else {
      printf("%d\n", num2[lower_bound(num2, num2 + cnt2, n) - num2]);
    }
  }
}

```