#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int a[5];
	int b[3] = {0};
	cin >> a[0];
	if(a[0] == 0) break;
	b[a[0]-1]++;
	REP(i,4){ 
	    cin >> a[1+i];
	    b[a[1+i]-1]++;
	}
	int c = 0;
	if(b[0] > 0) c++;
	if(b[1] > 0) c++;
	if(b[2] > 0) c++;
	if(c % 2 == 1){
	    REP(i,5) cout << 3 << endl;
	}else if(b[0] == 0){
	    REP(i,5){
		if(a[i] == 2) cout << 1 << endl;
		else cout << 2 << endl;
	    }
	}else if(b[1] == 0){
	    REP(i,5){
		if(a[i] == 3) cout << 1 << endl;
		else cout << 2 << endl;
	    }
	}else{
	    REP(i,5){
		if(a[i] == 1) cout << 1 << endl;
		else cout << 2 << endl;
	    }
	}
    }
    return 0;
}