#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;


int main(){

	int member[5],check[4],num_of_val;

	while(true){

		for(int i = 1; i <= 3; i++)check[i] = 0;

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

		if(member[0] == 0)break;
		else{
			check[member[0]]++;
		}

		for(int i = 1; i < 5; i++){
			scanf("%d",&member[i]);
			check[member[i]]++;
		}

		num_of_val = 0;

		for(int i = 1; i <= 3; i++){
			if(check[i] > 0)num_of_val++;
		}

		if(num_of_val == 3 || num_of_val == 1){
			printf("3\n3\n3\n3\n3\n");
		}else{
			if(check[1] > 0 && check[2] > 0){	//??°?????¨?????§???
				for(int i = 0; i < 5; i++){
					if(member[i] == 1)printf("1\n");
					else{
						printf("2\n");
					}
				}
			}else if(check[1] > 0 && check[3] > 0){	//??°?????¨??????
				for(int i = 0; i < 5; i++){
					if(member[i] == 3)printf("1\n");
					else{
						printf("2\n");
					}
				}
			}else{ //?????§?????¨??????
				for(int i = 0; i < 5; i++){
					if(member[i] == 2)printf("1\n");
					else{
						printf("2\n");
					}
				}
			}
		}
	}
    return 0;
}