#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<climits>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX

int main(void){
	while(1){
		int a[5];
		scanf("%d",a);
		if(a[0]==0)break;
		int is[3]={};
		rep(i,4){
			scanf("%d",&a[i+1]);
		}
		rep(i,5){
			a[i]--;
			is[a[i]]=1;
		}
		rep(i,5){
			int ans;
			int no = a[i];
			int s=0;
			rep(j,2)if(is[(no+j+1)%3]==1)s+=j+1;
			//printf("    %d\n",s);
			if(s==0 || s==3)ans=3;
			else if(s==1)ans=1;
			else ans=2;
			printf("%d\n",ans);
		}
	}
		
	return 0;
}