#include <iostream>
using namespace std;

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