#include<iostream>
#include<vector>

using namespace std;

#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){
	vector<int> inp(5);
	while(cin>>inp[0],inp[0]){
		bool judge[3] = {false};
		loop(i,1,5){
			cin>>inp[i];
			judge[inp[i]-1]=true;
		}
		if(judge[0]&&judge[1]&&judge[2])
			rep(i,5)cout<<3<<endl;
		else if(judge[0]&&judge[1]&&!judge[2])
			rep(j,5)
				if(inp[j]-1==0)	cout<<1<<endl;
				else 						cout<<2<<endl;
		else if(!judge[0]&&judge[1]&&judge[2])
			rep(j,5)
				if(inp[j]-1==1)	cout<<1<<endl;
				else 						cout<<2<<endl;
		else if(judge[0]&&!judge[1]&&judge[2])
			rep(j,5)
				if(inp[j]-1==2)	cout<<1<<endl;
				else 						cout<<2<<endl;
		else
			rep(j,5)cout<<3<<endl;
	}
}