description: 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
solution: #include <bits/stdc++.h>
  using namespace std;
  void __print(long long x) { cerr << x; }
  void __print(long double x) { cerr << x; }
  void __print(char x) { cerr << '\'' << x << '\''; }
  void __print(const char *x) { cerr << '\"' << x << '\"'; }
  void __print(const string &x) { cerr << '\"' << x << '\"'; }
  void __print(bool x) { cerr << (x ? "true" : "false"); }
  template <typename T, typename V>
  void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
  }
  template <typename T>
  void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
  }
  void _print() { cerr << "]\n"; }
  template <typename T, typename... V>
  void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
  }
  long long cpow(long long a, long long b, long long M) {
    long long ans = 1;
    while (b) {
      if (b & 1) ans = ans * a % M;
      b /= 2;
      a = a * a % M;
    }
    return ans;
  }
  const long long MOD = 1e9 + 7;
  const long long N = 2e5 + 5;
  template <typename ForwardIterator, typename T>
  ForwardIterator first_less_than(ForwardIterator first, ForwardIterator last,
                                  T value) {
    auto it = std::upper_bound(first, last, value);
    return (it == first ? last : --it);
  }
  long long ss(string s) {
    long long temp = 1, ans = 0;
    reverse(s.begin(), s.end());
    for (long long i = 0; i < s.size(); i++) {
      long long z = s[i] - '0';
      ans += temp * z;
      temp *= 10;
    }
    return ans;
  }
  int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    long long t;
    cin >> t;
    long long T = t;
    set<long long> s1, s2;
    for (long long i = 0; i <= 9; i++) {
      for (long long j = 0; j <= 9; j++) {
        for (long long dig = 1; dig <= 10; dig++) {
          if (i == j) continue;
          string s;
          for (long long zz = 0; zz < dig; zz++) s.push_back('.');
          for (long long temp = 0; temp < (long long)(1 << dig); temp++) {
            for (long long bit = 0; bit < dig; bit++) {
              if (temp & (long long)(1 << bit))
                s[bit] = (char)('0' + i);
              else
                s[bit] = (char)('0' + j);
            }
            long long val = ss(s);
            s2.insert(val);
          }
        }
      }
    }
    for (long long i = 0; i <= 9; i++) {
      {
        string s = "0000000000";
        {
          for (long long bit = 9; bit >= 0; bit--) {
            s[bit] = (char)('0' + i);
            long long val = ss(s);
            s1.insert(val);
          }
        }
      }
    }
    while (t--) {
      long long n, k;
      cin >> n >> k;
      auto it = s1.lower_bound(n);
      long long a = *it;
      long long b = 1e13;
      if (k == 2) {
        auto it1 = s2.lower_bound(n);
        b = *it1;
      }
      cout << min(a, b) << "\n";
    }
  }
  