#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
	const int n = 5;
	int hand[n];
	while(cin >> hand[0], hand[0]) {
		int ans[5];
		bool flag[4] = {false};
		for(int i = 1; i < n; ++i) {
			cin >> hand[i];
			flag[hand[i]] = true;
		}
		for(int i = 0; i < n; ++i) {
			if(flag[1] && flag[2] && !flag[3]) ans[i] = (hand[i] == 1) ? 1 : 2;
			else if(!flag[1] && flag[2] && flag[3]) ans[i] = (hand[i] == 2) ? 1 : 2;
			else if(flag[1] && !flag[2] && flag[3]) ans[i] = (hand[i] == 3) ? 1 : 2;
			else ans[i] = 3;
			cout << ans[i] << endl;
		}
	}
}