#include<iostream>
#include<map>
using namespace std;

int main(){
  int te[3] = {1,2,3};
  int paper[10],Min;
  while(true){
    Min = 10000000;
    map<int,int> exist;
    cin >> paper[0];
    exist[paper[0]]++;
    Min = min(Min,paper[0]);
    if(paper[0] == 0)break;
    for(int i=1;i<5;i++){
      cin >> paper[i];
      Min = min(Min,paper[i]);
      exist[paper[i]]++;
    }
    if(exist[1]!=0 && exist[2]!=0 && exist[3]!=0){
      for(int i=0;i<5;i++)cout << 3 << endl;
    }
    else if(exist[1] == 5 || exist[2] == 5 || exist[3] == 5){
for(int i=0;i<5;i++)cout << 3 << endl;
    }
    else if(exist[1]!=0 && exist[3]!=0 && exist[2] == 0){
      for(int i=0;i<5;i++){
	if(paper[i] == 3)cout << 1 << endl;
	else cout << 2 << endl;
      }
    }
    else {
      for(int i=0;i<5;i++){
	if(paper[i] == Min)cout << 1 << endl;
	else cout << 2 << endl;
      }

    }
  }
  return 0;
}