import sys def request(s): print s sys.stdout.flush() return raw_input() k=["{0:0>4}".format(i)for i in range(10000)] k=[i for i in k if len(set(i))==4] def l(a,b): r=[0,0] for i in range(4): if a[i] in b: if a[i]==b[i]: r[0]+=1 else: r[1]+=1 return r while 1: t=k.pop() x,y=map(int,request(t).split()) if x==4: break k=[i for i in k if l(t,i)==[x,y]] #print k