#include<iostream>
#include<cmath>
using namespace std;
int main() {
	int a[5];
	int b[5];
	while (cin >> a[0]){
		if (a == 0)break;
		else{
			bool b1 = false, b2 = false, b3 = false;
			for (int i = 1; i < 5; i++)
				cin >> a[i];
			for (int i = 0; i < 5; i++){
				if (a[i] == 1)b1 = true;
				else if (a[i] == 2)b2 = true;
				else b3 = true;
			}
			if (b1&&b2&&b3 || b1 && !b2 && !b3 || !b1&&b2 && !b3 || !b1 && !b2&&b3) {
				for (int i = 0; i < 5; i++) {
					b[i] = 3;
				}
			}
			else{
				if (b1 == b2) {
					for (int i = 0; i < 5; i++){
						if (a[i] == 1)b[i] = 1;
						else b[i] = 2;
					}
				}
				else if (b2 == b3) {
					for (int i = 0; i < 5; i++) {
						if (a[i] == 2)b[i] = 1;
						else b[i] = 2;
					}
				}
				else{
					for (int i = 0; i < 5; i++) {
						if (a[i] == 3)b[i] = 1;
						else b[i] = 2;
					}
				}
			}
			for (int i = 0; i < 5; i++) {
				cout << b[i] << endl;
			}
		}
	}
}