
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

bool win(int a, int b)
{
  return ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1));     
}
int main()
{
  while (true) {
    int a[5];
    for (int i = 0; i < 5; i++) {
      scanf("%d ", a + i);
      //printf("%d\n", a[i]);
    }
    if (a[0] == 0) {break;}
  
  
    bool f[] = {false, false, false};
    bool flag = true;
    f[a[0] - 1] = true;
    for (int i = 1; i < 5; i++) {
      if (a[i] != a[i - 1]) {
	flag = false;
      }
      f[a[i] - 1] = true;
    }
    bool aiko = false;
    if (flag) {
      aiko = true;
    } 
    for (int i = 0; i < 3; i++) {
      if (!f[i]) {goto next;}
    }
    aiko = true;
  next:;
    /*for (int i = 0; i < 5; i++) {
      printf("%d\n", a[i]);
      }*/
    for (int i = 0; i < 5; i++) {
      if (aiko) {printf("3\n");}
      else {
	for (int j = 0; j < 5; j++) {
	  if (i == j) {continue;}
	  if (a[i] == a[j]) {continue;}
	  if (win(a[i], a[j])) {
	    printf("1\n");
	    break;
	  } else if (win(a[j], a[i])) {
	    printf("2\n");
	    break;
	  }
	}
      }
    }
  }
}