#include <stdio.h>
#include <iostream>

using namespace std;

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