#include<stdio.h>
using namespace std;

int main(){
  int h[5],count[3],win,lose,drow;
  int i;
  
  while(1){

    count[0]=0; count[1]=0; count[2]=0;
    
    for(i=0;i<5;i++){
      scanf("%d",&h[i]);
      if(h[0]==0) return -1;
      if(h[i]==1) count[0]++;
      if(h[i]==2) count[1]++;      
      if(h[i]==3) count[2]++;
    }

    if(count[0] > 0 && count[1] > 0 && count[2] > 0){
      for(i=0;i<5;i++) printf("%d\n",3);
    }
    
    if(h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4]){
      for(i=0;i<5;i++) printf("%d\n",3);
    }

    if(count[0]==0 && count[1]!=0 && count[2]!=0){
      win=2; lose=3;
    }

    if(count[0]!=0 && count[1]==0 && count[2]!=0){
      win=3; lose=1;
    }

    if(count[0]!=0 && count[1]!=0 && count[2]==0){
      win=1; lose=2;
    }

    for(i=0;i<5;i++){
      if(win==h[i]) printf("%d\n",1);
      if(lose==h[i]) printf("%d\n",2);
    }
    
  }
  return 0;
}