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

int main(){
	int a,b,c,d,e;
	while(cin >> a >> b >> c >> d >> e && a ){
		a--,b--,c--,d--,e--;
		set<int> v;
		v.insert(a);
		v.insert(b);
		v.insert(c);
		v.insert(d);
		v.insert(e);
		if( v.size() == 3 || v.size() == 1){
			for(int i = 0 ; i < 5 ; i++)
			 cout << 3 << endl;
		}else{
			set<int>::iterator it = v.begin();
			set<int>::iterator it2 = it;
			it++;
			int W[3] = {};
			if( (*it2) == ((*it)+1)%3 ){
				W[*it] = 1;
				W[*it2] = 2;
			}else{
				W[*it] = 2;
				W[*it2] = 1;
			}
			cout << W[a] << endl;
			cout << W[b] << endl;
			cout << W[c] << endl;
			cout << W[d] << endl;
			cout << W[e] << endl;
		}
	}
}