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;
  const long long N = 300005, M = 1005;
  long long t, n, k;
  string s;
  vector<long long> v[2];
  void fun(long long val, long long f1, long long f2) {
    if (val > 2000000000) {
      return;
    }
    v[1].push_back(val);
    fun(val * 10 + f1, f1, f2);
    fun(val * 10 + f2, f1, f2);
  }
  void fun2(long long val, long long f1) {
    if (val > 2000000000) {
      return;
    }
    v[0].push_back(val);
    fun2(val * 10 + f1, f1);
  }
  int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> t;
    for (int i = 1; i <= 9; i++) {
      fun2(i, i);
    }
    sort(v[0].begin(), v[0].end());
    for (auto u : v[0]) v[1].push_back(u);
    for (int i = 0; i <= 9; i++) {
      for (int j = i + 1; j <= 9; j++) {
        if (i > 0) fun(i, i, j);
        fun(j, i, j);
      }
    }
    sort(v[1].begin(), v[1].end());
    while (t--) {
      cin >> n >> k;
      k--;
      long long high = (long long)v[k].size() - 1, low = 0, mid, ans = 0;
      while (high >= low) {
        mid = (high + low) / 2;
        if (n <= v[k][mid]) {
          ans = v[k][mid];
          high = mid - 1;
        } else
          low = mid + 1;
      }
      cout << ans << "\n";
    }
    return 0;
  }
  