cart = [4,1,4,1,2,1,2,1]

while True:

	try:

		que = list(map(int, input().split()))

		mx,mxcart = 0, "99999999"

		for sp in range(8):

			sm = 0

			for num in range(8):

				if cart[(sp+num)%8] <= que[num]:

					sm += cart[(sp+num)%8]

				else:

					sm += que[num]

			if sm > mx:

				mx = sm

				mxcart = "".join(map(str, cart[sp:]+cart[:sp]))

			elif sm == mx:

				acart = "".join(map(str, cart[sp:]+cart[:sp]))

				if int(mxcart) > int(acart):

					mxcart = acart

		print(" ".join(map(str, mxcart)))

	except:

		break
c = [4,1,4,1,2,1,2,1]

while True:

	try:

		que = list(map(int, input().split()))

		mx,mxc = 0, "99999999"

		for sp in range(8):

			sm = 0

			for num in range(8):

				sm += c[(sp+num)%8] if c[(sp+num)%8] <= que[num] else que[num]

			if sm > mx:

				mx = sm

				mxc = "".join(map(str, c[sp:]+c[:sp]))

			elif sm == mx:

				ac = "".join(map(str, c[sp:]+c[:sp]))

				if int(mxc) > int(ac):

					mxc = ac

		print(" ".join(map(str, mxc)))

	except:

		break
cart = [4, 1, 4, 1, 2, 1, 2, 1]
while True:
    try:
        que = list(map(int, input().split()))
        mx, mxcart = 0, "99999999"
        for sp in range(8):
            sm = 0
            for num in range(8):
                if cart[(sp + num) % 8] <= que[num]:
                    sm += cart[(sp + num) % 8]
                else:
                    sm += que[num]
            if sm > mx:
                mx = sm
                mxcart = "".join(map(str, cart[sp:] + cart[:sp]))
            elif sm == mx:
                acart = "".join(map(str, cart[sp:] + cart[:sp]))
                if int(mxcart) > int(acart):
                    mxcart = acart
        print(" ".join(map(str, mxcart)))
    except:
        break

c = [4, 1, 4, 1, 2, 1, 2, 1]
while True:
    try:
        que = list(map(int, input().split()))
        mx, mxc = 0, "99999999"
        for sp in range(8):
            sm = 0
            for num in range(8):
                sm += c[(sp + num) % 8] if c[(sp + num) % 8] <= que[num] else que[num]
            if sm > mx:
                mx = sm
                mxc = "".join(map(str, c[sp:] + c[:sp]))
            elif sm == mx:
                ac = "".join(map(str, c[sp:] + c[:sp]))
                if int(mxc) > int(ac):
                    mxc = ac
        print(" ".join(map(str, mxc)))
    except:
        break

-cart = [4, 1, 4, 1, 2, 1, 2, 1] +c = [4, 1, 4, 1, 2, 1, 2, 1] -        mx, mxcart = 0, "99999999" +        mx, mxc = 0, "99999999" -                if cart[(sp + num) % 8] <= que[num]: -                    sm += cart[(sp + num) % 8] -                else: -                    sm += que[num] +                sm += c[(sp + num) % 8] if c[(sp + num) % 8] <= que[num] else que[num] -                mxcart = "".join(map(str, cart[sp:] + cart[:sp])) +                mxc = "".join(map(str, c[sp:] + c[:sp])) -                acart = "".join(map(str, cart[sp:] + cart[:sp])) -                if int(mxcart) > int(acart): -                    mxcart = acart -        print(" ".join(map(str, mxcart))) +                ac = "".join(map(str, c[sp:] + c[:sp])) +                if int(mxc) > int(ac): +                    mxc = ac +        print(" ".join(map(str, mxc)))