#include <bits/stdc++.h>
using namespace std;
vector<string> res_update(string num, vector<string> possible);
string pick_optimal(vector<string> possible, vector<string> all);
int main() {
  vector<string> possible, all;
  for (int i = 0; i < 10000; i++) {
    string temp = "";
    temp += (i / 1000) % 10 + '0';
    temp += (i / 100) % 10 + '0';
    temp += (i / 10) % 10 + '0';
    temp += (i) % 10 + '0';
    if (temp[0] != temp[1] && temp[0] != temp[2] && temp[0] != temp[3] &&
        temp[1] != temp[2] && temp[1] != temp[3] && temp[2] != temp[3]) {
      possible.push_back(temp);
    }
    all.push_back(temp);
  }
  string num = "0011";
  possible = res_update(num, possible);
  while (possible.size() > 1) {
    num = pick_optimal(possible, all);
    possible = res_update(num, possible);
  }
  if (possible.size() == 1) {
    cout << possible.front() << endl;
  }
  return 0;
}
string pick_optimal(vector<string> possible, vector<string> all) {
  string minMax;
  int least = 10000000;
  for (string s : all) {
    bool digits[10] = {false};
    for (int i = 0; i < 4; i++) {
      digits[s[i] - (int)'0'] = true;
    }
    vector<vector<int>> tot(5, vector<int>(5, 0));
    int temp = -11;
    for (string &poss : possible) {
      int b = 0, c = 0;
      for (int i = 0; i < 4; i++) {
        if (digits[poss[i] - (int)'0']) c++;
        if (poss[i] == s[i]) b++;
      }
      c = c - b;
      tot[b][c]++;
    }
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        temp = max(temp, tot[i][j]);
      }
    }
    if (temp < least) {
      least = temp;
      minMax = s;
    } else if (temp == least && count(possible.begin(), possible.end(), s)) {
      minMax = s;
    }
  }
  return minMax;
}
vector<string> res_update(string num, vector<string> possible) {
  cout << num << endl;
  int cow, bull;
  cin >> bull >> cow;
  if (bull == 4 && cow == 0) {
    return {};
  }
  vector<string> output;
  bool temp[10] = {false};
  for (char c : num) {
    temp[c - '0'] = true;
  }
  for (string &i : possible) {
    int b = 0, c = 0;
    for (int j = 0; j < 4; j++) {
      if (temp[i[j] - '0']) {
        c++;
        if (i[j] == num[j]) b++;
      }
    }
    c = c - b;
    if (c == cow && b == bull) {
      output.push_back(i);
    }
  }
  return output;
}
