a, l = [0, 1, 2, 3], [1, 1, 1, 1] print(a[0], a[1], a[2], a[3]) x = t = int(input()[0]) n, m = 0, 1 while x < 4: n = (n-1)%4 if l[n]: b = a[:] a[n] = (a[n]+1)%10 if a[n] in b: n, m = (n+1)%4, m+1 continue print(a[0], a[1], a[2], a[3]) x = int(input()[0]) if x > t : l[n], t = 0, x elif x < t : a[n], l[n], m = (a[n]-m)%10, 0, 1