until (a = gets.to_i).zero?
  given = [a] + 4.times.map {gets.to_i}
  
  hands = given.uniq
  if hands.size == 3 || hands.size == 1
    result = [3] * 5
  else
    point = (hands[0] - hands[1]) % 3 == 2 ? 1 : 2
    result = given.map do |hand|
      hand == hands[0] ? point : 3 - point
    end
  end
  
  puts result
end
