#include <iostream>
using namespace std;
int main()
{
	int h[5], i, t[3];
	while (cin >> h[0] && h[0])
	{
		t[0] = t[1] = t[2] = 0;
		t[h[0]-1]++;
		for (i = 1; i < 5; i++)
		{
			cin >> h[i];
			t[h[i]-1]++;
		}
		if ((h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4]) || (t[0] > 0 && t[1] > 0 && t[2] > 0))
			for (i = 0; i < 5; i++)
				cout << 3 << endl;
		else
		{
			if (t[0] > 0 && t[1] > 0)
			{
				for (i = 0; i < 5; i++)
				{
					if (h[i] == 1)
						cout << 1 << endl;
					else
						cout << 2 << endl;
				}
			}
			else if (t[1] > 0 && t[2] > 0)
			{
				for (i = 0; i < 5; i++)
				{
					if (h[i] == 2)
						cout << 1 << endl;
					else
						cout << 2 << endl;
				}
			}
			else
			{
				for (i = 0; i < 5; i++)
				{
					if (h[i] == 3)
						cout << 1 << endl;
					else
						cout << 2 << endl;
				}
			}
		}
	}
}