#include <iostream>
using namespace std;

int main(){
	int a[5];
	while(cin >> a[0],a[0]){
		int cnt[3] = {};
		for(int i = 1;i < 5;i++) cin >> a[i];
		for(int i = 0;i < 5;i++) cnt[a[i] - 1]++;
		if((cnt[0] && cnt[1] && cnt[2]) || cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5){
			for(int i = 0;i < 5;i++) cout << 3 << endl;
			continue;
		}
		for(int i = 0;i < 5;i++){
			if(!cnt[0]){
				if(a[i] == 2) cout << 1 << endl;
				else cout << 2 << endl;
			}
			else if(!cnt[1]){
				if(a[i] == 3) cout << 1 << endl;
				else cout << 2 << endl;
			}
			else {
				if(a[i] == 1) cout << 1 << endl;
				else cout << 2 << endl;
			}
		}
	}
	return 0;
}