#include<iostream>
#include<utility>
#include<vector>
using namespace std;

int main() {
	typedef pair<int, int>P;

	int a;
	while (cin >> a, a) {
		vector<int>rv;
		vector<int>sv;
		vector<int>pv;

		if (a == 1)rv.push_back(1);
		else if (a == 2)sv.push_back(1);
		else pv.push_back(1);

		for (int i = 2;i <= 5;i++) {
			int b;
			cin >> b;
			if (b == 1)rv.push_back(i);
			else if (b == 2)sv.push_back(i);
			else pv.push_back(i);
		}

		int r = 0,p = 0,s = 0;

		if (rv.empty() && !sv.empty() && !pv.empty()) {
			s = 1;
			p = -1;
		}
		else if (!rv.empty() && sv.empty() && !pv.empty()) {
			r = -1;
			p = 1;
		}
		else if (!rv.empty() && !sv.empty() && pv.empty()) {
			r = 1;
			s = -1;
		}

		int k[5];
		int a = rv.size();
		for (int i = 0;i < a;i++) {
			if (r == 1) k[rv[i] - 1] = 1;
			else if (r == -1) k[rv[i] - 1] = 2;
			else k[rv[i] - 1] = 3;
		}

		int b = sv.size();
		for (int i = 0;i < b;i++) {
			if (s == 1)k[sv[i] - 1] = 1;
			else if (s == -1)k[sv[i] - 1] = 2;
			else k[sv[i] - 1] = 3;
		}

		int c = pv.size();
		for (int i = 0;i < c;i++) {
			if (p == 1)k[pv[i] - 1] = 1;
			else if (p == -1)k[pv[i] - 1] = 2;
			else k[pv[i] - 1] = 3;
		}

		for (int i = 0;i < 5;i++) {
			cout << k[i] << endl;
		}
	}
	return 0;
}