#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	int h[5], cnt[4];
	
	while (cin >> h[0], h[0]) {
		FOR(i, 1, 5) cin >> h[i];
		
		memset(cnt, 0, sizeof(cnt));
		REP(i, 5) cnt[h[i]]++;
		
		int ans[5];
		int win = -1, lose = -1, draw = 0;
		
		int zero = 0;
		FOR(i, 1, 4) if (cnt[i] > 0) draw++;
		if (draw == 1) draw = 3;
		
		if (draw == 3) {
			REP(i, 5) ans[i] = 3;
		}
		else {
			if (cnt[1] > 0 && cnt[2] > 0) win = 1;
			if (cnt[2] > 0 && cnt[3] > 0) win = 2;
			if (cnt[3] > 0 && cnt[1] > 0) win = 3;			
			REP(i, 5) {
				if (h[i] == win) ans[i] = 1;
				else ans[i] = 2;
			}
		}
		
		REP(i, 5) printf("%d\n", ans[i]);
		
	}
	return 0;
}