#include<iostream>
using namespace std;

int judge[4];
int input[5];

int main(){
	while(cin >> input[0], input[0]){
		for(int i=0; i < 4; i++) judge[i] = 0;
		judge[input[0]] = 1;
		for(int i=1; i < 5; i++){
			cin >> input[i];
			judge[input[i]] = 1;
		}

		if(judge[1] && judge[2] && judge[3]) for(int i=0; i < 5; i++) cout << '3' << endl;
		else if(judge[1] && judge[2]){
			for(int i=0; i < 5; i++){
				if(input[i] == 1) cout << '1' << endl;
				else cout << '2' << endl;
			}
		}
		else if(judge[2] && judge[3]){
			for(int i=0; i < 5; i++){
				if(input[i] == 2) cout << '1' << endl;
				else cout << '2' << endl;
			}
		}
		else if(judge[1] && judge[3]){
			for(int i=0; i < 5; i++){
				if(input[i] == 3) cout << '1' << endl;
				else cout << '2' << endl;
			}
		}
		else {
			for(int i=0; i < 5; i++){
				cout << '3' << endl;
			}
		}
	}
}