#include <iostream>

int main(){
	//紙 3 はさみ 2 石 1
	bool eflag = false;
	while(!eflag){
		int hands[5] = {0}, things[4] = {0};
		for(int i=0;i<5&&!eflag;i++){
			int n;
			std::cin >> n;
			hands[i] = n, things[n]++;
			if(!n)eflag = true;
		}
		if(!eflag){
			int winner = 0;
			//あいこのとき
			if(things[1] && things[2] && things[3])
				winner = -1;
			else if(things[1] && things[2])
				winner = 1;
			else if(things[2] && things[3])
				winner = 2;
			else if(things[1] && things[3])
				winner = 3;
			else
				winner = -1;
			for(int i=0;i<5;i++){
				if(winner < 0)
					std::cout << "3\n";
				else if(hands[i] == winner)
					std::cout << "1\n";
				else
					std::cout << "2\n";
			}
		}
	}
}