#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int count[3], p[5];
	
	while(true){
		
		for(int i = 0; i < 3; i++){
			count[i] = 0;
		}
		
		cin >> p[0];
		if(p[0] == 0){
			break;
		}
		p[0]--;
		count[p[0]]++;
		
		for(int i = 1; i < 5; i++){
			cin >> p[i];
			p[i]--;
			count[p[i]]++;
		}
		
		int emp = 0;
		
		int win, lose;
		
		for(int i = 0; i < 3; i++){
			if(count[i] == 0){
				win = (i + 1) % 3;
				lose = (i + 2) % 3;
				emp++;
			}
		}
		
		if(emp == 0 || emp == 2){
			for(int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
		}else{
			for(int i = 0; i < 5; i++){
				if(p[i] == win){
					cout << "1" << endl;
				}else{
					cout << "2" << endl;
				}
			}
		}
	}
	
	return 0;
}