#include <iostream>

using namespace std;

void solve()
{
	int hand[5];
	while(cin >> hand[0], hand[0])
	{
		for(int i = 1; i < 5; ++i)
		{
			cin >> hand[i];
		}
		int rockCount = 0;
		int paperCount = 0;
		int scissorsCount = 0;
		for(int i = 0; i < 5; ++i)
		{
			if(hand[i] == 1)
			{
				++rockCount;
			}
			else if(hand[i] == 2)
			{
				++scissorsCount;
			}
			else
			{
				++paperCount;
			}
		}
		if((rockCount && scissorsCount && paperCount)
			|| (rockCount == 0 && scissorsCount == 0) 
			|| (scissorsCount == 0 && paperCount == 0) 
			|| (paperCount == 0 && rockCount == 0))
		{
			for(int i = 0; i < 5; ++i)
			{
				cout << "3" << endl;
			}
		}
		else if(rockCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 2)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
		else if(scissorsCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 3)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
		else if(paperCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 1)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}