#include <bits/stdc++.h>
using namespace std;
bool can[10000];
char g[10000][10000];
int num[10000][4], a[10000][25];
int get(int i) {
  for (int j = 0; j <= 3; j++) {
    cout << num[i][j];
  }
  cout << endl;
  fflush(stdout);
  int p, q;
  cin >> p >> q;
  return 5 * p + q;
}
int getg(int i, int j) {
  int p = 0, q = 0, a[4], b[4];
  for (int k = 3; k >= 0; k--) {
    a[k] = num[i][k];
    b[k] = num[j][k];
    if (a[k] == b[k]) p++;
  }
  for (int k = 0; k <= 3; k++)
    for (int l = 0; l <= 3; l++) q += (a[k] == b[l]);
  return 4 * p + q;
}
bool testifcan(int i) {
  for (int j = 0; j <= 3; j++)
    for (int k = j + 1; k <= 3; k++)
      if (num[i][j] == num[i][k]) return false;
  return true;
}
int main() {
  for (int i = 0; i <= 9; i++)
    for (int j = 0; j <= 9; j++)
      for (int k = 0; k <= 9; k++)
        for (int l = 0; l <= 9; l++) {
          int i1 = i * 1000 + j * 100 + k * 10 + l;
          num[i1][0] = i;
          num[i1][1] = j;
          num[i1][2] = k;
          num[i1][3] = l;
          can[i1] = testifcan(i1);
        }
  for (int i = 0; i <= 9999; i++)
    for (int j = i; j <= 9999; j++)
      if (can[j] && can[j]) g[j][i] = g[i][j] = char(getg(i, j));
  for (int k = 1; k <= 7; k++) {
    double minx = 1000000;
    int mini = 0, n;
    memset(a, 0, sizeof(a));
    for (int i = 0; i <= 9999; i++)
      if (can[i])
        for (int j = i; j <= 9999; j++)
          if (can[j]) {
            a[i][g[i][j]]++;
            a[j][g[i][j]]++;
          }
    for (int i = 0; i <= 9999; i++)
      if (can[i]) {
        double x = 0;
        for (int j = 0; j <= 24; j++)
          if (a[i][j] >= 2) x += a[i][j] * log(a[i][j]);
        if (x < minx) minx = x, mini = i;
      }
    n = get(mini);
    if (n == 20) return 0;
    for (int j = 0; j <= 9999; j++)
      if (g[mini][j] != n) can[j] = 0;
  }
  return 0;
}
