#include<bits/stdc++.h>

using namespace std;

int Person[5], Judge[4];


void show() {
	for (int i = 0; i < 5; ++i) {
		cout << Person[i] << endl;
	}
}

bool isDraw() {
	
	if (Judge[1] == 5 || Judge[2] == 5 || Judge[3] == 5) {
		return true;
	}
	if (Judge[1] != 0 && Judge[2] != 0 && Judge[3] != 0) {
		return true;
	}
	return false;
}

void judge() {
	int i, a, b;

	a = Person[0];
	for (i = 1; i < 5; ++i) {
		if (Person[i] != a) {
			b = Person[i];
			break;
		}
	}
	//cout << a << " " << b << endl;
	if ( (a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1) ) {
		Person[0] = 1;
	}
	if ( (a == 1 && b == 3) || (a == 2 && b == 1) || (a == 3 && b == 2) ) {
		Person[0] = 2;
	}
	for (int j = 1; j < 5; ++j) {
		if (Person[j] == a) {
			Person[j] = Person[0];
		} else{
			Person[j] = (Person[0] == 1) ? 2 : 1;
		}
	}
}

int main() {

	while (cin >> Person[0], Person[0]) {
		memset(Judge, 0, sizeof(Judge));
		++Judge[Person[0]];
		for (int i = 1; i < 5; ++i) {
			cin >> Person[i];
			++Judge[Person[i]];
		}
		if (isDraw()) {
			fill(Person, Person + 5, 3);
			show();
			continue;
		}
		judge();
		show();
	}

	return 0;
}
