#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int one[5];
int te[5];
int han[3];

main(){
	int n;
	
	while(cin>>n){
		if(n==0)break;
		
		for(int i=0;i<5;i++){
			one[i]=te[i]=0;
		}
		
		one[0]=n;
		++te[n];
		
		for(int i=1;i<5;i++){
			cin>>n;
			one[i]=n;
			++te[n];
		}
		
		int hiki=0;
		for(int i=1;i<=3;i++){
			if(te[i]==5)hiki+=10;
		}
		
		for(int i=1;i<=3;i++){
			if(te[i])++hiki;
		}
		
		if(hiki/10 || hiki%10==3){
			for(int i=0;i<5;i++){
				puts("3");
			}
			continue;
		}
		
		if(te[1]==0){
			han[1]=3;
			han[2]=1;
			han[3]=2;
		}else if(te[2]==0){
			han[1]=2;
			han[2]=3;
			han[3]=1;
		}else{
			han[1]=1;
			han[2]=2;
			han[3]=3;
		}
		
		for(int i=0;i<5;i++){
			printf("%d\n",han[one[i]]);
		}
	}
	return 0;
}