#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int a[5];
	int b[5];
	while(b[0]=a[0]=in()){
		int i;
		for(i=1;i<5;i++){
			b[i]=a[i]=in();
		}
		sort(a,a+5);
		if(a[0]==a[4]||(1<<a[0]|1<<a[1]|1<<a[2]|1<<a[3]|1<<a[4])==14){
			cout<<3<<endl<<3<<endl<<3<<endl<<3<<endl<<3<<endl;
		}else{
			if(a[0]==1&&a[4]==2){
				for(i=0;i<5;i++){
					if(b[i]==1)cout<<1<<endl;
					else cout<<2<<endl;
				}
			}
			if(a[0]==1&&a[4]==3){
				for(i=0;i<5;i++){
					if(b[i]==1)cout<<2<<endl;
					else cout<<1<<endl;
				}
			}
			if(a[0]==2&&a[4]==3){
				for(i=0;i<5;i++){
					if(b[i]==2)cout<<1<<endl;
					else cout<<2<<endl;
				}
			}
		}
	}
	return 0;
}