#include <cstdio>

int main(void)
{
	int hand[5];
	int i;
	int g, c, p;
	
	while (1){
		g = c = p = false;
		
		scanf("%d", &hand[0]);
		if (hand[0] == 0) break;
		g |= (hand[i] == 1);
		c |= (hand[i] == 2);
		p |= (hand[i] == 3);
		
		for (i = 1; i < 5; i++){
			scanf("%d", &hand[i]);
			g |= (hand[i] == 1);
			c |= (hand[i] == 2);
			p |= (hand[i] == 3);
		}
		
		int a = g + c + p;
		if ((a == 3) || (a == 1)){
			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 (c && p){
			for (i = 0; i < 5; i++){
				if (hand[i] == 2) 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");
			}
		}
	}
	
	return (0);
}