#include<iostream>
using namespace std;

int a[5];

void slove(int win){
  for(int i=0; i<5; i++){
    if(a[i] == win) cout << "1" << endl;
    else cout << "2" << endl;
  }
}

int main(){
  while(cin >> a[0]){
    if(a[0]==0) break;
    cin >> a[1] >> a[2] >> a[3] >> a[4];
    int count[5],flag=0;
    for(int i=0; i<5; i++) count[i] = 0;
    for(int i=0; i<5; i++){
      count[a[i]]++;
    }
    
    if((count[1]>0 && count[2]>0 && count[3]>0) || count[1]==5 || count[2]==5 || count[3]==5){
      for(int i=0; i<5; i++) cout << "3" << endl;
    }
    else{
      if(count[1] == 0) slove(2);
      if(count[2] == 0) slove(3);
      if(count[3] == 0) slove(1);
    }
  }
  return 0;
}