I decided to play rock-paper-scissors with a group of five good friends. Rock-paper-scissors has three hands: goo, choki, and par. If the game between goo and choki is a match between goo and choki, goo is "winning" and choki is "losing". , Par and Goo have the rule that Par is "winning" and Goo is "losing". If everyone has the same hand, or if all of Goo, Choki, and Par come out, it will be "Aiko".

Create a program that inputs the hands of five rock-paper-scissors players and outputs the wins and losses of each person. Rock-paper-scissors hands are represented by the numbers 1 for goo, 2 for choki, and 3 for par. Win / loss is represented by a number of 1, "win" is 1, "los" is 2, and "Aiko" is 3, and they are output according to the input order.



Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:


h1
h2
h3
h4
h5


The i-th line is given the i-th hand hi (1, 2 or 3).

The number of datasets does not exceed 200.

Output

Outputs the wins and losses of 5 players for each input dataset. Output the win / loss (1, 2 or 3) of the i-th person on the i-line.

Example

Input

1
2
3
2
1
1
2
2
2
1
0


Output

3
3
3
3
3
1
2
2
2
1

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
d = {1: 2, 2: 3, 3: 1}
while True:
	h = int(input())
	if h == 0:
		break
	h = [h] + [int(input()) for _ in range(4)]
	if len(set(h)) == 3 or len(set(h)) == 1:
		print(*[3] * 5, sep='\n')
		continue
	for c in h:
		print([2, 1][d[c] in h])


while 1:
	a = int(input())
	if a == 0:
		break
	a = [a] + [int(input()) for _ in range(4)]
	r = a.count(1)
	s = a.count(2)
	p = 5 - r - s
	if [r, s, p].count(0) == 1:
		if r and s:
			w = 1
		elif r and p:
			w = 3
		else:
			w = 2
		[print([2, 1][w == x]) for x in a]
	else:
		print('3\n' * 5, end='')


datas = [0] * 5
while 1:
	try:
		lens = [0] * 3
		status = [0] * 3
		for i in range(0, 5):
			datas[i] = int(input())
			lens[datas[i] - 1] += 1
		if lens[0] > 0 and lens[1] > 0 and (lens[2] > 0) or (lens[0] == 5 or lens[1] == 5 or lens[2] == 5):
			for i in range(0, 5):
				print(3)
		else:
			if lens[0] > 0:
				status[1] = 2
				status[2] = 1
			if lens[1] > 0:
				status[0] = 1
				status[2] = 2
			if lens[2] > 0:
				status[0] = 2
				status[1] = 1
			for i in range(0, 5):
				print(status[datas[i] - 1])
	except:
		break


def judge(h, hands):
	if h == '1':
		if '2' in hands:
			if '3' not in hands:
				return 1
			else:
				return 3
		elif '2' not in hands:
			if '3' not in hands:
				return 3
			else:
				return 2
	elif h == '2':
		if '3' in hands:
			if '1' not in hands:
				return 1
			else:
				return 3
		elif '3' not in hands:
			if '1' not in hands:
				return 3
			else:
				return 2
	elif '1' in hands:
		if '2' not in hands:
			return 1
		else:
			return 3
	elif '1' not in hands:
		if '2' not in hands:
			return 3
		else:
			return 2
while True:
	hands = []
	for _ in range(5):
		h = input()
		if h == '0':
			exit()
		else:
			hands.append(h)
	for h in hands:
		print(judge(h, hands))


win = [0, 2, 3, 1]
lose = [0, 3, 1, 2]
while True:
	exist = [False for i in range(4)]
	h = [0 for i in range(5)]
	h[0] = int(input())
	exist[h[0]] = True
	if h[0] == 0:
		break
	for i in range(1, 5):
		h[i] = int(input())
		exist[h[i]] = True
	for i in range(5):
		if exist[win[h[i]]] and (not exist[lose[h[i]]]):
			print(1)
		elif not exist[win[h[i]]] and exist[lose[h[i]]]:
			print(2)
		else:
			print(3)


a = []
while True:
	n = int(input())
	if n == 0:
		break
	a.append(n)
	if len(a) == 5:
		uni = set(a)
		if len(uni) == 2 and 1 in uni and (2 in uni):
			for b in a:
				print(2 if b == 2 else 1)
		elif len(uni) == 2 and 2 in uni and (3 in uni):
			for b in a:
				print(2 if b == 3 else 1)
		elif len(uni) == 2 and 3 in uni and (1 in uni):
			for b in a:
				print(2 if b == 1 else 1)
		else:
			for _ in range(5):
				print(3)
		a = []


