#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a;
	while(cin>>a,a){
		vector<int>in(5);
		in[0]=a;
		rep(i,4)cin>>in[i+1];
		bool h[3]={0};
		rep(i,5)in[i]--;
		rep(i,5)h[in[i]]=true;
		int sum=h[0]+h[1]+h[2];
		if(sum==3||sum==1){
			rep(i,5)cout<<3<<endl;
			continue;
		}
		if(!h[0]){
			rep(i,5)if(in[i]==1)cout<<1<<endl;
			else cout<<2<<endl;
		}else if(!h[1]){
			rep(i,5)if(in[i]==2)cout<<1<<endl;
			else cout<<2<<endl;
		}else if(!h[2]){
			rep(i,5)if(in[i]==0)cout<<1<<endl;
			else cout<<2<<endl;
		}
	}
}