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

int main(void)
{
	int te[5];
	set<int> check;
	while(cin>>te[0]){
		if(!te[0]) break;
		check.clear();
		for(int i=1; i< 5; i++){
			cin >> te[i];
		}
		for(int i=0; i<5; i++){
			check.insert(te[i]);
		}
		int tmp = 0;
		if(check.size()==2){
			if(check.find(1) == check.end()){
				tmp = -1;
			}else if(check.find(2) == check.end()){
				tmp = -2;
			}
			for(int i=0;i<5;i++){
				if(te[i]+tmp==1){
					cout << "1" << endl;
				}else{
					cout << "2" << endl;
				}
			}
			
		}else{
			for(int i=0;i<5; i++){
				cout <<"3"<< endl;
			}
		}
	}
	return 0;
}