#include <cstdio>

using namespace std;

int main()
{
	while (1){
		int hand[5];
		int state = 0;
		
		for (int i = 0; i < 5; i++){
			scanf("%d",hand + i);
			if (hand[i] == 0) return (0);
			state |= (1 << (hand[i] - 1));
		}
		
		if (__builtin_popcount(state) != 2){
			printf("3\n3\n3\n3\n3\n");
		}
		else {
			if (state == 5){
				for (int i = 0; i < 5; i++) printf("%d\n", hand[i] == 1 ? 2 : 1);
			}
			if (state == 6){
				for (int i = 0; i < 5; i++) printf("%d\n", hand[i] == 3 ? 2 : 1);
			}
			if (state == 3){
				for (int i = 0; i < 5; i++) printf("%d\n", hand[i] == 2 ? 2 : 1);
			}
		}
	}
}