#include<bits/stdc++.h>
#define WIN 1
#define LOSE 2
#define DRAW 3
using namespace std;
int main(){
  while(1){
    int p=0,c=0,g=0,finish=0;
    int te[5];
    for(int i=0;i<5;i++){
      cin>>te[i];
      if(te[i]==0){
	finish=1;
	break;
      }
      switch(te[i]){
      case 1:g++;break;
      case 2:c++;break;
      case 3:p++;break;
      }
    }
    if(finish==1)
      break;
    if(g!=0&&c!=0&&p!=0||g==0&&c==0||g==0&&p==0||c==0&&p==0){
      for(int i=0;i<5;i++)
	cout<<DRAW<<endl;
    }else if(g==0){
      for(int i=0;i<5;i++){
	if(te[i]==2)
	  cout<<WIN<<endl;
	else
	  cout<<LOSE<<endl;
      }
    }else if(c==0){
      for(int i=0;i<5;i++){
	if(te[i]==3)
	  cout<<WIN<<endl;
	else
	  cout<<LOSE<<endl;
      }
    }else if(p==0){
      for(int i=0;i<5;i++){
	if(te[i]==1)
	  cout<<WIN<<endl;
	else
	  cout<<LOSE<<endl;
      }
    }
  }
  return 0;
}