#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int people[6];
	int hand[5];

	while( cin >> people[0] , people[0] )
	{
		for(int i = 1; i <= 4; i++)
		{
			cin >> people[i];
		}

		memset(hand, 0, sizeof(hand));
		
		for(int i = 0; i < 5; i++)
		{
			hand[people[i]]++;
		}

		if(hand[1] && hand[2] && hand[3])
		{
			for(int i = 0; i < 5; i++)
			{
				people[i] = 3;
			}
		}
		else if(hand[1] && hand[2])
		{
			for(int i = 0; i < 5; i++)
			{
				if(people[i] == 1)
				{
					people[i] = 1;
				}
				else
				{
					people[i] = 2;
				}
			}
		}
		else if(hand[2] && hand[3])
		{
			for(int i = 0; i < 5; i++)
			{
				if(people[i] == 2)
				{
					people[i] = 1;
				}
				else 
				{
					people[i] = 2;
				}
			}
		}
		else if(hand[1] && hand[3])
		{
			for(int i = 0; i < 5; i++)
			{
				if(people[i] == 3)
				{
					people[i] = 1;
				}
				else
				{
					people[i] = 2;
				}
			}
		}
		else
		{
			for(int i = 0; i < 5; i++)
			{
				people[i] = 3;
			}
		}

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