#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
struct INT {
  int a[4];
  INT() { a[0] = a[1] = a[2] = a[3] = 0; }
  INT(int x) {
    for (int i = 0; i < 4; i++) a[3 - i] = x % 10, x /= 10;
  }
  int operator[](int x) { return a[x]; }
  int operator*(INT x) {
    int ans = 0;
    for (int i = 0; i < 4; i++)
      if (x[i] == a[i]) ans++;
    return ans;
  }
  int operator/(INT x) {
    int ans = 0;
    for (int i = 0; i < 4; i++) {
      if (x[i] == a[i]) continue;
      for (int j = 0; j < 4; j++)
        if (x[i] == a[j]) {
          ans++;
          break;
        }
    }
    return ans;
  }
  bool operator==(INT x) {
    bool ans = true;
    for (int i = 0; i < 4; i++)
      if (a[i] != x[i]) ans = false;
    return ans;
  }
  bool operator<(INT x) {
    for (int i = 0; i < 4; i++)
      if (a[i] == x[i])
        continue;
      else if (a[i] < x[i])
        return true;
      else
        return false;
    return false;
  }
  bool operator>(INT x) {
    for (int i = 0; i < 4; i++)
      if (a[i] == x[i])
        continue;
      else if (a[i] > x[i])
        return true;
    return false;
  }
  void print() {
    for (int i = 0; i < 4; i++) cout << a[i];
    cout << endl;
  }
};
vector<INT> nums;
void generate() {
  set<INT> XX;
  for (int i = 0; i < 1e4; i++) {
    INT x = INT(i);
    map<int, bool> ww;
    for (int i = 0; i < 4; i++) ww[x[i]] = true;
    if (ww.size() == 4) nums.push_back(x);
  }
}
int check(INT x, int c, int d) {
  int ans = 0;
  int ww[10];
  for (auto w : nums) {
    int c1 = x * w, d1 = x / w;
    if (c == c1 && d == d1) ans++;
  }
  return ans;
}
INT find() {
  int mn = INF;
  INT ans = INT(0);
  for (int t = 0; t < min(248, (int)nums.size()); t++) {
    INT x = nums[t];
    int mx = 0;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4 - i; j++) mx = max(mx, check(x, i, j));
    if (mn > mx) mn = mx, ans = x;
  }
  return ans;
}
void rm(INT x, int a, int b) {
  vector<int> R;
  for (auto it = nums.begin(); it != nums.end(); it++)
    if (x / *it != b || x * *it != a) R.push_back(it - nums.begin());
  for (auto it = R.rbegin(); it != R.rend(); it++)
    nums.erase(nums.begin() + *it);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  generate();
  int seed = time(0);
  srand(seed);
  cerr << seed << endl;
  while (nums.size()) {
    INT s = find();
    s.print();
    int a, b;
    cin >> a >> b;
    if (a == 4 && b == 0) return 0;
    rm(s, a, b);
  }
  return 0;
}
