#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt")
using namespace std;
const long long INF = 1e18 + 13;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
template <typename T>
std::istream& operator>>(std::istream& in, std::vector<T> vec) {
  for (T& a : vec) in >> a;
  return in;
}
const string SEPARATOR = " ";
template <typename T>
std::ostream& operator<<(std::ostream& out, std::vector<T> vec) {
  for (T& a : vec) out << a << SEPARATOR;
  return out;
}
template <typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U> pr) {
  in >> pr.first >> pr.second;
  return in;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& out, std::pair<T, U> pr) {
  out << pr.first << SEPARATOR << pr.second;
  return out;
}
long long k1sz = 0;
long long nxt = 0;
long long k1[100], k2[1000000];
void solve() {
  long long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << *lower_bound(k1, k1 + k1sz, n);
  } else
    cout << *lower_bound(k2, k2 + nxt, n);
  cout << endl;
}
void rec(string& n, long long k, long long l) {
  k2[nxt++] = stoll(n);
  if (((long long)(n).size()) == 10) return;
  n.push_back((char)(k + '0'));
  rec(n, k, l);
  n.pop_back();
  n.push_back((char)(l + '0'));
  rec(n, k, l);
  n.pop_back();
}
void precalc() {
  for (long long i = 1; i < 10; ++i) {
    string s = "";
    for (long long j = 1; j <= 10; ++j) {
      s.push_back((char)(i + '0'));
      k1[k1sz++] = stoll(s);
    }
  }
  sort(k1, k1 + k1sz);
  string s;
  for (long long i = 1; i < 10; ++i) {
    s.push_back((char)(i + '0'));
    for (long long j = 0; j < 10; ++j) {
      rec(s, i, j);
    }
    s.pop_back();
  }
  sort(k2, k2 + nxt);
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long n = 1;
  cin >> n;
  precalc();
  while (n--) {
    solve();
  }
}

### 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("Ofast,fast-math,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt")
using namespace std;
const long long INF = 1e18 + 13;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
template <typename T>
std::istream& operator>>(std::istream& in, std::vector<T> vec) {
  for (T& a : vec) in >> a;
  return in;
}
const string SEPARATOR = " ";
template <typename T>
std::ostream& operator<<(std::ostream& out, std::vector<T> vec) {
  for (T& a : vec) out << a << SEPARATOR;
  return out;
}
template <typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U> pr) {
  in >> pr.first >> pr.second;
  return in;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& out, std::pair<T, U> pr) {
  out << pr.first << SEPARATOR << pr.second;
  return out;
}
long long k1sz = 0;
long long nxt = 0;
long long k1[100], k2[1000000];
void solve() {
  long long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << *lower_bound(k1, k1 + k1sz, n);
  } else
    cout << *lower_bound(k2, k2 + nxt, n);
  cout << endl;
}
void rec(string& n, long long k, long long l) {
  k2[nxt++] = stoll(n);
  if (((long long)(n).size()) == 10) return;
  n.push_back((char)(k + '0'));
  rec(n, k, l);
  n.pop_back();
  n.push_back((char)(l + '0'));
  rec(n, k, l);
  n.pop_back();
}
void precalc() {
  for (long long i = 1; i < 10; ++i) {
    string s = "";
    for (long long j = 1; j <= 10; ++j) {
      s.push_back((char)(i + '0'));
      k1[k1sz++] = stoll(s);
    }
  }
  sort(k1, k1 + k1sz);
  string s;
  for (long long i = 1; i < 10; ++i) {
    s.push_back((char)(i + '0'));
    for (long long j = 0; j < 10; ++j) {
      rec(s, i, j);
    }
    s.pop_back();
  }
  sort(k2, k2 + nxt);
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long n = 1;
  cin >> n;
  precalc();
  while (n--) {
    solve();
  }
}

```