#include <iostream>
#include <cstring>
using namespace std;

int main(void){
	int i,sum,x[5],ans[3];
	bool flg[3];

	while(1){
		memset(flg,0,sizeof(flg));
		for(i=0;i<5;i++){
			cin>>x[i];
			if(x[i] == 0) return 0;
			flg[x[i]-1] = true;
		}

		sum = flg[0] + flg[1] + flg[2];
		if(sum==1 || sum==3){
			for(i=0;i<5;i++) printf("3\n");
		}
		else{
			if(flg[0] && flg[1]){
				ans[0] = 1;
				ans[1] = 2;
			}
			else if(flg[0] && flg[2]){
				ans[0] = 2;
				ans[2] = 1;
			}
			else{
				ans[1] = 1;
				ans[2] = 2;
			}
			for(i=0;i<5;i++){
				printf("%d\n",ans[x[i]-1]);
			}
		}
	}
}