#!/usr/bin/ruby -Ku

require 'pp'

loop do
  n = gets.split(nil)[0].to_i
  
  break if n == 0

  player = Array.new
  hand = Array.new(4)
  
  player.push n
  hand[n] = 1
  4.times{
    n = gets.split(nil)[0].to_i
    player.push n
    hand[n] = 1
  }
  
  if !hand[1] && hand[2] && hand[3] then # 2win 3lose
    5.times{|i| player[i] -= 1}
  elsif hand[1] && !hand[2] && hand[3] then # 3win 1lose
    5.times{|i| player[i] = ((player[i]-1==0)?1:0) + 1}
  elsif hand[1] && hand[2] && !hand[3] then # 1win 2lose
  elsif
    5.times{|i|player[i] = 3}
  end

  player.each{|h| puts h};
end