data = []

while data[0] != 0 do

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

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

  break if data[0] == 0

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

  5.times do |i|
    if !winner
      p 3
      next
    end

    if data[i] == winner
      p 1
    else
      p 2
    end
  end

  data.clear
end