#include<iostream>

using namespace std;

int main(){
	int player[5] = {0};
	int cnt = 0;

	while(1){
		int flag = -1;

		cin >> flag;

		if(flag == 0)break;
		cnt++;

		player[0] = flag;

		cin >> player[1] >> player[2] >> player[3] >> player[4];
	}

	for(int i=0;i<cnt-1;i++)
		for(int j=0;j<5;j++)
			cout << '3' << endl;

	bool gu = false,pa = false,ty = false;

	for(int i=0;i<5;i++){
		if(player[i] == 1)gu = true;
		else if(player[i] == 2)ty = true;
		else if(player[i] == 3)pa = true;
	}

	for(int i=0;i<5;i++){
		if(gu && pa){
			if(player[i] == 3)cout << '1' << endl;
			else cout << '2' << endl;
		}
		else if(gu && ty){
			if(player[i] == 1)cout << '1' << endl;
			else cout << '2' << endl;
		}
		else if(ty && pa){
			if(player[i] == 2)cout << '1' << endl;
			else cout << '2' << endl;
		}
	}
	return 0;
}