#include<iostream>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;


const int END_OF_INPUT = 0;


int main() {
	int a_n;
	
	while (cin >> a_n && a_n != 0){
		vector<int> m_list;
		m_list.push_back(a_n);

		for (int i = 0; i < 4; ++i){
			cin >> a_n;
			m_list.push_back(a_n);
		}

		int is_even = 0;
		bool rps[3];
		for (int i = 1; i <= 3; ++i){
			vector<int>::iterator cIter = find(m_list.begin(), m_list.end(), i);
			rps[i - 1] = false;
			if (cIter != m_list.end()){
				++is_even;
				rps[i - 1] = true;
			}
		}
		if (is_even == 3 || is_even == 1){
			// even 
			for (int i = 1; i <= 5; ++i){
				cout << "3" << endl;
			}
		}
		else{
			int winner = 0;
			if (rps[0] && rps[1]){
				// グー
				winner = 1;
			}
			else if (rps[1] && rps[2]){
				// ちょき
				winner = 2;
			}
			else if (rps[2] && rps[3]){
				// パー
				winner = 3;
			}

			for (int i = 0; i < 5; ++i){
				if (m_list[i] == winner){
					cout << "1" << endl;
				}
				else{
					cout << "2" << endl;
				}
			}
		}


		

	}
	


}