#include<iostream>
using namespace std;
int a, b, c, d, e, x[4], f;
int main() {
	while (true) {
		x[0] = 0;
		x[1] = 0;
		x[2] = 0;
		x[3] = 0;
		cin >> a;
		if (a == 0) { break; }
		x[a]++;
		cin >> b >> c >> d >> e;
		x[b]++;
		x[c]++;
		x[d]++;
		x[e]++;
		if (x[1] >= 1 && x[2] >= 1 && x[3] >= 1) { cout << '3' << endl << '3' << endl << '3' << endl << '3' << endl << '3' << endl; }
		else if (x[1] >= 5 || x[2] >= 5 || x[3] >= 5) { cout << '3' << endl << '3' << endl << '3' << endl << '3' << endl << '3' << endl; }
		else {
			if (x[2] == 0) {
				if (a == 1) { a = 4; }
				if (b == 1) { b = 4; }
				if (c == 1) { c = 4; }
				if (d == 1) { d = 4; }
				if (e == 1) { e = 4; }
			}
			if (x[1] == 0) { f = 2; }
			if (x[2] == 0) { f = 3; }
			if (x[3] == 0) { f = 1; }
			if (a == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (b == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (c == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (d == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (e == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
		}
	}
	return 0;
}