#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

bool flag[4];
int hand[5];
int ans[5];

void solve() {
  for(int i = 0 ; i < 5 ; i++) {
    if(hand[i] == 1) flag[1] = true; //O[
    if(hand[i] == 2) flag[2] = true; //`L
    if(hand[i] == 3) flag[3] = true; //p[
  }
}

int main() { 
  while(cin >> hand[0], hand[0]) {
    for(int i = 1 ; i < 5 ; i++) cin >> hand[i];
    memset(flag, false, sizeof(flag));
    solve();
    
    for(int i = 0 ; i < 5 ; i++) { 
      if(flag[1] == true && flag[2] == true && flag[3] == true) {
	ans[i] = 3;
      }
      else if(flag[1] == true && flag[2] == false && flag[3] == false) {
	ans[i] = 3;
      }
      else if(flag[2] == true && flag[1] == false && flag[3] == false) {
	ans[i] = 3;
      }
      else if(flag[3] == true && flag[2] == false && flag[1] == false) {
	ans[i] = 3;
      }
      else if(flag[1] == true && flag[2] == true && flag[3] == false) {
	if(hand[i] == 1) ans[i] = 1;
	if(hand[i] == 2) ans[i] = 2;
      }	      
      else if(flag[1] == true && flag[3] == true && flag[2] == false) {
	if(hand[i] == 1) ans[i] = 2;
	if(hand[i] == 3) ans[i] = 1;
      }	      
      else if(flag[2] == true && flag[3] == true && flag[1] == false) {
	if(flag[i] == 2) ans[i] = 1;
	if(flag[i] == 3) ans[i] = 2;
      }
    }

    for(int i = 0 ; i < 5 ; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}