#include <iostream>
#include <cstring>

using namespace std;

int main(void){
    int i,j,k,l;
    int data[5];
    int result[5];
    int judge[3];
    bool f=false;
    
    while(true){
        memset(judge,0,sizeof(judge));
        
        for(i=0;i<5;i++){
            cin>>data[i];
            if(data[i]==0){
                f=true;
                break;
            }
            judge[data[i]-1]++;
        }
        if(f)break;
        
        if(judge[0]>0&&judge[1]>0&&judge[2]>0){
            for(i=0;i<5;i++){
                cout<<'3'<<endl;
            }
            continue;
        }
        if(judge[0]==0&&judge[1]==0){
            for(i=0;i<5;i++){
                cout<<'3'<<endl;
            }
            continue;
        }
        if(judge[1]==0&&judge[2]==0){
            for(i=0;i<5;i++){
                cout<<'3'<<endl;
            }
            continue;
        }
        if(judge[2]==0&&judge[0]==0){
            for(i=0;i<5;i++){
                cout<<'3'<<endl;
            }
            continue;
        }
        
        if(judge[0]&&judge[1]){
            for(i=0;i<5;i++){
                if(data[i]==1){
                    cout<<'1'<<endl;
                }else{
                    cout<<'2'<<endl;
                }
            }
            continue;
        }
        if(judge[1]&&judge[2]){
            for(i=0;i<5;i++){
                if(data[i]==2){
                    cout<<'1'<<endl;
                }else{
                    cout<<'2'<<endl;
                }
            }
            continue;
        }
        if(judge[2]&&judge[0]){
            for(i=0;i<5;i++){
                if(data[i]==3){
                    cout<<'1'<<endl;
                }else{
                    cout<<'2'<<endl;
                }
            }
            continue;
        }
    }
    return(0);
}