while True:
	line = []
	line.append(int(input()))
	if line[0] == 0:
		break
	for _ in range(4):
		line.append(int(input()))
	se = set(line)
	if len(se) == 1 or len(se) == 3:
		for _ in range(5):
			print('3')
	else:
		if sum(se) == 3:
			for i in line:
				if i == 1:
					print('1')
				else:
					print('2')
		if sum(se) == 4:
			for i in line:
				if i == 3:
					print('1')
				else:
					print('2')
		if sum(se) == 5:
			for i in line:
				if i == 2:
					print('1')
				else:
					print('2')


from sys import stdin
readline = stdin.readline
(R, S, P) = (1, 2, 3)
(W, L, D) = (1, 2, 3)
rps = {(R, S, P): {R: D, S: D, P: D}, (R, S): {R: W, S: L}, (S, P): {S: W, P: L}, (R, P): {P: W, R: L}, (R,): {R: D}, (S,): {S: D}, (P,): {P: D}}
while True:
	hands = []
	hands.append(int(readline()))
	if hands[0] == 0:
		break
	for _ in range(4):
		hands.append(int(readline()))
	hands_set = tuple(sorted(set(hands)))
	for h in hands:
		print(rps[hands_set][h])


def judge(h, hset):
	rest = hset - {h}
	if len(rest) in (0, 2):
		return 3
	if h % 3 + 1 in rest:
		return 1
	else:
		return 2
while True:
	h1 = int(input())
	if h1 == 0:
		break
	hlst = []
	hset = set()
	hlst.append(h1)
	hset.add(h1)
	for _ in range(4):
		h = int(input())
		hlst.append(h)
		hset.add(h)
	for h in hlst:
		print(judge(h, hset))


while True:
	h1 = int(input())
	if h1 == 0:
		break
	h = [h1, *map(int, (input() for _ in [0] * 4))]
	s = set(h)
	if len(s) % 2 == 1:
		print(*[3] * 5, sep='\n')
	else:
		result = [0, 0, 0, 0]
		if 1 in s and 2 in s:
			(result[1], result[2]) = (1, 2)
		elif 2 in s and 3 in s:
			(result[2], result[3]) = (1, 2)
		else:
			(result[1], result[3]) = (2, 1)
		print(*(result[n] for n in h), sep='\n')


while True:
	has = [False, False, False, False]
	n = input()
	if n == '0':
		break
	te = []
	te.append(n)
	has[int(n)] = True
	for adf in range(4):
		n = input()
		has[int(n)] = True
		te.append(n)
	if has[1] and has[2] and has[3]:
		for qwer in range(5):
			print(3)
	elif te[1] == te[2] and te[2] == te[3] and (te[3] == te[4]) and (te[0] == te[4]):
		for asdd in range(5):
			print(3)
	elif not has[3]:
		for g in range(5):
			if te[g] == '1':
				print('1')
			else:
				print('2')
	elif not has[2]:
		for g in range(5):
			if te[g] == '3':
				print('1')
			else:
				print('2')
	else:
		for g in range(5):
			if te[g] == '2':
				print('1')
			else:
				print('2')


while True:
	h = int(input())
	if h == 0:
		break
	dataset = [h] + [int(input()) for _ in range(4)]
	if len(set(dataset)) == 3 or len(set(dataset)) == 1:
		print(*[3] * 5, sep='\n')
		continue
	for data in dataset:
		if data == 1:
			print(2 if 3 in dataset else 1)
		elif data == 2:
			print(2 if 1 in dataset else 1)
		else:
			print(2 if 2 in dataset else 1)


import sys
from sys import stdin
input = stdin.readline

def main(args):
	while True:
		hands = [0] * 5
		hands[0] = int(input())
		if hands[0] == 0:
			break
		hands[1] = int(input())
		hands[2] = int(input())
		hands[3] = int(input())
		hands[4] = int(input())
		if 1 in hands and 2 in hands and (3 in hands):
			for _ in range(5):
				print(3)
		elif hands.count(hands[0]) == 5:
			for _ in range(5):
				print(3)
		else:
			for h in hands:
				if h + 1 in hands or (h == 3 and 1 in hands):
					print(1)
				else:
					print(2)
main(sys.argv[1:])


while 1:
	hands = []
	h = int(input())
	if h == 0:
		break
	hands.append(h)
	for _ in range(4):
		h = int(input())
		hands.append(h)
	h_uni = list(set(hands))
	if len(h_uni) != 2:
		for _ in range(5):
			print(3)
		continue
	h_uni.sort()
	if h_uni[0] == 1 and h_uni[1] == 2:
		for h in hands:
			if h == 1:
				print(1)
			else:
				print(2)
	elif h_uni[0] == 1 and h_uni[1] == 3:
		for h in hands:
			if h == 1:
				print(2)
			else:
				print(1)
	else:
		for h in hands:
			if h == 2:
				print(1)
			else:
				print(2)


