
while (a = gets.to_i) != 0
  b = gets.to_i
  c = gets.to_i
  d = gets.to_i
  e = gets.to_i
  five= [a,b,c,d,e]
  kinds = [false,false,false]
  five.each {|i| kinds[i-1] = true}
  count = 0
  kinds.each {|bool| count += 1 if bool}

  if count == 1 || count == 3
    puts [3]*5
    next
  end

  if kinds[0] == false # チョキ・パー
    win = 2
  elsif kinds[1] == false # グー・パー
    win = 3
  else # グー・チョキ
    win = 1
  end

  0.upto(4) {|i| puts five[i] == win ? 1 : 2 }

end