#include "iostream"
using namespace std;

int LinearSearch(int x, int S[], int N) {
	S[N] = x;
	for (int i = 0; ; i++) {
		if (S[i] == x)
			if (i < N) {
				return 1;
			}
			else
				return 0;
	}
}

int main()
{
	int h[6] = { 1 };
	int w;
	while (1) {
		for (int i = 0; i < 5; i++) {
			cin >> h[i];
			if (h[i] == 0)
				break;
		}
		if (LinearSearch(0, h, 5))
			break;
		if (LinearSearch(1, h, 5))
			if (LinearSearch(2, h, 5)) {
				if (LinearSearch(3, h, 5))
					w = 4;
				else
					w = 1;
			}
			else {
				if (LinearSearch(3, h, 5))
					w = 3;
				else w = 4;
			}
		else if (LinearSearch(2, h, 5)) {
			if (LinearSearch(3, h, 5))
				w = 2;
			else
				w = 4;
		}
		else
			w = 4;
		for (int i = 0; i < 5; i++) {
			if (w == 4)
				cout << 3 << endl;
			if (w == 1)
				if (h[i] == 1)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			if (w == 2)
				if (h[i] == 2)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			if (w == 3)
				if (h[i] == 3)
					cout << 1 << endl;
				else
					cout << 2 << endl;
		}
	}
}