#include <stdio.h>

#define PEOPLE    5
#define STACK_MAX 200

enum RPS {
  END_SIGN,
  ROCK,
  SCISSORS,
  PAPER,
};

enum RESULT {
  not_used3,
  WIN,
  LOSE,
  DRAW,
};

int array_sum(int *round) {
  int sum = 0;
  for (int i = 0; i < PEOPLE; i++) {
    sum += round[i];
  }
  return sum;
}

void print_result(int *array, int range_start, int range_end) {
  for (int i = range_start; i <= range_end; i++) {
    printf("%d\n", array[i]);
  }
}

void draw_all(int *array, int range_start, int range_end) {
  for (int i = range_start; i <= range_end; i++) {
    array[i] = DRAW;
  }
}

void mark_result(int *array, int range_end, int win) {
  int range_start = range_end - PAPER - 1;
  for (int i = range_start; i < range_end; i++) {
    if ( array[i] == win ) {
      array[i] = WIN;
    } else {
      array[i] = LOSE;
    }
  }
}

int main() {

  int stack[STACK_MAX];

  int tmp;
  int data_num = 0;
  while ( scanf("%d", &tmp) ) {
    if (tmp == END_SIGN) {
      break;
    }
    stack[data_num++] = tmp;
  }

  int round = 0;
  for (int i = 0; i < data_num; i++) {
    if ( i % PEOPLE == 4 ) {

      // テ・ツ?ィテ・ツ督。テ・ツ青古」ツ?佚ヲツ卍?
      int sum = stack[i] + stack[i - 1]
        + stack[i - 2] + stack[i - 3] + stack[i - 4];
      if ( sum % PEOPLE == 0 ) {
        draw_all(stack, i - 4, i);
        print_result(stack, i - 4, i);
        continue;
      }

      // テ」ツ?敕」ツつ古、ツサツ・テ・ツ、ツ?
      int rock_flag     = 0;
      int scissors_flag = 0;
      int paper_flag    = 0;
      for (int j = 0; j < PEOPLE; j++) {
        switch ( stack[i - j] ) {
          case ROCK:
            rock_flag = 1;
            break;
          case SCISSORS:
            scissors_flag = 1;
            break;
          case PAPER:
            paper_flag = 1;
            break;
        }
      }

      // テ・ツ?ィテ・ツ督。テゥツ?陛」ツ??
      if ( rock_flag && scissors_flag && paper_flag ) {
        draw_all(stack, i - 4, i);
      }
      else if ( rock_flag && scissors_flag ) {
        mark_result(stack, i, rock_flag);
      }
      else if ( scissors_flag && paper_flag ) {
        mark_result(stack, i, scissors_flag);
      }
      else if ( paper_flag && rock_flag ) {
        mark_result(stack, i, paper_flag);
      }
      print_result(stack, i - 4, i);
      
      round++;
    }
  }

}