#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	while(1){
		int d[5]={},kd[4]={},c=0;
		cin>>d[0];
		if(d[0]==0) break;
		rep(i,1,5) cin>>d[i];
		rep(i,0,5) if(kd[d[i]]==0) kd[d[i]]++;
		rep(i,1,4) if(kd[i]) c++;
		//o(c);
		if(c==1||c==3) rep(i,0,5) o(3);
		else if(kd[1]==1&&kd[2]==1){
			rep(i,0,5){
				if(d[i]==1) o(1);
				else o(2);
			}
		}else if(kd[2]==1&&kd[3]==1){
			rep(i,0,5){
				if(d[i]==2) o(1);
				else o(2);
			}
		}else if(kd[3]==1&&kd[1]==1){
			rep(i,0,5){
				if(d[i]==3) o(1);
				else o(2);
			}
		}
	}
}