#include<iostream>
using namespace std;

int hand,rock[6],sci[6],par[6],cou_r,cou_s,cou_p;

void priming(int x,int i){
  if(x==1){
    rock[i]=1;
    cou_r++;
  }else if(x==2){
    sci[i]=1;
    cou_s++;
  }else if(x==3){
    par[i]=1;
    cou_p++;
  }
}

int main(){
  
  while(1){
    for(int i=0;i<6;i++)rock[i]=sci[i]=par[i]=0;
    cou_r=cou_s=cou_p=0;
    cin>>hand;
    
    if(hand==0)break;
    
    priming(hand,0);
    
    for(int i=1;i<5;i++) {
      cin>>hand;
      priming(hand,i);
    }
    
    if((cou_r!=0&&cou_s!=0&&cou_p!=0)||cou_r==5||cou_s==5||cou_p==5){
      for(int i=0;i<5;i++)cout<<"3"<<endl;
    }else if(cou_p==0){
      for(int i=0;i<5;i++){
	if(rock[i]==1)cout<<"1"<<endl;
	else cout<<"2"<<endl;
      }
    }else if(cou_r==0){
      for(int i=0;i<5;i++){    
	if(sci[i]==1)cout<<"1"<<endl;
	else cout<<"2"<<endl;
      }
    }else if(cou_s==0){
      for(int i=0;i<5;i++){
        if(par[i]==1)cout<<"1"<<endl;
        else cout<<"2"<<endl;
      }
    }
  
  }
  return 0;
}