#include<iostream>
using namespace std;

int main(){
	while(1){
		int n, hand[3] = {0};
		cin >> n;
		if(n == 0) break;
		hand[n - 1] = 1;
		for(int i = 1;i < 5;i++){
			int h;
			cin >> h;
			hand[h - 1] |= 1 << i;
		}
		for(int i = 0;i < 5;i++){
			int h = 0;
			while(!(hand[h] & 1 << i)) h++;
			int ans = 0;
			if(hand[(h + 1) % 3]) ans += 1;
			if(hand[(3 + h - 1) % 3]) ans += 2;
			if(ans == 0) ans = 3;
			cout << ans << endl;
		}
	}
		
	return 0;
}