#include <iostream>

using namespace std;

int main(){
        while(1){
                unsigned char hand[5]={};
                unsigned char sum=0;
                for(int i=0;i<5;i++){
                        int h;
                        cin>>h;
                        if(h==0) return 0;
                        hand[i]=1<<(h-1);
                        sum|=hand[i];
                }
                if(sum==7) cout<<"3\n3\n3\n3\n3\n";
                else {
                        for(int i=0;i<5;i++){
                                if(sum==hand[i]) cout<<"3\n";
                                else if((sum^hand[i])==(hand[i]<<1)||(sum^hand[i])==(hand[i]>>2)) cout<<"1\n";
                                else if((sum^hand[i])==(hand[i]>>1)||(sum^hand[i])==(hand[i]<<2)) cout<<"2\n";
                        }
                }
        }
        return 0;
}