#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void print_aiko()
{
	rep(i, 5) cout << 3 << endl;
}

int main()
{
	int hand[5];
	map<int, int> num;

	while (cin >> hand[0])
	{
		num.clear();
		if (hand[0] == 0) break;
		num[hand[0]]++;

		for (int i = 1; i < 5; i++)
		{
			cin >> hand[i];
			num[hand[i]]++;
		}

		if ((num[1] > 0 && num[2] > 0 && num[3] > 0)
			|| num[1] == 5 || num[2] == 5 || num[3] == 5)
		{
			print_aiko();
			continue;
		}

		//??°??????0???
		if (num[1] == 0)
		{
			num[2] = 1;
			num[3] = 2;
		}
		//?????§??????0???
		else if (num[2] == 0)
		{
			num[1] = 2;
			num[3] = 1;
		}
		else if (num[3] == 0)
		{
			num[1] = 1;
			num[2] = 2;
		}

		rep(i, 5)
		{
			cout << num[hand[i]] << endl;
		}
	}
}