def quest(t): print(*t,flush=True) p,q=map(int,input().split()) if p==4: exit() return p,q def eat_bite(s,t): eat=bite=0 for i in range(4): if s[i] in t: if s[i]==t[i]: eat+=1 else: bite+=1 return eat,bite from itertools import permutations X=[a+b+c+d for a,b,c,d in permutations("0123456789",r=4)] X_len=len(X) F=[1]*(X_len) while True: for i in range(X_len): if F[i]: r=quest(X[i]) break F[i]=0 for j in range(i+1,X_len): if r!=eat_bite(X[i],X[j]): F[j]=0