#include<iostream>

using namespace std;

void Aiko ( void ) ;
void Shori ( int ) ;

int jan[4] = {0};
int mem[5];

int main () {
	
	while (cin >> mem[0],mem[0]){
		int hoge = 0;
		for ( int i = 0; i < 4; i++ ) {
			jan[i] = 0;
		}
		
		jan[mem[0]]++;
		for ( int i = 1; i < 5; i++ ) {
			cin >> mem[i];
			jan[mem[i]]++;
		}
		for ( int i = 1; i < 4; i++ ) {
			if ( jan[i] )	{
				hoge++;
			}
		}
		if ( hoge != 2 ){
			Aiko ();
		} else {
			for ( int i = 1; i < 4; i++ ) {
				if ( !jan[i] ) {
					if ( i == 1 ) {
						Shori (2);
					} else if ( i == 2 ) {
						Shori (3);
					} else {
						Shori (1);
					}
					break;
				}
			}
		}
	}
	return 0;
}

void Aiko () {
	for ( int i = 0; i < 5; i++ ) {
		cout << "3" << endl;
	}
}

void Shori (int Win) {
	for ( int i = 0; i < 5; i++ ) {
		if ( mem[i] == Win ) {
			cout << "1" << endl;
		} else {
			cout << "2" << endl;
		}
	}
}