#include<iostream>

using namespace std;

int main(){
  int hands[5], i, numRock, numScis, numPaper;
  while(cin >> hands[0], hands[0]){
    for(i=1; i<5; i++){
      cin >> hands[i];
    }
    numRock=0, numScis=0, numPaper=0;
    for(i=0; i<5; i++){
      if(hands[i]==1)numRock++;
      if(hands[i]==2)numScis++;
      if(hands[i]==3)numPaper++;
    }
    if(numRock==0){
      for(i=0; i<5; i++){
        if(hands[i]==2){
          cout << 1 << endl;
        }else{
          cout << 2 << endl;
	}
      }
    }else if(numScis==0){
      for(i=0; i<5; i++){
	if(hands[i]==3){
          cout << 1 << endl;
	}else{
          cout << 2 << endl;
        }
      }
    }else if(numPaper==0){
      for(i=0; i<5; i++){
        if(hands[i]==1){
          cout << 1 << endl;
        }else{
          cout << 2 << endl;
        }
      }
    }else{
      for(i=0; i<5; i++){
	cout << 3 << endl;
      }
    }
  }
}