#include<iostream>

using namespace std;

int main(){

  int data[5], d[3];

  while(1){

    for(int i = 0; i < 3; i++) d[i] = 0;


    for(int i = 0; i < 5; i++){
      cin >> data[i];
      if(data[0] == 0) return 0;
      if(data[i] == 1) d[0]++;
      else if(data[i] == 2) d[1]++;
      else d[2]++;
    }

      if(d[0] > 0 && d[1] > 0 && d[2] > 0 || d[0] == 5 || d[1] == 5 || d[2] == 5){
	for(int j = 0; j < 5; j++) cout << "3" << endl;
      }else if(d[0] == 0){
	for(int j = 0; j < 5; j++){
	  if(data[j] == 2) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }else if(d[1] == 0){
	for(int j = 0; j < 5; j++){
	  if(data[j] == 3) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }else{
	for(int j = 0; j < 5; j++){
	  if(data[j] == 1) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }
  }
}