#include <bits/stdc++.h>
using namespace std;

int main(){
	int hand[5], result[5];
	int rock, scissors, paper, win;
	
	while(cin >> hand[0], hand[0]){
		cin >> hand[1] >> hand[2] >> hand[3] >> hand[4];
		
		rock = scissors = paper = 0;
		for(int i = 0; i < 5; ++i){
			switch(hand[i]){
				case 1: ++rock; break;
				case 2: ++scissors; break;
				case 3: ++paper; break;
				default: break;
			}
		}
		
		if(rock == 5 || scissors == 5 || paper == 5 || (rock > 0 && scissors > 0 && paper > 0)){
			for(int i = 0; i < 5; ++i) result[i] = 3;
		}else{
			if(rock == 0) win = 2;
			else if(scissors = 0) win = 3;
			else win = 1;
			
			for(int i = 0; i < 5; ++i){
				if(hand[i] == win) result[i] = 1;
				else result[i] = 2;
			}
		}
		
		for(int i = 0; i < 5; ++i) cout << result[i] << endl;
	}
	
	return 0;
}