#include<iostream>
using namespace std;

int main(){
	int hand[5];
	int d[3]={2,3,1};
	while(1){
		cin >> hand[0];
		if(hand[0] == 0) break;
		int cou[4] = {0};
		cou[hand[0]]++;
		for(int i=1;i<=4;i++){
			cin >> hand[i];
			cou[hand[i]]++;
		}
		int tmp=0,temp=0;
		for(int i=1;i<=3;i++){
			if(cou[i] == 5){
				tmp = 1;
				break;
			}
			else if(cou[i] == 0){
				temp = i;
			}
		}
		for(int i=0;i<5;i++){
			if(tmp == 1 || temp == 0) cout << "3" << endl;
			else {
				if(hand[i] == d[temp-1]) cout << "1" << endl;
				else cout << "2" << endl;
			}
		}
	}
}