#include <cstdio>
using namespace std;

bool isdraw(int used)
{
	if(used == (1<<3)-1) return true;
	for(int i=0; i<3; i++)
		if(used == (1<<i)) return true;
		
	return false;
}

int main()
{
	int t;
	while(scanf("%d", &t), t)
	{
		int ar[5], used=0;
		ar[0]=t;
		used|=(1<<(ar[0]-1));
		for(int i=1; i<5; i++)
		{
			scanf("%d", &ar[i]);
			used|=(1<<(ar[i]-1));
		}
		
		for(int i=0; i<5; i++)
		{
			if(isdraw(used)) puts("3");
			else
			{
				if(used&(1<<(ar[i])%3)) puts("1");
				else puts("2");
			}
		}
	}
}