#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int hand[6]={0};
    while(cin>>hand[0],hand[0]){
            int flg[5]={0};
        for(int i=1;i<5;i++)cin>>hand[i];
        for(int i=0;i<5;i++){
            if(hand[i]==1)flg[1]=1;
            if(hand[i]==2)flg[2]=1;
            if(hand[i]==3)flg[3]=1;
        }
        if(flg[1]==1&&flg[2]==1&&flg[3]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[1]==1&&flg[2]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[2]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[1]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
    }
    return 0;
}