#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &p) {
  os << "[";
  for (auto &it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
template <class T>
bool umin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool umax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
void stugs() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int n, k;
string str;
long long int fool[12][1030][2];
long long int dp(long long int i, long long int mask, long long int d,
                 string &ans) {
  if (__builtin_popcount(mask) > k) return 0;
  if (i >= n) return 1;
  if (fool[i][mask][d] != -1) return fool[i][mask][d];
  char lb = '0';
  if (d == 1) lb = str[i];
  for (char j = lb; j <= '9'; j++) {
    long long int x = 0;
    if (d == 1 and j == lb) x = 1;
    if (dp(i + 1, mask | (1 << (j - '0')), x, ans)) {
      ans = j + ans;
      return fool[i][mask][d] = 1;
    }
  }
  return fool[i][mask][d] = 0;
}
void solve() {
  cin >> str >> k;
  n = str.length();
  string ans = "";
  memset(fool, -1, sizeof fool);
  dp(0, 0, 1, ans);
  cout << ans << endl;
}
int32_t main() {
  stugs();
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}

### Prompt

Your challenge is to write 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;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &p) {
  os << "[";
  for (auto &it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
template <class T>
bool umin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool umax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
void stugs() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int n, k;
string str;
long long int fool[12][1030][2];
long long int dp(long long int i, long long int mask, long long int d,
                 string &ans) {
  if (__builtin_popcount(mask) > k) return 0;
  if (i >= n) return 1;
  if (fool[i][mask][d] != -1) return fool[i][mask][d];
  char lb = '0';
  if (d == 1) lb = str[i];
  for (char j = lb; j <= '9'; j++) {
    long long int x = 0;
    if (d == 1 and j == lb) x = 1;
    if (dp(i + 1, mask | (1 << (j - '0')), x, ans)) {
      ans = j + ans;
      return fool[i][mask][d] = 1;
    }
  }
  return fool[i][mask][d] = 0;
}
void solve() {
  cin >> str >> k;
  n = str.length();
  string ans = "";
  memset(fool, -1, sizeof fool);
  dp(0, 0, 1, ans);
  cout << ans << endl;
}
int32_t main() {
  stugs();
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}

```