// 0205
#include <iostream>
using namespace std;

int main(){
	while(1){
		int j[5], rps[3] = {0};

		cin>>j[0];
		if(j[0] == 0)
			break;
		
		for(int i=1;i<5;i++)
			cin>>j[i];

		for(int i=0;i<5;i++)
			rps[j[i]-1]++;

		if((rps[0] != 0) && (rps[1] != 0) && (rps[2] != 0)){
			for(int i=0;i<5;i++)
				j[i] = 3;
		}else if((rps[0] == 5) || (rps[1] == 5) || (rps[2] == 5)){
			for(int i=0;i<5;i++)
				j[i] = 3;
		}else if(rps[0] == 0){
			for(int i=0;i<5;i++)
				if(j[i] == 2)
					j[i] = 1;
				else
					j[i] = 2;
		}else if(rps[1] == 0){
			for(int i=0;i<5;i++)
				if(j[i] == 3)
					j[i] = 1;
				else
					j[i] = 2;
		}

		for(int i=0;i<5;i++)
			cout<<j[i]<<endl;
	}

	return 0;
}