#include <stdio.h>
int main()
{
	int hund[5],hundkind[4];
	int winkind[5],win,lose;
	bool chek;

	scanf("%d",&hund[0]);

	while(hund[0] != 0){
		for(int i = 1; i < 5; i++){
			scanf("%d",&hund[i]);
		}

		for(int i = 1; i < 4; i++){
			hundkind[i] = 0;
		}
		chek = false;
		for(int i = 0; i < 5; i++){
			hundkind[ hund[i] ]++;
		}

		if(hundkind[1] != 0 && hundkind[2] != 0 && hundkind[3] != 0){
			for(int i = 0; i < 5; i++){
				winkind[i] = 3;
				chek = false;
			}
		}
		else if(hundkind[1] == 5 || hundkind[2] == 5 || hundkind[3] == 5){
			for(int i = 0; i < 5; i++){
				winkind[i] = 3;
				chek = false;
			}
		}
		else if(hundkind[3] != 0 && hundkind[1] != 0){
			win = 3;
			lose = 1;
			chek = true;
		}
		else{
			for(int i = 1; i < 3; i++){
				if(hundkind[i] != 0 && hundkind[i+1] != 0){
					win = i;
					lose = i+1;
					chek = true;
				}
			}
		}
		for(int i = 0; i < 5 && chek; i++){
			if(hund[i] == win){
				winkind[i] = 1;
			}
			else{
				winkind[i] = 2;
			}
		}

		for(int i = 0; i < 5; i++){
			printf("%d\n",winkind[i]);
		}

		scanf("%d",&hund[0]);
	}

	return 0;
}