#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k;
int64_t to_i64(string s) {
  int64_t ret = 0;
  for (char ch : s) ret = ret * 10 + (ch - '0');
  return ret;
}
int64_t get(string l, string r) {
  set<char> s;
  string ret = l;
  for (char ch : l) s.insert(ch);
  if (s.size() > k) return INT_MAX;
  if (r.empty()) return to_i64(ret);
  if (r[0] == '9') return INT_MAX;
  auto it = s.upper_bound(r[0]);
  if (it == s.end() && s.size() == k) return INT_MAX;
  if (s.size() < k) s.insert(r[0] + 1);
  ret += *s.upper_bound(r[0]);
  set<char> t = s;
  t.insert('0');
  if (t.size() <= k) s = t;
  while (ret.size() < l.size() + r.size()) ret += *s.begin();
  ;
  return to_i64(ret);
}
void solve(int Case) {
  scanf("%d %d", &n, &k);
  string s = to_string(n);
  ;
  int64_t ans = INT_MAX;
  ans = min(ans, get("", s));
  ans = min(ans, get(s, ""));
  for (int i = 1; i <= s.size() - 1; ++i)
    ans = min(ans, get(s.substr(0, i), s.substr(i, s.size() - i)));
  if (k >= 2) {
    int64_t tmp = 1;
    while (tmp < n) tmp *= 10;
    ans = min(ans, tmp);
  }
  printf("%lld\n", ans);
}
int main() {
  int T = 1;
  scanf("%d", &T);
  for (int t = 1; t <= T; ++t) solve(t);
  return 0;
}

### Prompt

Please create a solution in cpp 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 int N = 1e5 + 5;
int n, k;
int64_t to_i64(string s) {
  int64_t ret = 0;
  for (char ch : s) ret = ret * 10 + (ch - '0');
  return ret;
}
int64_t get(string l, string r) {
  set<char> s;
  string ret = l;
  for (char ch : l) s.insert(ch);
  if (s.size() > k) return INT_MAX;
  if (r.empty()) return to_i64(ret);
  if (r[0] == '9') return INT_MAX;
  auto it = s.upper_bound(r[0]);
  if (it == s.end() && s.size() == k) return INT_MAX;
  if (s.size() < k) s.insert(r[0] + 1);
  ret += *s.upper_bound(r[0]);
  set<char> t = s;
  t.insert('0');
  if (t.size() <= k) s = t;
  while (ret.size() < l.size() + r.size()) ret += *s.begin();
  ;
  return to_i64(ret);
}
void solve(int Case) {
  scanf("%d %d", &n, &k);
  string s = to_string(n);
  ;
  int64_t ans = INT_MAX;
  ans = min(ans, get("", s));
  ans = min(ans, get(s, ""));
  for (int i = 1; i <= s.size() - 1; ++i)
    ans = min(ans, get(s.substr(0, i), s.substr(i, s.size() - i)));
  if (k >= 2) {
    int64_t tmp = 1;
    while (tmp < n) tmp *= 10;
    ans = min(ans, tmp);
  }
  printf("%lld\n", ans);
}
int main() {
  int T = 1;
  scanf("%d", &T);
  for (int t = 1; t <= T; ++t) solve(t);
  return 0;
}

```