import sys import random k=sorted([i for i in["{0:0>4}".format(i)for i in range(10000)]if len(set(i))==4],key=lambda x:random.random()) for _ in range(5040): print k[0] sys.stdout.flush() s=raw_input() if s=="4 0": break elif s=="0 0": k=[i for i in k if not(i[0]in k[0]or i[1]in k[0]or i[2]in k[0]or i[3]in k[0])] elif s=="0 4": k=[i for i in k if i[0]in k[0]and i[1]in k[0]and i[2]in k[0]and i[3]in k[0]] else: k=[i for i in k if i[0]in k[0]or i[1]in k[0]or i[2]in k[0]or i[3]in k[0]] k.pop(0) #print len(k) if len(k)==0: break