#include <cstdio>

using namespace std;

int main()
{
	for(;;){
		int hist[3] = {0};
		int input[5];
		for(int i=0; i<5; ++i){
			scanf("%d", &input[i]);
			--input[i];
			if(input[i] == -1)
				break;
			hist[input[i]]++;
		}
		if(input[0] == -1)
			break;
		
		for(int i=0; i<5; ++i){
			bool weak = !!hist[(input[i]+1)%3];
			bool strong = !!hist[(input[i]+2)%3];
			printf("%d\n", weak ? (strong ? 3 : 1) : (strong ? 2 : 3));
		}
	}
	return 0;
}