#include<iostream>
using namespace std;

int main(){
	int a[5];
	int b[4];
	while(true){
		b[1] = 0;
		b[2] = 0;
		b[3] = 0;
		for(int i=0; i<5; i++){
			cin >> a[i];
			if(!a[0])
				return 0;
			b[a[i]]++;
		}
		if(b[1] == 5 || b[2] == 5 || b[3] == 5 || (b[1] && b[2] && b[3]))
			for(int i=0; i<5; i++)
				cout << 3 << endl;
		else if(!b[1])
			for(int i=0; i<5; i++){
				if(a[i] == 2)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
		else if(!b[2])
			for(int i=0; i<5; i++){
				if(a[i] == 3)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
		else
			for(int i=0; i<5; i++){
				if(a[i] == 1)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
	}
}