data = []

while data[0] != 0 do

  hand = {rock: 0, scissors: 0, paper: 0}

  5.times do |i|
    a = gets.chomp.to_i
    break if a == 0
    data.push(a)
    case data[i]
      when 1
        hand[:rock] += 1
      when 2
        hand[:scissors] += 1
      when 3
        hand[:paper] += 1
    end
  end

  break if a == 0

  if hand[:rock] == 0 do
    winner = 2
  elsif hand[:scissors] == 0 do
    winner = 3
  elsif hand[:paper] == 0 do
    winner = 1
  end

  5.times do |i|
    if !winner do
      p 3
      next
    end
  
    if data[i] == winner do
      p 1
    else
      p 2
    end
  end
end