#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int a[5], tmp, *b;
	
	while(1){
		cin >> tmp;
		if(tmp == 0){
			break;
		}
		a[0] = tmp;
		b = (int *)calloc(4, sizeof(int));
		b[tmp]++;
		for(int i = 1; i < 5; i++){
			cin >> tmp;
			a[i] = tmp;
			b[tmp]++;
		}
		
		if((b[1] != 0 && b[2] != 0 && b[3] != 0) || (b[1] == 0 && b[1] == b[2]) || (b[2] == 0 && b[2] == b[3]) || (b[3] == 0 && b[1] == b[3])){
			for(int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
			free(b);
			continue;
		} else if(b[1] == 0){
			tmp = 2;
		} else if(b[2] == 0){
			tmp = 3;
		} else {
			tmp = 1;
		}
		
		for(int i = 0; i < 5; i++){
			cout << ((a[i] == tmp)? "1" : "2") << endl;
		}
		free(b);
	}
	
	return 0;
}