#include <iostream>

using namespace std;

int main() {
	int data[5];
	while (cin >> data[0]) {
		if (data[0] == 0) {
			break;
		}
		cin >> data[1] >> data[2] >> data[3] >> data[4];
		int jan[3] = {0};
		for (int i = 0; i < 5; i++) {
			jan[data[i]-1]++;
		}
		if ((jan[0] > 0 && jan[1] > 0 && jan[2] > 0) || jan[0] == 5 || jan[1] == 5 || jan[2] == 5) {
			for (int i = 0; i < 5; i++) {
				cout << 3 << endl;
			}
		} else if (jan[0] == 0) {
			for (int i = 0; i < 5; i++) {
				if (data[i] == 2) {
					cout << 1 << endl;
				} else {
					cout << 2 << endl;
				}
			}
		} else if (jan[1] == 0) {
			for (int i = 0; i < 5; i++) {
				if (data[i] == 3) {
					cout << 1 << endl;
				} else {
					cout << 2 << endl;
				}
			}
		} else if (jan[2] == 0) {
			for (int i = 0; i < 5; i++) {
				if (data[i] == 1) {
					cout << 1 << endl;
				} else {
					cout << 2 << endl;
				}
			}
		}
	}
	return 0;
}