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

using namespace std;

int main(int argc, char const* argv[])
{
	vector<int> data;
	data.resize( 5 );

	while( cin >> data[0] && data[0] != 0 ){
		for( int i = 1;i < 5;i++ ) cin >> data[i];
		int rock = count( data.begin(), data.end(), 1 );
		int paper = count( data.begin(), data.end(), 3 );
		int scissors = count( data.begin(), data.end(), 2 );

		if( rock && paper && scissors ){
			for( int i = 0;i < 5;i++ ) cout << 3 << endl;
			continue;
		}

		if( rock == 0 ){
			for( unsigned int i = 0;i < data.size();i++ ){
				if( data[i] == 2 ) cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}

		if( paper == 0 ){
			for( unsigned int i = 0;i < data.size();i++ ){
				if( data[i] == 1 ) cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}

		if( scissors == 0 ){
			for( unsigned int i = 0;i < data.size();i++ ){
				if( data[i] == 3 ) cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
	}
	return 0;
}