#include<iostream>
#include<vector>
#include<algorithm>

int calc(std::vector<int>&v){

	int cnt = 0;
	std::vector<int>::iterator g, t, p;

	g = std::find(v.begin(), v.end(), 1);
	t = std::find(v.begin(), v.end(), 2);
	p = std::find(v.begin(), v.end(), 3);

	if (g != v.end())cnt++;
	if (t != v.end())cnt++;
	if (p != v.end())cnt++;

	if (cnt == 1 || cnt == 3)return -1;
	else if (cnt == 2){
		if (g == v.end())return 2;
		if (t == v.end())return 3;
		if (p == v.end())return 1;
	}
	return -1;
}

int main(){

	std::vector<int>jan(5);
	while (std::cin >> jan[0], jan[0]){

		std::cin >> jan[1] >> jan[2] >> jan[3] >> jan[4];

		int res = calc(jan);

		if (res == -1){
			for (int i = 0; i < 5; i++){
				std::cout << 3 << std::endl;
			}
		}

		else{
			for (int i = 0; i < 5; i++){
				if (jan[i] == res)std::cout << 1 << std::endl;
				else std::cout << 2 << std::endl;
			}
		}

	}
	return 0;
}