import itertools import random import collections def is_finish(x, y): return x == 4 l = list(itertools.permutations(range(10), 4)) while True: ans_cand = collections.defaultdict(list) query = l[0] for cand in l: x, y = sum(a == b for a, b in zip(l, query)), sum(a in cand for a in l) ans_cand[(x, x-y)].append(cand) print(*query) X, Y = map(int, input().split()) if X == 4: exit(0) else: l = ans_cand[(x, y)]