#include <iostream>
using namespace std;

int main(){
	int hand[5];
	int result[5];
	int r, s, p;
	bool rock, scissors, paper;
	
	
	for(;;){
		rock = scissors = paper = false;
		r = p = s = 0;
		for(int i = 0; i < 5; i++){
			cin >> hand[i];
			if(hand[i] == 0) return 0;
		}
		
		for(int i = 0; i < 5; i++){
			if(hand[i] == 1){
				rock = true;
			}else if(hand[i] == 2){
				scissors = true;
			}else if(hand[i] == 3){
				paper = true;
			}
			
			// あいこではない場合
			
		}
		
		if(rock == true && paper == true){
			r = 2;
			p = 1;
		}else if(rock == true && scissors == true){
			r = 1;
			s = 2;
		}else if(paper = true && scissors == true){
			p = 2;
			s = 1;
		}

		
		if(rock == true && paper == true && scissors == true){ // グーチョキパーすべてが場に出ている場合あいこ
			r = p = s = 3;
		}
		
		for(int i = 0; i < 5; i++){
			if(hand[i] == 1){
				result[i] = r;
			}else if(hand[i] == 2){
				result[i] = s;
			}else if(hand[i] == 3){
				result[i] = p;
				
			}
		}	
		
		for(int i = 0; i < 5; i++){
			cout << result[i] << endl;
		}
	}
	
	return 0;
}