
#include <cstdio>

using namespace std;

int main( void )
{

	int hand_list[5];
	int hands = 0;
	while( 1 )
	{
		for( int i = 0; i < 5; ++i )
		{
			scanf( "%d", &hand_list[i] );
			if( hand_list[0] == 0 )
				goto end_0205;
			hands |= 1 << (hand_list[i] - 1);
		}

		for( int i = 0; i < 5; ++i )
		{
			if( hands == 0x0001 || hands == 0x0002 || hands == 0x0004 || hands == 0x0007 )
			{
				puts( "3" );
			}
			else
			{
				if( hands == 0x0003 )
				{
					if( hand_list[i] == 2 ) puts( "2" );
					else puts( "1" );
				}
				else if( hands == 0x0006 )
				{
					if( hand_list[i] == 3 ) puts( "2" );
					else puts( "1" );
				}
				else if( hands == 0x0005 )
				{
					if( hand_list[i] == 1 ) puts( "2" );
					else puts( "1" );
				}
			}
		}
	}

end_0205:
	return 0;

}