//rock//
#include <iostream>

using namespace std;

int main(){
	int hand[5];
	bool handbe[3];
	bool isdraw;
	while (1){
		isdraw = false;
		handbe[0] = false;
		handbe[1] = false;
		handbe[2] = false;

		cin >> hand[0];
		if (hand[0] == 0)break;
		handbe[hand[0]-1] = true;
		for (int i = 1; i < 5; ++i){
			cin >> hand[i];
			handbe[hand[i]-1] = true;
		}

		if (handbe[0]){//あいこ判定
			if (handbe[1] == handbe[2])isdraw = true;
		} else{
			if (handbe[1] != handbe[2])isdraw = true;
		}

		if (isdraw){
			for (int i = 0; i < 5; ++i){
				cout << "3" << endl;
			}
			continue;
		}

		for (int j = 0; j < 3; ++j){
			if (handbe[j] && handbe[(j+1)%3]){
				for (int i = 0; i < 5; ++i){
					cout << (hand[i] == j+1 ? 1 : 2) << endl;
				}
			}
		}
	}

	return 0;
}