#include<iostream>
using namespace std;
int main() {
	int n;
	int out[4] = { false };
	while (cin >> n&&n != 0) {
		int line[5];
		bool used[4] = { false };
		int count = 1;
		used[n] = true;
		line[0] = n;
		for (int i = 1; i < 5; ++i) {
			cin >> line[i];
			if (used[line[i]] == false)++count;
			used[line[i]] = true;
		}
		if (count == 3 || count == 1) {
			for(int i=0;i<5;++i)
			cout << 3 << endl;
		}
		else {
			if (used[1] == false) {
				out[2] = 1;
				out[3] = 2;
			}
			else if (used[2] == false) {
				out[1] = 2;
				out[3] = 1;
			}
			else {
				out[1] = 1;
				out[2] = 2;
			}
			for (int i = 0; i < 5; ++i) {
				cout << out[line[i]] << endl;
			}
		}
	}
	return 0;
}