from itertools import permutations, filterfalse def judge(a, b): x, y = 0, 0 for i in range(len(a)): if a[i] == b[i]: x += 1 y = 8 - len(set(list(a) + list(b))) - x return x, y def main(): ans = list(permutations("0123456789", 4)) while True: q = ans[0] print(" ".join(q)) x, y = map(int, input().split()) if (x, y) == (4, 0): return else: ans = list(filterfalse(lambda n: judge(n, q) != (x, y), ans)) if __name__ == '__main__': main()