#include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int exist(int a[5], int n)
{
	for (int i = 0; i < 5; i++)
	{
		if (a[i] == n)
			return n*n;
	}
	return 0;
}

int r3(int a[5])
{
	int c = 0;
	for (int i = 1; i < 4; i++)
	{
		c += exist(a, i);
	}
	if (c == 5 || c == 10 || c == 13)
		return c;
	return -1;
}


int main()
{
	int a[5];
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] && a[0] != 0)
	{
		int p = r3(a);
		if (p == -1)
		{
			for (int i = 0; i < 5; i++)
				cout << 3 << endl;
		}
		else
		{
			if (p == 5)
			{
				for (int i = 0; i < 5; i++)
					cout << a[i] << endl;
			}
			else if (p == 10)
			{
				for (int i = 0; i < 5; i++)
					cout << (a[i] - 3) / (-2) + 1 << endl;
			}
			else
				for (int i = 0; i < 5; i++)
					cout << a[i] - 1 << endl;
		}
	}
	
	return 0;
}