#include <iostream>
using namespace std;


int main(){
  int sum[3],raw[5];
  int ta,tb,winnum;
  while (1){
    for (int i=0;i<3;i++) sum[i]=0;
    ta=0;tb=0;winnum=0;
    cin >>raw[0];
    if (raw[0]==0) break;
    cin >> raw[1] >> raw[2] >> raw[3] >> raw[4];
    for (int i=0;i<5;i++)sum[raw[i]-1]++;
    if ((sum[0]!=0&&sum[1]!=0&&sum[2]!=0)||(sum[0]==0&&sum[1]==0)||(sum[1]==0&&sum[2]==0)||(sum[0]==0&&sum[2]==0)){
      cout << "3" << endl << "3" << endl << "3" << endl << "3" << endl << "3" << endl;
    }else{
      for(int i=0;i<3;i++){
	if (sum[i]==0)continue;
	if (ta==0)ta=i+1;
	else tb=i+1;
      }
      if (ta>tb)swap(ta,tb);
      if (ta==1&&tb==2)winnum=1;
      else if (ta==2&&tb==3)winnum=2;
      else if (ta==1&&tb==3)winnum=3;
      for (int i=0;i<5;i++)
	if (winnum == raw[i])cout << "1" << endl;
	else cout << "2" << endl;
    }
  }

  return 0;
}