#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

//aの勝敗  1-win 2-lose 3-draw
int re(int a, int b) {
	int ret;
	switch (a) {
	case 1:
		ret = (b == 1) ? 3 : (b == 2) ? 1 : 2;
		break;
	case 2:
		ret = (b == 1) ? 2 : (b == 2) ? 3 : 1;
		break;
	case 3:
		ret = (b == 1) ? 1 : (b == 2) ? 2 : 3;
		break;
	}
	return ret;
}

int main() {
	while (true) {
		int x; cin >> x;
		if (x == 0)break;
		VI h(5); h[0] = x;
		rep(i, 4)cin >> h[i + 1];

		rep(i, 5) {
			int win = 0, lose = 0, draw = 0;
			rep(j, 5) {
				if (i != j) {
					switch (re(h[i], h[j])) {
					case 1:
						win++; break;
					case 2:
						lose++; break;
					case 3:
						draw++; break;
					}
				}
			}

			int ans;
			if ((win && lose) || (!win && !lose))ans = 3;
			else if (win)ans = 1;
			else ans = 2;
			Cout(ans);
		}
	}
}
