#include <iostream>

#define NMAX (5)

using namespace std;

int hand[NMAX];

int main() {
	int result;
	for(int i; cin >> i && i!= 0;) {
		hand[0] = i;
		cin >> hand[1] >> hand[2] >> hand[3] >> hand[4];
		result = 0;
		for(int j=0; j<5; j++) {
			switch(hand[j]) {
			case 1:
				result |= 1;
				break;
			case 2:
				result |= 2;
				break;
			case 3:
				result |= 4;
			}
		}
		int typenum = 0;
		for(int res = result; res; res >>= 1)
			typenum++;
		
		switch(typenum) {
		case 1:
		case 3:
			for(int k=0; k<5; k++)
				cout << 3 << endl;
			break;
		case 2:
			if(result & 1) {
				for(int k=0; k<5; k++)
					if(hand[k] == 2)
						cout << 1 << endl;
					else
						cout << 2 << endl;				
			}else if(result & 2) {
				for(int k=0; k<5; k++)
					if(hand[k] == 3)
						cout << 1 << endl;
					else
						cout << 2 << endl;								
			}else{
				for(int k=0; k<5; k++)
					if(hand[k] == 1)
						cout << 1 << endl;
					else
						cout << 2 << endl;								
			}
			break;
		default:
			cerr << "err" << endl;
		}
	}	
	return 0;
}