#include <bits/stdc++.h>
using namespace std;
void print(long long t) { cerr << t; }
void print(string t) { cerr << t; }
void print(char t) { cerr << t; }
void print(long double t) { cerr << t; }
void print(double t) { cerr << t; }
void print(unsigned long long t) { cerr << t; }
template <class T, class V>
void print(pair<T, V> p);
template <class T>
void print(vector<T> v);
template <class T>
void print(set<T> v);
template <class T, class V>
void print(map<T, V> v);
template <class T>
void print(multiset<T> v);
template <class T, class V>
void print(pair<T, V> p) {
  cerr << "{";
  print(p.first);
  cerr << ",";
  print(p.second);
  cerr << "}";
}
template <class T>
void print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    print(i);
    cerr << " ";
  }
  cerr << "]";
}
const long long inf = 0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void zz() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
long long f(long long n, long long k) {
  string s = to_string(n);
  long long m = s.size();
  long long p = 0;
  long long d = 0;
  set<long long> st;
  for (long long i = 0; i < m; i++) {
    st.insert(s[i] - '0');
    if (st.size() > k) break;
    d += 1;
    p = p * 10 + s[i] - '0';
  }
  if (d == m) return p;
  p = p * 10 + s[d] - '0' + 1;
  for (long long i = d + 1; i < m; i++) {
    p *= 10;
  }
  return f(p, k);
}
void slv() {
  long long n, k;
  cin >> n >> k;
  long long ans = f(n, k);
  cout << ans << endl;
}
int32_t main() {
  zz();
  long long t = 1;
  cin >> t;
  while (t--) {
    slv();
  }
}

### 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;
void print(long long t) { cerr << t; }
void print(string t) { cerr << t; }
void print(char t) { cerr << t; }
void print(long double t) { cerr << t; }
void print(double t) { cerr << t; }
void print(unsigned long long t) { cerr << t; }
template <class T, class V>
void print(pair<T, V> p);
template <class T>
void print(vector<T> v);
template <class T>
void print(set<T> v);
template <class T, class V>
void print(map<T, V> v);
template <class T>
void print(multiset<T> v);
template <class T, class V>
void print(pair<T, V> p) {
  cerr << "{";
  print(p.first);
  cerr << ",";
  print(p.second);
  cerr << "}";
}
template <class T>
void print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    print(i);
    cerr << " ";
  }
  cerr << "]";
}
const long long inf = 0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void zz() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
long long f(long long n, long long k) {
  string s = to_string(n);
  long long m = s.size();
  long long p = 0;
  long long d = 0;
  set<long long> st;
  for (long long i = 0; i < m; i++) {
    st.insert(s[i] - '0');
    if (st.size() > k) break;
    d += 1;
    p = p * 10 + s[i] - '0';
  }
  if (d == m) return p;
  p = p * 10 + s[d] - '0' + 1;
  for (long long i = d + 1; i < m; i++) {
    p *= 10;
  }
  return f(p, k);
}
void slv() {
  long long n, k;
  cin >> n >> k;
  long long ans = f(n, k);
  cout << ans << endl;
}
int32_t main() {
  zz();
  long long t = 1;
  cin >> t;
  while (t--) {
    slv();
  }
}

```