#include <cstdio>

#define CH_G(a, g) (a == 1) ? true : g
#define CH_C(a, c) (a == 2) ? true : c
#define CH_P(a, p) (a == 3) ? true : p


int main(void)
{
	int hand[5];
	int i;
	bool g, c, p;
	
	while (1){
		g = c = p = false;
		
		scanf("%d", &hand[0]);
		if (hand[0] == 0) break;
		g = CH_G(hand[i], g);
		c = CH_C(hand[i], c);
		p = CH_P(hand[i], p);
		
		for (i = 1; i < 5; i++){
			scanf("%d", &hand[i]);
			g = CH_G(hand[i], g);
			c = CH_C(hand[i], c);
			p = CH_P(hand[i], p);
		}
		
		if ((g && c && p) || (g && !c && !p) || (!g && c && !p) || (!g && !c && p)){
			for (i = 0; i < 5; i++) printf("3\n");
		}
		else if (g && c){
			for (i = 0; i < 5; i++){
				if (hand[i] == 1) printf("1\n");
				else printf("2\n");
			}
		}
		else if (g && p){
			for (i = 0; i < 5; i++){
				if (hand[i] == 3) printf("1\n");
				else printf("2\n");
			}
		}
		else if (c && p){
			for (i = 0; i < 5; i++){
				if (hand[i] == 2) printf("1\n");
				else printf("2\n");
			}
		}
	}
	
	return (0);
}