#include <iostream>
#include <vector>
#include <set>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.rps", "r", stdin );

	enum { WIN = 1, LOSE = 2, DRAW = 3 };
	enum { ROCK = 0, SISSOR = 1, PAPER = 2};
	int n;
	int i, j;

	while (1){

		vector <int> winlose (5, 0 );
		vector <int> res (5, 0 );
		set <int> hand;

		for (i = 0; i < 5; ++i ){
			cin >> n;

			if (n == 0){
				goto end;
			} // end if

			winlose[i] = n - 1; // 0: rock 1: sissor 2: paper
			hand.insert (winlose[i] );		
		} // end for

		if (hand.size() == 1 || hand.size() == 3 ){
			for (i = 0; i < 5; ++i){
				res[i] = DRAW;
			} // end for
		}else{
			vector <bool> h (3, false );
			set <int>::iterator it = hand.begin();
			for (; it != hand.end(); ++it ){
				h[(*it)] = true;
			} // end for
			for (j = 0; j < 3; ++j){	
				if (!h[j]){	// without hand;
					for (i = 0; i < 5; ++i){
						switch(j){
							case ROCK:
								res[i] = ( winlose[i] == SISSOR ? WIN : LOSE);					break;
							case SISSOR:
								res[i] = ( winlose[i] == PAPER ? WIN : LOSE);					break;
							case PAPER:
								res[i] = ( winlose[i] == ROCK ? WIN : LOSE);					break;
						} // end switch
					} // end for
					break;
				} // end if
			} // end for
		} // end for

		for (i = 0; i < 5; ++i){
			cout << res[i] << endl;
		} // end for
	} // end loop
end:		
	return 0;
}