Title: Rock-Paper-Scissors

A group of 5 friends decided to play rock-paper-scissors. In this game, there are three hand signs: rock, paper, and scissors. Rock beats scissors, scissors beats paper, and paper beats rock. If all players show the same hand sign or if all three signs are shown, it's a tie.

Create a program that takes the hand signs of the 5 players as input and outputs the result of each player's match. Rock is represented by 1, scissors by 2, and paper by 3. The result is represented by 1 for win, 2 for loss, and 3 for a tie, and should be output in the order of input.

Input:
Multiple datasets are given as input, ending with a single line containing zero. Each dataset is in the format:
h1
h2
h3
h4
h5
where hi represents the hand sign (1, 2, or 3) of the i-th person.

The number of datasets does not exceed 200.

Output:
For each dataset, output the results of the 5 players' matches. Each line should contain the result (1, 2, or 3) for the i-th player.

Sample Input:
1
2
3
2
1
1
2
2
2
1
0

Output for the Sample Input:
3
3
3
3
3
1
2
2
2
1

# Buggy version:
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")
    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)

# Fixed version:
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)

# Buggy version:
# -*- coding: utf-8 -*-
#import pdb;    pdb.set_trace()
import sys

def solv(v):
    w = set(v)
    if len(w)==1 or len(w)==3:
        d={1:2, 2:2, 3:2}
    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()
    
if __name__ == '__main__':
    main()



# Fixed version:
# -*- coding: utf-8 -*-
#import pdb;    pdb.set_trace()
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()
    
if __name__ == '__main__':
    main()

# Buggy version:
# AOJ 0205: Rock, Paper, Scissors
# Python3 2018.6.25 bal4u

h = [0]*5
while True:
	try:
		for i in range(5): h[i] = int(input())
	except: break
	print(type(h), h)
	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')


# Fixed version:
# AOJ 0205: Rock, Paper, Scissors
# Python3 2018.6.25 bal4u

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')