#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){

	while(1){
	    int a[10] = {0};
	    short flg = 0;
        short aiko1=0,aiko2=0,aiko3=0;
        for(int i = 0; i < 5; i++){
            cin >> a[i];
            if(i != 0){
                if(a[i-1] == a[i])flg++;
            }
            else{
                if(a[i] == 0)goto end;
                else flg++;
            }
            if(a[i] == 1)aiko1++;
            if(a[i] == 2)aiko2++;
            if(a[i] == 3)aiko3++;
        }
        //あいこの出力
        if(flg == 5 || aiko1 != 0 && aiko2 != 0 && aiko3!= 0){
            for(int i = 0; i < 5; i++)cout << 3 << endl;
        }
        if(aiko1 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 2) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        if(aiko2 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 3) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        if(aiko3 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
	}
    end:
	return 0;
}