#include <iostream>
using namespace std;

int main()
{
	int h[5];

	cin >> h[0];

	while (h[0]) {
		for (int i = 1; i < 5; i++)
			cin >> h[i];

		int f[3] = { 0, 0, 0 }, r[5] = { 0, 0, 0, 0, 0 };

		for (int i = 0; i < 5; i++)
			f[h[i] - 1] = 1;
		
		if ((f[0] + f[1] + f[2]) % 2 == 1)
			for (int i = 0; i < 5; i++)
				r[i] = 3;
		else {
			for (int j = 0; j < 3; j++) {
				if (!f[j]) {
					for (int i = 0; i < 5; i++) {
						if (h[i] == (j + 1) % 3 + 1)
							r[i] = 1;
						else
							r[i] = 2;
					}
				}
			}
		}

		for (int i = 0; i < 5; i++)
			cout << r[i] << endl;

		cin >> h[0];
	}

	return 0;
}
