#include <iostream>
using namespace std;

int main() {
	int hn[5];
	int i,j,fl1=0,fl2=0,fl3=0;
	while(1){
		for(i=0;i<5;i++){
			cin >> hn[i];
			if(hn[i]==1) fl1=1;
			if(hn[i]==2) fl2=1;
			if(hn[i]==3) fl3=1;
		}
		if(hn[0]==0) break;
		if((fl1==1 && fl2==1) && fl3==0){
			for(j=0;j<5;j++){
				if(hn[j]==1) cout << "1" << endl;
				if(hn[j]==2) cout << "2" << endl;
			}
		}else if((fl1==1 && fl3==1) && fl2==0){
			for(j=0;j<5;j++){
				if(hn[j]==1) cout << "2" << endl;
				if(hn[j]==3) cout << "1" << endl;
			}
		}else if((fl3==1 && fl2==1) && fl1==0){
			for(j=0;j<5;j++){
				if(hn[j]==2) cout << "1" << endl;
				if(hn[j]==3) cout << "2" << endl;
			}
		}else{
			for(j=0;j<5;j++) cout << "3" << endl;
		}
		fl1=0;
		fl2=0;
		fl3=0;
	}
	return 0;
}