while True:
	h = int(input())
	if h == 0:
		break
	h = [h] + [int(input()) for _ in range(4)]
	if len(set(h)) == 3 or len(set(h)) == 1:
		print(*[3] * 5, sep='\n')
		continue
	d = {1: 2, 2: 3, 3: 1}
	for c in h:
		print([2, 1][d[c] in h])


while True:
	L = []
	H = []
	for _ in range(5):
		c = int(input())
		if c == 0:
			exit()
		L.append(c)
	h = set(L)
	if len(h) in [1, 3]:
		for _ in range(5):
			H.append(3)
	else:
		r = list(set([1, 2, 3]) - h)[0]
		if r == 1:
			w = 2
		elif r == 2:
			w = 3
		else:
			w = 1
		for i in L:
			if i == w:
				H.append(1)
			else:
				H.append(2)
	for i in H:
		print(i)


while True:
	h = int(input())
	if h == 0:
		break
	h = [h] + [int(input()) for _ in range(4)]
	if len(set(h)) == 3 or len(set(h)) == 1:
		print(*['3'] * 5, sep='\n')
		continue
	for c in h:
		if c == 1:
			print('1' if 2 in h else '2')
		elif c == 2:
			print('1' if 3 in h else '2')
		else:
			print('1' if 1 in h else '2')


import sys, math, os
PYDEV = os.environ.get('PYDEV')
if PYDEV == 'True':
	sys.stdin = open('sample-input.txt', 'rt')
while True:
	try:
		game = [int(input()) for _ in range(5)]
	except EOFError:
		break
	if 1 in game and 2 in game:
		w = 1
	elif 1 in game:
		w = 3
	else:
		w = 2
	if len(set(game)) != 2:
		for g in game:
			print(3)
	else:
		for g in game:
			print(1 if g == w else 2)


while True:
	h1 = int(input())
	if h1 == 0:
		break
	h = [h1] + [int(input()) for _ in range(4)]
	if len(set(h)) == 1 or len(set(h)) == 3:
		print(*[3] * 5, sep='\n')
		continue
	for hi in h:
		print([2, 1][hi % 3 + 1 in h])


while True:
	try:
		a = [int(input()) for i in range(5)]
	except:
		break
	if 1 in a and 2 in a and (3 in a) or a.count(a[0]) == 5:
		for i in range(5):
			print(3)
	elif not 3 in a:
		for b in a:
			if b == 1:
				print(1)
			else:
				print(2)
	elif not 2 in a:
		for b in a:
			if b == 1:
				print(2)
			else:
				print(1)
	else:
		for b in a:
			if b == 2:
				print(1)
			else:
				print(2)


import sys

def solv(v):
	w = set(v)
	if len(w) == 1 or len(w) == 3:
		d = {1: 3, 2: 3, 3: 3}
	elif 1 in w and 2 in w:
		d = {1: 1, 2: 2}
	elif 2 in w and 3 in w:
		d = {2: 1, 3: 2}
	else:
		d = {3: 1, 1: 2}
	return list(map(lambda x: d[x], v))

def main():
	if True:
		fh = sys.stdin
	else:
		fh = open('vol2_0205.txt', 'r')
	try:
		while True:
			te = []
			for _ in range(5):
				x = int(fh.readline().strip())
				if x == 0:
					raise Exception
				te.append(x)
			b = solv(te)
			for i in b:
				print(i)
	except Exception:
		1
	fh.close()
main()


def check_aiko(arr):
	if all((arr[0] == a for a in arr)):
		return True
	rps = [1, 2, 3]
	for t in rps:
		if t not in arr:
			return False
	return True

def check_v(arr):
	rps = {}
	o = []
	for t in arr:
		if t not in rps:
			rps[t] = 0
	if 1 in rps.keys() and 2 in rps.keys():
		(rps[1], rps[2]) = (1, 2)
	elif 2 in rps.keys() and 3 in rps.keys():
		(rps[2], rps[3]) = (1, 2)
	elif 1 in rps.keys() and 3 in rps.keys():
		(rps[3], rps[1]) = (1, 2)
	for n in arr:
		o.append(rps.get(n))
	return o

def algorithm():
	g = []
	out = []
	while True:
		inp = int(input())
		if inp == 0:
			break
		g.append(inp)
		if len(g) == 5:
			if check_aiko(g):
				out = [3] * 5
			else:
				out = check_v(g)
			for o in out:
				print(o)
			g.clear()
			out.clear()

def main():
	algorithm()
main()


h = [0] * 5
while True:
	try:
		for i in range(5):
			h[i] = int(input())
	except:
		break
	if len(set(h)) == 1 or len(set(h)) == 3:
		print(*[3] * 5, sep='\n')
		continue
	ans = [1] * 5
	for i in range(5):
		if h[i] == 1:
			ans[i] += h.count(3) > 0
		elif h[i] == 2:
			ans[i] += h.count(1) > 0
		else:
			ans[i] += h.count(2) > 0
	print(*ans, sep='\n')