#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
#include<map>
#include<string>
using namespace std;

int main(){
	while(true){
		int hand[5], res[3];
		bool latte[3] = {};
		for(int i = 0; i < 5; i++){
			cin >> hand[i];
			if(hand[i] == 0) return 0;
			hand[i]--;
			latte[hand[i]] = true;
		}
		for(int i = 0; i < 3; i++){
			if( latte[ (i+1)%3 ] && !latte[ (i+2)%3 ] ) res[i] = 1;
			else if( latte[ (i+2)%3 ] && !latte[ (i+1)%3 ] ) res[i] = 2;
			else res[i] = 3;
		}
		for(int i = 0; i < 5; i++){
			printf("%d\n", res[ hand[i] ] );
		}
	}
	return 0;
}