#include<iostream>
using namespace std;
int main(){
  int h[5],cnt[4];
  
  while(cin >> h[0],h[0]!=0){
    for(int i=1;i<5;i++) cin >> h[i];
    
    cnt[1] = 0;
    cnt[2] = 0;
    cnt[3] = 0;
    
    for(int i=0;i<5;i++) cnt[ h[i] ]++;
    
    for(int i=0;i<5;i++){
      
      if(cnt[1] == 5 || cnt[2] == 5 || cnt[3] == 5) cout << 3 << endl;
      else if(cnt[1] != 0 && cnt[2] != 0 && cnt[3] != 0) cout << 3 << endl;
      
      else if(cnt[1] == 0){
	if(h[i] == 2) cout << 1 << endl;
	if(h[i] == 3) cout << 2 << endl;
      }
      else if(cnt[2] == 0){
	if(h[i] == 3) cout << 1 << endl;
	if(h[i] == 1) cout << 2 << endl;
      }
      else if(cnt[3] == 0){
	if(h[i] == 1) cout << 1 << endl;
	if(h[i] == 2) cout << 2 << endl;
      }
    }

  }
  return(0);
}

