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

int winner(int a, int b)
{
  if (a == 1 && b == 2) return (1);
  else if (a == 2 && b == 3) return (2);
  else if (a == 1 && b == 3) return (3);
}

int main()
{
  int input[5];

  while (scanf("%d", &input[0]), input[0]){
    bool check[4] = {false};
    check[input[0]] = true;
    for (int i = 1; i < 5; i++){
      scanf("%d", &input[i]);
      check[input[i]] = true;
    }
    
    if (check[1] && check[2] && check[3]){
      for (int i = 0; i < 5; i++) printf("3\n");
    }
    else {
      int tmp[2];
      for (int i = 1, j = 0; i <= 3; i++){
        if (check[i]) tmp[j++] = i;
      }
      int win = winner(tmp[0], tmp[1]);
      for (int i = 0; i < 5; i++){
        if (input[i] == win){
          printf("1\n");
        }
        else {
          printf("2\n");
        }
      }
    }
  }

  return (0);
}