#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
bool isdiff(int x) {
  set<int> sp;
  for (int(i) = 0; (i) < (int)(4); (i)++) {
    sp.insert(x % 10);
    x /= 10;
  }
  return sp.size() == 4;
}
int c1[5], c2[5];
bool vis[11];
pair<int, int> ck(int x, int y) {
  for (int(i) = 0; (i) < (int)(4); (i)++) {
    c1[i] = x % 10;
    x /= 10;
  }
  for (int(i) = 0; (i) < (int)(4); (i)++) {
    c2[i] = y % 10;
    y /= 10;
    vis[c2[i]] = 1;
  }
  int a = 0, b = 0;
  for (int(i) = 0; (i) < (int)(4); (i)++)
    if (c1[i] == c2[i]) a++;
  for (int(i) = 0; (i) < (int)(4); (i)++)
    if (c1[i] != c2[i]) {
      if (vis[c1[i]]) b++;
    }
  for (int(i) = 0; (i) < (int)(4); (i)++) vis[c2[i]] = 0;
  return {a, b};
}
int num[5][5];
int ans[10005], tot;
int calDis(int x) {
  memset(num, 0, sizeof num);
  for (int(i) = 1; (i) <= (int)(tot); (i)++) {
    pair<int, int> p = ck(ans[i], x);
    num[p.first][p.second]++;
  }
  int tmp = 0;
  for (int(i) = 0; (i) < (int)(5); (i)++)
    for (int(j) = 0; (j) < (int)(5); (j)++) tmp = max(tmp, num[i][j]);
  return tmp;
}
void fmain(int tid) {
  for (int(i) = 0; (i) < (int)(10000); (i)++)
    if (isdiff(i)) ans[++tot] = i;
  int T = 123;
  while (tot > 1) {
    int mx = (1 << 30);
    if (T == -1)
      for (int(i) = 1; (i) <= (int)(tot); (i)++) {
        int tmp = calDis(ans[i]);
        if (tmp < mx) {
          mx = tmp;
          T = ans[i];
        }
      }
    printf("%04d\n", T);
    fflush(stdout);
    int a, b;
    scanf("%d%d", &a, &b);
    int idx = 0;
    for (int(i) = 1; (i) <= (int)(tot); (i)++) {
      pair<int, int> p = ck(ans[i], T);
      if (p.first == a && p.second == b) ans[++idx] = ans[i];
    }
    tot = idx;
    T = -1;
  }
  printf("%04d\n", ans[1]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
