#include<iostream>
#include<vector>

using namespace std;

int result[5];

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
	while(cin>>result[0],result[0]){
		bool d = 0;
		bool	hand[3] = {false};
		loop(i,1,5)cin>>result[i];
		rep(i,5)hand[result[i]-1]=true;
		if(!hand[0]&&!hand[1]) d = true;
		else if(!hand[1]&&!hand[2]) d = true;
		else if(!hand[0]&&!hand[2]) d = true;
		if(hand[0]&&hand[1]&&hand[2]||d)
			rep(i,5)cout<<3<<endl;
		else if(!hand[0])
			rep(i,5)
				if(result[i]==2)cout<<1<<endl;
				else cout<<2<<endl;
		else if(!hand[1])
			rep(i,5)
				if(result[i]==3)cout<<1<<endl;
				else cout<<2<<endl;
		else if(!hand[2])
			rep(i,5)
				if(result[i]==1)cout<<1<<endl;
				else cout<<2<<endl;
	}
}